/* ============================================================
   PSDSARC SAR Dashboard — Design System
   Tokens → Primitives → Layout → Components → Views → Utilities
   ============================================================ */

/* ─── 1. Design tokens ──────────────────────────────────────── */
:root {
    /* Spacing (4-pt scale) */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

    /* Type scale */
    --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-base: 14px;
    --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 24px;
    --lh-tight: 1.3; --lh-normal: 1.5; --lh-loose: 1.65;
    --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700; --fw-black: 800;

    /* Radius */
    --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 12px; --r-pill: 999px;

    /* Motion */
    --t-fast: 120ms; --t-base: 180ms; --t-slow: 240ms;
    --ease: cubic-bezier(.4,0,.2,1);

    /* Layout */
    --sidebar-w: 240px;
    --sidebar-w-collapsed: 64px;
    --topbar-h: 56px;

    /* Color — dark theme (default) */
    --bg:           #0b1020;
    --bg-elev-1:    #111933;
    --surface:      #141d3a;
    --surface-2:    #1a2547;
    --border:       #243155;
    --border-strong:#2f3e6e;
    --text:         #e8ecf5;
    --text-muted:   #a3acc7;
    --text-faint:   #7681a3;
    --text-subtle:  #5a6485;

    --accent:       #7aa2ff;
    --accent-strong:#3b6dff;
    --accent-hover: #2a55e0;
    --accent-soft:  rgba(59,109,255,.16);
    --focus-ring:   rgba(122,162,255,.45);

    --sev-normal:    #2dd4bf;
    --sev-normal-bg: rgba(45,212,191,.15);
    --sev-normal-fg: #5eead4;

    --sev-attention:    #fbbf24;
    --sev-attention-bg: rgba(251,191,36,.16);
    --sev-attention-fg: #fcd34d;

    --sev-critical:    #f43f5e;
    --sev-critical-bg: rgba(244,63,94,.18);
    --sev-critical-fg: #fda4af;

    --good:    #22c55e;
    --good-bg: rgba(34,197,94,.16);
    --good-fg: #86efac;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,.35);
    --shadow-lg: 0 18px 40px rgba(0,0,0,.5);
}

[data-theme="light"] {
    --bg:           #f4f6fb;
    --bg-elev-1:    #ffffff;
    --surface:      #ffffff;
    --surface-2:    #f8fafc;
    --border:       #e4e8f0;
    --border-strong:#cdd5e2;
    --text:         #0f172a;
    --text-muted:   #475569;
    --text-faint:   #64748b;
    --text-subtle:  #94a3b8;

    --accent:       #2563eb;
    --accent-strong:#2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft:  rgba(37,99,235,.10);
    --focus-ring:   rgba(37,99,235,.35);

    --sev-normal-bg: #d1fae5;
    --sev-normal-fg: #065f46;
    --sev-attention-bg: #fef3c7;
    --sev-attention-fg: #92400e;
    --sev-critical-bg: #fee2e2;
    --sev-critical-fg: #991b1b;
    --good-bg: #d1fae5;
    --good-fg: #065f46;

    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow-md: 0 4px 14px rgba(15,23,42,.08);
    --shadow-lg: 0 18px 40px rgba(15,23,42,.14);
}

/* ─── 2. Reset & base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    transition: background-color var(--t-base) var(--ease), color var(--t-base) var(--ease);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--r-sm); }

/* ─── 3. App shell ──────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns var(--t-slow) var(--ease);
}
.app-shell:has(.sidebar.collapsed) {
    grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
}

/* ─── 4. Sidebar ────────────────────────────────────────────── */
.sidebar {
    grid-column: 1;
    background: var(--bg-elev-1);
    border-right: 1px solid var(--border);
    position: sticky; top: 0;
    height: 100vh;
    display: flex; flex-direction: column;
    overflow: hidden;
}

.sidebar-brand {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-4);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-h);
}
.brand-mark {
    width: 32px; height: 32px; flex: none;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff; font-weight: var(--fw-bold); font-size: var(--fs-md);
    box-shadow: 0 2px 8px rgba(59,109,255,.4);
}
.brand-text {
    display: flex; flex-direction: column; line-height: 1.15;
    font-size: var(--fs-md); font-weight: var(--fw-bold);
    color: var(--text); letter-spacing: .3px;
    white-space: nowrap;
}
.brand-text small {
    font-size: 10px; font-weight: var(--fw-medium);
    color: var(--text-faint);
    letter-spacing: 1.2px; text-transform: uppercase;
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1; overflow-y: auto;
    padding: var(--sp-3) var(--sp-2);
    display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
    display: flex; align-items: center; gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-3);
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    text-align: left;
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
    white-space: nowrap;
}
.nav-item:visited { color: var(--text-muted); }
.nav-item:focus { outline: none; }
.nav-item:focus-visible { box-shadow: 0 0 0 2px var(--focus-ring); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon {
    width: 22px; flex: none;
    text-align: center;
    font-size: var(--fs-base);
    opacity: .9;
}
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
    background: var(--surface-2);
    color: var(--text-muted);
    padding: 1px var(--sp-2);
    border-radius: var(--r-pill);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    min-width: 22px; text-align: center;
}
.nav-item.active .nav-badge { background: var(--accent-strong); color: #fff; }

/* Sidebar footer — system stats */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: var(--sp-3);
    display: flex; flex-direction: column; gap: var(--sp-3);
}
.sidebar-stats {
    display: flex; flex-direction: column; gap: var(--sp-2);
}
.stat-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-2);
    font-size: var(--fs-xs);
}
.stat-label {
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .8px;
    font-weight: var(--fw-bold);
}
.stat-val {
    color: var(--text);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
}

