/* ==========================================================================
   JustAudit CRM - app.css
   Professional, clean CRM UI. Sidebar + topbar shell. Responsive.
   ========================================================================== */

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --c-bg:            #f4f6fb;
    --c-surface:       #ffffff;
    --c-surface-2:     #f8fafc;
    --c-border:        #e3e8ef;
    --c-border-strong: #cbd5e1;

    --c-text:      #1f2733;
    --c-text-soft: #52606d;
    --c-muted:     #8a97a8;

    --c-on-accent: #ffffff;   /* text/icons on primary/success/danger fills */

    --c-primary:        #1f6feb;
    --c-primary-dark:   #1a5fd0;
    --c-primary-soft:   #e8f1fe;

    --c-success: #1a7f4b;
    --c-success-soft: #e4f5ec;
    --c-success-border: #b9e2cb;
    --c-warning: #b7791f;
    --c-warning-soft: #fbf1de;
    --c-warning-border: #ecd7ac;
    --c-danger:  #c02b2b;
    --c-danger-soft: #fbe6e6;
    --c-danger-border: #f0c0c0;
    --c-info:    #2563a8;
    --c-info-soft: #e6eefb;
    --c-info-border: #c2d6f2;

    --stage-cold:      #64748b;
    --stage-warm:      #d97706;
    --stage-hot:       #dc2626;
    --stage-onboarded: #16a34a;
    --stage-lost:      #94a3b8;

    --c-cold-soft:  #eef1f5;
    --c-cold-border:#dde3ea;

    /* Sidebar — stays dark in both themes but tokenised so dark mode can tune it */
    --c-sidebar-bg:          #10233f;
    --c-sidebar-text:        #c7d3e4;
    --c-sidebar-text-strong: #ffffff;
    --c-sidebar-border:      rgba(255, 255, 255, .08);
    --c-sidebar-hover:       rgba(255, 255, 255, .06);
    --c-sidebar-muted:       #6b7d97;

    --c-wa-bubble:  #e7ffdb;
    --c-wa-border:  #c5edb3;

    --c-overlay:    rgba(16, 24, 40, .55);

    /* Ticket priority / status pill colours (soft bg / strong text) */
    --prio-low:    #64748b;
    --prio-normal: #1f6feb;
    --prio-high:   #d97706;
    --prio-urgent: #dc2626;

    --radius:    10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .10);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);

    --sidebar-w: 240px;
    --topbar-h:  60px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 var(--space-3); font-weight: 650; color: var(--c-text); }
h1 { font-size: 20px; }
h2 { font-size: 16px; }

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .85em;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 1px 5px;
}

.muted { color: var(--c-muted); }
.small { font-size: 12px; }
.centered { text-align: center; }
.num, .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-danger { color: var(--c-danger); }

/* ---------- App shell ---------------------------------------------------- */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--c-sidebar-bg);
    color: var(--c-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    font-weight: 700;
    color: var(--c-sidebar-text-strong);
    border-bottom: 1px solid var(--c-sidebar-border);
    min-height: var(--topbar-h);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--c-primary);
    color: var(--c-on-accent);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .5px;
}
.brand-text { font-size: 15px; display: flex; flex-direction: column; line-height: 1.15; gap: 1px; }
.brand-product { letter-spacing: -0.02em; }
.brand-byline {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    color: var(--c-sidebar-muted);
    font-style: italic;
}
.brand-sub { color: var(--c-primary); font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; margin-left: 0; }
.brand-stack { display: flex; flex-direction: column; gap: 1px; line-height: 1.15; }
.auth-brand .brand-product { font-size: 18px; font-weight: 700; }
.auth-brand .brand-byline { color: var(--c-muted); }
.brand-tag { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--c-primary); }

.sidebar-nav {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--c-sidebar-text);
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--c-sidebar-hover); color: var(--c-sidebar-text-strong); text-decoration: none; }
.nav-item.is-active { background: var(--c-primary); color: var(--c-on-accent); }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; }

.nav-section {
    margin: var(--space-4) var(--space-3) 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--c-sidebar-muted);
}
.nav-section:first-child { margin-top: var(--space-2); }

.sidebar-foot {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--c-sidebar-border);
}
.sidebar-foot .muted { color: var(--c-sidebar-muted); }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-5);
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-title { flex: 1; }
.topbar-title h1 { margin: 0; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.icon-btn {
    display: none;
    background: none;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    width: 36px; height: 36px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--c-text-soft);
}
.icon-btn svg { width: 18px; height: 18px; }

