/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
    /* neaMetrics brand: charcoal + crimson + grey (sampled from the logo) */
    --primary:    #9E274A;   /* crimson — primary action / brand accent */
    --primary-hv: #85203E;   /* crimson dark (hover) */
    --accent2:    #9E274A;   /* crimson — attention badges */
    --accent2-ink:#FFFFFF;
    --brand-grey: #A3A3A3;   /* grey — the logo's second loop */
    --danger:     #9E274A;   /* breach / danger = brand crimson */
    --danger-bg:  #F6E7EC;
    --danger-hv:  #85203E;
    --warning:    #B47908;
    --warning-bg: #F6ECD6;
    --success:    #1F7A4D;
    --success-bg: #E9F1EC;
    --info:       #174A8B;   /* blue — awaiting client */
    --info-bg:    #EAF0F7;
    --bg:         #F4F4F5;   /* page (neutral grey) */
    --bg-sub:     #F7F7F8;
    --card:       #FFFFFF;
    --card-head:  #F7F7F8;
    --border:     #E5E5E7;
    --border-2:   #EDEDEF;
    --line-in:    #DBDBDE;   /* input border */
    --line-hov:   #BFBFC4;
    --text:       #221F1F;   /* charcoal ink (brand) */
    --ink2:       #3A3A3E;
    --ink3:       #55555A;
    --muted:      #6B6B70;
    --muted2:     #8A8A90;
    --radius:     10px;
    /* Sidebar (charcoal) */
    --sidebar:        #221F1F;
    --sidebar-active: rgba(255, 255, 255, 0.08);
    --sidebar-ink:    #A0A0A0;
    --glow:           rgba(158, 39, 74, 0.30);
}

body {
    margin: 0;
    font-family: 'Figtree', system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.content-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content-body { flex: 1; padding: 28px; }

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
.topbar {
    height: 66px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(244, 246, 250, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-titles { min-width: 0; }
.topbar-title {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.1;
    color: var(--text);
}
.topbar-sub { font-size: 12.5px; color: var(--muted); }
.topbar-spacer { flex: 1; }
.topbar-lastsync { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.btn-topbar {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border: 1px solid var(--line-in);
    background: #fff;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink2);
    cursor: pointer;
    transition: border-color 0.12s;
    white-space: nowrap;
}
.btn-topbar:hover:not(:disabled) { border-color: var(--line-hov); }
.btn-topbar:disabled { opacity: 0.7; cursor: default; }
.sync-ic.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sync-ic.spin { animation: none; } }

@media (max-width: 720px) {
    .sidebar { width: 64px; }
    .sidebar .nav-label, .sidebar .sidebar-brand, .sidebar .sidebar-tag,
    .sidebar .nav-group, .sidebar .sidebar-userinfo { display: none; }
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.dash-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dash-icon { font-size: 1.6rem; }

.dash-title h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.last-sync {
    color: var(--muted);
    font-size: 0.8rem;
}

.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-sync:hover:not(:disabled) { background: var(--primary-hv); }
.btn-sync:disabled, .btn-sync.syncing { opacity: 0.65; cursor: not-allowed; }

/* ── Error banner ──────────────────────────────────────────────────────────── */
.error-banner {
    background: var(--danger-bg);
    border: 1px solid #fca5a5;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.875rem;
}

.notify-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #eff6ff;
    border: 1px solid #93c5fd;
    color: #1e40af;
    padding: 10px 16px;
    border-radius: var(--radius);
    margin: 0 24px 12px;
    font-size: 0.85rem;
}
.notify-banner span { flex: 1; }
.btn-notify-enable {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.btn-notify-enable:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* ── Stats row ─────────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 800px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    border-top: 3px solid transparent;
}
.stat-danger { border-top-color: var(--danger); }
.stat-warn   { border-top-color: var(--warning); }
.stat-ok     { border-top-color: var(--success); }
.stat-neutral{ border-top-color: var(--primary); }

.stat-num {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}
.stat-danger .stat-num { color: var(--danger); }
.stat-warn   .stat-num { color: var(--warning); }
.stat-ok     .stat-num { color: var(--success); }
.stat-neutral .stat-num { color: var(--primary); }

.stat-label { color: var(--muted); font-size: 0.8rem; }

/* ── Section cards ─────────────────────────────────────────────────────────── */
.section-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--card-head);
}

.section-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 8px;
    border-radius: 13px;
    font-size: 0.75rem;
    font-weight: 700;
}
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-ok     { background: var(--success-bg); color: var(--success); }

/* ── Email table ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.email-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.email-table th {
    text-align: left;
    padding: 10px 16px;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--card-head);
}

.email-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.email-table tr:last-child td { border-bottom: none; }
.email-table tbody tr:hover td { background: var(--card-head); }

/* Row severity indicators */
.row-high td:first-child { border-left: 3px solid var(--danger); }
.row-med  td:first-child { border-left: 3px solid var(--warning); }

