/* ============================================================================
 * CVFinder — design tokens
 * Professional slate + emerald palette. Cool neutral surfaces, a single warm
 * green accent, layered shadows for depth instead of hard borders everywhere.
 * ========================================================================= */
:root {
    /* Surfaces */
    --bg: #f5f7fa;                /* main canvas */
    --bg-soft: #0f172a;            /* sidebar / dark surfaces (slate-900) */
    --bg-soft-2: #1e293b;          /* gradient stop for sidebar (slate-800) */
    --bg-card: #ffffff;            /* cards on the light canvas */
    --bg-card-alt: #f8fafc;        /* nested / inset surfaces (slate-50) */
    --bg-input: #ffffff;

    /* Borders */
    --border: #e2e8f0;             /* slate-200 */
    --border-strong: #cbd5e1;      /* slate-300 */

    /* Accent — emerald */
    --primary: #10b981;            /* emerald-500 */
    --primary-dim: #059669;        /* emerald-600 (hover / headings) */
    --primary-deep: #047857;       /* emerald-700 */
    --primary-glow: rgba(16, 185, 129, 0.28);
    --primary-soft: rgba(16, 185, 129, 0.10);
    --primary-on: #ffffff;         /* text on primary bg */

    /* Text */
    --text: #0f172a;               /* slate-900 */
    --text-soft: #334155;          /* slate-700 */
    --text-dim: #64748b;            /* slate-500 */
    --sidebar-text: #e2e8f0;
    --sidebar-text-dim: #94a3b8;

    /* Status */
    --danger: #e11d48;             /* rose-600 */
    --danger-soft: rgba(225, 29, 72, 0.10);
    --warning: #d97706;            /* amber-600 */
    --warning-soft: rgba(217, 119, 6, 0.10);
    --success: var(--primary-dim);

    /* Effects */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.10), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
    --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
 * Base
 * ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    font-size: 14.5px;
    line-height: 1.55;
    margin: 0; padding: 0; min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
}

/* Tabular figures wherever numbers carry meaning. */
.stat, .badge, .tag, th, .topbar-user, .muted strong, code, kbd { font-variant-numeric: tabular-nums; }

/* Subtle scrollbars that match the palette. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
*::-webkit-scrollbar-track { background: transparent; }

a { color: var(--primary-dim); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-deep); text-decoration: none; }

h1, h2, h3, h4, h5 {
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.015em;
    margin-top: 0;
    line-height: 1.25;
}
h1 { font-size: 1.875rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; margin-bottom: 12px; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; color: var(--text-soft); }

p { margin: 0 0 12px; color: var(--text-soft); }
p:last-child { margin-bottom: 0; }

::selection { background: var(--primary-soft); color: var(--primary-deep); }

/* ============================================================================
 * App shell
 * ========================================================================= */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: 252px;
    background:
        radial-gradient(ellipse 600px 280px at -10% 0%, rgba(16, 185, 129, 0.08), transparent 70%),
        linear-gradient(180deg, var(--bg-soft) 0%, var(--bg-soft-2) 100%);
    padding: 22px 0 16px;
    display: flex; flex-direction: column;
    color: var(--sidebar-text);
    box-shadow: 1px 0 0 rgba(255, 255, 255, 0.04) inset, 4px 0 24px -8px rgba(0, 0, 0, 0.30);
    position: sticky; top: 0; height: 100vh;
}

.app-brand {
    padding: 0 24px 20px; font-size: 1.35rem; font-weight: 800;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    letter-spacing: -0.025em;
    display: flex; align-items: center; gap: 10px;
}
.app-brand span { color: var(--primary); font-weight: 800; }
.app-brand::before {
    content: '';
    display: inline-block;
    width: 28px; height: 28px;
    background:
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.35), transparent 50%),
        linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.20);
    margin-right: 0;
}

/* Sidebar section label (optional — applied where you mark <div class="nav-section">) */
.nav-section {
    padding: 14px 24px 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--sidebar-text-dim);
    opacity: 0.7;
}

