/* ==========================================================
 * THEME
 * ========================================================== */

:root {
    --ink: #15213b;
    --muted: #64748b;
    --line: #e5d9bd;
    --canvas: #fff0cd;
    --surface: #ffffff;
    --sidebar: #4f6e5a;
    --accent: #4f6e5a;
    --accent-dark: #3d5746;
    --accent-soft: #e5eee8;
    --rose: #be123c;
    --rose-soft: #ffe4e6;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
    font-family: "DM Sans", Inter, ui-sans-serif, system-ui, -apple-system,
        BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html,
body,
#app {
    min-height: 100%;
}

body {
    margin: 0;
    min-width: 320px;
    background: var(--canvas);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.5;
}

[v-cloak] {
    display: none;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-dark);
}

button,
input,
select,
textarea {
    font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(79, 110, 90, 0.24);
    outline-offset: 2px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2,
h3 {
    color: var(--ink);
    letter-spacing: -0.03em;
}

h1 {
    font-size: 1.45rem;
}

h2 {
    margin-bottom: 0.35rem;
    font-size: 1.18rem;
}

h3 {
    font-size: 1.08rem;
}

small,
.muted {
    color: var(--muted);
}

.muted {
    font-size: 0.84rem;
}

/* ==========================================================
 * BUTTONS
 * ========================================================== */

button,
[role="button"] {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.58rem 0.9rem;
    border: 1px solid var(--accent);
    border-radius: 9px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    line-height: 1.1;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease,
        transform 0.18s ease;
}

button:hover,
[role="button"]:hover {
    border-color: var(--accent-dark);
    background: var(--accent-dark);
    color: #ffffff;
    transform: translateY(-1px);
}

button:disabled {
    cursor: wait;
    opacity: 0.58;
    transform: none;
}

.secondary,
.button-ghost {
    border-color: var(--line);
    background: var(--surface);
    color: #475569;
}

.secondary:hover,
.button-ghost:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: var(--ink);
}

/* ==========================================================
 * APPLICATION SHELL
 * ========================================================== */

.app-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    height: 100vh;
    flex-direction: column;
    padding: 1.6rem 1rem 1rem;
    background: var(--sidebar);
    color: #cbd5e1;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.1rem 0.55rem 2rem;
    color: #ffffff;
}

.brand:hover {
    color: #ffffff;
}

.brand-logo {
    display: block;
    width: 145px;
    height: auto;
}

.sidebar-nav {
    display: grid;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.72rem 0.8rem;
    border-radius: 9px;
    color: #b8c4d9;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.18s ease, color 0.18s ease,
        transform 0.18s ease;
}

.nav-link:hover,
.nav-link.router-link-exact-active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.nav-link:hover {
    transform: translateX(2px);
}

.nav-icon {
    display: grid;
    width: 22px;
    place-items: center;
    font-size: 1.1rem;
}

.sidebar-footer {
    margin: auto 0 0;
    padding: 1.1rem 0.6rem 0.2rem;
    color: #8ea0bd;
    font-size: 0.78rem;
    line-height: 1.45;
}

.main-shell {
    min-width: 0;
}

.app-topbar {
    display: flex;
    min-height: 82px;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 2.2rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
}

.view-heading {
    margin-right: auto;
}

.view-heading h1 {
    margin-bottom: 0.1rem;
}

.view-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.user-avatar {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 800;
}

.user-avatar-photo {
    object-fit: cover;
}

.user-copy {
    display: grid;
    line-height: 1.25;
}