/* ── Cell content ──────────────────────────────────────────────────────────── */
.subject {
    font-weight: 500;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview {
    color: var(--muted);
    font-size: 0.78rem;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 3px;
}

.addr {
    color: var(--muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mono { font-family: 'JetBrains Mono', Consolas, monospace; color: var(--muted); }

.mailbox-pill {
    display: inline-block;
    background: var(--card-head);
    color: var(--primary);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.age-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.age-high { background: var(--danger-bg);  color: var(--danger); }
.age-med  { background: var(--warning-bg); color: var(--warning); }

.overdue { color: var(--danger); font-weight: 600; white-space: nowrap; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.no-breaches {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
}
.no-breaches-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
    color: var(--success);
}

/* ── Expandable full-mail view ──────────────────────────────────────────────── */
.subject-link { cursor: pointer; user-select: none; }
.subject-link:hover { color: var(--primary); }
.expand-caret { display: inline-block; width: 1em; color: var(--muted); }

.detail-row td { background: var(--bg); padding: 0; }
.mail-full { padding: 16px 20px; }
.mail-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.mail-meta strong { color: var(--text); font-size: 0.9rem; }
.mail-body {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 0;
    max-height: 480px;
    overflow: auto;
}
.mail-body-html {
    font-family: -apple-system, BlinkMacSystemFont,
        'Segoe UI', Roboto, sans-serif;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 0;
    max-height: 480px;
    overflow: auto;
    word-break: break-word;
}
.mail-body-html img {
    max-width: 100%;
    height: auto;
}
.mail-body-html table {
    border-collapse: collapse;
    max-width: 100%;
}
.mail-body-html a {
    color: var(--info);
    text-decoration: underline;
}

/* ── Sidebar nav ─────────────────────────────────────────────────────────────── */
.sidebar-head {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 6px 18px;
}
.sidebar-logo {
    background: #fff;
    border-radius: 10px;
    padding: 11px 13px;
    display: flex;
}
.sidebar-logo img { width: 100%; height: auto; display: block; }
.sidebar-tag {
    font-size: 11px;
    color: var(--sidebar-ink);
    letter-spacing: .02em;
    padding-left: 2px;
}
.nav-group {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--sidebar-ink);
    padding: 14px 10px 6px;
}
.app-nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 9px;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--sidebar-ink);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}
.nav-ic { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { flex: 1; min-width: 0; }
.app-nav-link:hover { color: #fff; background: var(--sidebar-active); }
.app-nav-link.active { color: #fff; background: var(--sidebar-active); }
.nav-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
}
.nav-badge-breach { background: var(--accent2); color: var(--accent2-ink); }
.nav-badge-atrisk { background: #E7A619; color: #3A2B00; }
.nav-badge-mine {
    background: var(--info);
    color: #fff;
    margin-left: 2px;
}
.nav-badge-triage { background: #E7A619; color: #3A2B00; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin: 10px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-input {
    width: 100%;
    max-width: 420px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 8px;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.local-filter {
    display: flex;
    align-items: center;
    gap: 9px;
    width: min(100%, 520px);
    margin-bottom: 16px;
    padding: 9px 12px;
    background: #fff;
    border: 1px solid var(--line-in);
    border-radius: 9px;
    color: var(--muted2);
}
.local-filter:focus-within { border-color: var(--primary); }
.local-filter-icon { font-size: 1.1rem; line-height: 1; }
.local-filter input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
}
.local-filter-count {
    color: var(--muted);
    font-size: 0.75rem;
    white-space: nowrap;
}
.local-filter-compact {
    width: min(38vw, 380px);
    margin: 0 0 0 auto;
}
.conversation-actions {
    display: flex;
    align-items: end;
    gap: 10px;
}
.conversation-actions label {
    display: grid;
    gap: 3px;
    color: var(--muted);
    font-size: 0.72rem;
}
.conversation-actions select {
    min-width: 150px;
    padding: 7px 9px;
    border: 1px solid var(--line-in);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
}
.conv-owner {
    margin-top: 7px;
    color: var(--muted);
    font-size: 0.72rem;
}
.ownership-history { padding: 14px 18px; }
.ownership-history summary {
    cursor: pointer;
    font-weight: 700;
}
.ownership-history-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}
.ownership-history-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
}
.ownership-history-meta {
    color: var(--muted);
    font-size: 0.75rem;
    white-space: nowrap;
}
@media (max-width: 900px) {
    .board-toolbar { flex-wrap: wrap; }
    .local-filter-compact {
        order: 3;
        width: 100%;
        margin: 8px 0 0;
    }
}

.btn-link-danger {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.btn-link-danger:hover { background: var(--danger-bg); }

/* ── Login (split-screen) ────────────────────────────────────────────────────── */
.login-split {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
}

/* Left hero panel */
.login-hero {
    background: var(--sidebar);
    color: #fff;
    padding: 56px 64px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.login-hero-glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(
        680px 480px at 78% 8%,
        var(--glow),
        transparent 60%);
}
.login-hero > *:not(.login-hero-glow) { position: relative; z-index: 1; }

.login-mark { display: flex; align-items: center; gap: 12px; }
.login-mark-badge {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent2);
    color: var(--accent2-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    box-shadow: 0 6px 18px rgba(245, 130, 32, 0.4);
}
.login-mark-name { font-weight: 700; font-size: 19px; letter-spacing: -.01em; }

.login-hero-copy { max-width: 440px; }
.login-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.09);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--sidebar-ink);
    margin-bottom: 24px;
}
.login-headline {
    font-size: 40px;
    line-height: 1.08;
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 0 0 18px;
}
.login-lede {
    font-size: 16px;
    line-height: 1.6;
    color: var(--sidebar-ink);
    margin: 0;
}

.login-features {
    display: flex;
    gap: 28px;
    font-size: 13px;
    color: var(--sidebar-ink);
    flex-wrap: wrap;
}
.login-feature strong {
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: block;
    margin-bottom: 2px;
}

/* Right form panel */
.login-form-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: var(--bg);
}
.login-form { width: 100%; max-width: 380px; }
.login-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 0 0 6px;
}
.login-subtitle {
    font-size: 14.5px;
    color: var(--muted);
    margin: 0 0 28px;
}
.login-field-label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink3);
    margin-bottom: 7px;
}
.login-field {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14.5px;
    background: #fff;
    margin-bottom: 16px;
    color: var(--text);
}
.login-field:focus { outline: none; border-color: var(--primary); }
.login-submit {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(158, 39, 74, 0.28);
    margin-top: 6px;
    transition: background 0.15s;
}
.login-submit:hover { background: var(--primary-hv); }
.login-logo {
    width: 190px;
    max-width: 60%;
    height: auto;
    display: block;
    margin-bottom: 26px;
}
.login-footnote {
    font-size: 12.5px;
    color: var(--muted);
    text-align: center;
    margin: 22px 0 0;
}

@media (max-width: 820px) {
    .login-split { grid-template-columns: 1fr; }
    .login-hero { display: none; }
}

/* ── Sidebar user footer ─────────────────────────────────────────────────────── */
.sidebar-user {
    margin-top: auto;
    padding: 12px 10px 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--brand-grey);
    color: #221F1F;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}