.nav-item {
    display: flex; align-items: center;
    padding: 10px 24px;
    margin: 2px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text-dim);
    font-size: 0.92rem;
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}
.nav-item:hover { color: #ffffff; background: rgba(255, 255, 255, 0.04); text-decoration: none; }
.nav-item.active {
    color: #ffffff;
    background: rgba(16, 185, 129, 0.12);
    text-decoration: none;
}
.nav-item.active::before {
    content: '';
    position: absolute; left: -12px; top: 8px; bottom: 8px;
    width: 3px; background: var(--primary); border-radius: 0 3px 3px 0;
}
.app-sidebar a { color: inherit; }

.app-main {
    flex: 1;
    padding: 28px 44px 56px;
    max-width: 1320px;
    width: 100%;
    min-width: 0; /* allow children to shrink inside flex */
}

/* ============================================================================
 * Topbar
 * ========================================================================= */
.topbar {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 10px 16px;
    margin-bottom: 24px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    position: sticky;
    top: 12px;
    z-index: 50;
}
.topbar-user {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 0.86rem; color: var(--text-soft);
}
.topbar-user strong { color: var(--text); font-weight: 600; }
.topbar-sep { opacity: 0.35; padding: 0 2px; }
.topbar-badge { margin-left: 4px; }
.topbar-btn { padding: 6px 12px; font-size: 0.76rem; }

/* ============================================================================
 * Cards
 * ========================================================================= */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), border-color var(--transition);
    position: relative;
}

/* The first heading inside a card gets a subtle bottom border treatment
 * to act as a section separator without needing extra markup. */
.card > h2:first-child,
.card > .flex-row:first-child > h2:only-child {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

/* Nested cards (search results, list rows) — flatter, no separator on heading. */
.card .card {
    background: var(--bg-card-alt);
    box-shadow: none;
    border-color: var(--border);
    padding: 14px 16px;
    margin-bottom: 10px;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
}
.card .card:hover {
    border-color: var(--border-strong);
    background: #ffffff;
}
.card .card > h2:first-child,
.card .card > .flex-row:first-child > h2:only-child {
    padding-bottom: 0; border-bottom: none; margin-bottom: 8px;
}

/* ============================================================================
 * Buttons
 * ========================================================================= */
.btn {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.86rem;
    letter-spacing: 0;
    text-transform: none;
    transition: all var(--transition);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    line-height: 1.2;
    white-space: nowrap;
    user-select: none;
}
.btn:hover {
    border-color: var(--primary);
    color: var(--primary-deep);
    background: var(--primary-soft);
}
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
    border-color: var(--primary);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] {
    opacity: 0.5; cursor: not-allowed;
    background: var(--bg-card); color: var(--text-dim); border-color: var(--border);
    box-shadow: none;
}

.btn.btn-primary {
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dim) 100%);
    border-color: var(--primary-dim);
    color: var(--primary-on);
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn.btn-primary:hover {
    background: linear-gradient(180deg, var(--primary-dim) 0%, var(--primary-deep) 100%);
    border-color: var(--primary-deep);
    color: var(--primary-on);
    box-shadow: 0 6px 16px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn.btn-primary:disabled {
    background: var(--primary-soft); border-color: transparent; color: var(--primary-dim);
    box-shadow: none;
}

.btn.btn-danger { color: var(--danger); border-color: var(--border-strong); background: var(--bg-card); }
.btn.btn-danger:hover { background: var(--danger); color: #ffffff; border-color: var(--danger); box-shadow: 0 4px 12px rgba(225, 29, 72, 0.30); }

.btn.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.btn-ghost:hover { background: var(--bg-card-alt); color: var(--text); border-color: var(--border); box-shadow: none; }

/* ============================================================================
 * Forms
 * ========================================================================= */
.form-group { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
label, .form-group label {
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
}

input, select, textarea {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.92rem;
    width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.02);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow), inset 0 1px 1px rgba(15, 23, 42, 0.02);
    background: #ffffff;
}
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%2364748b' d='M6 9L1.5 4h9z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }

/* ============================================================================
 * Pills, tags, badges
 * ========================================================================= */