.user-copy strong {
    max-width: 220px;
    overflow: hidden;
    font-size: 0.86rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-copy small {
    font-size: 0.72rem;
}

.logout-button {
    min-height: 36px;
    margin-left: 0.35rem;
    padding: 0.48rem 0.68rem;
    font-size: 0.78rem;
}

.page-content {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 2rem 2.2rem 3rem;
}

/* ==========================================================
 * CARDS AND GRIDS
 * ========================================================== */

.card,
article {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid article {
    position: relative;
    min-height: 128px;
    margin: 0;
    padding: 1.2rem;
    overflow: hidden;
}

.stats-grid article::after {
    content: "";
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent-soft);
}

.stats-grid article:nth-child(even)::after {
    background: var(--canvas);
}

.stats-grid small {
    display: block;
    max-width: calc(100% - 46px);
    font-weight: 600;
}

.metric {
    display: block;
    margin-top: 1.3rem;
    font-size: 2rem;
    line-height: 1.05;
    letter-spacing: -0.04em;
}

.dashboard-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.leads-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.leads-toolbar p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.leads-toolbar button {
    flex: 0 0 auto;
}

.dashboard-header p,
.data-card > p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.data-card,
.detail-card {
    margin: 0 0 1.5rem;
    padding: 1.3rem;
}

.dashboard > .card {
    padding: 1.3rem;
}

.data-card > .table-wrapper {
    margin: 1rem -1.3rem -1.3rem;
}

.task-list {
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
}

.task-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

/* ==========================================================
 * SMART CALL LIST
 * ========================================================== */

.call-queue-card {
    padding-bottom: 0;
}

.smart-call-list {
    margin: 1rem -1.3rem 0;
}

.smart-call-row {
    display: grid;
    grid-template-columns: 48px minmax(220px, 1.4fr) minmax(170px, 1fr) minmax(170px, 1fr) minmax(150px, 0.8fr);
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.3rem;
    border-top: 1px solid var(--line);
}

.smart-call-row:hover {
    background: #fffdf8;
}

.call-rank {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.82rem;
    font-weight: 800;
}

.call-identity,
.call-context,
.call-contact {
    display: grid;
    min-width: 0;
    gap: 0.18rem;
}

.call-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.priority-reason {
    margin: 0.3rem 0 0;
    color: var(--accent-dark);
    font-size: 0.78rem;
}

.call-context small,
.call-contact small {
    color: var(--muted);
    font-size: 0.72rem;
}

.call-context strong,
.call-contact a {
    overflow: hidden;
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.call-context span,
.compact-link {
    color: var(--muted);
    font-size: 0.75rem;
}

.call-contact > a:not(.compact-link) {
    color: var(--accent);
    font-weight: 800;
}

/* ==========================================================
 * CSV IMPORTS
 * ========================================================== */

.import-step,
.import-summary {
    margin-bottom: 1.25rem;
    padding: 1.3rem;
}

.import-upload {
    display: flex;
    align-items: end;
    gap: 1rem;
    margin-top: 1rem;
}

.import-upload input {
    flex: 1;
}

.mapping-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    margin: 1rem 0;
}

.csv-sample {
    margin: 1rem 0;
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 9px;
}

.csv-sample summary {
    cursor: pointer;
    font-weight: 700;
}

.csv-sample .table-wrapper {
    margin-top: 0.8rem;
}

.import-preview-table {
    margin: 1rem 0;
}

.import-preview-table table {
    min-width: 900px;
}

.import-row-duplicate {
    background: #fff8e8;
}

.import-row-invalid {
    background: var(--rose-soft);
}

.import-warnings {
    margin: 0.45rem 0 0;
    padding-left: 1rem;
    color: #92400e;
    font-size: 0.76rem;
}

.import-summary {
    border-left: 4px solid var(--accent);
    background: var(--accent-soft);
}

/* ==========================================================
 * TABLES
 * ========================================================== */

.overflow-auto,
.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.table-card {
    padding: 0;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.88rem;
}

th,
td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.045em;
    text-transform: uppercase;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: #fafbff;
}

td [role="button"] {
    min-height: 32px;
    padding: 0.4rem 0.65rem;
    font-size: 0.76rem;
}

/* ==========================================================
 * FORMS AND MODAL
 * ========================================================== */