.sidebar-userinfo { flex: 1; min-width: 0; }
.sidebar-who {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-role { font-size: 11px; color: var(--sidebar-ink); }
.sidebar-logout-form { display: flex; }
.sidebar-logout {
    background: none;
    border: none;
    color: var(--sidebar-ink);
    cursor: pointer;
    padding: 4px;
    display: flex;
    border-radius: 6px;
}
.sidebar-logout:hover { color: #fff; }

/* ── Attachments ─────────────────────────────────────────────────────────────── */
.mail-attachments { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.attach-chip {
    display: inline-block;
    background: var(--card-head);
    border: 1px solid var(--border);
    color: var(--primary);
    text-decoration: none;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.8rem;
}
.attach-chip:hover { background: var(--danger-bg); }

/* ── Dashboard KPI tiles ─────────────────────────────────────────────────────── */
.kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 26px; }
.kpi-tile {
    flex: 1; min-width: 180px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: 0 1px 2px rgba(60,40,20,.04);
}
.kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.kpi-value { display: flex; align-items: baseline; gap: 8px; }
.kpi-num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.kpi-red { color: var(--danger); }
.kpi-blue { color: var(--info); }
.kpi-amber { color: var(--warning); }
.kpi-green { color: var(--success); }
.kpi-sub { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.kpi-sub-red { color: var(--danger); }
.kpi-sub-amber { color: #E7A619; font-weight: 600; }

/* ── AI Insights panel ──────────────────────────── */
.insights-panel {
    margin: 0 0 16px;
}
.insights-head {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.insights-count {
    background: var(--badge-bg, #333);
    color: #fff;
    font-size: 0.7rem;
    padding: 1px 7px;
    border-radius: 10px;
}
.insight-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #eee);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 6px;
    border-left: 3px solid #888;
}
.insight-info { border-left-color: #3B82F6; }
.insight-warning {
    border-left-color: #E7A619;
}
.insight-critical {
    border-left-color: #E53E3E;
}
.insight-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    margin-bottom: 4px;
}
.insight-badge {
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.03em;
}
.insight-badge-info {
    background: #DBEAFE;
    color: #1D4ED8;
}
.insight-badge-warning {
    background: #FEF3C7;
    color: #92400E;
}
.insight-badge-critical {
    background: #FEE2E2;
    color: #991B1B;
}
.insight-cat {
    color: #999;
    font-style: italic;
}
.insight-time {
    color: #aaa;
    margin-left: auto;
}
.insight-dismiss {
    font-size: 1rem;
    color: #aaa;
    cursor: pointer;
    padding: 0 2px;
}
.insight-dismiss:hover { color: #E53E3E; }
.insight-title {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 2px;
}
.insight-body {
    font-size: 0.8rem;
    color: #666;
    line-height: 1.4;
}
.insight-client {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.7rem;
    background: #F3F4F6;
    padding: 1px 6px;
    border-radius: 3px;
    color: #555;
}

/* ── Dashboard board ─────────────────────────────────────────────────────────── */
.board-head { font-size: 0.95rem; font-weight: 700; }
.board-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.view-toggle {
    display: inline-flex;
    background: var(--border);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}
.view-toggle button {
    border: none;
    background: none;
    padding: 6px 14px;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.view-toggle button.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 2px rgba(20, 30, 55, 0.08);
}

.board-filters {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 18px;
    padding: 11px 14px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.board-filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.board-filter-group + .board-filter-group {
    padding-left: 24px;
    border-left: 1px solid var(--border);
}
.board-filter-label {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.filter-segments {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    overflow-x: auto;
    background: var(--border);
    border-radius: 9px;
}
.filter-segments button {
    padding: 6px 11px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.filter-segments button:hover:not(.active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.55);
}
.filter-segments button.active {
    color: var(--primary);
    background: #fff;
    box-shadow: 0 1px 3px rgba(20, 30, 55, 0.12);
}

.group-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}
.group-chips-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted2);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-right: 2px;
}
.group-chip {
    border: 1px solid var(--line-in);
    background: #fff;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink2);
    cursor: pointer;
}
.group-chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.group-pill {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--muted);
    background: var(--border-2);
    padding: 2px 8px;
    border-radius: 999px;
    flex-shrink: 0;
}
.priority-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}
.priority-1 {
    background: #E7A619;
    color: #3A2B00;
}
.priority-2 {
    background: var(--primary);
    color: #fff;
}

/* ── Saved views ─────── */
.saved-views-wrap {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.saved-view-pill {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border .15s;
}
.saved-view-pill:hover {
    border-color: var(--primary);
}
.saved-view-pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.saved-view-pill.save-btn,
.saved-view-pill.del-btn {
    font-size: 15px;
    padding: 2px 10px;
    line-height: 1;
}
.saved-view-pill.del-btn {
    border-color: var(--primary);
    color: var(--primary);
}
.save-view-dialog {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.save-view-dialog input[type="text"],
.save-view-dialog input:not([type]) {
    font-size: 13px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    width: 160px;
}

.status-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.status-us     { background: var(--danger-bg);  color: var(--danger); }
.status-client { background: var(--info-bg);    color: var(--info); }
.status-done   { background: var(--success-bg); color: var(--success); }

/* List view */
.list-table {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(20, 30, 55, 0.04);
}
.list-head, .list-row {
    display: grid;
    grid-template-columns: 2.6fr 1.4fr 1.1fr 1fr;
    gap: 14px;
    padding: 12px 18px;
    align-items: center;
}
@media (max-width: 900px) {
    .board-filters {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }
    .board-filter-group + .board-filter-group {
        padding: 10px 0 0;
        border-top: 1px solid var(--border);
        border-left: none;
    }
}
.list-head {
    background: var(--bg-sub);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted2);
}
.list-row {
    border-bottom: 1px solid var(--border-2);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--bg-sub); }
.list-subject {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}
.list-client { display: flex; align-items: center; gap: 8px; min-width: 0; }
.list-due { font-size: 12.5px; font-weight: 700; color: var(--muted); }

/* Split view */
.split {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    align-items: start;
}
.split-list {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden auto;
    box-shadow: 0 1px 2px rgba(20, 30, 55, 0.04);
    max-height: 72vh;
}
.split-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-2);
    cursor: pointer;
}
.split-item:last-child { border-bottom: none; }
.split-item:hover { background: var(--bg-sub); }
.split-item.sel { background: var(--info-bg); }
.split-item-sub { font-size: 11.5px; color: var(--muted2); margin-top: 3px; }
.split-detail {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 1px 2px rgba(20, 30, 55, 0.04);
}
.split-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.split-detail-title { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    align-items: start;
}
.board-col { border-radius: 14px; padding: 12px; border: 1px solid; }
.board-col-us     { background: #F7ECEE; border-color: #EBD9DD; }
.board-col-client { background: #EAF0F7; border-color: #D8E3F0; }
.board-col-done   { background: #E9F1EC; border-color: #D5E6DC; }
.board-col-head {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 6px 12px;
    font-size: 0.8rem; font-weight: 700;
}
.board-head-us { color: var(--danger); }
.board-head-client { color: var(--info); }
.board-head-done { color: var(--success); }
.board-count { color: var(--muted2); font-weight: 600; margin-left: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-red { background: var(--danger); }
.dot-blue { background: #2C6FBF; }
.dot-green { background: #1F9A5F; }

.conv-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 13px;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(20,30,55,.05);
}
.conv-top { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.conv-due { font-size: 0.72rem; font-weight: 700; color: var(--muted); }
.conv-due-red { color: var(--danger); }
.conv-due-amber { color: #E7A619; }
.conv-subject {
    font-size: 0.84rem; font-weight: 600; line-height: 1.35;
    margin-bottom: 8px; color: var(--text);
}
.conv-client { display: flex; align-items: center; gap: 8px; }
.avatar {
    width: 22px; height: 22px; border-radius: 50%;
    color: #fff; font-size: 0.62rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.conv-client-name { font-size: 0.76rem; color: var(--muted); }

/* ── Board: collapsible client groups ────────────────────────────────────────── */
.conv-group {
    display: flex;
    align-items: center;
    gap: 9px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 11px 13px;
    margin-bottom: 10px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(20, 30, 55, 0.05);
    transition: border-color 0.12s;
    user-select: none;
}
.conv-group:hover { border-color: var(--primary); }
.conv-group-name {
    flex: 1;
    min-width: 0;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-group-overdue {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--danger);
    white-space: nowrap;
}
.conv-group-atrisk {
    font-size: 0.7rem;
    font-weight: 700;
    color: #E7A619;
    white-space: nowrap;
}
.conv-group-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--card-head);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
}
.conv-group-caret { color: var(--muted); font-size: 0.72rem; width: 0.8em; }
.conv-group-children {
    border-left: 2px solid var(--border);
    padding-left: 9px;
    margin-bottom: 10px;
}
.conv-group-children .conv-card:last-child { margin-bottom: 0; }

/* ── Buttons (secondary / danger / small) ────────────────────────────────────── */
.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    color: var(--ink2);
    border: 1px solid var(--line-in);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.12s;
}
.btn-outline:hover { border-color: var(--line-hov); }

.btn-danger-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    color: var(--danger);
    border: 1px solid #EBD3D3;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s;
}
.btn-danger-outline:hover { background: var(--danger-bg); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ── Info banners ────────────────────────────────────────────────────────────── */
.info-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #FDF6E6;
    border: 1px solid #EFD79A;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 18px;
    font-size: 0.86rem;
    color: #7A5A00;
    line-height: 1.5;
}
.info-line {
    font-size: 0.86rem;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 18px;
    max-width: 820px;
}

/* ── Entity card grid (Clients) ──────────────────────────────────────────────── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.entity-card {
    display: block;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 1px 2px rgba(60, 40, 20, 0.04);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.entity-card:hover {
    border-color: var(--line-hov);
    box-shadow: 0 6px 20px rgba(20, 30, 55, 0.08);
}
.entity-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.entity-avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 11px;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.entity-headtext { min-width: 0; flex: 1; }
.entity-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.entity-domain {
    font-size: 12px;
    color: var(--muted2);
    font-family: 'JetBrains Mono', monospace;
}
.entity-stats {
    display: flex;
    gap: 24px;
    padding-top: 12px;
    border-top: 1px solid var(--border-2);
}
.entity-stat-num { font-size: 18px; font-weight: 800; color: var(--text); }
.entity-stat-label { font-size: 11.5px; color: var(--muted2); }

/* ── Excluded view ───────────────────────────────────────────────────────────── */
.chip-count {
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0.7;
    margin-left: 3px;
}
.exc-head, .exc-row {
    display: grid;
    grid-template-columns: 2.6fr 1fr 1.1fr 1.1fr;
    gap: 14px;
    padding: 12px 18px;
    align-items: center;
}
.exc-head {
    background: var(--bg-sub);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted2);
}
.exc-item { border-bottom: 1px solid var(--border-2); }
.exc-item:last-child { border-bottom: none; }
.exc-item.open { background: var(--bg-sub); }
.exc-row-click { cursor: pointer; }
.exc-row-click:hover { background: var(--bg-sub); }
.exc-caret { color: var(--muted); font-size: .72rem; margin-right: 4px; }
.exc-body-wrap { padding: 0 18px 16px; }
.exc-loading { color: var(--muted); font-size: 13px; padding: 8px 0; }
.exc-group { font-size: 12.5px; color: var(--ink2); }
.exc-date { font-size: 12px; }
.reason-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.reason-internal  { background: var(--border-2);      color: var(--ink3); }
.reason-automated { background: var(--warning-bg);    color: var(--warning); }
.reason-bulk      { background: var(--info-bg);       color: var(--info); }
.reason-subject   { background: rgba(163,163,163,.22); color: var(--ink2); }
.reason-spam      { background: var(--danger-bg);     color: var(--danger); }
.reason-other     { background: var(--border-2);      color: var(--muted); }

/* ── Stats ───────────────────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    align-items: start;
}
.stat-list-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border-2);
}
.stat-list-row:last-child { border-bottom: none; }
.stat-name-wrap { min-width: 0; }
.stat-name {
    font-size: 0.86rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
}
.stat-bar {
    height: 6px;
    min-width: 2px;
    border-radius: 3px;
    background: var(--primary);
}
.stat-count {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink2);
}

/* ── Search results ──────────────────────────────────────────────────────────── */
.search-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--muted2);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 22px 0 12px;
}
.search-section-title:first-of-type { margin-top: 4px; }

/* ── List card (Triage / Spam) ───────────────────────────────────────────────── */
.list-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(60, 40, 20, 0.04);
}

/* Triage rows */
.triage-item { border-bottom: 1px solid var(--border-2); }
.triage-item:last-child { border-bottom: none; }
.triage-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 18px;
}
.triage-mail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 18px 16px 70px;
}
.triage-mail .msg { background: var(--bg-sub); }
.msg-subject { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.exc-loading { color: var(--muted); font-size: 0.85rem; padding: 6px 0; }
.triage-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.triage-main { flex: 1; min-width: 0; }
.triage-name { font-size: 14px; font-weight: 600; }
.triage-email {
    font-size: 12px;
    color: var(--muted2);
    font-weight: 400;
    font-family: 'JetBrains Mono', monospace;
}
.triage-meta { font-size: 11.5px; color: var(--muted2); margin-top: 2px; }
.triage-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.triage-select, .triage-newname {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
    background: #fff;
}
.triage-select { max-width: 160px; }
.triage-newname { width: 150px; }
.triage-newname:focus, .triage-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Spam grid table */
.spam-add {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.spam-add-value { flex: 1; max-width: 360px; margin-bottom: 0; }
.spam-add-kind { width: 130px; margin-bottom: 0; }
.spam-head, .spam-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr 110px;
    gap: 14px;
    padding: 12px 18px;
    align-items: center;
}
.spam-head {
    background: var(--card-head);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted2);
}
.spam-row { border-bottom: 1px solid var(--border-2); }
.spam-row:last-child { border-bottom: none; }
.spam-value {
    font-size: 13px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    word-break: break-all;
}
.spam-row-action { text-align: right; }
.type-pill {
    font-size: 11.5px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--border-2);
    color: var(--ink3);
}