.tag {
    display: inline-block;
    padding: 3px 10px;
    margin: 2px;
    border: 1px solid transparent;
    color: var(--primary-deep);
    background: var(--primary-soft);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.badge-pending { background: var(--warning-soft); color: var(--warning); }
.badge-approved { background: var(--primary-soft); color: var(--primary-deep); }
.badge-rejected { background: var(--danger-soft); color: var(--danger); }

/* ============================================================================
 * Alerts
 * ========================================================================= */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid transparent;
    border-left-width: 4px;
    font-size: 0.92rem;
}
.alert-error   { color: var(--danger);      border-color: var(--danger);      background: var(--danger-soft); }
.alert-success { color: var(--primary-deep); border-color: var(--primary-dim); background: var(--primary-soft); }
.alert-warning { color: var(--warning);     border-color: var(--warning);     background: var(--warning-soft); }

/* ============================================================================
 * Layout helpers
 * ========================================================================= */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.muted { color: var(--text-dim); font-size: 0.88rem; }

.flex-row { display: flex; gap: 12px; align-items: center; }
.flex-spacer { flex: 1; }
.text-right { text-align: right; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-4 { margin-top: 32px; }

/* ============================================================================
 * Terms and Conditions scroll box
 * ========================================================================= */
.terms-scroll-box {
    height: 440px;
    overflow-y: scroll;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    background: var(--bg-card-alt);
    font-size: 0.9rem;
    line-height: 1.65;
    scroll-behavior: smooth;
}
.terms-body h3 { margin: 0 0 4px; font-size: 1.05rem; }
.terms-body h4 { margin: 20px 0 6px; font-size: 0.93rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.terms-body p  { margin: 0 0 10px; }
.terms-body ul { margin: 0 0 10px; padding-left: 20px; }
.terms-body li { margin-bottom: 5px; }
.terms-accept-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    margin-top: 12px;
}
.terms-accept-bar input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; }
.terms-accept-bar label { font-size: 0.9rem; color: var(--text-soft); cursor: pointer; }

/* ============================================================================
 * Tables
 * ========================================================================= */
table { width: 100%; border-collapse: collapse; }
/* Admin list tables can be column-heavy; if they exceed the card width they scroll
 * horizontally within the card instead of overflowing the page. Cells still wrap
 * normally, so action buttons and badges aren't forced onto one long line. */
.card > table { display: block; overflow-x: auto; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th {
    color: var(--text-dim);
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg-card-alt);
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--bg-card-alt); }
tbody tr:last-child td { border-bottom: none; }

/* ============================================================================
 * Skill picker
 * ========================================================================= */
.skill-picker {
    max-height: 220px; overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-card-alt);
}
.skill-picker label {
    display: block; padding: 4px 0;
    color: var(--text-soft); font-size: 0.9rem; font-weight: 500;
    cursor: pointer; text-transform: none; letter-spacing: 0;
}
.skill-picker input[type=checkbox] { margin-right: 8px; width: auto; }

/* ============================================================================
 * Dialogs
 * ========================================================================= */
.dialog-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    animation: dialog-fade 0.15s ease-out;
}
.dialog {
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    border-radius: var(--radius-lg);
    min-width: 420px; max-width: 620px;
    animation: dialog-pop 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

@keyframes dialog-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialog-pop  { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ============================================================================
 * Hero (landing page)
 * ========================================================================= */
.hero {
    text-align: center;
    padding: 88px 20px 64px;
    margin: -28px -44px 32px;
    background:
        radial-gradient(ellipse 800px 320px at 50% 0%, rgba(16, 185, 129, 0.12), transparent 65%),
        radial-gradient(ellipse 600px 240px at 80% 100%, rgba(16, 185, 129, 0.05), transparent 70%),
        linear-gradient(180deg, #ffffff, var(--bg));
    border-bottom: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}
/* Subtle dotted texture in the hero — adds depth without noise. */
.hero::before {
    content: '';
    position: absolute; inset: 0;
    background-image: radial-gradient(circle, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
    background-size: 22px 22px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
    pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary-deep) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.03em;
    margin-bottom: 12px;
}
.hero .tagline {
    color: var(--text-soft);
    font-size: 1.15rem;
    line-height: 1.55;
    margin-top: 0;
    max-width: 620px;
    margin-left: auto; margin-right: auto;
}

/* Eyebrow pill above the hero title — apply with class="eyebrow" if desired. */
.eyebrow {
    display: inline-block;
    padding: 5px 12px;
    margin-bottom: 18px;
    background: var(--primary-soft);
    color: var(--primary-deep);
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

/* ============================================================================
 * Feature cards (Home page)
 * ========================================================================= */
.feature-card {
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    position: relative;
    overflow: hidden;
}
.feature-card::after {
    content: '';
    position: absolute; left: 0; right: 0; top: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-deep));
    opacity: 0;
    transition: opacity var(--transition);
}
.feature-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-strong);
}
.feature-card:hover::after { opacity: 1; }
.feature-card .feature-icon {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary-deep);
    font-size: 1.25rem;
    margin-bottom: 14px;
    border: 1px solid rgba(16, 185, 129, 0.20);
}