form {
    display: grid;
    gap: 1rem;
}

label {
    display: grid;
    gap: 0.42rem;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    font-weight: 400;
}

input::placeholder,
textarea::placeholder {
    color: #94a3b8;
}

dialog {
    position: fixed;
    inset: 0;
    z-index: 100;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 1.5rem;
    border: 0;
    background: rgba(15, 23, 42, 0.52);
}

dialog:not([open]) {
    display: none;
}

dialog[open] {
    display: grid;
    place-items: center;
}

dialog > article {
    width: min(680px, calc(100vw - 2rem));
    max-height: calc(100vh - 3rem);
    margin: 0;
    padding: 1.5rem;
    overflow-y: auto;
}

dialog header {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

dialog header h3 {
    margin: 0;
}

dialog header button[aria-label="Close"] {
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: var(--line);
    background: #ffffff;
    color: var(--muted);
}

dialog header button[aria-label="Close"]::before {
    content: "×";
    font-size: 1.3rem;
}

dialog footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    margin-top: 0.4rem;
}

mark {
    display: block;
    padding: 0.7rem 0.8rem;
    border-radius: 8px;
    background: var(--rose-soft);
    color: var(--rose);
}

/* ==========================================================
 * DETAIL PAGE
 * ========================================================== */

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.detail-header p {
    margin-bottom: 0;
}

.detail-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-stats .metric {
    max-width: calc(100% - 42px);
    font-size: 1.15rem;
}

.detail-card h2 {
    margin-bottom: 1.25rem;
}

.detail-card .grid + .grid {
    margin-top: 0.3rem;
}

.detail-card .grid > div,
.detail-card > div:not(.grid) {
    min-width: 0;
}

.detail-card strong:not(.metric) {
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.detail-card p {
    margin: 0.25rem 0 1rem;
    overflow-wrap: anywhere;
}

/* ==========================================================
 * SETTINGS
 * ========================================================== */

.settings-card {
    margin-bottom: 1.5rem;
    padding: 1.3rem;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.4rem;
}

.section-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.success-message {
    margin: 0;
    padding: 0.75rem 0.9rem;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.user-cell img,
.table-avatar {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: 50%;
}

.user-cell img {
    object-fit: cover;
}

.table-avatar {
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 800;
}

.status-badge {
    display: inline-flex;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.75rem;
    font-weight: 700;
}

.status-badge.is-inactive {
    background: #f1f5f9;
    color: var(--muted);
}

/* ==========================================================
 * BUSINESS BADGES
 * ========================================================== */

.business-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0.25rem 0.58rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: #f1f5f9;
    color: #475569;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.qualification-select {
    min-width: 150px;
    min-height: 32px;
    margin: 0;
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
    font-size: 0.82rem;
}

button.qualification-badge-button {
    min-height: 26px;
    margin: 0;
    padding: 0.25rem 0.58rem;
    border-radius: 999px;
    line-height: 1.2;
    transform: none;
}

button.qualification-badge-button:hover {
    filter: brightness(0.96);
    transform: none;
}

.detail-stats .qualification-select {
    margin-top: 0.55rem;
}

.qualification-reasons {
    margin: 0.55rem 0 0;
    padding-left: 1rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 400;
    text-align: left;
}

.badge-pipeline,
.badge-status,
.badge-priority-normal {
    border-color: #c7d7cc;
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.badge-hot,
.badge-lost,
.badge-priority-high {
    border-color: #fecdd3;
    background: var(--rose-soft);
    color: var(--rose);
}

.badge-warm {
    border-color: #ead9a6;
    background: var(--canvas);
    color: #795c18;
}

.badge-cold,
.badge-priority-low {
    border-color: #cbd5e1;
    background: #f1f5f9;
    color: #475569;
}

.detail-stats .metric {
    margin-top: 1.7rem;
}

.social-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 0.4rem;
}

.social-links a {
    padding: 0.38rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--canvas);
    font-size: 0.82rem;
    font-weight: 700;
}