/* ── Settings ────────────────────────────────────────────────────────────────── */
.settings-wrap { max-width: 760px; }
.settings-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(60, 40, 20, 0.04);
}
.settings-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.settings-desc {
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 18px;
    line-height: 1.5;
}
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.settings-field { display: flex; flex-direction: column; }
.settings-field > label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink3);
    margin-bottom: 6px;
}
.settings-field input,
.settings-field textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 13.5px;
    background: #fff;
    font-family: inherit;
    color: var(--text);
}
.settings-field input:focus,
.settings-field textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.settings-field textarea {
    resize: vertical;
    min-height: 96px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12.5px;
    line-height: 1.6;
}
.settings-field input.settings-mono { font-family: 'JetBrains Mono', monospace; }
.settings-hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.settings-mono { font-family: 'JetBrains Mono', monospace; }
.settings-check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    color: var(--ink2);
    cursor: pointer;
}
.settings-check input { width: 16px; height: 16px; accent-color: var(--primary); }
.settings-source-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-top: 1px solid var(--border-2);
    flex-wrap: wrap;
}
.settings-source-row:first-of-type {
    border-top: none;
}
.health-status-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0 8px 0;
    flex-wrap: wrap;
}
.health-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.health-ok {
    background: #15803d;
    color: #fff;
}
.health-err {
    background: var(--primary);
    color: #fff;
}
.health-unknown {
    background: var(--bg-2);
    color: var(--fg-muted);
}
.health-err-msg {
    font-size: 0.75rem;
    color: var(--primary);
    word-break: break-word;
}
.settings-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

/* ── Conversation thread ─────────────────────────────────────────────────────── */
a.conv-card { display: block; text-decoration: none; color: inherit; }
a.conv-card:hover { border-color: var(--primary); }

.thread { padding: 8px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #fff;
}
.msg-inbound  { border-left: 3px solid var(--danger); }
.msg-outbound { border-left: 3px solid var(--success); }
.msg-internal { border-left: 3px solid var(--muted); opacity: .8; }
.msg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.msg-dir { font-size: .68rem; font-weight: 700; text-transform: uppercase;
           letter-spacing: .04em; padding: 2px 7px; border-radius: 5px; }