/* ============================================================================
 * Inline code & kbd
 * ========================================================================= */
code, kbd {
    font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.85em;
    padding: 2px 6px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-soft);
}
kbd { box-shadow: inset 0 -1px 0 var(--border-strong); }

/* ============================================================================
 * Misc utilities & visual polish
 * ========================================================================= */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.stat { font-size: 1.6rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.stat-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* ============================================================================
 * Sidebar nav badge (unread message count, etc.)
 * ========================================================================= */
.nav-item { justify-content: space-between; }
.nav-badge {
    display: inline-flex;
    align-items: center; justify-content: center;
    min-width: 22px; height: 20px;
    padding: 0 7px;
    margin-left: 10px;
    border-radius: 999px;
    background: var(--primary);
    color: var(--primary-on);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.20);
    font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: #ffffff; color: var(--primary-deep); }

/* ============================================================================
 * Messages — thread list + bubbles
 * ========================================================================= */
.thread-list { display: flex; flex-direction: column; gap: 6px; }
.thread-row {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: all var(--transition);
}
.thread-row:hover { border-color: var(--border-strong); background: var(--bg-card-alt); }
.thread-row.is-selected {
    border-color: var(--primary);
    border-left-color: var(--primary);
    background: var(--primary-soft);
}
.thread-row.is-unread {
    background: #ffffff;
    border-left-color: var(--primary);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.thread-row.is-unread.is-selected { background: var(--primary-soft); }
.thread-row-header {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 4px;
}
.thread-row-subject {
    font-weight: 600;
    color: var(--text);
    flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 8px;
}
.thread-row.is-unread .thread-row-subject { font-weight: 700; }
.thread-row:not(.is-unread) .thread-row-subject { color: var(--text-soft); font-weight: 500; }
.thread-row-badge { flex-shrink: 0; }
.thread-row-counterpart {
    font-size: 0.78rem;
    color: var(--text-soft);
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-row-preview {
    font-size: 0.85rem;
    color: var(--text-dim);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-row.is-unread .thread-row-preview { color: var(--text-soft); }
.thread-row-meta { font-size: 0.75rem; margin-top: 4px; }

.unread-dot {
    display: inline-block;
    width: 8px; height: 8px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.20);
}

.unread-divider {
    display: flex; align-items: center; gap: 12px;
    margin: 16px 0 12px;
    color: var(--primary-deep);
    font-size: 0.74rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
}
.unread-divider::before,
.unread-divider::after {
    content: ''; flex: 1; height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0.6;
}

.message-bubble {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--bg-card);
    transition: border-color var(--transition);
}
.message-bubble.is-mine {
    background: var(--bg-card-alt);
    border-left: 3px solid var(--primary);
}
.message-bubble.is-theirs { border-left: 3px solid var(--border); }
.message-bubble.is-unread {
    border-color: var(--primary);
    background: rgba(16, 185, 129, 0.04);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.08);
}
.message-meta {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    font-size: 0.78rem;
}
.message-read-tick {
    margin-left: 8px;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--primary-deep);
}
.message-read-tick.muted { color: var(--text-dim); }

/* ============================================================================
 * Mobile hamburger drawer
 * ========================================================================= */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 36px; height: 28px;
    padding: 4px;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.nav-toggle span { display: block; height: 3px; background: var(--text); border-radius: 2px; }
