/* ============================================================
   Matrix Security Intelligence Platform — v6.0 "Cartographer's Atlas"
   Editorial / Archival / Hand-Built Design System

   Brand: Terracotta Rust + Deep Blueprint + Warm Cream
   Typography: Fraunces (serif headlines) + Space Grotesk (UI) + IBM Plex Mono
   Shapes: Sharp corners, hard offset shadows, solid borders, no glass
   ============================================================ */

/* ── Fonts loaded via <link> in base.html ─────────────────── */

/* ── Design Tokens — Default "Blueprint Nocturne" ──────────── */
:root {
    /* ── Brand Palette: Terracotta + Copper ── */
    --accent:        #d8693f;            /* bright rust / terracotta */
    --accent-hover:  #e88556;
    --accent-light:  rgba(216, 105, 63, 0.12);
    --accent-glow:   rgba(216, 105, 63, 0.22);
    --accent-muted:  rgba(216, 105, 63, 0.72);
    --accent-ink:    #7a3418;            /* deep rust for small caps */

    --secondary:       #7ba695;           /* oxidized copper-green */
    --secondary-light: rgba(123, 166, 149, 0.12);

    --tertiary:        #e8a33a;           /* amber gold */
    --tertiary-light:  rgba(232, 163, 58, 0.12);

    /* ── Backgrounds: solid, layered like paper stacks ── */
    --bg-root:      #0e1a24;             /* deep blueprint navy */
    --bg-surface:   #142433;             /* panel surface */
    --bg-card:      #182c3e;             /* card body */
    --bg-elevated:  #223a4e;             /* raised card */
    --bg-input:     #0a1520;             /* darker sunken input */
    --bg-hover:     rgba(216, 105, 63, 0.08);
    --bg-inset:     #0a1520;
    --bg-paper:     #e9dfc9;             /* cream (used in reverse tags) */

    /* ── Borders: visible, solid, structural ── */
    --border:        #2a4459;            /* navy-desaturated */
    --border-hover:  #d8693f;            /* rust on hover — strong signal */
    --border-focus:  #e8a33a;            /* amber focus ring */
    --border-subtle: #1e3244;
    --border-strong: #3a5871;
    --border-ink:    #0a1520;            /* near-black edge */

    /* ── Text: warm cream, not cold white ── */
    --text:           #e9dfc9;           /* warm paper cream */
    --text-secondary: #b5aa92;           /* aged cream */
    --text-muted:     #7d8a99;           /* dusty blue-grey */
    --text-dim:       #4a5668;

    /* ── Status Colors: muted, non-neon ── */
    --ok:             #7ba695;           /* oxidized copper */
    --ok-light:       rgba(123, 166, 149, 0.14);
    --warn:           #e8a33a;           /* amber */
    --warn-light:     rgba(232, 163, 58, 0.14);
    --danger:         #c9502a;           /* terracotta danger */
    --danger-light:   rgba(201, 80, 42, 0.14);
    --critical:       #a83a1c;           /* deep rust */
    --critical-light: rgba(168, 58, 28, 0.18);
    --info:           #7ba695;
    --info-light:     rgba(123, 166, 149, 0.12);
    --success:        #7ba695;

    /* ── Typography: editorial serif + distinctive sans ── */
    --font-ui:      'Space Grotesk', 'Inter Tight', -apple-system, system-ui, sans-serif;
    --font-display: 'Fraunces', 'Georgia', 'Times New Roman', serif;
    --font-mono:    'IBM Plex Mono', 'JetBrains Mono', 'Consolas', monospace;

    /* ── Shape: sharp, architectural ── */
    --radius:    3px;
    --radius-lg: 4px;
    --radius-sm: 2px;

    /* ── Shadows: hard offset, like stamped paper ── */
    --shadow-sm:   2px 2px 0 0 rgba(10, 21, 32, 0.75);
    --shadow-md:   4px 4px 0 0 rgba(10, 21, 32, 0.80);
    --shadow-lg:   6px 6px 0 0 rgba(10, 21, 32, 0.85);
    --shadow-hard: 3px 3px 0 0 var(--border-ink);
    --shadow-glow: 0 0 0 2px rgba(216, 105, 63, 0.20);

    /* ── Transitions: snappy, not squishy ── */
    --transition:      0.14s cubic-bezier(0.2, 0.8, 0.2, 1);
    --transition-slow: 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);

    /* ── Legacy glass tokens kept as no-ops for back-compat ── */
    --glass-blur:    none;
    --glass-blur-sm: none;
}

/* ── Light Theme — "Cream Paper" ───────────────────────────── */
[data-theme="light"] {
    --accent:        #a83a1c;            /* deep rust ink */
    --accent-hover:  #c9502a;
    --accent-light:  rgba(168, 58, 28, 0.08);
    --accent-glow:   rgba(168, 58, 28, 0.14);
    --accent-muted:  rgba(168, 58, 28, 0.72);
    --accent-ink:    #7a3418;

    --secondary:       #3e5b4e;           /* forest ink */
    --secondary-light: rgba(62, 91, 78, 0.08);

    --tertiary:        #b07520;           /* burnt amber */
    --tertiary-light:  rgba(176, 117, 32, 0.10);

    --bg-root:      #f1e8d3;             /* base paper */
    --bg-surface:   #faf6ee;             /* lightest cream (cards sit on) */
    --bg-card:      #faf6ee;
    --bg-elevated:  #ffffff;
    --bg-input:     #ffffff;
    --bg-hover:     rgba(168, 58, 28, 0.06);
    --bg-inset:     #e5d5b3;
    --bg-paper:     #1a1713;

    --border:        #1a1713;            /* ink edge */
    --border-hover:  #a83a1c;
    --border-focus:  #b07520;
    --border-subtle: #c0b597;
    --border-strong: #1a1713;
    --border-ink:    #1a1713;

    --text:           #1a1713;           /* darkest ink */
    --text-secondary: #3d3730;
    --text-muted:     #7a6f60;
    --text-dim:       #9a8e7b;

    --ok:             #3e5b4e;
    --ok-light:       rgba(62, 91, 78, 0.10);
    --warn:           #b07520;
    --warn-light:     rgba(176, 117, 32, 0.10);
    --danger:         #a83a1c;
    --danger-light:   rgba(168, 58, 28, 0.10);
    --critical:       #7a1e0a;
    --critical-light: rgba(122, 30, 10, 0.12);
    --info:           #3e5b4e;
    --info-light:     rgba(62, 91, 78, 0.08);
    --success:        #3e5b4e;

    --shadow-sm:   2px 2px 0 0 rgba(26, 23, 19, 0.85);
    --shadow-md:   4px 4px 0 0 rgba(26, 23, 19, 0.90);
    --shadow-lg:   6px 6px 0 0 rgba(26, 23, 19, 0.95);
    --shadow-hard: 3px 3px 0 0 #1a1713;
    --shadow-glow: 0 0 0 2px rgba(168, 58, 28, 0.18);
}