/* Collapsed sidebar */
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-stats { display: none; }
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-footer { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; padding: var(--sp-3) 0; }
.sidebar.collapsed .nav-item.active { box-shadow: none; background: var(--accent-soft); }

/* ─── 5. Main area & topbar ─────────────────────────────────── */
.main-area {
    grid-column: 2;
    min-width: 0;
    display: flex; flex-direction: column;
}
.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: var(--sp-4);
    padding: 0 var(--sp-6);
    background: var(--bg-elev-1);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}
.sidebar-toggle {
    width: 36px; height: 36px;
    border-radius: var(--r-md);
    color: var(--text-muted);
    display: grid; place-items: center;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }

.topbar-title {
    flex: 1;
    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    color: var(--text);
    letter-spacing: .2px;
}
.topbar-right {
    display: flex; align-items: center; gap: var(--sp-4);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}

/* ─── 6. Theme toggle ───────────────────────────────────────── */
.theme-toggle {
    height: 34px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text-muted);
    display: grid; place-items: center;
    font-size: var(--fs-base);
    transition: all var(--t-fast) var(--ease);
}
.theme-toggle:hover { background: var(--surface); color: var(--text); border-color: var(--accent); }
.sidebar.collapsed .theme-toggle { width: 34px; }

/* ─── 7. Layout grid ────────────────────────────────────────── */
.tab-panel { animation: fadein var(--t-base) var(--ease); }
.tab-panel.hidden { display: none; }
.tabs { display: none; } /* legacy */

@keyframes fadein {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

.main-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--sp-4);
    padding: var(--sp-6);
}
.row-monitor {
    grid-template-rows: auto auto auto;
    grid-auto-rows: auto;
    align-items: start;
}

/* ─── 8. Panel (card primitive) ─────────────────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}
.panel h2 {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding-bottom: var(--sp-3);
    margin-bottom: var(--sp-4);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-2);
}
.panel h3 {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .8px;
    margin: var(--sp-4) 0 var(--sp-2);
}

/* Panel placement (monitor view) */
.panel-feed      { grid-column: 1; grid-row: 1; }
.panel-ai        { grid-column: 2; grid-row: 1; }
.panel-controls  { grid-column: 1; grid-row: 2; }
.panel-log       { grid-column: 2; grid-row: 2; }
.panel-operator  { grid-column: 1; grid-row: 3; }
.panel-incidents { grid-column: 2; grid-row: 3; }
.panel-memory    { display: none; }
.panel-alerts    { grid-column: 1 / -1; }
.panel-ask       { grid-column: 1 / -1; }

/* ─── 9. Live feed ──────────────────────────────────────────── */
.feed-container {
    border-radius: var(--r-lg);
    overflow: hidden;
    background: #000;
    aspect-ratio: 16/9;
}
.feed-container img { width: 100%; height: 100%; object-fit: contain; }

/* ─── 10. AI analysis ───────────────────────────────────────── */
.severity-display {
    text-align: center;
    font-size: var(--fs-lg);
    font-weight: var(--fw-black);
    letter-spacing: 1.5px;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-lg);
    margin-bottom: var(--sp-4);
}
.severity-normal    { background: var(--sev-normal-bg);    color: var(--sev-normal-fg); }
.severity-attention { background: var(--sev-attention-bg); color: var(--sev-attention-fg); }
.severity-critical  { background: var(--sev-critical-bg);  color: var(--sev-critical-fg); animation: pulse 2s infinite; }
.severity-none      { background: var(--surface-2);        color: var(--text-muted); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .6; }
}

.ai-text {
    font-size: var(--fs-base);
    line-height: var(--lh-loose);
    color: var(--text);
}
.ai-reasoning {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    line-height: var(--lh-loose);
    font-style: italic;
    margin-top: var(--sp-3);
    padding-top: var(--sp-3);
    border-top: 1px dashed var(--border);
}
.tool-calls { display: flex; flex-direction: column; gap: var(--sp-1); }
.tool-call {
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-sm);
    padding: var(--sp-2) var(--sp-3);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: var(--fs-sm);
    color: var(--text);
}

/* ─── 11. Action log ────────────────────────────────────────── */
.log-list { max-height: 300px; overflow-y: auto; }
.log-entry {
    display: flex; align-items: baseline; gap: var(--sp-3);
    padding: var(--sp-2) 0;
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--border);
}
.log-entry:last-child { border-bottom: none; }
.log-time {
    color: var(--text-faint);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: var(--fs-xs);
    flex-shrink: 0;
}

/* ─── 12. Incidents ─────────────────────────────────────────── */
.gallery {
    display: flex; flex-direction: column; gap: var(--sp-2);
    max-height: 360px; overflow-y: auto;
}
.incident-card {
    background: var(--surface-2);
    padding: var(--sp-3);
    border-radius: var(--r-md);
    border-left: 3px solid var(--text-subtle);
    font-size: var(--fs-sm);
}
.incident-attention { border-left-color: var(--sev-attention); }
.incident-critical  { border-left-color: var(--sev-critical); }
.incident-normal    { border-left-color: var(--sev-normal); }
.incident-time {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    color: var(--text-faint);
    font-size: var(--fs-xs);
}
.incident-type {
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: .6px;
    font-size: var(--fs-xs);
    color: var(--text);
    margin: var(--sp-1) 0 var(--sp-2);
}