.msg-dir-inbound  { background: var(--danger-bg);  color: var(--danger); }
.msg-dir-outbound { background: var(--success-bg); color: var(--success); }
.msg-dir-internal { background: var(--card-head);  color: var(--muted); }
.msg-time { margin-left: auto; font-size: .74rem; }
.msg-reply-time {
    font-size: .7rem;
    font-weight: 600;
    color: var(--success);
    background: var(--success-bg);
    padding: 2px 8px;
    border-radius: 5px;
    white-space: nowrap;
}
.msg-spam { margin-left: 8px; }

/* Collapsible follow-up messages (first message stays open) */
.msg-head-toggle { cursor: pointer; }
.msg-head-toggle:hover .msg-dir { filter: brightness(0.96); }
.msg-caret {
    color: var(--muted);
    font-size: 0.72rem;
    width: 0.8em;
    flex-shrink: 0;
}
.msg-collapsed { background: var(--card-head); }
.msg-preview {
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 8px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Chat view ────────────────────────────────────── */
/* ── Chat view ────────────────────────────────────── */
.view-toggle {
    display: flex;
    gap: 4px;
    padding: 3px;
    border-radius: 8px;
    background: var(--card-head);
}

    .view-toggle button {
        padding: 4px 12px;
        border: none;
        border-radius: 6px;
        background: transparent;
        color: var(--muted);
        cursor: pointer;
        font-size: .76rem;
        font-weight: 600;
        transition: background .15s, color .15s;
    }

        .view-toggle button.active {
            background: #fff;
            color: var(--text);
            box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
        }


/* ── Chat timeline (ChatView component) ─────────── */
.chat-timeline {
    display: flex;
    flex-direction: column;
    padding: 12px 16px 0;
}

/* Timeline item: gutter (number + line) + card */
.ct-item {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 0;
    min-height: 0;
}
.ct-gutter {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 12px;
}
.ct-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: .7rem;
    font-weight: 800;
    flex-shrink: 0;
    z-index: 1;
}
.ct-line {
    flex: 1;
    width: 2px;
    background: #e4cbd3;
    min-height: 14px;
}

/* Card */
.ct-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    margin-bottom: 10px;
    overflow: hidden;
}
.ct-inbound .ct-card {
    border-color: #ecd4dc;
    background: #fffafb;
}
.ct-internal .ct-card {
    border-style: dashed;
    background: var(--card-head);
}

/* Collapsed item — compact spacing */
.ct-collapsed .ct-card {
    opacity: .92;
}

/* Header row */
.ct-toggle {
    cursor: pointer;
    user-select: none;
}
.ct-toggle:hover {
    background: rgba(180, 30, 65, .04);
}
.ct-caret {
    color: var(--primary);
    font-size: .7rem;
    width: 14px;
    flex-shrink: 0;
}
.ct-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-size: .75rem;
    background: rgba(255,255,255,.82);
}
.ct-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.ct-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.ct-reply-ref {
    color: var(--primary);
    font-size: .72rem;
    font-weight: 700;
}
.ct-sep {
    color: #ddb8c4;
    font-weight: 300;
}
.ct-name {
    color: var(--primary);
    font-size: .84rem;
    font-weight: 700;
}
.ct-inbound .ct-name {
    color: var(--text);
}
.ct-email {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
}
.ct-time {
    color: var(--muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
}

/* Speaker button */
.ct-speak {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card-head);
    color: var(--primary);
    cursor: pointer;
    font-size: .76rem;
    transition: background .15s, transform .15s;
}
.ct-speak:hover {
    background: var(--danger-bg);
    transform: scale(1.06);
}
.ct-speak:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Body */
.ct-body {
    padding: 10px 16px 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: .84rem;
    line-height: 1.55;
    color: var(--text);
    max-height: 200px;
    overflow-y: auto;
}
.ct-body:empty::after {
    content: "(no text)";
    opacity: .5;
}

/* Collapsed preview */
.ct-preview {
    padding: 4px 16px 8px;
    font-size: .78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.ct-preview:hover {
    color: var(--text);
}

/* Attachments */
.ct-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
}
.ct-attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: 1px solid var(--primary);
    border-radius: 5px;
    background: #fff;
    color: var(--primary);
    font-size: .73rem;
    font-weight: 600;
    text-decoration: none;
}
.ct-attach-chip:hover {
    background: var(--danger-bg);
}

/* Signature toggle */
.ct-sig-toggle {
    padding: 0 16px 10px;
    font-size: .75rem;
}
.ct-sig-toggle summary {
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}
.ct-sig-toggle summary:hover {
    text-decoration: underline;
}
.ct-sig-body {
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--card-head);
    border-radius: 6px;
    font-size: .78rem;
    color: var(--muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: inherit;
    border: none;
}

/* ── MailThread component ─────────────────── */
.mt-summary {
    padding: 10px 14px;
    margin-bottom: 8px;
    background: var(--card-head);
    border-radius: 6px;
    border-left: 3px solid var(--primary);
}
.mt-summary-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--primary);
    display: block;
    margin-bottom: 4px;
}
.mt-summary-text {
    font-size: .84rem;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}
.mt-subject {
    padding: 4px 14px 2px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
}
.mt-item {
    display: block;
    margin-bottom: 4px;
}

/* Reply link — visual connector above card */
.ct-reply-link {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 14px;
    height: 22px;
    position: relative;
}
.ct-reply-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}
.ct-reply-trace {
    flex: 1;
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--primary) 0%,
        #ecd4dc 100%
    );
    max-width: 120px;
}
.ct-reply-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: var(--danger-bg);
    color: var(--primary);
    font-size: .65rem;
    font-weight: 800;
    flex-shrink: 0;
}
.ct-has-parent {
    border-top-color: var(--primary);
    border-top-width: 2px;
}

/* Footer */
.ct-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 14px;
    font-size: .78rem;
    color: var(--muted);
}
.ct-msg-count {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ct-collapse-btn {
    border: none;
    background: none;
    color: var(--muted);
    font-size: .75rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.ct-collapse-btn:hover {
    background: var(--card-head);
    color: var(--text);
}

/* Mobile */
@media (max-width: 760px) {
    .ct-item {
        grid-template-columns: 36px 1fr;
    }
    .ct-num {
        width: 26px;
        height: 26px;
        font-size: .6rem;
    }
    .ct-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .ct-right {
        width: 100%;
        justify-content: flex-end;
    }
    .ct-body { padding: 8px 12px 10px; }
    .ct-attachments { padding: 0 12px 10px; }
}

/* ── AI assistant panel ─────────────────────────── */
/* ── AI floating FAB ──────────────────────── */
.ai-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    z-index: 900;
    transition: background 0.15s, transform 0.15s;
}
.ai-fab:hover {
    background: var(--primary-hv);
    transform: scale(1.06);
}

/* ── AI slide-out drawer ──────────────────── */
.ai-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    max-width: 92vw;
    height: 100vh;
    background: var(--card);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0,0,0,0.10);
    z-index: 950;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}