/* Light-mode: paper texture + inked surfaces */
[data-theme="light"] body::before {
    background:
        /* warm paper grain */
        radial-gradient(circle at 10% 15%, rgba(168, 58, 28, 0.04) 0%, transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(62, 91, 78, 0.04) 0%, transparent 40%);
    animation: none;
    opacity: 1;
}
[data-theme="light"] body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(26, 23, 19, 0.10) 0.6px, transparent 0.6px);
    background-size: 18px 18px;
    opacity: 0.5;
}
[data-theme="light"] .ambient-orb { display: none; }

[data-theme="light"] .nav-bar {
    background: #faf6ee;
    border-bottom: 2px solid #1a1713;
    box-shadow: 0 4px 0 0 rgba(26, 23, 19, 0.12);
}
[data-theme="light"] .nav-links {
    background: transparent;
    border: none;
}
[data-theme="light"] .sf-panel-inner,
[data-theme="light"] .ai-sidebar {
    background: #faf6ee;
    border-color: #1a1713;
}
[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: #1a1713;
}
[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: #a83a1c;
}
[data-theme="light"] ::selection {
    background: #e8a33a;
    color: #1a1713;
}
@media (max-width: 768px) {
    [data-theme="light"] .nav-links {
        background: #faf6ee;
        border: 2px solid #1a1713;
    }
}

/* ── Operator Theme — "Rust Noir" ─────────────────────────── */
[data-theme="operator"],
[data-theme="red"] {
    --accent:        #e5583a;            /* blazing rust */
    --accent-hover:  #ff6d4f;
    --accent-light:  rgba(229, 88, 58, 0.16);
    --accent-glow:   rgba(229, 88, 58, 0.32);
    --accent-muted:  rgba(229, 88, 58, 0.84);
    --accent-ink:    #8a1e08;

    --secondary:       #e8a33a;           /* amber highlight */
    --secondary-light: rgba(232, 163, 58, 0.14);

    --tertiary:        #d9b384;
    --tertiary-light:  rgba(217, 179, 132, 0.12);

    --bg-root:      #120807;             /* near-black ember */
    --bg-surface:   #1a0e0a;
    --bg-card:      #22130d;
    --bg-elevated:  #2c1810;
    --bg-input:     #0a0403;
    --bg-hover:     rgba(229, 88, 58, 0.10);
    --bg-inset:     #0a0403;
    --bg-paper:     #e9dfc9;

    --border:        #4a1f12;            /* dried blood edge */
    --border-hover:  #e5583a;
    --border-focus:  #e8a33a;
    --border-subtle: #2a1008;
    --border-strong: #7a2e18;
    --border-ink:    #000000;

    --text:           #f4e4d4;           /* warm bone */
    --text-secondary: #c9a68e;
    --text-muted:     #8a6858;
    --text-dim:       #5a4030;

    --ok:             #c9a86a;
    --ok-light:       rgba(201, 168, 106, 0.12);
    --warn:           #e8a33a;
    --warn-light:     rgba(232, 163, 58, 0.14);
    --danger:         #e5583a;
    --danger-light:   rgba(229, 88, 58, 0.16);
    --critical:       #ff3a1e;
    --critical-light: rgba(255, 58, 30, 0.20);
    --info:           #d9b384;
    --info-light:     rgba(217, 179, 132, 0.10);
    --success:        #c9a86a;

    --shadow-sm:   2px 2px 0 0 rgba(0, 0, 0, 0.95);
    --shadow-md:   4px 4px 0 0 rgba(0, 0, 0, 0.95);
    --shadow-lg:   6px 6px 0 0 rgba(0, 0, 0, 0.95);
    --shadow-hard: 3px 3px 0 0 #000000;
    --shadow-glow: 0 0 0 2px rgba(229, 88, 58, 0.36);
}