.content {
    padding: var(--space-5);
    flex: 1;
    max-width: 1280px;
    width: 100%;
}

.app-foot {
    display: flex;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    color: var(--c-muted);
    font-size: 12px;
    border-top: 1px solid var(--c-border);
}

/* ---------- User chip / dropdown --------------------------------------- */
.user-chip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: 1px solid var(--c-border);
    border-radius: 999px;
    padding: 4px 10px 4px 4px;
    cursor: pointer;
    color: var(--c-text);
}
.user-chip:hover { background: var(--c-surface-2); }
.user-chip svg { width: 14px; height: 14px; color: var(--c-muted); }

.avatar {
    display: inline-grid;
    place-items: center;
    width: 30px; height: 30px;
    border-radius: 999px;
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    font-weight: 700;
    font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; text-align: left; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--c-muted); }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 180px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: none;
    z-index: 50;
}
.dropdown.is-open .dropdown-menu { display: block; }
.dropdown-menu a {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--c-text);
    font-weight: 500;
}
.dropdown-menu a:hover { background: var(--c-surface-2); text-decoration: none; }
.dropdown-menu a.danger { color: var(--c-danger); }
.dropdown-sep { height: 1px; background: var(--c-border); margin: 6px 0; }

/* ---------- Buttons --------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: var(--c-on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); }
.btn-ghost { background: var(--c-surface); border-color: var(--c-border-strong); color: var(--c-text); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-danger { background: var(--c-danger); color: var(--c-on-accent); }
.btn-danger:hover:not(:disabled) { background: #a52222; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.link { color: var(--c-primary); font-weight: 600; font-size: 13px; }

/* ---------- Alerts / flash ------------------------------------------- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    margin-bottom: var(--space-4);
    font-weight: 500;
}
.alert-success { background: var(--c-success-soft); border-color: var(--c-success-border); color: var(--c-success); }
.alert-error   { background: var(--c-danger-soft);  border-color: var(--c-danger-border);  color: var(--c-danger); }
.alert-warning { background: var(--c-warning-soft); border-color: var(--c-warning-border); color: var(--c-warning); }
.alert-info    { background: var(--c-info-soft);    border-color: var(--c-info-border);    color: var(--c-info); }

/* ---------- Panels / cards ------------------------------------------ */
.panel {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-4);
    border-bottom: 1px solid var(--c-border);
}
.panel-head h2 { margin: 0; }
.panel-body { padding: var(--space-4); }
.panel-body.no-pad { padding: 0; }
.panel-body .pad, .pad { padding: var(--space-4); }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    margin-top: var(--space-5);
}

/* ---------- Stat grid --------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4) var(--space-4) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-card.is-alert { border-color: #f0c0c0; background: var(--c-danger-soft); }
.stat-label { color: var(--c-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--c-text-soft); }

/* ---------- Bar list (pipeline) --------------------------------- */
.bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.bar-list li { display: grid; grid-template-columns: 80px 1fr 40px; align-items: center; gap: var(--space-3); }
.bar-label { font-weight: 600; font-size: 13px; }
.bar-track { background: var(--c-surface-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--c-primary); transition: width .3s; }
.bar-fill.stage-cold { background: var(--stage-cold); }
.bar-fill.stage-warm { background: var(--stage-warm); }
.bar-fill.stage-hot { background: var(--stage-hot); }
.bar-fill.stage-onboarded { background: var(--stage-onboarded); }
.bar-fill.stage-lost { background: var(--stage-lost); }
.bar-count { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Tables --------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 11px var(--space-4); text-align: left; border-bottom: 1px solid var(--c-border); }
.table th { background: var(--c-surface-2); font-weight: 600; color: var(--c-text-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--c-surface-2); }
.table td strong { display: block; }
.row-link { cursor: pointer; }

/* ---------- Pills / badges ---------------------------------- */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    color: var(--c-text-soft);
}
.pill.stage-cold { background: var(--c-cold-soft); color: var(--stage-cold); border-color: var(--c-cold-border); }
.pill.stage-warm { background: var(--c-warning-soft); color: var(--stage-warm); border-color: var(--c-warning-border); }
.pill.stage-hot { background: var(--c-danger-soft); color: var(--stage-hot); border-color: var(--c-danger-border); }
.pill.stage-onboarded { background: var(--c-success-soft); color: var(--stage-onboarded); border-color: var(--c-success-border); }
.pill.stage-lost { background: var(--c-cold-soft); color: var(--stage-lost); border-color: var(--c-cold-border); }