.ai-drawer.open {
    transform: translateX(0);
}
.ai-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ai-drawer-head h3 {
    font-size: 0.92rem;
    font-weight: 700;
    margin: 0;
}
.ai-drawer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-drawer-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    line-height: 1;
}
.ai-drawer-close:hover {
    background: var(--bg-sub);
    color: var(--text);
}
.ai-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #EBD3D3;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.82rem;
    margin: 0 12px 8px;
    flex-shrink: 0;
}

.ai-privacy {
    align-items: flex-start;
    background: #fff8e6;
    border-top: 1px solid #f1d58a;
    color: #684d05;
    display: flex;
    font-size: 0.78rem;
    gap: 0.45rem;
    line-height: 1.35;
    padding: 0.7rem 1rem;
}

.ai-privacy input {
    margin-top: 0.15rem;
}
.ai-text {
    font-family: inherit;
    font-size: 0.84rem;
    line-height: 1.6;
    word-break: break-word;
    margin: 0;
}
.ai-text p {
    margin: 0.4em 0;
}
.ai-text p:first-child {
    margin-top: 0;
}
.ai-text p:last-child {
    margin-bottom: 0;
}
.ai-text h1, .ai-text h2, .ai-text h3 {
    font-size: 0.92rem;
    font-weight: 700;
    margin: 0.6em 0 0.3em;
}
.ai-text h1:first-child,
.ai-text h2:first-child,
.ai-text h3:first-child {
    margin-top: 0;
}
.ai-text ul, .ai-text ol {
    margin: 0.3em 0;
    padding-left: 1.4em;
}
.ai-text li {
    margin: 0.15em 0;
}
.ai-text code {
    background: var(--card-head);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.8rem;
}
.ai-text pre {
    background: var(--card-head);
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    margin: 0.4em 0;
}
.ai-text pre code {
    background: none;
    padding: 0;
}
.ai-text strong {
    font-weight: 700;
}
.ai-text hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.5em 0;
}
.ai-speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.65rem;
    color: var(--muted);
    padding: 0 2px;
    line-height: 1;
    margin-left: auto;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.ai-speak-btn:hover {
    opacity: 1;
    color: var(--primary);
}
.ai-chat-meta {
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 4px;
    display: flex;
    gap: 4px;
}
.ai-speaking-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    background: var(--bg-sub);
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--muted);
    flex-shrink: 0;
}
.ai-stop-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 0.72rem;
    cursor: pointer;
    color: var(--danger);
}
.ai-stop-btn:hover {
    background: var(--danger-bg);
}
.summary-player {
    display: inline-flex;
    align-items: center;
}
.summary-player-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 12px;
    font-size: 0.78rem;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}
.summary-player-btn:hover {
    background: var(--bg-sub);
}
.summary-player-btn.playing {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.summary-player-btn:disabled {
    opacity: 0.5;
    cursor: default;
}
.summary-player-icon {
    font-size: 0.7rem;
}
.ai-picker {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 0.78rem;
    background: #fff;
    color: var(--text);
    min-width: 120px;
}
.ai-picker:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── AI skill (persona) picker ────────────── */
.ai-skill-picker {
    padding: 10px 16px 0;
    flex-shrink: 0;
}
.ai-skill-picker select {
    width: 100%;
}

/* ── AI prompt buttons row ───────────────── */
.ai-skills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 12px 16px 8px;
    flex-shrink: 0;
}
.ai-skill-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #fff;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.ai-skill-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--danger-bg);
}
.ai-skill-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.ai-skill-icon {
    font-size: 0.9rem;
}
.ai-skill-list-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

/* ── AI chat body (scrollable) ────────────── */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
}
.ai-empty {
    color: var(--muted2);
    font-size: 0.84rem;
    text-align: center;
    margin: auto 0;
    padding: 40px 20px;
}
.ai-chat-msg {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.84rem;
}
.ai-chat-user {
    background: var(--info-bg);
    border: 1px solid #D0DDEF;
    align-self: flex-end;
    max-width: 90%;
}
.ai-chat-assistant {
    background: var(--bg-sub);
    border: 1px solid var(--border);
    align-self: flex-start;
    max-width: 100%;
}
.ai-chat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-chat-skill-tag {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--danger-bg);
    color: var(--primary);
    text-transform: none;
    letter-spacing: 0;
}
.ai-thinking {
    color: var(--muted);
    font-size: 0.82rem;
    font-style: italic;
    animation: ai-pulse 1.5s ease-in-out infinite;
}
@keyframes ai-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ── AI input bar (pinned bottom) ─────────── */
.ai-input-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--card);
}
.ai-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.84rem;
    background: var(--bg-sub);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.ai-input:focus {
    border-color: var(--primary);
    background: #fff;
}
.ai-input::placeholder {
    color: var(--muted2);
}
.ai-send-btn {
    padding: 9px 16px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.ai-send-btn:hover:not(:disabled) {
    background: var(--primary-hv);
}
.ai-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.ai-provider-list {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.ai-provider-item {
    border-bottom: 1px solid var(--border-2);
}
.ai-provider-item:last-child {
    border-bottom: none;
}
.ai-provider-item.open {
    background: var(--bg-sub);
}
.ai-provider-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    user-select: none;
}
.ai-provider-summary:hover {
    background: var(--bg-sub);
}
.ai-provider-caret {
    color: var(--muted);
    font-size: 0.72rem;
    width: 0.8em;
    flex-shrink: 0;
}
.ai-provider-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    min-width: 0;
}
.ai-type-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.ai-type-claude {
    background: #F3E8D0;
    color: #7A5A00;
}
.ai-type-openai {
    background: #D9ECD9;
    color: #2A6B2A;
}
.ai-type-local {
    background: var(--info-bg);
    color: var(--info);
}
.ai-provider-model {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--muted);
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-provider-edit {
    padding: 10px 14px 14px;
}
.ai-provider-edit .settings-grid {
    margin-bottom: 8px;
}
.ai-provider-edit .btn-danger-outline {
    margin-top: 4px;
}

/* ── AI Usage Dashboard ─────────────────── */
.usage-table-card {
    margin-top: 16px;
}
.usage-table-card .table-wrap {
    overflow-x: auto;
}
.usage-table-card .email-table th.num,
.usage-table-card .email-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.usage-when {
    white-space: nowrap;
    color: var(--ink2);
}
.source-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.source-skill {
    background: var(--info-bg);
    color: var(--info);
}
.source-freeform {
    background: var(--success-bg);
    color: var(--success);
}
.source-auto {
    background: var(--warning-bg);
    color: var(--warning);
}
.ai-meta-provider {
    font-weight: 600;
    color: var(--ink2);
}
.ai-meta-when {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.8rem;
}
.usage-link {
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.usage-link:hover {
    text-decoration: underline;
}

/* ── Quarantine ─────── */
.quarantine-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.q-account {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}
.q-folder {
    font-size: 12px;
    color: var(--ink3);
}
.q-subject {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.q-sender {
    font-size: 12px;
    color: var(--ink3);
}
.q-error {
    font-size: 12px;
    color: var(--danger);
    word-break: break-word;
}
.q-when {
    font-size: 12px;
    color: var(--ink3);
    white-space: nowrap;
}
.q-dismissed-label {
    font-size: 12px;
    color: var(--ink3);
    font-style: italic;
}
.quarantine-dismissed {
    opacity: 0.5;
}

/* ── Collector assignment (Users page) ── */
.collector-assign {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    padding: 8px 0;
}
.collector-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
}

/* ── Stats enhancements ─── */
.stats-range-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.stats-collector-bar,
.collector-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.collector-bar-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-right: 4px;
}
.range-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--ink3);
    cursor: pointer;
    transition: all .15s;
}
.range-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.range-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.priority-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}
.priority-high {
    background: var(--warning-bg);
    color: var(--warning);
}
.priority-critical {
    background: var(--danger-bg);
    color: var(--danger);
}
.sla-pill {
    font-weight: 700;
    font-size: 13px;
}
.sla-detail {
    font-size: 12px;
    color: var(--ink3);
    margin-left: 4px;
}
.section-sub {
    font-size: 12px;
    color: var(--ink3);
    font-weight: 400;
}