[data-theme="operator"] body::before,
[data-theme="red"] body::before {
    background:
        radial-gradient(circle at 30% 20%, rgba(229, 88, 58, 0.08) 0%, transparent 45%),
        radial-gradient(circle at 72% 78%, rgba(232, 163, 58, 0.05) 0%, transparent 40%);
    animation: none;
    opacity: 1;
}
[data-theme="operator"] body::after,
[data-theme="red"] body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(229, 88, 58, 0.09) 0.7px, transparent 0.7px);
    background-size: 18px 18px;
    opacity: 0.55;
}
[data-theme="operator"] .ambient-orb,
[data-theme="red"] .ambient-orb { display: none; }
[data-theme="operator"] .nav-bar,
[data-theme="red"] .nav-bar {
    background: #1a0e0a;
    border-bottom: 2px solid var(--accent);
    box-shadow: 0 4px 0 0 rgba(0, 0, 0, 0.85);
}
[data-theme="operator"] .nav-brand,
[data-theme="red"] .nav-brand {
    color: var(--accent);
}
[data-theme="operator"] .nav-brand::before,
[data-theme="red"] .nav-brand::before {
    background: var(--accent);
    box-shadow: 2px 2px 0 0 #000;
}
[data-theme="operator"] .nav-links,
[data-theme="red"] .nav-links {
    background: transparent;
    border: none;
}
[data-theme="operator"] .nav-link:hover,
[data-theme="red"] .nav-link:hover {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}
[data-theme="operator"] .nav-link.active,
[data-theme="red"] .nav-link.active {
    color: #120306;
    background: var(--accent);
    border-color: #000;
    box-shadow: 2px 2px 0 0 #000;
}
[data-theme="operator"] .sf-panel-inner,
[data-theme="operator"] .ai-sidebar,
[data-theme="red"] .sf-panel-inner,
[data-theme="red"] .ai-sidebar {
    background: #1a0e0a;
    border-color: var(--accent);
}
[data-theme="operator"] ::-webkit-scrollbar-thumb,
[data-theme="red"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 77, 95, 0.26);
}
[data-theme="operator"] ::-webkit-scrollbar-thumb:hover,
[data-theme="red"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 125, 136, 0.42);
}
[data-theme="operator"] ::selection,
[data-theme="red"] ::selection {
    background: rgba(255, 77, 95, 0.22);
    color: #fff;
}
[data-theme="operator"] .theme-glitch,
[data-theme="red"] .theme-glitch {
    position: relative;
    display: inline-block;
    color: #ff8b96;
    text-shadow:
        0 0 8px rgba(255, 77, 95, 0.48),
        0 0 20px rgba(255, 77, 95, 0.30),
        0 0 34px rgba(255, 77, 95, 0.18);
    animation: operatorFlicker 3.8s linear infinite;
}
[data-theme="operator"] .theme-glitch::before,
[data-theme="operator"] .theme-glitch::after,
[data-theme="red"] .theme-glitch::before,
[data-theme="red"] .theme-glitch::after {
    content: attr(data-text);
    position: absolute;
    inset: 0;
    pointer-events: none;
}
[data-theme="operator"] .theme-glitch::before,
[data-theme="red"] .theme-glitch::before {
    color: #ff4357;
    text-shadow: -2px 0 rgba(255, 181, 187, 0.50);
    animation: operatorGlitchBefore 2.1s steps(2, end) infinite;
    opacity: 0.82;
}
[data-theme="operator"] .theme-glitch::after,
[data-theme="red"] .theme-glitch::after {
    color: #ffd7db;
    text-shadow: 2px 0 rgba(255, 77, 95, 0.45);
    filter: blur(0.8px);
    animation: operatorGlitchAfter 2.7s steps(2, end) infinite;
    opacity: 0.54;
}
[data-theme="operator"] .page-header h1,
[data-theme="operator"] .main-header h1,
[data-theme="red"] .page-header h1,
[data-theme="red"] .main-header h1 {
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ── Sentinel Theme — "Field Journal" ─────────────────────── */
[data-theme="sentinel"] {
    --accent:        #d9b384;            /* vellum tan */
    --accent-hover:  #e8c69a;
    --accent-light:  rgba(217, 179, 132, 0.14);
    --accent-glow:   rgba(217, 179, 132, 0.22);
    --accent-muted:  rgba(217, 179, 132, 0.78);
    --accent-ink:    #5a4428;

    --secondary:       #7ba695;           /* forest copper */
    --secondary-light: rgba(123, 166, 149, 0.12);

    --tertiary:        #c06838;           /* muted rust */
    --tertiary-light:  rgba(192, 104, 56, 0.10);

    --bg-root:      #141a18;             /* deep forest-ink */
    --bg-surface:   #1c2422;
    --bg-card:      #222e2a;
    --bg-elevated:  #2a3834;
    --bg-input:     #0d1413;
    --bg-hover:     rgba(123, 166, 149, 0.08);
    --bg-inset:     #0d1413;
    --bg-paper:     #e9dfc9;

    --border:        #3a4e45;
    --border-hover:  #d9b384;
    --border-focus:  #7ba695;
    --border-subtle: #253029;
    --border-strong: #4a6356;
    --border-ink:    #000000;

    --text:           #ede4cf;
    --text-secondary: #b5a98c;
    --text-muted:     #7a8b82;
    --text-dim:       #455851;

    --ok:             #7ba695;
    --ok-light:       rgba(123, 166, 149, 0.14);
    --warn:           #d9b384;
    --warn-light:     rgba(217, 179, 132, 0.14);
    --danger:         #c06838;
    --danger-light:   rgba(192, 104, 56, 0.16);
    --critical:       #a83a1c;
    --critical-light: rgba(168, 58, 28, 0.18);
    --info:           #7ba695;
    --info-light:     rgba(123, 166, 149, 0.12);
    --success:        #7ba695;

    --shadow-sm:   2px 2px 0 0 rgba(0, 0, 0, 0.75);
    --shadow-md:   4px 4px 0 0 rgba(0, 0, 0, 0.80);
    --shadow-lg:   6px 6px 0 0 rgba(0, 0, 0, 0.85);
    --shadow-hard: 3px 3px 0 0 #000;
    --shadow-glow: 0 0 0 2px rgba(217, 179, 132, 0.22);
}
[data-theme="sentinel"] body::before {
    background:
        radial-gradient(circle at 20% 22%, rgba(123, 166, 149, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 78% 78%, rgba(217, 179, 132, 0.05) 0%, transparent 38%);
    animation: none;
    opacity: 1;
}
[data-theme="sentinel"] body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(217, 179, 132, 0.08) 0.7px, transparent 0.7px);
    background-size: 20px 20px;
    opacity: 0.42;
}
[data-theme="sentinel"] .ambient-orb { display: none; }
[data-theme="sentinel"] .nav-bar {
    background: #1c2422;
    border-bottom: 2px solid var(--accent);
    box-shadow: 0 4px 0 0 rgba(0, 0, 0, 0.60);
}
[data-theme="sentinel"] .nav-brand {
    color: var(--accent);
}
[data-theme="sentinel"] .nav-brand::before {
    background: var(--accent);
    box-shadow: 2px 2px 0 0 #000;
}
[data-theme="sentinel"] .nav-links {
    background: transparent;
    border: none;
}
[data-theme="sentinel"] .nav-link:hover {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}
[data-theme="sentinel"] .nav-link.active {
    color: #0d1413;
    background: var(--accent);
    border-color: #000;
    box-shadow: 2px 2px 0 0 #000;
}
[data-theme="sentinel"] .sf-panel-inner,
[data-theme="sentinel"] .ai-sidebar {
    background: #1c2422;
    border-color: var(--accent);
}
[data-theme="sentinel"] ::-webkit-scrollbar-thumb {
    background: var(--accent);
}
[data-theme="sentinel"] ::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}
[data-theme="sentinel"] ::selection {
    background: var(--accent);
    color: #0d1413;
}
[data-theme="sentinel"] .page-header h1,
[data-theme="sentinel"] .main-header h1 {
    letter-spacing: 0.01em;
}

@keyframes operatorFlicker {
    0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; filter: blur(0); }
    20% { opacity: 0.88; filter: blur(1.2px); }
    63% { opacity: 0.92; filter: blur(0.7px); }
}
@keyframes operatorGlitchBefore {
    0%, 100% { transform: translate(0, 0); clip-path: inset(0 0 0 0); }
    12% { transform: translate(-1px, -1px); clip-path: inset(0 0 78% 0); }
    24% { transform: translate(2px, 1px); clip-path: inset(62% 0 8% 0); }
    36% { transform: translate(-2px, 0); clip-path: inset(24% 0 48% 0); }
    48% { transform: translate(1px, -1px); clip-path: inset(80% 0 4% 0); }
    60% { transform: translate(-1px, 1px); clip-path: inset(40% 0 34% 0); }
    72% { transform: translate(2px, 0); clip-path: inset(8% 0 72% 0); }
}
@keyframes operatorGlitchAfter {
    0%, 100% { transform: translate(0, 0); clip-path: inset(0 0 0 0); }
    10% { transform: translate(1px, 0); clip-path: inset(72% 0 6% 0); }
    22% { transform: translate(-2px, 1px); clip-path: inset(18% 0 52% 0); }
    34% { transform: translate(2px, -1px); clip-path: inset(56% 0 14% 0); }
    46% { transform: translate(-1px, 0); clip-path: inset(10% 0 70% 0); }
    58% { transform: translate(1px, 1px); clip-path: inset(44% 0 28% 0); }
    70% { transform: translate(-2px, -1px); clip-path: inset(84% 0 2% 0); }
}

/* ── Theme Toggle Button ──────────────────────────────────── */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 8px;
    font-size: 16px;
    font-family: var(--font-mono);
    line-height: 1;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}
.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-light);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Accessibility ─────────────────────────────────────────── */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-root);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.55;
    font-feature-settings: "ss01", "cv11";        /* Space Grotesk stylistic alts */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Editorial display type — use for .nav-brand, h1, page-header */
.font-display,
h1, h2, .card-header-display {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-variation-settings: "SOFT" 30, "opsz" 144;
    letter-spacing: -0.015em;
}

/* ── Paper-grain + blueprint dot-grid ambient ── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 15% 18%, rgba(216, 105, 63, 0.05) 0%, transparent 42%),
        radial-gradient(circle at 82% 76%, rgba(123, 166, 149, 0.05) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
    animation: none;
}
/* Fine dot-grid like graph paper */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(216, 105, 63, 0.11) 0.7px, transparent 0.7px);
    background-size: 18px 18px;
    opacity: 0.4;
}
@keyframes ambientShift {
    /* kept for back-compat but does nothing */
    0%, 100% { filter: none; }
}