/* Ticket status pills */
.pill.ticket-new      { background: var(--c-info-soft);    color: var(--c-info);    border-color: var(--c-info-border); }
.pill.ticket-open     { background: var(--c-warning-soft); color: var(--c-warning); border-color: var(--c-warning-border); }
.pill.ticket-waiting  { background: #efe7fb;               color: #6d3fbf;          border-color: #d8c6f2; }
.pill.ticket-resolved { background: var(--c-success-soft); color: var(--c-success); border-color: var(--c-success-border); }
.pill.ticket-closed   { background: var(--c-cold-soft);    color: var(--stage-lost); border-color: var(--c-cold-border); }

/* Ticket priority pills */
.pill.prio-low    { background: var(--c-cold-soft);    color: var(--prio-low);    border-color: var(--c-cold-border); }
.pill.prio-normal { background: var(--c-primary-soft); color: var(--prio-normal); border-color: #c2d6f2; }
.pill.prio-high   { background: var(--c-warning-soft); color: var(--prio-high);   border-color: var(--c-warning-border); }
.pill.prio-urgent { background: var(--c-danger-soft);  color: var(--prio-urgent); border-color: var(--c-danger-border); }

.score {
    display: inline-grid;
    place-items: center;
    min-width: 30px;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    font-weight: 700;
    font-size: 12px;
}

/* ---------- Forms ------------------------------------------ */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 13px; color: var(--c-text-soft); }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=date], input[type=datetime-local], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-soft);
}
textarea { min-height: 90px; resize: vertical; }

/* ---------- Auth page ----------------------------------- */
.auth-page { background: linear-gradient(135deg, #10233f, #1f6feb); }
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-5);
}
.auth-card {
    background: var(--c-surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: var(--space-6);
    width: 100%;
    max-width: 380px;
}
.auth-brand { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); }
.auth-brand h1 { margin: 0; font-size: 18px; }
.auth-brand p { margin: 0; font-size: 12px; }
.auth-card .btn-block { margin-top: var(--space-2); }

/* ---------- Empty state -------------------------------- */
.empty-state { text-align: center; padding: var(--space-6); }
.empty-state h1 { font-size: 48px; color: var(--c-border-strong); margin-bottom: var(--space-2); }

/* ---------- Toasts ------------------------------------ */
.toast-root {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 100;
}
.toast {
    background: #1f2733;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-weight: 500;
    font-size: 13px;
    min-width: 220px;
    animation: toast-in .18s ease;
}
.toast.is-success { background: var(--c-success); }
.toast.is-error { background: var(--c-danger); }
.toast.is-warning { background: var(--c-warning); }
.toast.is-hiding { opacity: 0; transform: translateX(12px); transition: .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } }

/* ---------- Modal / confirm -------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--c-overlay);
    display: grid;
    place-items: center;
    padding: var(--space-5);
    z-index: 90;
    animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    overflow: hidden;
}
.modal-head { padding: var(--space-4); border-bottom: 1px solid var(--c-border); font-weight: 650; }
.modal-body { padding: var(--space-4); }
.modal-foot { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: var(--space-2); background: var(--c-surface-2); }

/* ==========================================================================
   Phase 2 — Leads, filters, lead profile, pipeline board
   ========================================================================== */

/* ---------- Disabled nav items (Phase 3 placeholders) --------------- */
.nav-item.is-disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.nav-soon {
    margin-left: auto;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: rgba(255, 255, 255, .12);
    padding: 1px 6px;
    border-radius: 999px;
}