/* ─── 13. Operator instructions ─────────────────────────────── */
.instructions {
    display: flex; flex-direction: column; gap: var(--sp-2);
    max-height: 220px; overflow-y: auto;
    margin-bottom: var(--sp-3);
    padding-right: var(--sp-2);
}
.instruction-item {
    background: var(--accent-soft);
    color: var(--accent);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    line-height: var(--lh-normal);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-family: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    border-left: 3px solid var(--accent);
}
#instruction-form, #ask-form {
    display: flex; gap: var(--sp-2); align-items: stretch;
}

/* ─── 14. Form controls ─────────────────────────────────────── */
input[type="text"], select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-3);
    font-size: var(--fs-md);
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input[type="text"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
input[type="text"]::placeholder { color: var(--text-faint); }
#instruction-input, #ask-input { flex: 1; }

/* Buttons */
.btn,
#instruction-form button,
#ask-form button {
    padding: 0 var(--sp-5);
    height: 38px;
    background: var(--accent-strong);
    color: #fff;
    border-radius: var(--r-md);
    font-weight: var(--fw-semibold);
    font-size: var(--fs-md);
    transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover,
#instruction-form button:hover,
#ask-form button:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface); border-color: var(--border-strong); }

/* ─── 15. Badges ────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px var(--sp-2);
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: .6px;
    line-height: 1.4;
}
.badge-connected     { background: var(--good-bg);          color: var(--good-fg); }
.badge-disconnected  { background: var(--sev-critical-bg);  color: var(--sev-critical-fg); }
.badge-normal,
.badge-none          { background: var(--sev-normal-bg);    color: var(--sev-normal-fg); }
.badge-attention     { background: var(--sev-attention-bg); color: var(--sev-attention-fg); }
.badge-critical      { background: var(--sev-critical-bg);  color: var(--sev-critical-fg); animation: pulse 2s infinite; }

/* ─── 16. Alerts archive ────────────────────────────────────── */
.alerts-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: var(--sp-3);
    margin-bottom: var(--sp-4);
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}
.alerts-header h2 { border: none; padding: 0; margin: 0; }
.alerts-controls { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.alerts-controls input[type="text"] { width: 240px; }
.alerts-controls button {
    height: 38px;
    padding: 0 var(--sp-4);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    transition: all var(--t-fast) var(--ease);
}
.alerts-controls button:hover { background: var(--surface); border-color: var(--border-strong); }

.alerts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--sp-4);
}
.alert-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
}
.alert-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
}
.alert-card.sev-critical  { border-top: 3px solid var(--sev-critical); }
.alert-card.sev-attention { border-top: 3px solid var(--sev-attention); }
.alert-card.sev-normal    { border-top: 3px solid var(--sev-normal); }

.alert-thumb {
    aspect-ratio: 16/9;
    background: #000;
    position: relative;
}
.alert-thumb img { width: 100%; height: 100%; object-fit: cover; }
.alert-thumb .no-frame {
    width: 100%; height: 100%;
    display: grid; place-items: center;
    color: var(--text-faint);
    background: var(--bg);
    font-size: var(--fs-sm);
}
.alert-thumb-id {
    position: absolute; top: var(--sp-2); left: var(--sp-2);
    background: rgba(0,0,0,.7);
    color: #fff;
    padding: 2px var(--sp-2);
    border-radius: var(--r-pill);
    font-size: 10px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    backdrop-filter: blur(4px);
}

.alert-info { padding: var(--sp-3); font-size: var(--fs-sm); }
.alert-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: var(--sp-2);
}
.alert-sev {
    font-weight: var(--fw-bold);
    font-size: 10px;
    letter-spacing: .8px;
    padding: 2px var(--sp-2);
    border-radius: var(--r-pill);
}
.sev-critical .alert-sev  { background: var(--sev-critical-bg);  color: var(--sev-critical-fg); }
.sev-attention .alert-sev { background: var(--sev-attention-bg); color: var(--sev-attention-fg); }
.sev-normal .alert-sev    { background: var(--sev-normal-bg);    color: var(--sev-normal-fg); }
.alert-time {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    color: var(--text-faint);
    font-size: var(--fs-xs);
}
.alert-tool {
    color: var(--text-muted);
    font-size: var(--fs-xs);
    margin-bottom: var(--sp-1);
}
.alert-msg {
    color: var(--text);
    line-height: var(--lh-normal);
    min-height: 36px;
}
.alert-channels {
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
    border-top: 1px solid var(--border);
    font-size: var(--fs-base);
}

/* ─── 17. Ask the agent (chat) ──────────────────────────────── */
.chat-container {
    display: flex; flex-direction: column;
    gap: var(--sp-3);
    height: min(70vh, 720px);
}
.chat-suggestions {
    display: flex; flex-wrap: wrap; gap: var(--sp-2);
}
.chip {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
}
.chip:hover {
    background: var(--accent-strong);
    color: #fff;
    border-color: var(--accent-strong);
}