::selection { background: var(--accent); color: var(--bg-root); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 0; border: 2px solid var(--bg-root); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Navigation Bar — "Field Desk" ──────────────────────────── */
.nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 64px;
    background: var(--bg-surface);
    border-bottom: 2px solid var(--accent);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 0 0 var(--border-ink);
    /* no backdrop-filter, no glass */
}
.nav-brand {
    font-family: var(--font-display);
    font-weight: 600;
    font-style: italic;
    font-size: 20px;
    color: var(--text);
    background: none;
    -webkit-text-fill-color: unset;
    letter-spacing: -0.01em;
    text-transform: none;
    display: flex;
    align-items: center;
    gap: 12px;
    font-feature-settings: "ss01";
    font-variation-settings: "SOFT" 100, "opsz" 144;
}
.nav-brand::before {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border: 2px solid var(--border-ink);
    box-shadow: 2px 2px 0 0 var(--border-ink);
    border-radius: 0;
    transform: none;
}
.nav-brand .brand-text {
    /* lowercase + italic serif for editorial wordmark */
    text-transform: none;
    font-style: italic;
}
.nav-links {
    display: flex;
    gap: 4px;
    background: transparent;
    padding: 0;
    border: none;
    border-radius: 0;
}
.nav-link {
    padding: 8px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-ui);
    letter-spacing: 0.01em;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    position: relative;
    white-space: nowrap;
}
.nav-link:hover {
    color: var(--accent);
    background: transparent;
    border-color: var(--accent);
}
.nav-link.active {
    color: var(--bg-root);
    background: var(--accent);
    border-color: var(--border-ink);
    box-shadow: 2px 2px 0 0 var(--border-ink);
    font-weight: 600;
}

/* ── Nav Dropdown Groups — solid drawer ── */
.nav-group {
    position: relative;
    display: inline-flex;
}
.nav-dropdown-trigger {
    background: none;
    border: 2px solid transparent;
    font-family: inherit;
    cursor: pointer;
}
.nav-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 2px solid var(--border-ink);
    border-radius: 0;
    padding: 6px 0;
    z-index: 1000;
    box-shadow: 4px 4px 0 0 var(--border-ink);
}
.nav-group.open .nav-dropdown {
    display: block;
}
.nav-dropdown-item {
    display: block;
    padding: 10px 18px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}
.nav-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-left-color: var(--accent);
}
.nav-dropdown-item.active {
    color: var(--bg-root);
    background: var(--accent);
    border-left-color: var(--border-ink);
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    display: inline-block;
    transition: all var(--transition);
}
.status-dot.connected {
    background: var(--ok);
    box-shadow: 0 0 8px rgba(52,211,153,0.5);
    animation: pulse-status 2s ease-in-out infinite;
}
.status-dot.disconnected {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(248,113,113,0.3);
}
@keyframes pulse-status {
    0%, 100% { box-shadow: 0 0 8px rgba(52,211,153,0.5); }
    50%      { box-shadow: 0 0 16px rgba(52,211,153,0.7); }
}
.status-label { color: var(--text-muted); font-weight: 500; }

/* ── Buttons — "Stamped Card" ──────────────────────────────── */
.btn {
    padding: 8px 18px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-ui);
    letter-spacing: 0.01em;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition), border-color var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 2px 2px 0 0 var(--border-ink);
    text-shadow: none;
}
.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-elevated);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 0 var(--border-ink);
}
.btn:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 0 var(--border-ink);
}
.btn-sm { padding: 5px 12px; font-size: 12px; box-shadow: 2px 2px 0 0 var(--border-ink); }
.btn-primary {
    background: var(--accent);
    border-color: var(--border-ink);
    color: var(--bg-root);
    font-weight: 600;
    box-shadow: 3px 3px 0 0 var(--border-ink);
}
.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--bg-root);
    border-color: var(--border-ink);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 0 var(--border-ink);
}
.btn-primary:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 0 var(--border-ink);
}
.btn-danger {
    background: var(--danger);
    border-color: var(--border-ink);
    color: var(--bg-paper);
    font-weight: 600;
}
.btn-danger:hover {
    background: var(--critical);
    color: var(--bg-paper);
    border-color: var(--border-ink);
}
.btn-accent {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}
.btn-accent:hover {
    background: var(--accent);
    color: var(--bg-root);
}
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
    box-shadow: none;
}
.btn-ghost:hover {
    color: var(--accent);
    background: transparent;
    border-color: var(--accent);
    box-shadow: none;
    transform: none;
}

/* ── Inputs — "Punched Card" ──────────────────────────────── */
.input {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font-ui);
    width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    box-shadow: inset 2px 2px 0 0 rgba(0, 0, 0, 0.18);
}
.input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: inset 2px 2px 0 0 rgba(0, 0, 0, 0.18), 0 0 0 3px var(--accent-light);
}
.input:hover:not(:focus) {
    border-color: var(--accent);
}
.input::placeholder { color: var(--text-dim); font-style: italic; }
.input-sm { padding: 6px 10px; font-size: 12px; width: auto; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; }

/* ── Layout ──────────────────────────────────────────────────── */
.main-content {
    padding: 24px;
    max-width: 1440px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.page-header h1 {
    font-size: 30px;
    font-weight: 500;
    font-style: italic;
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 70, "opsz" 144;
    letter-spacing: -0.02em;
    color: var(--text);
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}
.page-actions { display: flex; gap: 8px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 12px; }
.inline-error {
    color: var(--danger);
    background: var(--danger-light);
    border: 2px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    box-shadow: 2px 2px 0 0 var(--border-ink);
}
.inline-success {
    color: var(--success);
    background: var(--ok-light);
    border: 2px solid var(--ok);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    box-shadow: 2px 2px 0 0 var(--border-ink);
}

/* ── Cards — "Filed Document" ───────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    position: relative;
}
.card::before {
    /* thin rust accent rule along top edge — filing tab */
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 48px;
    height: 3px;
    background: var(--accent);
}
.card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translate(-1px, -1px);
}
.card-header {
    padding: 14px 20px 12px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-ui);
    border-bottom: 2px solid var(--border-strong);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface);
}
.card-body { padding: 20px; }

/* ── KPI Cards ───────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--bg-card);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 22px 20px 18px;
    text-align: left;
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 4px;
    background: var(--accent);
    transition: none;
    opacity: 1;
}
.kpi-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translate(-2px, -2px);
}
.kpi-value {
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 0, "opsz" 144;
    font-size: 38px;
    font-weight: 500;
    color: var(--text);
    background: none;
    -webkit-text-fill-color: unset;
    letter-spacing: -0.035em;
    line-height: 1.0;
    font-feature-settings: "tnum";     /* tabular figures */
    display: block;
}
.kpi-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 600;
    font-family: var(--font-ui);
}
.kpi-trend {
    font-size: 11px;
    font-family: var(--font-mono);
    margin-top: 4px;
    font-weight: 500;
    color: var(--text-muted);
}
.kpi-trend.up { color: var(--ok); }
.kpi-trend.down { color: var(--danger); }
.kpi-card.kpi-warn { border-color: var(--warn); }
.kpi-card.kpi-warn::before { background: var(--warn); }
.kpi-card.kpi-warn .kpi-value { color: var(--warn); }
.kpi-card.kpi-danger { border-color: var(--danger); }
.kpi-card.kpi-danger::before { background: var(--danger); }
.kpi-card.kpi-danger .kpi-value { color: var(--danger); }
.kpi-card.kpi-ok { border-color: var(--ok); }
.kpi-card.kpi-ok::before { background: var(--ok); }
.kpi-card.kpi-ok .kpi-value { color: var(--ok); }