/* ---------- Stage tabs --------------------------------------------- */
.stage-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}
.stage-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-text-soft);
    font-weight: 600;
    font-size: 13px;
}
.stage-tab:hover { text-decoration: none; border-color: var(--c-border-strong); }
.stage-tab.is-active { background: var(--c-text); color: var(--c-surface); border-color: var(--c-text); }
.stage-tab-count {
    background: var(--c-surface-2);
    color: var(--c-text-soft);
    border-radius: 999px;
    padding: 0 7px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.stage-tab.is-active .stage-tab-count { background: rgba(255, 255, 255, .2); color: #fff; }

/* ---------- Filter bar -------------------------------------------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.filter-bar select, .filter-bar input { width: auto; }
.filter-search { min-width: 260px; flex: 1 1 260px; }

/* ---------- Sortable table headers ------------------------------- */
.th-sort { color: inherit; font: inherit; font-weight: 600; }
.th-sort:hover { color: var(--c-primary); text-decoration: none; }
.table-leads td { vertical-align: top; }
.col-actions { white-space: nowrap; }
.col-actions .link + .link { margin-left: var(--space-3); }

/* ---------- Pager ----------------------------------------------- */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--c-border);
}
.pager-links { display: flex; gap: var(--space-2); }

/* ---------- Lead form ----------------------------------------- */
.lead-form .panel-foot {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    border-top: 1px solid var(--c-border);
    background: var(--c-surface-2);
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}
.req { color: var(--c-danger); font-style: normal; }
.field-hint { color: var(--c-muted); font-size: 12px; }
.field-err { color: var(--c-danger); font-size: 12px; font-weight: 600; }
.svc-fieldset { border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.svc-fieldset legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--c-text-soft); }
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-2);
}
.checkbox { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; }
.checkbox input { width: auto; }

/* ---------- Lead profile layout ----------------------------- */
.lead-layout { display: grid; grid-template-columns: 1fr 340px; gap: var(--space-5); align-items: start; }
.lead-main, .lead-side { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.kv-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); font-weight: 600; }

/* ---------- Stage progress visual -------------------------- */
.stage-progress {
    list-style: none;
    margin: 0 0 var(--space-3);
    padding: 0;
    display: flex;
    gap: var(--space-2);
}
.stage-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
    font-size: 12px;
    font-weight: 600;
    color: var(--c-muted);
}
.stage-step .stage-dot {
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--c-border);
}
.stage-step.is-done .stage-dot   { background: var(--stage-onboarded); }
.stage-step.is-current .stage-dot { background: var(--c-primary); }
.stage-step.is-done, .stage-step.is-current { color: var(--c-text); }
.stage-progress.is-lost .stage-step .stage-dot { background: var(--stage-lost); opacity: .5; }

.stage-quick { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); }
.field-inline { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--c-text-soft); }
.field-inline select { width: auto; min-width: 150px; }

/* ---------- Quick-log form -------------------------------- */
.quicklog-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-3); }
.quicklog .field { margin-bottom: var(--space-3); }

/* ---------- Timeline ------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { display: flex; gap: var(--space-3); padding-bottom: var(--space-4); position: relative; }
.timeline-item:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 5px; top: 16px; bottom: 0;
    width: 2px;
    background: var(--c-border);
}
.timeline-mark {
    flex: 0 0 12px;
    width: 12px; height: 12px;
    border-radius: 999px;
    background: var(--c-primary);
    margin-top: 3px;
    z-index: 1;
}
.timeline-item.type-status_change .timeline-mark { background: var(--stage-hot); }
.timeline-item.type-note .timeline-mark { background: var(--c-muted); }
.timeline-item.type-task .timeline-mark { background: var(--c-warning); }
.timeline-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.timeline-top { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.timeline-type { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--c-text-soft); }
.timeline-body p { margin: 2px 0; }

.pill.outcome-positive { background: var(--c-success-soft); color: var(--c-success); border-color: #b9e2cb; }
.pill.outcome-neutral  { background: var(--c-surface-2);    color: var(--c-text-soft); }
.pill.outcome-negative { background: var(--c-danger-soft);  color: var(--c-danger); border-color: #f0c0c0; }

/* ---------- Chips --------------------------------------- */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
    display: inline-flex;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    font-size: 12px;
    font-weight: 600;
}

/* ---------- Score bar ---------------------------------- */
.score-bar {
    display: inline-block;
    width: 80px; height: 8px;
    border-radius: 999px;
    background: var(--c-surface-2);
    overflow: hidden;
    vertical-align: middle;
    margin-right: 6px;
}
.score-bar-fill { display: block; height: 100%; background: var(--c-primary); border-radius: 999px; }