.chat-history {
    flex: 1;
    display: flex; flex-direction: column; gap: var(--sp-3);
    overflow-y: auto;
    padding: var(--sp-2);
}
.chat-msg {
    max-width: 78%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-xl);
    font-size: var(--fs-base);
    line-height: var(--lh-loose);
    word-wrap: break-word;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--accent-strong);
    color: #fff;
    border-bottom-right-radius: var(--r-sm);
}
.chat-msg.bot {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: var(--r-sm);
}
.chat-msg.bot.thinking { color: var(--text-muted); font-style: italic; }
.chat-msg ul { margin: var(--sp-2) 0 var(--sp-2) var(--sp-5); }
.chat-msg li { margin: var(--sp-1) 0; }
.chat-msg p + p { margin-top: var(--sp-2); }
.chat-msg strong { color: var(--text); font-weight: var(--fw-semibold); }
.chat-msg.user strong { color: #fff; }
.chat-msg code {
    background: rgba(255,255,255,.12);
    padding: 1px 6px;
    border-radius: var(--r-sm);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: .92em;
}
.chat-citations { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-2); }
.citation-chip {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 2px var(--sp-2);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
}
.citation-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── 18. Modal ─────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(6px);
    display: grid; place-items: center;
    z-index: 1000;
    animation: fadein var(--t-base) var(--ease);
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    max-width: min(90vw, 1100px);
    max-height: 90vh;
    overflow: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}
.modal-close {
    position: absolute; top: var(--sp-3); right: var(--sp-4);
    color: var(--text-muted);
    font-size: 26px;
    line-height: 1;
    width: 32px; height: 32px;
    border-radius: var(--r-md);
    z-index: 10;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body {
    display: flex; gap: var(--sp-6);
    padding: var(--sp-6);
}
.modal-body img {
    max-width: 700px;
    max-height: 70vh;
    border-radius: var(--r-lg);
    background: #000;
}
.modal-meta {
    flex: 1; min-width: 240px;
    font-size: var(--fs-base);
}
.modal-meta p { line-height: var(--lh-loose); margin: var(--sp-2) 0; }
.modal-channels {
    margin-top: var(--sp-4);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: var(--sp-5);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
.modal-channels strong { color: var(--text); }

/* ─── 19. Utilities ─────────────────────────────────────────── */
.dim { color: var(--text-muted); }
.empty {
    color: var(--text-faint);
    font-style: italic;
    font-size: var(--fs-md);
    padding: var(--sp-5);
    text-align: center;
}
.hidden { display: none !important; }
pre.memory-text {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    white-space: pre-wrap;
}

/* ─── 20. Scrollbars ────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ─── 21. Responsive ────────────────────────────────────────── */
@media (max-width: 1200px) {
    .main-grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
}
@media (max-width: 1024px) {
    .app-shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
    .sidebar:not(.expanded) .brand-text,
    .sidebar:not(.expanded) .nav-label,
    .sidebar:not(.expanded) .nav-badge,
    .sidebar:not(.expanded) .sidebar-stats { display: none; }
    .sidebar:not(.expanded) .nav-item { justify-content: center; padding: var(--sp-3) 0; }

    .main-grid {
        grid-template-columns: minmax(0, 1fr);
        padding: var(--sp-4);
    }
    .panel-feed, .panel-ai, .panel-log,
    .panel-operator, .panel-incidents,
    .panel-alerts, .panel-ask {
        grid-column: 1; grid-row: auto;
    }
}
@media (max-width: 640px) {
    :root { --sidebar-w-collapsed: 56px; --topbar-h: 52px; }
    .main-grid { padding: var(--sp-3); gap: var(--sp-3); }
    .panel { padding: var(--sp-4); }
    .modal-body { flex-direction: column; padding: var(--sp-4); }
    .modal-body img { max-width: 100%; }
    .alerts-controls input[type="text"] { width: 100%; }
    .topbar { padding: 0 var(--sp-4); gap: var(--sp-3); }
    .topbar-title { font-size: var(--fs-base); }
}

/* ─── Settings: source picker ─────────────────────────────── */
.source-tabs {
    display: flex; flex-wrap: wrap; gap: var(--sp-2);
    margin: var(--sp-4) 0 var(--sp-4) 0;
}
.source-tab {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--fs-md); font-weight: var(--fw-medium);
    cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast);
}
.source-tab:hover { background: var(--surface-2); }
.source-tab.active {
    background: var(--accent-soft); border-color: var(--accent);
    color: var(--accent);
}
.form-group { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.form-group label { font-size: var(--fs-sm); color: var(--text-muted); font-weight: var(--fw-medium); }
.form-input {
    background: var(--bg-elev-1); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4); font-size: var(--fs-base);
    width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.source-hint { font-size: var(--fs-xs); color: var(--text-faint); }
.source-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-3); }
.btn-primary {
    background: var(--accent-strong); color: white;
    border: none; border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-5); font-weight: var(--fw-semibold);
    cursor: pointer; font-size: var(--fs-base);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
    background: transparent; color: var(--text-muted);
    border: 1px solid var(--border); border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-5); cursor: pointer; font-size: var(--fs-base);
}
.btn-secondary:hover { color: var(--text); border-color: var(--border-strong); }
.source-status {
    margin-top: var(--sp-3); font-size: var(--fs-sm);
    padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
    min-height: 28px;
}
.source-status.ok      { background: var(--sev-normal-bg);    color: var(--sev-normal-fg); }
.source-status.pending { background: var(--accent-soft);      color: var(--accent); }
.source-status.error   { background: var(--sev-critical-bg);  color: var(--sev-critical-fg); }
.source-current code {
    background: var(--bg-elev-1); padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-md); font-size: var(--fs-sm); color: var(--text);
    border: 1px solid var(--border); display: inline-block;
}
.source-presets { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.source-presets .chip { cursor: pointer; }

/* ─── Agent page: image attachment ───────────────────────── */
.ask-form {
    display: flex; align-items: center; gap: var(--sp-2);
}
.ask-attach {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex-shrink: 0;
    border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface); cursor: pointer;
    font-size: 18px; user-select: none;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.ask-attach:hover { background: var(--surface-2); border-color: var(--border-strong); }
.ask-image-preview {
    display: flex; align-items: center; gap: var(--sp-3);
    margin: var(--sp-2) 0;
    padding: var(--sp-2) var(--sp-3);
    background: var(--bg-elev-1);
    border: 1px solid var(--border); border-radius: var(--r-md);
}
.ask-image-preview img {
    height: 56px; width: 56px; object-fit: cover; border-radius: var(--r-sm);
}
.ask-image-preview button {
    background: transparent; border: none; color: var(--text-muted);
    font-size: 18px; cursor: pointer; margin-left: auto;
}
.ask-image-preview button:hover { color: var(--sev-critical); }
.chat-image {
    display: block; max-width: 320px; max-height: 240px;
    border-radius: var(--r-md); margin-bottom: var(--sp-2);
}

/* ─── Settings: video file picker row ─────────────────────── */
.file-picker-row { display: flex; gap: var(--sp-2); align-items: stretch; }
.file-picker-row .form-input { flex: 1; }
.file-picker-row .btn-secondary { padding: 0 var(--sp-4); flex-shrink: 0; }

/* ─── Live Monitor: feed controls ─────────────────────────── */
.feed-controls {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: var(--sp-2);
    margin-top: var(--sp-3);
}
.feed-btn {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-md);
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--fs-sm); font-weight: var(--fw-medium);
    cursor: pointer; text-decoration: none;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.feed-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.feed-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.feed-btn-ghost { background: transparent; color: var(--text-muted); }