.custom-fields-display {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.custom-fields-display pre {
    margin: 0.3rem 0 0;
    padding: 0.7rem;
    overflow-x: auto;
    border-radius: 8px;
    background: #f8fafc;
    color: var(--ink);
    white-space: pre-wrap;
}

.custom-fields-editor {
    display: grid;
    gap: 0.8rem;
    margin: 0;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.custom-fields-editor legend {
    padding: 0 0.35rem;
    color: var(--ink);
    font-weight: 700;
}

.custom-field-row {
    display: grid;
    grid-template-columns: minmax(140px, 0.8fr) 110px minmax(180px, 1.5fr) auto;
    align-items: start;
    gap: 0.65rem;
}

.custom-field-row button {
    min-height: 44px;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.checkbox-field input {
    width: auto;
    min-height: auto;
}

/* ==========================================================
 * CONTACTS
 * ========================================================== */

.contact-list {
    display: grid;
    gap: 0.8rem;
    margin-top: 1rem;
}

.contact-item {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffdf8;
}

.contact-main,
.contact-actions,
.contact-links,
.contact-meta {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.contact-main {
    justify-content: space-between;
}

.contact-main strong {
    margin-right: 0.5rem;
}

.contact-main p {
    margin: 0.25rem 0 0;
    color: var(--muted);
}

.contact-links,
.contact-meta {
    flex-wrap: wrap;
}

.contact-meta {
    margin: 0.8rem 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.contact-meta span:not(:last-child)::after {
    margin-left: 0.65rem;
    content: "·";
}

.contact-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.contact-actions button {
    min-height: 34px;
    padding: 0.42rem 0.7rem;
    font-size: 0.82rem;
}

.danger-action {
    color: var(--rose);
}

.contact-notice {
    margin: 0.8rem 0;
    padding: 0.7rem 0.8rem;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-dark);
}

/* ==========================================================
 * CALL RESULTS
 * ========================================================== */

.call-contact-select {
    width: min(280px, 100%);
    margin: 0;
}

.call-result-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 1rem;
}

.call-result-buttons button {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
}

.call-result-summary {
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--accent-soft);
}

.call-result-summary p {
    margin-bottom: 0.5rem;
}

.call-result-summary ul {
    margin: 0;
    padding-left: 1.2rem;
}

.call-result-summary li + li {
    margin-top: 0.35rem;
}

/* ==========================================================
 * CRM TASKS
 * ========================================================== */

.next-action {
    display: grid;
    gap: 0.2rem;
    margin: 1rem 0;
    padding: 1rem;
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-soft);
}

.next-action strong {
    font-size: 1.05rem;
}

.next-action span {
    color: var(--muted);
    font-size: 0.85rem;
}

.crm-task-list {
    display: grid;
    gap: 0.75rem;
    margin-top: 1rem;
}

.crm-task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffdf8;
}

.task-copy {
    min-width: 0;
}

.task-copy strong {
    margin-left: 0.5rem;
}

.task-copy p {
    margin: 0.55rem 0 0;
    white-space: pre-wrap;
}

.crm-task-item.task-done,
.crm-task-item.task-cancelled {
    opacity: 0.68;
}

.crm-task-item.task-done .task-copy > div:first-child,
.crm-task-item.task-cancelled .task-copy > div:first-child {
    text-decoration: line-through;
}

/* ==========================================================
 * ACTIVITY TIMELINE
 * ========================================================== */

.quick-note-form {
    margin: 1rem 0 1.5rem;
    padding: 1rem;
    border-radius: 10px;
    background: var(--accent-soft);
}

.quick-note-actions {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
}

.quick-note-actions label {
    width: min(320px, 100%);
    margin: 0;
}

.timeline {
    position: relative;
    display: grid;
    gap: 0;
    margin-top: 1rem;
}