/* ---------- Kanban pipeline board --------------------- */
.kanban {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(240px, 1fr);
    gap: var(--space-4);
    overflow-x: auto;
    padding-bottom: var(--space-3);
    align-items: start;
}
.kanban-col {
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 120px;
}
.kanban-col-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3);
    border-bottom: 1px solid var(--c-border);
}
.kanban-drop {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    flex: 1;
    min-height: 60px;
    transition: background .15s;
}
.kanban-drop.is-dragover { background: var(--c-primary-soft); }
.kanban-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: grab;
}
.kanban-card.is-dragging { opacity: .5; }
.kanban-card-title { font-weight: 650; color: var(--c-text); }
.kanban-card-title:hover { color: var(--c-primary); text-decoration: none; }
.kanban-card-meta { display: flex; align-items: center; gap: var(--space-2); margin-top: 2px; }
.kanban-card-move { margin-top: var(--space-2); }
.kanban-card-move select { width: 100%; padding: 5px 8px; font-size: 12px; }
.kanban-empty { text-align: center; padding: var(--space-3); }

/* ---------- Follow-ups centre --------------------------------------- */
.table-followups td { vertical-align: top; }
.table-followups .pill { margin-left: var(--space-2); }
.table-followups .col-actions form { margin-right: var(--space-1); }
.table-followups .col-actions .small,
.table-followups td .muted { display: block; }

/* ---------- Reports: monthly column chart -------------------------- */
.col-chart {
    display: flex;
    align-items: flex-end;
    gap: var(--space-3);
    height: 180px;
    padding-top: var(--space-4);
}
.col-chart-item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    gap: 4px;
}
.col-chart-value { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--c-text-soft); }
.col-chart-bar {
    width: 60%;
    max-width: 46px;
    min-height: 3px;
    background: var(--c-primary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: height .3s;
}
.col-chart-label { font-size: 11px; color: var(--c-muted); }

/* ---------- Responsive ------------------------------ */
@media (max-width: 1024px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .lead-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .icon-btn { display: inline-flex; }
    .content { padding: var(--space-4); }
    .user-meta { display: none; }
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(16, 24, 40, .4); z-index: 35;
    }
    .form-grid { grid-template-columns: 1fr; }
    .quicklog-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .table thead { display: none; }
    .filter-search { min-width: 0; }
}

/* ==========================================================================
   Phase 4 - persuasion toolkit (templates + compose cockpit)
   ========================================================================== */
.compose-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}
.compose-preview { position: sticky; top: var(--space-4); }

textarea.mono,
.preview-bubble {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.55;
}
textarea.mono { min-height: 260px; resize: vertical; }

.preview-bubble {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    color: var(--c-text);
}
.preview-bubble-wa {
    background: var(--c-wa-bubble);
    border-color: var(--c-wa-border);
}
.preview-mail p { margin: 4px 0; }

.compose-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.compose-log {
    display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center;
    padding-top: var(--space-3); border-top: 1px solid var(--c-border);
}

.panel-suggest { border-left: 3px solid var(--c-primary); }
.suggest-label { margin: 0 0 var(--space-3); font-weight: 600; color: var(--c-text); }

@media (max-width: 1024px) {
    .compose-grid { grid-template-columns: 1fr; }
    .compose-preview { position: static; }
}

/* ==========================================================================
   Phase 6 - two-module redesign: theme toggle, dark mode, support tickets
   ========================================================================== */

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--c-muted);
    margin: 0 0 var(--space-3);
}

/* ---------- Theme toggle button ---------------------------------------- */
.theme-toggle { display: inline-flex; }
.theme-toggle svg { width: 18px; height: 18px; }
:root[data-theme="dark"] .theme-icon-sun,
:root:not([data-theme="dark"]) .theme-icon-moon { display: none; }

.auth-topbar {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
}
.auth-topbar .theme-toggle {
    background: rgba(255, 255, 255, .14);
    border-color: rgba(255, 255, 255, .3);
    color: #fff;
}