.feed-upload { cursor: pointer; }
.feed-status {
    margin-left: auto;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    padding: var(--sp-1) var(--sp-2);
    border-radius: var(--r-sm);
}
.feed-status.ok      { color: var(--sev-normal-fg); }
.feed-status.pending { color: var(--accent); }
.feed-status.error   { color: var(--sev-critical-fg); }

/* ─── Settings: upload widget ─────────────────────────────── */
.settings-upload {
    display: flex; align-items: center; gap: var(--sp-3);
    margin-top: var(--sp-3);
    padding: var(--sp-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    background: var(--bg-elev-1);
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.settings-upload:hover, .settings-upload.dragging {
    background: var(--surface-2); border-color: var(--accent);
}
.settings-upload-icon { font-size: 22px; }
.settings-upload-text { font-size: var(--fs-sm); color: var(--text-muted); }
.settings-upload-options {
    display: flex; align-items: center; gap: var(--sp-2);
    margin-top: var(--sp-2);
    font-size: var(--fs-sm); color: var(--text-muted);
}

/* ─── Help tooltips ─────────────────────────────────────────── */
.help-tip {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; flex-shrink: 0;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-faint);
    font-size: 10px; font-weight: var(--fw-bold);
    cursor: help;
    margin-left: var(--sp-2);
    position: relative;
    text-transform: none; letter-spacing: 0;
    border: 1px solid var(--border);
    transition: background var(--t-fast), color var(--t-fast);
}
.help-tip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.help-tip::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    max-width: 340px;
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-elev-1);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    font-size: var(--fs-xs);
    font-weight: var(--fw-regular);
    line-height: var(--lh-normal);
    letter-spacing: normal;
    text-transform: none;
    white-space: normal;
    opacity: 0; pointer-events: none;
    transform: translateY(-4px);
    transition: opacity var(--t-fast), transform var(--t-fast);
    z-index: 50;
}
.help-tip:hover::after, .help-tip:focus::after {
    opacity: 1; transform: translateY(0);
}

/* ─── Live Monitor: stream-controls panel ─────────────────── */
.panel-controls .controls-row {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: var(--sp-2);
}
.panel-controls .controls-row + .controls-row { margin-top: var(--sp-3); }
.panel-controls .controls-picker .form-input { flex: 1; min-width: 200px; }
.panel-controls .controls-label {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-weight: var(--fw-medium);
}
.panel-controls .feed-status {
    margin-top: var(--sp-3);
    display: block;
}

/* Tighter feed panel — kill the gap below the image */
.panel-feed { display: flex; flex-direction: column; }
.panel-feed .feed-container { margin-top: 0; }

/* ─── Operator Instructions: mission picker ───────────────── */
.mission-row {
    display: flex; align-items: center; gap: var(--sp-3);
    margin-bottom: var(--sp-2);
}
.mission-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
}
.mission-row .form-input { flex: 1; }
.mission-description {
    font-size: var(--fs-xs);
    color: var(--text-faint);
    margin-bottom: var(--sp-3);
    font-style: italic;
    min-height: 16px;
}

/* ─── Sidebar: account row (theme + logout) ───────────────── */
.sidebar-account {
    display: flex; gap: var(--sp-2); align-items: stretch;
}
.sidebar-account .theme-toggle,
.sidebar-account .logout-btn {
    flex: 1;
}
.logout-btn {
    display: inline-flex; align-items: center; justify-content: center;
    text-decoration: none;
}