.timeline::before {
    position: absolute;
    top: 0.8rem;
    bottom: 0.8rem;
    left: 6px;
    width: 2px;
    background: var(--line);
    content: "";
}

.timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 1rem;
    padding-bottom: 1.2rem;
}

.timeline-marker {
    z-index: 1;
    width: 14px;
    height: 14px;
    margin-top: 0.35rem;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.timeline-content {
    padding: 0 0 1rem;
    border-bottom: 1px solid var(--line);
}

.timeline-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.timeline-heading strong {
    margin-left: 0.5rem;
}

.timeline-heading time {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.82rem;
}

.activity-content {
    margin: 0.75rem 0;
    white-space: pre-wrap;
}

/* ==========================================================
 * LOGIN
 * ========================================================== */

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 2rem;
    background:
        radial-gradient(circle at 15% 20%, rgba(79, 110, 90, 0.2), transparent 30%),
        radial-gradient(circle at 85% 80%, rgba(255, 240, 205, 0.8), transparent 32%),
        var(--canvas);
}

.auth-card {
    width: min(430px, 100%);
    padding: 2rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    padding: 1rem;
    border-radius: 12px;
    background: var(--sidebar);
}

.auth-logo {
    display: block;
    width: 150px;
    height: auto;
}

.auth-card h1 {
    margin-bottom: 0.25rem;
    font-size: 1.65rem;
}

.auth-intro {
    margin-bottom: 1.5rem;
    color: var(--muted);
}

.auth-card form button {
    width: 100%;
    margin-top: 0.3rem;
}

.hint {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

/* ==========================================================
 * STATES
 * ========================================================== */

.error {
    margin-bottom: 1rem;
    padding: 0.8rem 1rem;
    border: 1px solid #fecdd3;
    border-radius: 9px;
    background: var(--rose-soft);
    color: var(--rose);
    box-shadow: none;
}

[aria-busy="true"] {
    color: var(--muted);
}

.email-variable-list {
    display: grid;
    gap: 0.75rem;
    margin: 1rem 0;
}

.process-page-heading {
    margin-bottom: 1rem;
}

.process-admin-list {
    display: grid;
    gap: 1rem;
}

.process-admin-card h3,
.process-dialog h4 {
    margin: 0;
}

.process-title-line,
.process-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.process-stats {
    margin: 1rem 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.process-step-summary {
    display: grid;
    gap: 0.55rem;
    margin: 0;
    padding-left: 1.4rem;
}

.process-step-summary li {
    display: grid;
    grid-template-columns: 55px minmax(180px, 0.8fr) minmax(220px, 1fr);
    gap: 0.75rem;
    align-items: baseline;
}

.process-step-summary small,
.process-stop-rules {
    color: var(--muted);
}

.process-dialog {
    width: min(820px, calc(100vw - 2rem));
}

.process-rule-grid,
.process-variable-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.process-steps-heading {
    margin-top: 1.25rem;
}

.process-step-editor {
    margin: 0.8rem 0;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--accent-soft);
}

.process-step-editor > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.process-enroll-control,
.process-enrollment-main {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.process-enroll-control select {
    min-width: 220px;
    margin: 0;
}

.process-enrollment-list,
.process-history-list {
    display: grid;
    gap: 0.75rem;
}

.process-enrollment-item {
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--accent-soft);
}

.process-enrollment-main {
    justify-content: space-between;
}

.process-enrollment-progress {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.8rem;
}

.process-enrollment-progress > div {
    display: grid;
    gap: 0.15rem;
}

.process-enrollment-progress small,
.process-enrollment-main small,
.process-history-list small {
    color: var(--muted);
}

.process-warning {
    margin: 0.75rem 0 0;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    background: #fff7d6;
    color: #7c5a05;
    font-size: 0.9rem;
}

.process-history {
    margin-top: 1rem;
}

.process-history summary {
    cursor: pointer;
    color: var(--accent-dark);
    font-weight: 600;
}

.process-history-list {
    margin-top: 0.75rem;
}

.process-history-list section {
    display: grid;
    gap: 0.25rem;
    padding: 0.65rem 0;
    border-top: 1px solid var(--line);
}

.process-history-list section > div {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ==========================================================
 * RESPONSIVE
 * ========================================================== */

@media (max-width: 1050px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .user-copy {
        display: none;
    }

    .smart-call-row {
        grid-template-columns: 42px minmax(210px, 1.4fr) minmax(150px, 1fr) minmax(140px, 0.8fr);
    }

    .smart-call-row .call-context:first-of-type {
        display: none;
    }
}

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: static;
        display: grid;
        height: auto;
        grid-template-columns: auto 1fr;
        align-items: center;
        gap: 1rem;
        padding: 0.8rem 1rem;
    }

    .brand {
        margin: 0;
    }

    .sidebar-nav {
        display: flex;
        justify-content: center;
    }

    .sidebar-footer {
        display: none;
    }

    .app-topbar {
        min-height: 74px;
        padding: 0.9rem 1.2rem;
    }

    .page-content {
        padding: 1.4rem 1.2rem 2.5rem;
    }
}