/* ── Security Score Grades ───────────────────────────────────── */
.score-grade { font-weight: 700; }
.grade-a { color: var(--ok); }
.grade-b { color: var(--accent); }
.grade-c { color: var(--warn); }
.grade-d { color: #FF9800; }
.grade-f { color: var(--danger); }

/* ── Data Table — "Ledger" ─────────────────────────────────── */
.data-table {
    width: 100%;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.data-table th {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 2px solid var(--accent);
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.14em;
    font-family: var(--font-ui);
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    z-index: 2;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 12px;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    transition: background var(--transition);
}
.data-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.12);     /* alternating rows like accounting paper */
}
.data-table tr:hover td {
    background: var(--bg-hover);
    color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }

/* ── Filter Bar ──────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 16px 0;
}
.pagination button {
    padding: 6px 12px;
    border: 2px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all var(--transition);
    box-shadow: 2px 2px 0 0 var(--border-ink);
}
.pagination button.active {
    background: var(--accent);
    border-color: var(--border-ink);
    color: var(--bg-root);
}
.pagination button:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Violations ──────────────────────────────────────────────── */
.violation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background var(--transition);
}
.violation-item:hover { background: var(--bg-hover); margin: 0 -20px; padding: 10px 20px; }
.violation-item:last-child { border-bottom: none; }
.violation-badge {
    font-size: 10px;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
    letter-spacing: 0.10em;
    font-family: var(--font-ui);
    border: 2px solid;
}
.badge-critical {
    background: var(--critical);
    color: var(--bg-paper);
    border-color: var(--border-ink);
}
.badge-high {
    background: var(--warn);
    color: var(--bg-root);
    border-color: var(--border-ink);
}
.badge-medium {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}
.violation-desc { flex: 1; color: var(--text-secondary); }
.violation-user {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ── SF Connection Panel — "Filing Drawer" ──────────────────── */
.sf-panel {
    position: fixed;
    top: 66px; right: 0;
    width: 420px;
    background: var(--bg-surface);
    border: 2px solid var(--accent);
    border-right: none;
    border-radius: 0;
    z-index: 200;
    box-shadow: -6px 6px 0 0 var(--border-ink);
    animation: slideIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slideIn {
    from { transform: translateX(20px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
.sf-panel-inner { padding: 26px; }
.sf-panel h3 {
    font-size: 22px;
    margin-bottom: 22px;
    font-weight: 500;
    font-style: italic;
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 60, "opsz" 144;
    letter-spacing: -0.015em;
    color: var(--text);
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}
.sf-panel-actions { display: flex; gap: 8px; margin-top: 20px; }
.sf-message { margin-top: 12px; font-size: 12px; }
.sf-message.error { color: var(--danger); }
.sf-oauth-section { margin-bottom: 8px; }
.sf-oauth-hint { font-size: 12px; color: var(--text-muted, #8892a4); margin-bottom: 12px; }
.btn-sf-oauth { width: 100%; justify-content: center; display: flex; align-items: center; background: #00a1e0; color: #fff; border-color: #00a1e0; }
.btn-sf-oauth:hover { background: #0092cc; border-color: #0092cc; }
.sf-divider { display: flex; align-items: center; gap: 8px; margin: 12px 0 8px; font-size: 11px; color: var(--text-muted, #8892a4); }
.sf-divider::before, .sf-divider::after { content: ''; flex: 1; height: 1px; background: var(--border, rgba(255,255,255,.12)); }

/* ── AI Status Indicator ─────────────────────────────────────── */
.ai-status {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.ai-status.ready {
    background: var(--ok-light);
    color: var(--ok);
    border: 2px solid var(--ok);
    text-transform: uppercase;
    letter-spacing: 0.10em;
}
.ai-status.loading {
    background: var(--warn-light);
    color: var(--warn);
    border: 2px solid var(--warn);
    text-transform: uppercase;
    letter-spacing: 0.10em;
}
.ai-status.offline {
    background: var(--danger-light);
    color: var(--danger);
    border: 2px solid var(--danger);
    text-transform: uppercase;
    letter-spacing: 0.10em;
}

/* ── AI Chat V3 — "Correspondence Desk" ─────────────────────── */
.ai-chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    background: var(--bg-card);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    overscroll-behavior: contain;
    contain: layout style;
}
.ai-msg {
    margin-bottom: 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
    animation: msgIn 0.25s ease-out;
    max-width: 85%;
}
@keyframes msgIn {
    from { transform: translateY(6px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.ai-user {
    margin-left: auto;
    background: var(--accent-light);
    border: 2px solid var(--accent);
    padding: 12px 18px;
    border-radius: var(--radius) var(--radius) 0 var(--radius);
    box-shadow: 2px 2px 0 0 var(--border-ink);
}
.ai-user .ai-msg-content { color: var(--text); }
.ai-bot {
    background: var(--bg-inset);
    border: 2px solid var(--border-strong);
    padding: 16px 20px;
    border-radius: var(--radius) var(--radius) var(--radius) 0;
    max-width: 90%;
    box-shadow: 2px 2px 0 0 var(--border-ink);
}
/* Bot response markdown styling */
.ai-bot .ai-response-content { font-size: 14px; line-height: 1.75; color: var(--text-primary); }
.ai-bot .ai-response-content h1,
.ai-bot .ai-response-content h2,
.ai-bot .ai-response-content h3 { color: var(--accent); margin: 16px 0 8px; font-size: 15px; }
.ai-bot .ai-response-content h1 { font-size: 17px; }
.ai-bot .ai-response-content p { margin: 8px 0; }
.ai-bot .ai-response-content ul, .ai-bot .ai-response-content ol { padding-left: 20px; margin: 8px 0; }
.ai-bot .ai-response-content li { margin: 4px 0; }
.ai-bot .ai-response-content code {
    background: var(--accent-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}
.ai-bot .ai-response-content pre {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    margin: 10px 0;
}
.ai-bot .ai-response-content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 12px;
}
.ai-bot .ai-response-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 12px;
}
.ai-bot .ai-response-content th,
.ai-bot .ai-response-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}
.ai-bot .ai-response-content th {
    background: var(--accent-light);
    font-weight: 600;
}
.ai-bot .ai-response-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 10px 0;
    padding: 8px 16px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 0 8px 8px 0;
}
.ai-bot .ai-response-content strong { color: var(--accent); }
.ai-system {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    text-align: center;
    max-width: 100%;
    padding: 8px;
}

/* ── Typing Indicator ──────────────────────────────────────── */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.ai-typing-indicator span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.4;
    animation: typingBounce 1.4s ease-in-out infinite;
}
.ai-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Action Buttons on each message ────────────────────────── */
.ai-msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.ai-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-ui);
}
.ai-action-btn:hover {
    color: var(--accent);
    background: var(--accent-light);
    border-color: var(--accent-light);
}
.ai-action-btn.copied {
    color: var(--ok);
    border-color: var(--ok);
}
.ai-msg-meta {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 6px;
    font-family: var(--font-mono);
    opacity: 0.6;
}

/* ── Prompt Templates Grid ─────────────────────────────────── */
.ai-templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    padding: 0 24px 12px;
}
.ai-template-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-ui);
    text-align: left;
}
.ai-template-btn:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}
.ai-template-icon { font-size: 16px; }

/* ── Chat Input Area ───────────────────────────────────────── */
.ai-chat-input {
    padding: 12px 24px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}
.ai-csv-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}
.ai-csv-row label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.ai-input-main {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ai-input-main textarea {
    flex: 1;
    resize: none;
    min-height: 40px;
    max-height: 160px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    border-radius: 12px;
    transition: border-color 0.2s;
}
.ai-input-main textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}
.ai-attach-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.ai-attach-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg-hover);
}
.ai-file-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}
.ai-file-indicator svg { flex-shrink: 0; color: var(--accent); }
#ai-file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.ai-file-status { font-size: 11px; margin-left: auto; white-space: nowrap; }
.ai-file-status.uploading { color: var(--warning, #f59e0b); }
.ai-file-status.ready { color: var(--success, #22c55e); }
.ai-file-status.error { color: var(--danger, #ef4444); }
.ai-file-remove {
    background: none; border: none; color: var(--text-muted);
    font-size: 16px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.ai-file-remove:hover { color: var(--danger, #ef4444); }
.ai-send-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
}
.ai-send-btn:disabled { opacity: 0.4; }

/* ── AI Thinking Block ───────────────────────────────────────── */
.ai-thinking-block {
    margin-bottom: 10px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
    overflow: hidden;
}
.ai-thinking-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 11px;
    color: var(--secondary);
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-ui);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: background 0.15s;
}
.ai-thinking-toggle:hover { background: var(--bg-hover); color: var(--accent); }
.ai-thinking-arrow { transition: transform 0.2s; font-size: 10px; }
.ai-thinking-block.open .ai-thinking-arrow { transform: rotate(90deg); }
.ai-thinking-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 0 12px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}
.ai-thinking-block.open .ai-thinking-content {
    max-height: 600px;
    overflow-y: auto;
    padding: 10px 12px;
}

/* ── Agent Toggle ──────────────────────────────────────────── */
.agent-toggle {
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 2px 10px;
    background: var(--bg-elevated);
}
.agent-toggle:has(input:checked) {
    background: var(--secondary-light);
    border-color: var(--secondary);
    color: var(--secondary);
}

/* ── Ghost button variant ──────────────────────────────────── */
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-ghost:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ── AI Sidebar — "Field Notes Panel" ───────────────────────── */
.ai-sidebar {
    position: fixed;
    top: 66px; right: 0;
    width: 480px;
    height: calc(100vh - 66px);
    background: var(--bg-surface);
    border-left: 2px solid var(--accent);
    z-index: 150;
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 0 0 var(--border-ink);
    animation: slideIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ai-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
}
.btn-close-sidebar {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color var(--transition);
    padding: 4px;
}
.btn-close-sidebar:hover { color: var(--danger); }
.btn-icon-sidebar {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.btn-icon-sidebar:hover { opacity: 1; }

/* AI conversation history */
.ai-msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 13px; line-height: 1.6; }
.ai-msg-user { background: var(--accent-light); border: 1px solid var(--accent); }
.ai-msg-user::before { content: '👤 '; font-size: 12px; }
.ai-msg-assistant { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border); }
.ai-msg-status { color: var(--accent); font-size: 12px; padding: 8px 0; }

.ai-sidebar-output {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-size: 13px;
    font-family: var(--font-sans, system-ui, sans-serif);
    white-space: normal;
    line-height: 1.6;
    word-wrap: break-word;
}

/* ── Markdown rendering inside AI sidebar ── */
.ai-sidebar-output h1,
.ai-sidebar-output h2,
.ai-sidebar-output h3 {
    color: var(--accent);
    margin: 16px 0 8px 0;
    font-size: 14px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}
.ai-sidebar-output h1 { font-size: 16px; }
.ai-sidebar-output h2 { font-size: 14px; }
.ai-sidebar-output h3 { font-size: 13px; border: none; }

.ai-sidebar-output p {
    margin: 8px 0;
}

.ai-sidebar-output ul,
.ai-sidebar-output ol {
    margin: 8px 0;
    padding-left: 20px;
}
.ai-sidebar-output li {
    margin: 4px 0;
}

.ai-sidebar-output strong { color: var(--text); font-weight: 700; }
.ai-sidebar-output em { color: var(--text-muted); font-style: italic; }

.ai-sidebar-output code {
    background: var(--accent-light);
    color: var(--accent);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.ai-sidebar-output pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 10px 0;
}
.ai-sidebar-output pre code {
    background: none;
    color: var(--text);
    padding: 0;
    font-size: 11px;
    line-height: 1.5;
}

.ai-sidebar-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 11px;
}
.ai-sidebar-output th {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
    text-align: left;
    padding: 6px 8px;
    border: 1px solid var(--border);
    white-space: nowrap;
}
.ai-sidebar-output td {
    padding: 5px 8px;
    border: 1px solid var(--border);
    vertical-align: top;
}
.ai-sidebar-output tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}
.ai-sidebar-output tr:hover {
    background: var(--bg-hover);
}

.ai-sidebar-output blockquote {
    border-left: 3px solid var(--accent);
    margin: 10px 0;
    padding: 6px 12px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 0 4px 4px 0;
}

.ai-sidebar-output hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.ai-sidebar-output a {
    color: var(--accent);
    text-decoration: underline;
}

/* Light theme overrides for markdown */
[data-theme="light"] .ai-sidebar-output code {
    background: rgba(0, 100, 200, 0.08);
}
[data-theme="light"] .ai-sidebar-output pre {
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .ai-sidebar-output th {
    background: rgba(0, 100, 200, 0.08);
}
[data-theme="light"] .ai-sidebar-output tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}
[data-theme="light"] .ai-sidebar-output blockquote {
    background: rgba(0, 100, 200, 0.04);
}
.ai-sidebar-input {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--border);
}
.ai-sidebar-input .input { flex: 1; }

/* ── Document List ───────────────────────────────────────────── */
.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background var(--transition);
}
.doc-item:hover { background: var(--bg-hover); }
.doc-name { font-weight: 500; color: var(--text); }
.doc-meta { color: var(--text-muted); font-size: 11px; }