/* ─── Public pages (landing + login) ──────────────────────── */
.public-page {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
.public-nav {
    position: sticky; top: 0; z-index: 50;
    background: rgba(11, 16, 32, .72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
[data-theme="light"] .public-nav { background: rgba(244, 246, 251, .82); }
.public-nav-inner {
    max-width: 1100px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-4) var(--sp-6);
}
.public-brand {
    display: flex; align-items: center; gap: var(--sp-3);
    text-decoration: none;
}
.public-nav-links {
    display: flex; align-items: center; gap: var(--sp-5);
}
.public-nav-links a {
    color: var(--text-muted); text-decoration: none;
    font-size: var(--fs-sm); font-weight: var(--fw-medium);
    transition: color var(--t-fast);
}
.public-nav-links a:hover { color: var(--text); }
.public-cta {
    background: var(--accent-strong); color: #fff !important;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-md);
    font-weight: var(--fw-semibold);
}
.public-cta:hover { background: var(--accent-hover); }

.public-main { max-width: 1100px; margin: 0 auto; padding: var(--sp-10) var(--sp-6); }

.hero { text-align: center; padding: var(--sp-10) 0; }
.hero-eyebrow {
    display: inline-block;
    font-size: var(--fs-xs); font-weight: var(--fw-bold);
    text-transform: uppercase; letter-spacing: 2px;
    color: var(--accent);
    background: var(--accent-soft);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-pill);
    margin-bottom: var(--sp-6);
}
.hero-title {
    font-size: clamp(32px, 5vw, 56px);
    line-height: 1.1;
    font-weight: var(--fw-bold);
    letter-spacing: -.02em;
    margin: 0 auto var(--sp-5);
    max-width: 820px;
}
.hero-title em {
    font-style: normal;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero-lede {
    font-size: var(--fs-lg);
    color: var(--text-muted);
    max-width: 680px;
    margin: 0 auto var(--sp-8);
    line-height: var(--lh-loose);
}
.hero-actions {
    display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap;
}
.hero-actions .btn-primary,
.hero-actions .btn-secondary {
    padding: var(--sp-3) var(--sp-6);
    font-size: var(--fs-base);
    text-decoration: none;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--sp-5);
    margin: var(--sp-10) 0;
}
.feature-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--sp-6);
    transition: border-color var(--t-base), transform var(--t-base);
}
.feature-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.feature-icon {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: var(--fs-xl);
    margin-bottom: var(--sp-4);
}
.feature-card h3 {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--sp-2);
}
.feature-card p {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    line-height: var(--lh-loose);
}
.feature-card code {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: var(--fs-xs);
    background: var(--bg-elev-1);
    padding: 1px 6px;
    border-radius: var(--r-sm);
}

.tech-strip, .about-strip {
    text-align: center;
    padding: var(--sp-8) 0;
    border-top: 1px solid var(--border);
}
.tech-strip h2, .about-strip h2 {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: var(--sp-5);
}
.tech-chips {
    display: flex; flex-wrap: wrap; gap: var(--sp-2);
    justify-content: center;
}
.tech-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-pill);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
}
.about-strip p {
    color: var(--text-muted);
    max-width: 640px;
    margin: 0 auto;
    line-height: var(--lh-loose);
}

.public-footer {
    max-width: 1100px; margin: 0 auto;
    padding: var(--sp-6);
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
    gap: var(--sp-3);
    border-top: 1px solid var(--border);
    font-size: var(--fs-xs);
    color: var(--text-faint);
}
.public-footer a { color: var(--accent); text-decoration: none; }

/* ─── Login page ─────────────────────────────────────────── */
.login-page {
    display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(ellipse at top, var(--accent-soft) 0%, transparent 50%),
        var(--bg);
}
.login-shell {
    width: 100%; max-width: 420px;
    padding: var(--sp-6);
    display: flex; flex-direction: column; align-items: center; gap: var(--sp-6);
}
.login-brand {
    text-decoration: none;
}
.login-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--sp-8);
    display: flex; flex-direction: column; gap: var(--sp-3);
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    margin-bottom: 0;
}
.login-card p { margin-bottom: var(--sp-3); }
.login-card label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: var(--sp-2);
}
.login-card input {
    background: var(--bg-elev-1);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--fs-base);
}
.login-card input:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.login-error {
    background: var(--sev-critical-bg);
    color: var(--sev-critical-fg);
    border-radius: var(--r-md);
    padding: var(--sp-3);
    font-size: var(--fs-sm);
}
.login-submit {
    margin-top: var(--sp-3);
    padding: var(--sp-3);
    font-size: var(--fs-base);
}
.login-back {
    text-align: center;
    font-size: var(--fs-sm);
    text-decoration: none;
    margin-top: var(--sp-3);
}
.login-back:hover { color: var(--accent); }