/* Trend chart */
.trend-chart {
    padding: 12px 16px 8px;
}
.trend-legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--ink3);
    margin-bottom: 10px;
}
.trend-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}
.trend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.trend-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 120px;
    overflow-x: auto;
}
.trend-day {
    flex: 1;
    min-width: 14px;
    max-width: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    height: 100%;
}
.trend-col {
    flex: 1;
    width: 100%;
    display: flex;
    gap: 1px;
    align-items: flex-end;
    position: relative;
}
.trend-bar {
    flex: 1;
    border-radius: 2px 2px 0 0;
    min-height: 1px;
    transition: height .2s;
}
.trend-bar-in {
    background: var(--info);
    opacity: 0.7;
}
.trend-bar-out {
    background: var(--success);
    opacity: 0.7;
}
.trend-value {
    font-size: 9px;
    font-weight: 600;
    color: var(--muted);
    text-align: center;
    line-height: 1;
    padding-bottom: 2px;
    font-variant-numeric: tabular-nums;
}
.trend-label {
    font-size: 10px;
    color: var(--ink3);
    margin-top: 4px;
    white-space: nowrap;
}

/* ── Full-text search ─────────────────────── */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    max-width: 720px;
}
.search-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--ink);
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px
        rgba(158, 39, 74, 0.12);
}
.search-meta {
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 12px;
}
.search-item {
    border-bottom: 1px solid var(--border);
}
.search-item:last-child {
    border-bottom: none;
}
.search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13.5px;
}
.search-row:hover {
    background: var(--card-head);
}
.search-row.open {
    background: var(--card-head);
    border-bottom: 1px solid var(--border);
}
.search-row.excluded-row {
    opacity: 0.55;
}
.search-subject {
    flex: 1;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.search-sender {
    width: 180px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-date {
    width: 130px;
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 12.5px;
}
.search-conv-link {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.search-conv-link:hover {
    text-decoration: underline;
}
.search-preview {
    padding: 2px 14px 8px 14px;
    font-size: 12.5px;
    line-height: 1.4;
}
.search-conv-wrap {
    padding: 12px 14px 16px 14px;
}
.search-view-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
}
.search-view-toggle button {
    padding: 5px 16px;
    font-size: 12.5px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    cursor: pointer;
}
.search-view-toggle button:first-child {
    border-radius: 6px 0 0 6px;
}
.search-view-toggle button:last-child {
    border-radius: 0 6px 6px 0;
    border-left: none;
}
.search-view-toggle button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.dir-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 4px;
    text-transform: uppercase;
}
.dir-inbound {
    background: rgba(23, 74, 139, 0.1);
    color: var(--info);
}
.dir-outbound {
    background: rgba(31, 122, 77, 0.1);
    color: var(--success);
}
.dir-internal {
    background: var(--border-2);
    color: var(--muted);
}
.col-dir { width: 52px; }
.col-date {
    width: 130px;
    white-space: nowrap;
}
.col-preview {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Calendar ────────────────────────────── */

.cal-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.cal-heading {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    min-width: 180px;
    text-align: center;
}
.cal-today-btn {
    margin-left: auto;
}
.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 10px;
    line-height: 1;
}
.btn-icon:hover {
    background: var(--bg-sub);
}

.cal-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}
.cal-dow {
    background: var(--card);
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 8px 0;
}
.cal-cell {
    background: var(--card);
    min-height: 80px;
    padding: 6px 8px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}