/* ── RAG Results ─────────────────────────────────────────────── */
.rag-result {
    padding: 14px;
    margin-bottom: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    transition: border-color var(--transition);
}
.rag-result:hover { border-color: var(--accent); }
.rag-result-score {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
}
.rag-result-text {
    margin-top: 6px;
    line-height: 1.5;
    color: var(--text-secondary);
}
.rag-result-file {
    font-size: 11px;
    color: var(--secondary);
    margin-top: 6px;
}

/* ── Toggle ──────────────────────────────────────────────────── */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}
.toggle-label input[type="checkbox"] { accent-color: var(--accent); }

/* ── Log Console ─────────────────────────────────────────────── */
.log-console {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    max-height: 300px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
    color: var(--text-muted);
}
.log-console div { white-space: pre-wrap; }

/* ── Events Grid ─────────────────────────────────────────────── */
.events-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
}
.events-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.events-grid label:hover { background: var(--bg-hover); }
.events-grid input[type="checkbox"] { accent-color: var(--accent); }

/* ── Progress Bar ────────────────────────────────────────────── */
.progress-bar-outer {
    height: 6px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin: 10px 0;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--secondary));
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}

/* ── Upload Zone ─────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--text);
    box-shadow: 0 0 24px var(--accent-light);
}

/* ── Filter Row — Query Builder ──────────────────────────────── */
.filter-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-wrap: wrap;
    transition: border-color var(--transition);
}
.filter-row:hover { border-color: var(--border-hover); }
.filter-row select, .filter-row input.filter-value {
    padding: 7px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12px;
    font-family: var(--font-ui);
    transition: border-color var(--transition);
}
.filter-row select:focus, .filter-row input.filter-value:focus {
    border-color: var(--border-focus);
    outline: none;
}
.filter-row select.filter-column { min-width: 160px; max-width: 220px; }
.filter-row select.filter-operator { min-width: 120px; max-width: 140px; }
.filter-row input.filter-value { flex: 1; min-width: 120px; }
.filter-row .btn-delete-filter { margin-left: auto; }