@media (max-width: 620px) {
    .sidebar {
        grid-template-columns: 1fr auto;
    }

    .sidebar-nav {
        justify-content: flex-end;
    }

    .brand-logo {
        width: 76px;
    }

    .nav-link {
        padding: 0.55rem 0.65rem;
    }

    .nav-icon {
        display: none;
    }

    .app-topbar {
        align-items: flex-start;
    }

    .user-avatar,
    .logout-button {
        display: none;
    }

    .view-heading h1 {
        font-size: 1.25rem;
    }

    .stats-grid,
    .detail-stats,
    .grid {
        grid-template-columns: 1fr;
    }

    .dashboard-header {
        align-items: stretch;
        flex-direction: column;
        gap: 0.8rem;
    }

    .detail-header {
        align-items: stretch;
        flex-direction: column;
    }

    .detail-header button {
        width: 100%;
    }

    .leads-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 0.8rem;
    }

    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .section-heading button {
        width: 100%;
    }

    .custom-fields-display,
    .custom-field-row {
        grid-template-columns: 1fr;
    }

    .contact-main,
    .contact-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .quick-note-actions,
    .timeline-heading,
    .crm-task-item {
        align-items: stretch;
        flex-direction: column;
    }

    .call-result-buttons button {
        flex: 1 1 100%;
    }

    .quick-note-actions button {
        width: 100%;
    }

    .leads-toolbar button {
        width: 100%;
    }

    .dashboard-header button {
        width: 100%;
    }

    .smart-call-row {
        grid-template-columns: 38px minmax(0, 1fr);
        align-items: start;
    }

    .smart-call-row .call-context,
    .smart-call-row .call-contact {
        grid-column: 2;
    }

    .import-upload {
        align-items: stretch;
        flex-direction: column;
    }

    .mapping-grid {
        grid-template-columns: 1fr;
    }

    .process-rule-grid,
    .process-variable-grid,
    .process-step-summary li,
    .process-enrollment-progress {
        grid-template-columns: 1fr;
    }

    .process-enroll-control,
    .process-enrollment-main {
        align-items: stretch;
        flex-direction: column;
    }

    .process-enroll-control select,
    .process-enroll-control button,
    .process-enrollment-main button {
        width: 100%;
    }

    dialog {
        padding: 0.5rem;
    }

    dialog > article {
        width: calc(100vw - 1rem);
        max-height: calc(100vh - 1rem);
        padding: 1.1rem;
    }

    dialog footer {
        flex-direction: column-reverse;
    }

    dialog footer button {
        width: 100%;
    }

    .auth-page {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.4rem;
    }
}