.cal-cell:hover {
    background: var(--bg-sub);
}
.cal-other {
    opacity: 0.35;
}
.cal-today {
    background: var(--danger-bg);
}
.cal-today:hover {
    background: var(--danger-bg);
    filter: brightness(0.95);
}
.cal-selected {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 1;
}
.cal-day-num {
    font-size: 0.85rem;
    font-weight: 500;
}
.cal-today .cal-day-num {
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.cal-in {
    background: var(--primary);
}
.cal-out {
    background: var(--success);
}
.cal-count {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 2px;
}

.cal-detail {
    width: 340px;
    flex-shrink: 0;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}
@media (max-width: 900px) {
    .cal-body {
        flex-direction: column;
    }
    .cal-detail {
        width: 100%;
        position: static;
        max-height: none;
    }
}
.cal-detail-heading {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px 0;
}
.cal-conv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.cal-conv-row:last-child {
    border-bottom: none;
}
.cal-conv-row:hover {
    background: var(--bg-sub);
}
.cal-conv-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.cal-conv-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.cal-msg-count {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}

.cal-event {
    font-size: 0.7rem;
    line-height: 1.3;
    padding: 1px 4px;
    margin-top: 2px;
    border-radius: 3px;
    background: var(--success-bg);
    border-left: 3px solid var(--success);
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-more {
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 1px;
    padding-left: 4px;
}
.cal-dots {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: 4px;
}
.cal-section-head {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 8px 14px 4px;
    border-bottom: 1px solid var(--border);
}
.cal-event-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.cal-event-row:last-child {
    border-bottom: none;
}
.cal-event-row.cal-clickable {
    cursor: pointer;
}
.cal-event-row.cal-clickable:hover {
    background: var(--bg-sub);
}
.cal-event-time {
    min-width: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--success);
    padding-top: 1px;
}
.cal-event-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.cal-method {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    background: var(--bg-sub);
    border-radius: 4px;
    padding: 2px 6px;
    align-self: flex-start;
}
.cal-conversations {
    margin-top: 20px;
}
.cal-ev-detail {
    padding: 0;
}
.cal-ev-fields {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.cal-ev-fields td {
    padding: 6px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.cal-ev-label {
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    width: 80px;
}
.cal-allday-badge {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--muted);
    background: var(--bg-sub);
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 8px;
}
.cal-ev-body {
    padding: 14px;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    line-height: 1.5;
    overflow-x: auto;
}
.cal-ev-body .mail-body {
    white-space: pre-wrap;
    font-size: 0.85rem;
    margin: 0;
}
.cal-ev-body .mail-body-html {
    overflow-x: auto;
}

/* ── Knowledge Base ──────────────────────── */
.kb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.kb-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.kb-search-input {
    flex: 1;
}
.kb-add-form {
    margin-bottom: 16px;
}
.kb-add-form .form-row {
    margin-bottom: 10px;
}
.kb-add-form .form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--muted);
}
.kb-add-form .form-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--fg);
}
.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.kb-error {
    color: var(--danger, #e74c3c);
    font-size: 0.85rem;
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(231, 76, 60, 0.08);
    border-radius: 6px;
}
.kb-sources {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.kb-source-card {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}
.kb-source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.kb-source-title {
    font-weight: 600;
    font-size: 0.95rem;
}
.kb-source-status {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
}
.kb-status-pending {
    background: rgba(108, 117, 125, 0.12);
    color: var(--muted);
}
.kb-status-crawling {
    background: rgba(52, 152, 219, 0.12);
    color: #3498db;
}
.kb-status-ready {
    background: rgba(39, 174, 96, 0.12);
    color: #27ae60;
}
.kb-status-error {
    background: rgba(231, 76, 60, 0.12);
    color: #e74c3c;
}
.kb-source-url {
    font-size: 0.85rem;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-source-url a {
    color: var(--accent, #3b82f6);
    text-decoration: none;
}
.kb-source-url a:hover {
    text-decoration: underline;
}
.kb-source-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 8px;
}
.kb-source-client {
    font-weight: 600;
}
.kb-source-actions {
    display: flex;
    gap: 6px;
}
.btn-danger {
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.3);
}
.btn-danger:hover {
    background: rgba(231, 76, 60, 0.08);
}

/* KB search results */
.kb-result {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.kb-result:last-child {
    border-bottom: none;
}
.kb-result-meta {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 4px;
}
.kb-result-score {
    font-weight: 600;
    color: var(--accent, #3b82f6);
}
.kb-result-content {
    font-size: 0.88rem;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Suggested replies */
.kb-reply-card {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    background: var(--bg);
}
.kb-reply-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.kb-reply-subject {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent, #3b82f6);
    text-decoration: none;
}
.kb-reply-subject:hover {
    text-decoration: underline;
}
.kb-reply-conf {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
}
.kb-reply-client {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.kb-reply-body {
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 8px 10px;
    background: rgba(59, 130, 246, 0.04);
    border-radius: 6px;
    margin-bottom: 6px;
    white-space: pre-wrap;
}
.kb-reply-sources {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 8px;
}
.kb-reply-actions {
    display: flex;
    gap: 6px;
}

/* ── KB chunk browser ── */
.kb-chunks-list {
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}
.kb-chunks-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.kb-chunk-item {
    padding: 8px 10px;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
}
.kb-chunk-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted, #777);
    margin-bottom: 4px;
}
.kb-chunk-idx {
    font-weight: 600;
    color: var(--accent, #3b82f6);
}
.kb-chunk-title {
    font-weight: 500;
}
.kb-chunk-url {
    margin-left: auto;
}
.kb-chunk-content {
    font-size: 0.88rem;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.45;
}

/* ── Watchlist page ── */
.wl-header-actions {
    display: flex;
    gap: 8px;
}
.wl-group-form {
    margin-bottom: 16px;
}
.wl-missed {
    border-color: var(--danger, #e74c3c);
}
.wl-missed-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger, #e74c3c);
    margin-right: 6px;
}
.wl-entries {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.wl-entry {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
}
.wl-entry.wl-waiting {
    border-left: 3px solid
        var(--danger, #e74c3c);
}
.wl-entry-main {
    flex: 1;
    min-width: 0;
}
.wl-subject {
    font-weight: 600;
    color: var(--text);
}
.wl-entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted, #777);
    margin-top: 2px;
}
.wl-client {
    font-weight: 500;
}
.wl-status {
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.wl-status-waiting_us {
    background: #fde2e2;
    color: #b91c1c;
}
.wl-status-waiting_client {
    background: #dbeafe;
    color: #1d4ed8;
}
.wl-status-answered {
    background: #d1fae5;
    color: #065f46;
}
.wl-mine {
    color: var(--accent, #3b82f6);
    font-weight: 500;
}
.wl-source {
    font-style: italic;
}
.wl-subject-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.wl-open-link {
    font-size: 0.78rem;
    color: var(--primary, #9E274A);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.wl-open-link:hover {
    text-decoration: underline;
}
.wl-summary-preview {
    padding: 8px 16px 12px 16px;
    background: var(--bg, #f4f4f5);
    border-top: 1px solid
        var(--border, #e0e0e0);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted, #555);
}
.wl-summary-text {
    margin: 0;
}
.wl-summary-loading {
    font-style: italic;
    color: var(--text-muted, #999);
}
.wl-entry-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.btn-close-conv {
    color: #666;
    border-color: #ccc;
}
.btn-close-conv:hover {
    background: #dc3545;
    color: #fff;
    border-color: #dc3545;
}
.wl-group-select {
    max-width: 140px;
    font-size: 0.82rem;
    padding: 2px 6px;
}

.wl-settings-groups {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.wl-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--surface-dim, #f3f3f3);
    border-radius: 6px;
    font-size: 0.88rem;
}

/* ── Watchlist digest card ── */
.wl-digest {
    border-color: var(--accent, #3b82f6);
    background: var(--surface, #fff);
}
.wl-digest .card-heading {
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.wl-digest-date {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--muted, #888);
}
.wl-digest-summary {
    font-size: 0.92rem;
    line-height: 1.55;
    margin: 8px 0 12px;
    white-space: pre-line;
}
.wl-digest-stats {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--muted, #888);
}
.wl-digest-stat {
    padding: 3px 8px;
    background: var(--surface-dim, #f3f3f3);
    border-radius: 4px;
}
.wl-digest-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background 0.15s;
}
.wl-digest-link:hover {
    background: var(--hover-bg, #e8e8e8);
    color: var(--accent, crimson);
}

/* ── Client search dropdown ── */
.wl-client-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 240px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    z-index: 10;
    margin-top: 2px;
}
.wl-client-option {
    padding: 6px 10px;
    font-size: 0.88rem;
    cursor: pointer;
}
.wl-client-option:hover {
    background: var(--surface-dim, #f3f3f3);
}

/* ── Collapsible group headers ── */
.wl-collapse-hdr {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.wl-chevron {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid
        var(--muted, #888);
    transition: transform 0.15s ease;
    flex-shrink: 0;
}
.wl-chevron-open {
    transform: rotate(90deg);
}

/* ── Watched client cards ── */
.wl-client-watch {
    border-left: 3px solid
        var(--accent, #3b82f6);
}

/* ── Suggested replies on conversation detail ── */
.suggested-replies {
    margin: 12px 0;
    border: 1px solid var(--accent, #3b82f6);
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--bg);
}
.suggested-reply-card {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 8px;
    background: var(--surface, #fff);
}
.sr-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}
.sr-confidence {
    font-weight: 700;
    color: var(--accent, #3b82f6);
}
.sr-sources {
    cursor: help;
    border-bottom: 1px dotted var(--muted);
}
.sr-body {
    white-space: pre-wrap;
    font-size: 0.92rem;
    line-height: 1.5;
    margin-bottom: 8px;
    max-height: 300px;
    overflow-y: auto;
}
.sr-actions {
    display: flex;
    gap: 6px;
}