/* ── File Tree ───────────────────────────────────────────────── */
.file-tree { font-size: 12px; font-family: var(--font-mono); }
.file-tree .folder { padding: 4px 0; color: var(--warn); font-weight: 500; }
.file-tree .file { padding: 3px 0 3px 24px; }
.file-tree a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
.file-tree a:hover { color: var(--secondary); text-decoration: underline; }

/* ── Step Workflow ───────────────────────────────────────────── */
.step-section { margin-bottom: 24px; }
.step-section.locked { opacity: 0.35; pointer-events: none; }
.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.step-number {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent);
    border: 2px solid var(--border-ink);
    border-radius: 0;
    font-weight: 700;
    font-size: 14px;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--bg-root);
    box-shadow: 3px 3px 0 0 var(--border-ink);
}
.step-title { font-size: 16px; font-weight: 600; }

/* ── Severity Badges ─────────────────────────────────────────── */
.severity-critical { color: var(--critical); font-weight: 700; }
.severity-high { color: var(--warn); font-weight: 600; }
.severity-medium { color: var(--text-muted); }
.severity-low { color: var(--ok); }

/* ── Stat Bar ────────────────────────────────────────────────── */
.stat-bar {
    display: flex;
    gap: 24px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.stat-item { display: flex; gap: 8px; align-items: center; }
.stat-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}
.stat-label { color: var(--text-muted); }

/* ── Table Wrapper ───────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    max-height: 520px;
    overflow-y: auto;
    border-radius: var(--radius);
}

/* ── Section ─────────────────────────────────────────────────── */
.section { margin-bottom: 24px; }
.section-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text);
    letter-spacing: -0.01em;
}

/* ── Query Builder ───────────────────────────────────────────── */
.query-hint kbd {
    padding: 2px 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
}
.query-hint code {
    padding: 2px 6px;
    background: var(--accent-light);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
}
.query-tab {
    padding: 7px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.query-tab:hover { color: var(--accent); border-color: var(--accent); }
.query-tab.active {
    background: var(--accent);
    color: var(--bg-root);
    border-color: var(--border-ink);
    box-shadow: 2px 2px 0 0 var(--border-ink);
}
.query-tab-add {
    padding: 7px 12px;
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition);
}
.query-tab-add:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Hamburger Menu Button (hidden on desktop) ─────────────── */
.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 101;
}
.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.3s ease;
}
.nav-hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-hamburger.active span:nth-child(2) { opacity: 0; }
.nav-hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: 1fr; }
    .nav-links { gap: 1px; }
    .nav-link { padding: 6px 10px; font-size: 12px; }
    .nav-dropdown-trigger { padding: 6px 10px; font-size: 12px; }
    .status-label { display: none; }
    .ai-sidebar { width: 380px; }
    .page-header { flex-direction: column; gap: 8px; align-items: flex-start; }
    .page-actions { width: 100%; flex-wrap: wrap; }
}
@media (max-width: 768px) {
    .nav-hamburger { display: flex; }
    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--bg-surface);
        border-bottom: 2px solid var(--accent);
        padding: 12px;
        z-index: 99;
        box-shadow: 0 4px 0 0 var(--border-ink);
    }
    .nav-links.nav-open { display: flex; }
    .nav-link { padding: 12px 16px; font-size: 14px; width: 100%; }
    /* Nav dropdown groups: stack vertically on mobile */
    .nav-group { display: flex; flex-direction: column; width: 100%; }
    .nav-dropdown-trigger { width: 100%; text-align: left; padding: 12px 16px; font-size: 14px; }
    .nav-dropdown {
        position: static;
        box-shadow: none;
        border: none;
        background: rgba(255,255,255,0.03);
        border-radius: 0;
        padding: 0 0 0 16px;
    }
    .nav-group .nav-dropdown { display: none; }
    .nav-group.open .nav-dropdown { display: block; }
    .nav-dropdown-item { padding: 10px 16px; font-size: 13px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .main-content { padding: 16px; }
    .nav-bar { padding: 0 12px; position: relative; }
    .filter-bar { flex-direction: column; }
    .filter-bar .input, .filter-bar select, .filter-bar .btn { width: 100%; }
    .btn { min-height: 44px; padding: 10px 16px; }
    .sf-panel { width: 100%; border-radius: 0; }
    .sf-panel-inner { width: 95vw; max-width: none; }
    .ai-sidebar { width: 100%; }
    .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .card { padding: 16px; }
    /* Posture score section */
    .posture-wrap { flex-direction: column; align-items: center; text-align: center; }
    .posture-ring-wrap { margin: 0 auto; }
    /* Compliance score */
    .cpl-score-section { flex-direction: column; align-items: center; text-align: center; }
    /* Modal dialogs */
    .modal-content { width: 95vw !important; max-width: none !important; margin: 16px; }
    /* Investigation bar */
    .inv-bar { flex-wrap: wrap; gap: 6px; }
    .inv-item { font-size: 11px; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .nav-brand { font-size: 12px; letter-spacing: 1.5px; }
    .nav-status { gap: 6px; }
    #sf-connect-btn { font-size: 11px; padding: 5px 10px; }
    .main-content { padding: 10px; }
    .card { padding: 12px; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 6px 8px; }
    .page-header h1 { font-size: 16px; }
    .page-actions .btn { font-size: 12px; padding: 8px 12px; min-height: 40px; }
    /* Compliance: stack filter buttons */
    .cpl-filter { flex-wrap: wrap; }
    .cpl-fw-tabs { gap: 4px; }
    .cpl-fw-tab { padding: 6px 12px; font-size: .75rem; }
    /* Timeline: compact */
    .tl-event-header { flex-wrap: wrap; gap: 4px; }
    .tl-controls { flex-direction: column; gap: 8px; }
    /* Account modal: compact */
    #account-modal .modal-content { padding: 16px; }
}

/* ── Pagination ────────────────────────────────────────────── */
.pg-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all var(--transition);
    min-width: 32px;
    text-align: center;
}
.pg-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}
.pg-btn:disabled {
    opacity: 0.3;
    cursor: default;
}
.pg-btn.pg-active {
    background: var(--accent);
    color: var(--bg-root);
    border-color: var(--border-ink);
    font-weight: 600;
    box-shadow: 2px 2px 0 0 var(--border-ink);
}