/* ---------- Dark theme ------------------------------------------------- */
:root[data-theme="dark"] {
    --c-bg:            #0f1620;
    --c-surface:       #172231;
    --c-surface-2:     #1e2b3c;
    --c-border:        #2b3a4e;
    --c-border-strong: #3a4c63;

    --c-text:      #e6ecf3;
    --c-text-soft: #aab8c8;
    --c-muted:     #7d8da4;

    --c-on-accent: #ffffff;

    --c-primary:      #4d95ff;
    --c-primary-dark: #3b82e6;
    --c-primary-soft: #1c2c44;

    --c-success:        #4ac07f;
    --c-success-soft:   #16281f;
    --c-success-border: #2c4a38;
    --c-warning:        #e0a34a;
    --c-warning-soft:   #2c2415;
    --c-warning-border: #4a3d21;
    --c-danger:         #f0736f;
    --c-danger-soft:    #2e1a1a;
    --c-danger-border:  #4c2c2c;
    --c-info:           #6aa9e6;
    --c-info-soft:      #16283b;
    --c-info-border:    #2c4258;

    --stage-cold:      #94a3b8;
    --stage-warm:      #e0a34a;
    --stage-hot:       #f0736f;
    --stage-onboarded: #4ac07f;
    --stage-lost:      #7d8da4;

    --c-cold-soft:   #1e2b3c;
    --c-cold-border: #2b3a4e;

    --c-sidebar-bg:          #0b1524;
    --c-sidebar-text:        #aebecf;
    --c-sidebar-text-strong: #ffffff;
    --c-sidebar-border:      rgba(255, 255, 255, .06);
    --c-sidebar-hover:       rgba(255, 255, 255, .08);
    --c-sidebar-muted:       #6b7d97;

    --c-wa-bubble:  #12351f;
    --c-wa-border:  #1f5230;

    --c-overlay:    rgba(0, 0, 0, .65);

    --prio-normal:  #4d95ff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
}

:root[data-theme="dark"] .auth-page { background: linear-gradient(135deg, #0b1524, #13315c); }
:root[data-theme="dark"] .pill.ticket-waiting { background: #241a3a; color: #b79cf0; border-color: #3c2c66; }
:root[data-theme="dark"] code { background: var(--c-surface-2); border-color: var(--c-border); }

/* ---------- Support: ticket queue + thread --------------------------- */
.ticket-meta-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.ticket-meta-row .pill { margin: 0; }

.table-tickets td { vertical-align: top; }
.table-tickets .subj { font-weight: 650; display: block; }
.table-tickets tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--c-danger); }

.ticket-layout { display: grid; grid-template-columns: 1fr 320px; gap: var(--space-5); align-items: start; }
.ticket-thread { display: flex; flex-direction: column; gap: var(--space-3); }
.ticket-msg {
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: var(--space-3) var(--space-4);
    background: var(--c-surface);
}
.ticket-msg.is-internal { background: var(--c-warning-soft); border-color: var(--c-warning-border); }
.ticket-msg.is-original { background: var(--c-surface-2); }
.ticket-msg-head { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.ticket-msg-head strong { font-size: 13px; }
.ticket-msg-body { white-space: pre-wrap; word-break: break-word; margin: 0; }

.ticket-actions-grid { display: grid; gap: var(--space-3); }
.ticket-actions-grid form { display: flex; gap: var(--space-2); align-items: flex-end; flex-wrap: wrap; }

@media (max-width: 1024px) {
    .ticket-layout { grid-template-columns: 1fr; }
}

.macro-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: flex-end;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--c-border);
    margin-bottom: var(--space-2);
}
.ticket-msg.is-customer { border-left: 3px solid var(--c-info); }
.ticket-msg.is-staff { background: var(--c-surface-2); border-left: 3px solid var(--c-primary); }

.queue-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
    margin-bottom: var(--space-3);
}
.queue-bulk { display: flex; align-items: center; gap: var(--space-2); }
.queue-hint { margin-left: auto; }
.queue-hint kbd {
    font: 600 11px/1 var(--font-mono, monospace);
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid var(--c-border);
    background: var(--c-surface-2);
}
.table-tickets.is-compact td,
.table-tickets.is-compact th { padding-top: 6px; padding-bottom: 6px; font-size: 13px; }
.table-tickets tr.is-focused { outline: 2px solid var(--c-primary); outline-offset: -2px; }
.col-check { width: 36px; text-align: center; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.auth-card-wide { max-width: 640px; width: 100%; }
.portal-thread { max-height: 420px; overflow-y: auto; margin: var(--space-4) 0; }
.alert-info { background: var(--c-info-soft); border: 1px solid var(--c-info-border); color: var(--c-info); }
.section-title-sm { font-size: 13px; font-weight: 650; margin: 0 0 var(--space-2); }
.attach-gallery { margin: var(--space-3) 0; }
.attach-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.attach-thumb {
    display: block;
    width: 112px; height: 84px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--c-border);
    background: var(--c-surface-2);
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