/* ─── Alert Archive: view tabs + grouped layout ───────────── */
.alerts-view-tabs {
    display: flex; gap: var(--sp-1);
    margin-bottom: var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.alerts-view-tab {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: var(--sp-3) var(--sp-5);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    display: inline-flex; align-items: center; gap: var(--sp-2);
    transition: color var(--t-fast), border-color var(--t-fast);
}
.alerts-view-tab:hover { color: var(--text); }
.alerts-view-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.alerts-view-tab .tab-count {
    background: var(--surface-2);
    color: var(--text-muted);
    padding: 1px var(--sp-2);
    border-radius: var(--r-pill);
    font-size: var(--fs-xs);
    min-width: 22px; text-align: center;
}
.alerts-view-tab.active .tab-count {
    background: var(--accent-strong);
    color: #fff;
}

.alerts-groups {
    display: flex; flex-direction: column; gap: var(--sp-6);
}
.alerts-group {
    border-left: 3px solid var(--border-strong);
    padding-left: var(--sp-4);
}
.alerts-group.sev-critical  { border-left-color: var(--sev-critical); }
.alerts-group.sev-attention { border-left-color: var(--sev-attention); }
.alerts-group.sev-normal    { border-left-color: var(--sev-normal); }

.alerts-group-head {
    display: flex; align-items: center; gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
.alerts-group-sev {
    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
    letter-spacing: 1.2px;
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--r-md);
    text-transform: uppercase;
}
.alerts-group.sev-critical  .alerts-group-sev { background: var(--sev-critical-bg); color: var(--sev-critical-fg); }
.alerts-group.sev-attention .alerts-group-sev { background: var(--sev-attention-bg); color: var(--sev-attention-fg); }
.alerts-group.sev-normal    .alerts-group-sev { background: var(--sev-normal-bg); color: var(--sev-normal-fg); }
.alerts-group-count {
    color: var(--text-faint);
    font-size: var(--fs-sm);
}

.alerts-subgroup { margin-bottom: var(--sp-4); }
.alerts-subgroup:last-child { margin-bottom: 0; }
.alerts-subgroup-head {
    display: flex; align-items: center; gap: var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .8px;
    margin-bottom: var(--sp-3);
}
.alerts-subgroup-count {
    background: var(--surface-2);
    color: var(--text-muted);
    padding: 1px var(--sp-2);
    border-radius: var(--r-pill);
    font-size: 10px;
}

/* No-image cards: tighter layout, no big image placeholder */
.alert-card-noimage .alert-thumb {
    width: 60px; height: 60px;
    flex-shrink: 0;
}
.alert-card-noimage .no-frame {
    width: 60px; height: 60px;
    display: grid; place-items: center;
    background: var(--bg-elev-1);
    border: 1px dashed var(--border);
    border-radius: var(--r-md);
    color: var(--text-faint);
    font-size: 9px;
    text-align: center;
    padding: var(--sp-1);
}
.alert-card-noimage .alert-thumb-id {
    font-size: 10px;
}

/* ─── Chat: inline image evidence ─────────────────────────── */
.chat-evidence {
    display: flex; flex-wrap: wrap; gap: var(--sp-3);
    margin-top: var(--sp-3);
}
.evidence-card {
    width: 140px;
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--t-fast), border-color var(--t-fast);
}
.evidence-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}
.evidence-card.sev-critical  { box-shadow: inset 0 0 0 2px var(--sev-critical); }
.evidence-card.sev-attention { box-shadow: inset 0 0 0 2px var(--sev-attention); }
.evidence-card img {
    display: block;
    width: 100%; height: 100px;
    object-fit: cover;
}
.evidence-meta {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-xs);
}
.evidence-id {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    color: var(--text);
    font-weight: var(--fw-semibold);
}
.evidence-sev {
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: var(--fw-bold);
}
.evidence-card.sev-critical  .evidence-sev { color: var(--sev-critical-fg); }
.evidence-card.sev-attention .evidence-sev { color: var(--sev-attention-fg); }

/* ─── Settings: recipients ────────────────────────────────── */
.recipients-list {
    display: flex; flex-direction: column; gap: var(--sp-2);
    margin: var(--sp-4) 0 var(--sp-3);
}
.recipient-row {
    display: flex; align-items: center; gap: var(--sp-3);
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
}
.recipient-icon { color: var(--text-faint); font-size: var(--fs-base); }
.recipient-email {
    flex: 1;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: var(--fs-sm);
    color: var(--text);
    word-break: break-all;
}
.recipient-remove {
    background: transparent;
    color: var(--text-faint);
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 0 var(--sp-2);
    transition: color var(--t-fast);
}
.recipient-remove:hover { color: var(--sev-critical); }
.recipients-add {
    display: flex; gap: var(--sp-2); align-items: stretch;
    margin-top: var(--sp-3);
}
.recipients-add .form-input { flex: 1; }

/* ─── Agent page: full-height layout with history rail ────── */
.agent-grid {
    /* Fill viewport: account for the topbar height. */
    height: calc(100vh - var(--topbar-h));
    padding: var(--sp-4);
    grid-template-columns: minmax(0, 1fr);
}
.agent-panel {
    display: flex; flex-direction: column;
    height: 100%;
    min-height: 0;
}
.agent-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: var(--sp-4);
    min-height: 0;
    flex: 1;
}
@media (max-width: 820px) {
    .agent-layout { grid-template-columns: 1fr; }
    .chat-rail { display: none; }
}