.nav-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45); z-index: 90;
}

@media (max-width: 900px) {
    .nav-toggle { display: inline-flex; }

    .app-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 100;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.30);
    }
    .app-shell.nav-open .app-sidebar { transform: translateX(0); }
    .app-shell.nav-open .nav-backdrop { display: block; }

    .app-main {
        padding: 16px;
        max-width: 100%;
    }
    .hero { margin: -16px -16px 16px; padding: 48px 16px 32px; }

    .topbar {
        flex-wrap: wrap; justify-content: flex-start;
        padding: 8px 12px;
    }
    .topbar-user { flex-wrap: wrap; font-size: 0.8rem; }

    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    .hero h1 { font-size: 2rem; }
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.15rem; }

    .card { padding: 18px; margin-bottom: 16px; }
    .dialog { min-width: 0; width: calc(100vw - 32px); padding: 22px; border-radius: var(--radius); }

    .card > table { display: block; overflow-x: auto; white-space: nowrap; }

    .flex-row { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .app-main { padding: 12px; }
    .btn { padding: 8px 14px; font-size: 0.8rem; }
    .topbar-btn { padding: 6px 10px; }
    .hero h1 { font-size: 1.6rem; }
}

/* ============================================================================
 * WASM boot loader + error banner
 * ========================================================================= */
.app-loader {
    position: fixed; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px;
    background: var(--bg);
    color: var(--text);
    z-index: 9999;
}
.app-loader-brand { font-size: 2rem; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.app-loader-brand span { color: var(--text); }
.app-loader-spinner {
    width: 44px; height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: app-loader-spin 0.9s linear infinite;
}
.app-loader-text {
    color: var(--text-dim); font-size: 0.78rem;
    letter-spacing: 0.08em; text-transform: uppercase;
}
@keyframes app-loader-spin { to { transform: rotate(360deg); } }

.busy-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 10000;
    animation: dialog-fade 0.15s ease;
}
.busy-overlay-spinner {
    width: 56px; height: 56px;
    border: 4px solid rgba(255, 255, 255, 0.25);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: app-loader-spin 0.8s linear infinite;
}

/* Prominent AI-search loader shown while the vector + LLM pipeline runs. */
.ai-search-loader {
    display: flex; flex-direction: column; align-items: center;
    gap: 14px; text-align: center;
    padding: 32px 24px; margin-top: 12px;
    background: linear-gradient(135deg, var(--bg-card-alt), var(--bg-card));
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
}
.ai-search-loader-brain {
    font-size: 2.6rem; line-height: 1;
    animation: ai-brain-pulse 1.4s ease-in-out infinite;
}
.ai-search-loader-ring {
    position: relative; width: 56px; height: 56px;
}
.ai-search-loader-ring::before {
    content: ""; position: absolute; inset: 0;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-right-color: var(--primary);
    border-radius: 50%;
    animation: app-loader-spin 0.9s linear infinite;
}
.ai-search-loader-msg {
    font-size: 1.02rem; font-weight: 700; color: var(--text);
    min-height: 1.4em; transition: opacity 0.3s ease;
}
.ai-search-loader-sub {
    font-size: 0.78rem; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--text-dim); font-weight: 600;
}
.ai-search-loader-dots span {
    display: inline-block; width: 7px; height: 7px; margin: 0 3px;
    background: var(--primary); border-radius: 50%;
    animation: ai-dot-bounce 1.2s ease-in-out infinite;
}
.ai-search-loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-search-loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-brain-pulse {
    0%, 100% { transform: scale(1); filter: none; }
    50% { transform: scale(1.12); filter: drop-shadow(0 0 6px var(--primary)); }
}
@keyframes ai-dot-bounce {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-6px); opacity: 1; }
}

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--danger);
    color: #ffffff;
    padding: 12px 20px;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
    z-index: 10000;
    font-size: 0.9rem;
}
#blazor-error-ui .dismiss {
    cursor: pointer; position: absolute;
    right: 16px; top: 8px; font-size: 1.1rem;
}
#blazor-error-ui a.reload { color: #ffffff; text-decoration: underline; margin-left: 12px; }