/* ── Utility Animations ──────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease-out; }
.fade-in-up { animation: fadeInUp 0.5s ease-out; }

/* ── Modal Overlay — "Envelope" ─────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 21, 32, 0.72);
    animation: fadeIn 0.18s ease-out;
}
.modal-content {
    background: var(--bg-surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius-lg);
    box-shadow: 6px 6px 0 0 var(--border-ink);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    animation: fadeInUp 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 2px solid var(--border-strong);
    background: var(--bg-elevated);
}
.modal-header h3 {
    font-size: 20px;
    font-weight: 500;
    font-style: italic;
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 60, "opsz" 144;
    letter-spacing: -0.01em;
}
.modal-body { padding: 20px; }

/* ── Progress Bar ──────────────────────────────────────────── */
.progress-bar-container {
    height: 6px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--secondary));
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* ── Spinner ────────────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: aiSpin 0.7s linear infinite;
    flex-shrink: 0;
}

/* ── Badge ──────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.25);
}
.badge-warning {
    background: var(--warn-light);
    color: var(--warn);
    border-color: rgba(251, 191, 36, 0.25);
}
.badge-success {
    background: var(--ok-light);
    color: var(--ok);
    border-color: rgba(52, 211, 153, 0.25);
}
.badge-info {
    background: var(--info-light);
    color: var(--info);
    border: 2px solid var(--info);
}

/* ── Risk Badge (Permission 360) ───────────────────────────── */
.risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    font-family: var(--font-ui);
    border: 2px solid;
}
.risk-critical { background: var(--critical); color: var(--bg-paper); border-color: var(--border-ink); }
.risk-high     { background: var(--warn); color: var(--bg-root); border-color: var(--border-ink); }
.risk-medium   { background: var(--info-light); color: var(--info); border-color: var(--info); }
.risk-low      { background: var(--ok-light); color: var(--ok); border-color: var(--ok); }

/* ── Mode Toggle (History) ─────────────────────────────────── */
.mode-toggle {
    display: inline-flex;
    gap: 2px;
    background: var(--bg-input);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* ── Tab Panel ─────────────────────────────────────────────── */
.tab-panel { animation: fadeIn 0.3s ease-out; }

/* ── Health Finding Card ───────────────────────────────────── */
.finding-card {
    padding: 16px;
    margin-bottom: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-left: 3px solid var(--text-muted);
    transition: border-color var(--transition);
}
.finding-card:hover { border-color: var(--border-hover); }
.finding-card.finding-critical { border-left-color: var(--critical); }
.finding-card.finding-high     { border-left-color: var(--warn); }
.finding-card.finding-medium   { border-left-color: var(--info); }

/* ── Light Theme modal overrides ──────────────────────────── */
[data-theme="light"] .modal-overlay { background: rgba(0, 0, 0, 0.30); }
[data-theme="light"] .modal-content { background: rgba(255, 255, 255, 0.90); border-color: rgba(0,0,0,0.08); }

/* ── Investigation Bar (shared across Investigate pages) ──── */
.inv-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    margin-bottom: 12px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: .8rem;
    flex-wrap: wrap;
}
.inv-sf-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: .75rem;
    white-space: nowrap;
    padding-right: 12px;
    border-right: 1px solid var(--border);
}
.inv-items {
    display: flex;
    gap: 6px;
    flex: 1;
    flex-wrap: wrap;
}
.inv-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    text-decoration: none;
    color: var(--text);
    transition: all .2s;
    white-space: nowrap;
}
.inv-item:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}
.inv-item-active {
    border-color: var(--accent);
    background: var(--accent-light);
}
.inv-item-label { font-weight: 600; font-size: .78rem; }
.inv-item-meta { font-size: .72rem; color: var(--text-muted); }
.inv-no-data { color: var(--text-muted); opacity: .6; }
.inv-running-text { color: var(--accent); }
.inv-score { font-weight: 600; color: var(--accent); }
.inv-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.inv-dot-ok { background: #10b981; }
.inv-dot-none { background: var(--text-muted); opacity: .4; }
.inv-dot-running {
    background: var(--accent);
    animation: inv-pulse 1.2s infinite;
}
@keyframes inv-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}
.inv-run-all {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    margin-left: auto;
}
.inv-run-all:hover {
    background: var(--accent);
    color: var(--bg);
}
.inv-run-all:disabled {
    opacity: .5;
    cursor: not-allowed;
}
/* Cross-links from Audit to Perm360 */
.inv-xlink {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: .72rem;
    font-weight: 500;
    text-decoration: none;
    transition: all .2s;
    white-space: nowrap;
}
.inv-xlink:hover {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* ── Toast Notification System ────────────────────────────── */
#matrix-toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 420px;
}
.matrix-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--bg-elevated);
    border: 2px solid var(--border-strong);
    box-shadow: 4px 4px 0 0 var(--border-ink);
    font-size: .88rem;
    line-height: 1.45;
    color: var(--text);
    pointer-events: all;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity .24s ease, transform .24s ease;
}
.matrix-toast-visible {
    opacity: 1;
    transform: translateX(0);
}
.matrix-toast-exit {
    opacity: 0;
    transform: translateX(40px) scale(.97);
}
.matrix-toast-info { background: var(--bg-elevated); border-color: var(--accent); border-left: 4px solid var(--accent); }
.matrix-toast-success { background: var(--bg-elevated); border-color: var(--ok); border-left: 4px solid var(--ok); }
.matrix-toast-warning { background: var(--bg-elevated); border-color: var(--warn); border-left: 4px solid var(--warn); }
.matrix-toast-error { background: var(--bg-elevated); border-color: var(--danger); border-left: 4px solid var(--danger); }
.matrix-toast-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.matrix-toast-msg { flex: 1; word-break: break-word; }
.matrix-toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    opacity: .6;
    transition: opacity .2s;
}
.matrix-toast-close:hover { opacity: 1; }

/* ── Agent Flow Visualization ─────────────────────────────── */
.ai-agent-flow {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--bg-inset);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
}
.af-node {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 2px solid var(--border-strong);
    width: 100%;
    transition: all .3s ease;
}
.af-node.af-running {
    border-color: var(--accent);
    background: var(--accent-light);
    animation: af-pulse 1.5s ease-in-out infinite;
}
.af-node.af-done {
    border-color: var(--ok);
    background: var(--ok-light);
}
.af-node.af-final {
    border-color: var(--secondary);
    background: var(--secondary-light);
}
@keyframes af-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 0 3px var(--accent-glow); }
}
.af-status { font-size: 1rem; flex-shrink: 0; }
.af-icon { font-size: 1.1rem; flex-shrink: 0; }
.af-label { flex: 1; min-width: 0; }
.af-name { font-size: .8rem; font-weight: 600; text-transform: capitalize; }
.af-detail { font-size: .7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.af-arrow { text-align: center; width: 100%; font-size: .65rem; color: var(--text-muted); line-height: 1; padding: 2px 0; opacity: .5; }