/* History rail */
.chat-rail {
    display: flex; flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border);
    padding-right: var(--sp-3);
    overflow: hidden;
}
.chat-new-btn {
    display: flex; align-items: center; gap: var(--sp-2);
    background: var(--accent-strong); color: #fff;
    border: none; border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
    font-weight: var(--fw-semibold); font-size: var(--fs-sm);
    cursor: pointer;
}
.chat-new-btn:hover { background: var(--accent-hover); }
.chat-new-btn span { font-size: 18px; line-height: 1; }
.chat-rail-label {
    margin-top: var(--sp-4);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: var(--sp-2) var(--sp-2) var(--sp-2);
}
.chat-sessions {
    flex: 1;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 2px;
}
.chat-rail-empty {
    padding: var(--sp-3);
    font-size: var(--fs-sm);
}
.chat-session {
    position: relative;
    padding: var(--sp-3);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background var(--t-fast);
}
.chat-session:hover { background: var(--surface-2); }
.chat-session.active {
    background: var(--accent-soft);
    box-shadow: inset 2px 0 0 var(--accent);
}
.chat-session-title {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 20px;
}
.chat-session-meta {
    display: flex; justify-content: space-between;
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 2px;
}
.chat-session-del {
    position: absolute; top: 6px; right: 6px;
    background: transparent; border: none;
    color: var(--text-faint); font-size: 16px;
    width: 20px; height: 20px;
    line-height: 1; cursor: pointer;
    border-radius: 50%;
    opacity: 0; transition: opacity var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.chat-session:hover .chat-session-del { opacity: 1; }
.chat-session-del:hover {
    color: #fff;
    background: var(--sev-critical);
}

/* Chat container: flex with input pinned at bottom */
.chat-container {
    display: flex; flex-direction: column;
    min-height: 0;
    height: 100%;
}
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-4);
    display: flex; flex-direction: column; gap: var(--sp-3);
}
.chat-empty {
    margin: auto;
    text-align: center;
    max-width: 520px;
    padding: var(--sp-6);
}
.chat-empty h3 {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    margin-bottom: var(--sp-2);
}
.chat-empty .chat-suggestions {
    justify-content: center;
    margin-top: var(--sp-5);
}
.ask-form {
    border-top: 1px solid var(--border);
    padding: var(--sp-3) var(--sp-4);
    flex-shrink: 0;
    background: var(--surface);
}
.ask-image-preview {
    margin: var(--sp-2) var(--sp-4) 0;
}

/* ─── Analytics dashboard ─────────────────────────────────── */
.analytics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
    align-items: start;
}
.analytics-grid .panel-full { grid-column: 1 / -1; }

.analytics-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: var(--sp-3);
}
.analytics-controls { display: flex; align-items: center; }

.kpi-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-4);
    padding: var(--sp-5) !important;
}
.kpi-tile {
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-4);
}
.kpi-label {
    font-size: var(--fs-xs);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: var(--fw-bold);
    margin-bottom: var(--sp-2);
}
.kpi-value {
    font-size: 28px;
    font-weight: var(--fw-bold);
    color: var(--text);
    line-height: 1.1;
}
.kpi-sub {
    font-size: var(--fs-xs);
    color: var(--text-faint);
    margin-top: var(--sp-1);
}

/* Stacked bar (severity) */
.bar-stack-track {
    display: flex;
    height: 22px;
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    margin-bottom: var(--sp-4);
}
.bar-stack-seg { height: 100%; transition: flex var(--t-base); }
.bar-stack-legend { display: flex; flex-direction: column; gap: var(--sp-2); }
.bar-stack-legend-row {
    display: flex; align-items: center; gap: var(--sp-3);
    font-size: var(--fs-sm);
}
.bar-stack-swatch {
    width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.bar-stack-legend-label {
    flex: 1; color: var(--text); font-weight: var(--fw-medium);
}
.bar-stack-legend-count {
    color: var(--text); font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
}

/* Horizontal bar rows (categories) */
.bar-rows { display: flex; flex-direction: column; gap: var(--sp-2); }
.bar-row {
    display: grid;
    grid-template-columns: 140px 1fr 96px;
    align-items: center;
    gap: var(--sp-3);
    font-size: var(--fs-sm);
}
.bar-row-label {
    color: var(--text-muted);
    font-weight: var(--fw-medium);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-row-track {
    height: 14px; background: var(--bg-elev-1);
    border-radius: var(--r-sm); overflow: hidden;
    border: 1px solid var(--border);
}
.bar-row-fill { height: 100%; transition: width var(--t-base); }
.bar-row-value {
    text-align: right; color: var(--text); font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
}

/* Time-series bars (vertical) */
.time-bars {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 4px;
    height: 120px;
    align-items: end;
}
.time-bars-tall { height: 180px; }
.time-bar {
    display: flex; flex-direction: column; align-items: center;
    height: 100%;
    justify-content: flex-end;
    cursor: help;
}
.time-bar-fill {
    width: 100%;
    min-height: 2px;
    background: var(--accent-strong);
    border-radius: 3px 3px 0 0;
    transition: height var(--t-base);
}
.time-bar-fill:hover { background: var(--accent); }
.time-bar-label {
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}
.time-bar-value {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Delivery / chat mini KPI grid */
.kpi-mini-grid,
.delivery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--sp-3);
}
.kpi-mini {
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
}
.kpi-mini-label {
    font-size: var(--fs-xs);
    color: var(--text-faint);
    font-weight: var(--fw-medium);
    margin-bottom: var(--sp-1);
}
.kpi-mini-value {
    font-size: 22px;
    font-weight: var(--fw-bold);
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 820px) {
    .analytics-grid { grid-template-columns: 1fr; }
    .bar-row { grid-template-columns: 100px 1fr 64px; }
}
