/* ════════════════════════════════════════════════════════════
   Vidhijna v3 — Indian Business Law AI
   Aesthetic: Refined legal chambers — warm ivory, deep walnut,
   burnished brass. Card panels with soft depth.
   ════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
    /* Warm dark palette — walnut / charcoal base */
    --walnut-950: #0f0e0c;
    --walnut-900: #1a1816;
    --walnut-850: #201e1b;
    --walnut-800: #2a2723;
    --walnut-700: #37332e;
    --walnut-600: #4a453d;
    --walnut-500: #5e574e;
    --walnut-400: #7a7268;

    /* Brass accent — warm, trustworthy */
    --brass-500: #c49a4b;
    --brass-400: #d4ab5e;
    --brass-300: #e0be7a;
    --brass-200: #ecd49e;
    --brass-100: #f5e6c3;
    --brass-dim: rgba(196, 154, 75, 0.10);
    --brass-glow: rgba(196, 154, 75, 0.18);
    --brass-border: rgba(196, 154, 75, 0.25);

    /* Ivory tones for text */
    --ivory-0: #faf6ef;
    --ivory-100: #f0ebe2;
    --ivory-200: #d6cfc3;
    --ivory-300: #b0a898;
    --ivory-400: #8a8070;
    --ivory-500: #645c50;

    /* Semantic */
    --risk-high: #e25656;
    --risk-med: #dba24f;
    --risk-low: #5bb87a;
    --risk-info: #5b8fd6;

    /* Surfaces — card-panel system */
    --surf-0: var(--walnut-950);
    --surf-1: var(--walnut-900);
    --surf-2: var(--walnut-800);
    --surf-3: var(--walnut-700);
    --surf-card: var(--walnut-850);
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.10);
    --border-card: rgba(255, 255, 255, 0.08);

    /* Typography — intentional pairings */
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-ui: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Shadows — layered depth */
    --shd-xs: 0 1px 2px rgba(0,0,0,0.3);
    --shd-sm: 0 2px 6px rgba(0,0,0,0.35);
    --shd-md: 0 6px 20px rgba(0,0,0,0.4);
    --shd-lg: 0 12px 40px rgba(0,0,0,0.45);
    --shd-xl: 0 24px 64px rgba(0,0,0,0.55);
    --shd-card: 0 4px 24px rgba(0,0,0,0.35), 0 1px 3px rgba(0,0,0,0.25);
    --shd-card-hover: 0 8px 40px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
    --shd-brass: 0 4px 24px rgba(196, 154, 75, 0.15);
    --shd-inset: inset 0 1px 0 rgba(255,255,255,0.04);

    /* Layout */
    --sb-w: clamp(200px, 18vw, 300px);
    --topbar-h: 3.5rem;
    --dock-h: 6rem;

    /* Accent aliases */
    --accent: var(--brass-500);
    --accent-text: var(--brass-300);
    --accent-dim: var(--brass-dim);
    --accent-glow: var(--brass-glow);

    /* Radii — card-panel system */
    --r-xs: 4px;
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-2xl: 28px;
    --r-card: 18px;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --t: 0.22s;
    --t-fast: 0.14s;
}

/* Mode accent overrides */
[data-mode="research"] {
    --accent: #5ba3d6;
    --accent-text: #8ec5f0;
    --accent-dim: rgba(91, 163, 214, 0.10);
    --accent-glow: rgba(91, 163, 214, 0.18);
}
[data-mode="chat"] {
    --accent: #5bb87a;
    --accent-text: #8ed6a4;
    --accent-dim: rgba(91, 184, 122, 0.10);
    --accent-glow: rgba(91, 184, 122, 0.18);
}
[data-mode="document"] {
    --accent: #a07ecc;
    --accent-text: #c4a8e8;
    --accent-dim: rgba(160, 126, 204, 0.10);
    --accent-glow: rgba(160, 126, 204, 0.18);
}
[data-mode="draft"] {
    --accent: #d68a4a;
    --accent-text: #eaad73;
    --accent-dim: rgba(214, 138, 74, 0.10);
    --accent-glow: rgba(214, 138, 74, 0.18);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    height: 100%;
    /* Use dvh where supported so mobile browser chrome doesn't break layout */
    height: 100dvh;
}
body {
    font-family: var(--font-ui);
    background: var(--surf-0);
    color: var(--ivory-200);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    line-height: 1.6;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(196,154,75,0.03) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(196,154,75,0.02) 0%, transparent 50%);
}

/* ── Drop overlay ───────────────────────────────────────────── */
.drop-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(15, 14, 12, 0.88);
    backdrop-filter: blur(16px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; visibility: hidden;
    transition: all 0.3s var(--ease);
}
.drop-overlay.active { opacity: 1; pointer-events: all; visibility: visible; }
.drop-card {
    padding: 60px 80px;
    background: var(--surf-card);
    border: 2px dashed var(--accent);
    border-radius: var(--r-2xl);
    box-shadow: var(--shd-xl), 0 0 80px var(--accent-glow);
    display: flex; flex-direction: column; align-items: center;
    gap: 16px; text-align: center;
}
.drop-scales { font-size: 3.5rem; line-height: 1; filter: drop-shadow(0 0 20px var(--accent-glow)); }
.drop-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; color: var(--ivory-0); }
.drop-formats { font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent); letter-spacing: 2px; }

/* ── Shell ──────────────────────────────────────────────────── */
.shell { display: flex; height: 100%; overflow: hidden; overflow-x: hidden; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sb-w); flex-shrink: 0;
    background: var(--surf-1);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 40;
    transition: width var(--t) var(--ease);
}
.sb-brand {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.brand-emblem {
    width: 38px; height: 38px; flex-shrink: 0;
    background: linear-gradient(145deg, var(--walnut-600), var(--walnut-800));
    border: 1px solid var(--brass-border);
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    color: var(--brass-400);
    box-shadow: var(--shd-brass), var(--shd-inset);
}
.brand-copy { flex: 1; min-width: 0; }
.brand-name {
    display: block;
    font-family: var(--font-display);
    font-size: 1.15rem; font-weight: 700;
    color: var(--ivory-0);
    letter-spacing: 0.01em; line-height: 1.2;
}
.brand-tagline {
    display: block;
    font-size: 0.58rem; font-weight: 600;
    color: var(--ivory-500);
    text-transform: uppercase; letter-spacing: 2px;
}
.sb-toggle {
    background: none; border: none; cursor: pointer;
    color: var(--ivory-400); padding: 5px;
    border-radius: var(--r-xs);
    transition: color var(--t);
}
.sb-toggle:hover { color: var(--ivory-100); }

/* Sidebar nav */
.sb-nav { padding: 18px 12px 10px; }
.sb-label {
    font-size: 0.56rem; font-weight: 700;
    color: var(--ivory-500);
    text-transform: uppercase; letter-spacing: 2px;
    padding: 0 8px; margin-bottom: 10px;
}
.mode-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 11px; width: 100%;
    background: none; border: 1px solid transparent;
    cursor: pointer; border-radius: var(--r-md);
    text-align: left; color: var(--ivory-300);
    transition: all var(--t-fast) var(--ease);
    margin-bottom: 3px;
}
.mode-item:hover {
    background: var(--surf-2);
    color: var(--ivory-100);
    border-color: var(--border);
}
.mode-item.active {
    background: var(--surf-card);
    color: var(--accent-text);
    border-color: var(--border-strong);
    box-shadow: var(--shd-xs), var(--shd-inset);
}
.mi-icon {
    width: 32px; height: 32px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--r-sm);
    background: var(--surf-2);
    color: var(--ivory-400);
    border: 1px solid var(--border);
    transition: all var(--t-fast);
}
.mode-item.active .mi-icon {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: rgba(255,255,255,0.08);
    box-shadow: 0 0 12px var(--accent-glow);
}
.mode-item:hover .mi-icon { color: var(--ivory-200); }
.mi-name { display: block; font-size: 0.82rem; font-weight: 600; line-height: 1.2; }
.mi-hint { display: block; font-size: 0.65rem; color: var(--ivory-500); margin-top: 1px; }
.mode-item.active .mi-hint { color: var(--accent-text); opacity: 0.6; }

/* Sidebar sections */
.sb-section { padding: 0 12px 14px; }
.sb-section.sb-threads { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.depth-control {
    background: var(--surf-card);
    border-radius: var(--r-lg);
    padding: 16px;
    border: 1px solid var(--border-card);
    box-shadow: var(--shd-xs);
}
.depth-row {
    display: flex; justify-content: space-between;
    font-size: 0.75rem; color: var(--ivory-300); margin-bottom: 10px;
}
.depth-val {
    font-family: var(--font-mono); font-weight: 700;
    color: var(--accent); font-size: 0.85rem;
}
.depth-slider {
    width: 100%; margin-bottom: 10px;
    -webkit-appearance: none; height: 3px;
    background: var(--surf-3); border-radius: 99px; outline: none;
}
.depth-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px;
    border-radius: 50%; background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow); cursor: pointer;
    transition: transform var(--t);
}
.depth-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.depth-presets { display: flex; gap: 4px; }
.dp-btn {
    flex: 1; padding: 6px 4px;
    font-size: 0.64rem; font-weight: 700;
    background: none; border: 1px solid var(--border);
    border-radius: var(--r-sm); cursor: pointer;
    color: var(--ivory-400); transition: all var(--t);
}
.dp-btn.active, .dp-btn:hover {
    background: var(--surf-3);
    color: var(--accent-text);
    border-color: var(--accent-dim);
}

.sb-select {
    width: 100%; background: var(--surf-card);
    border: 1px solid var(--border-card); border-radius: var(--r-md);
    padding: 10px 12px; font-family: var(--font-ui);
    font-size: 0.82rem; color: var(--ivory-200);
    outline: none; cursor: pointer;
    transition: border-color var(--t);
}
.sb-select:focus { border-color: var(--accent); }
.sb-select option { background: var(--surf-2); }

/* Thread list */
.thread-list { padding: 0 0 8px; }
.thread-empty {
    font-size: 0.72rem; color: var(--ivory-500);
    padding: 10px 8px; font-style: italic;
}
.thread-item {
    padding: 10px 12px;
    border-radius: var(--r-md); cursor: pointer;
    transition: all var(--t);
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
}
.thread-item:hover { background: var(--surf-2); }
.thread-item.active {
    background: var(--surf-card);
    border-left: 3px solid var(--accent);
    box-shadow: var(--shd-xs);
}
.ti-title {
    font-size: 0.78rem; font-weight: 500;
    color: var(--ivory-200);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ti-meta { font-size: 0.64rem; color: var(--ivory-500); margin-top: 3px; }

/* Sidebar footer */
.sb-foot {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
    margin-top: auto; background: var(--surf-1);
}
.sb-status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ivory-500); flex-shrink: 0;
    transition: background var(--t), box-shadow var(--t);
}
.sb-status-dot.online {
    background: var(--risk-low);
    box-shadow: 0 0 0 3px rgba(91, 184, 122, 0.2);
    animation: pulse-online 2s infinite;
}
.sb-status-dot.offline { background: var(--risk-high); }
@keyframes pulse-online {
    0%, 100% { box-shadow: 0 0 0 3px rgba(91, 184, 122, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(91, 184, 122, 0.1); }
}
.sb-status-text { font-size: 0.7rem; color: var(--ivory-400); font-weight: 500; }

/* ── Main ───────────────────────────────────────────────────── */
.main {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    background: var(--surf-0);
    position: relative;
    overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h); flex-shrink: 0;
    background: var(--surf-1);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; z-index: 30;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 14px; }
.mode-badge {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 14px;
    background: var(--accent-dim);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 99px;
    font-size: 0.74rem; font-weight: 700;
    color: var(--accent-text);
    letter-spacing: 0.02em;
    transition: all var(--t);
}
#mb-glyph { font-size: 0.9rem; }
.tb-thread {
    font-family: var(--font-mono); font-size: 0.7rem;
    color: var(--ivory-500); letter-spacing: 0.05em;
}
.loop-badge {
    display: flex; align-items: center; gap: 5px;
    padding: 5px 11px;
    background: var(--surf-card); border: 1px solid var(--border-card);
    border-radius: 99px; font-size: 0.7rem;
    font-weight: 700; color: var(--accent-text);
    font-family: var(--font-mono);
    box-shadow: var(--shd-xs);
}
.btn-new {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-md);
    font-family: var(--font-ui); font-size: 0.76rem; font-weight: 700;
    color: var(--ivory-200); cursor: pointer;
    transition: all var(--t);
    box-shadow: var(--shd-xs);
}
.btn-new:hover {
    background: var(--surf-3);
    border-color: var(--accent);
    color: var(--ivory-0);
    box-shadow: var(--shd-sm), 0 0 16px var(--accent-dim);
    transform: translateY(-1px);
}

.sp-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-card);
    background: var(--surf-card);
    color: var(--ivory-300);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: border-color var(--t), color var(--t), transform var(--t);
    box-shadow: var(--shd-xs);
}
.sp-toggle svg {
    width: 16px;
    height: 16px;
}
.sp-toggle:hover {
    border-color: var(--accent);
    color: var(--accent-text);
    box-shadow: var(--shd-sm);
    transform: translateY(-1px);
}

/* ── Workspace ──────────────────────────────────────────────── */
.workspace {
    flex: 1; position: relative; overflow: hidden;
    display: flex; flex-direction: column;
}
.view {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    min-height: 0; overflow: hidden;
    animation: view-in 0.3s var(--ease) both;
}
@keyframes view-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
.view.hidden { display: none !important; }
.view.active { z-index: 10; }

/* ══════════════════════════════════════════════════════════════
   WELCOME VIEW — Card-panel dashboard layout
   ══════════════════════════════════════════════════════════════ */
.view-welcome { overflow: hidden; }
.welcome-scroll {
    flex: 1; min-height: 0;
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 36px 36px 3rem;
}
.welcome-inner {
    max-width: 920px; margin: 0 auto;
    display: flex; flex-direction: column;
    align-items: center; text-align: center;
}

/* Hero area */
.wc-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.62rem; font-weight: 600;
    letter-spacing: 3px; color: var(--accent);
    text-transform: uppercase;
    margin-bottom: 22px;
    padding: 7px 18px;
    border: 1px solid var(--brass-border);
    border-radius: 99px;
    background: var(--accent-dim);
    box-shadow: 0 0 20px var(--accent-glow);
    max-width: 90vw;
    text-align: center;
    white-space: normal;
    word-break: break-word;
}
.wc-headline {
    font-family: var(--font-display);
    font-size: clamp(1.8rem, 5vw, 3.4rem); font-weight: 600;
    color: var(--ivory-0);
    line-height: 1.12; letter-spacing: -0.02em;
    margin-bottom: 18px;
    word-break: break-word;
}
.wc-headline em {
    font-style: italic;
    color: var(--accent-text);
    background: linear-gradient(135deg, var(--accent-text), var(--brass-200));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.wc-sub {
    font-size: 1.02rem; color: var(--ivory-300);
    max-width: min(580px, 90vw); line-height: 1.75;
    margin-bottom: 44px;
}

/* Stats strip — card panel style */
.wc-stats {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 14px; width: 100%;
    margin-bottom: 40px;
}
.wc-stat {
    padding: 22px 20px;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-card);
    display: flex; flex-direction: column;
    gap: 6px; text-align: center;
    box-shadow: var(--shd-card);
    transition: all 0.3s var(--ease);
    position: relative;
    overflow: hidden;
}
.wc-stat::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0; transition: opacity 0.3s;
}
.wc-stat:hover {
    transform: translateY(-3px);
    box-shadow: var(--shd-card-hover);
    border-color: var(--border-strong);
}
.wc-stat:hover::before { opacity: 1; }
.wc-stat-n {
    font-family: var(--font-display);
    font-size: 1.8rem; font-weight: 700;
    color: var(--accent);
    line-height: 1;
}
.wc-stat-l {
    font-size: 0.65rem; font-weight: 700;
    color: var(--ivory-500);
    text-transform: uppercase; letter-spacing: 1.2px;
}

/* Feature cards — main panels */
.wc-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px; width: 100%;
    margin-bottom: 40px;
}
.wc-card {
    padding: 0; overflow: hidden;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-card);
    cursor: pointer; text-align: left;
    transition: all 0.35s var(--ease);
    display: flex; flex-direction: column;
    position: relative;
    box-shadow: var(--shd-card);
}
.wc-card-top {
    padding: 28px 24px 20px;
    flex: 1;
    display: flex; flex-direction: column; gap: 10px;
    position: relative; z-index: 1;
}
.wc-card-bottom {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(0,0,0,0.12);
}
.wc-card-bottom-label {
    font-size: 0.7rem; font-weight: 600;
    color: var(--ivory-400);
}
.wc-card-bottom-arrow {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent-dim);
    border: 1px solid var(--brass-border);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
    font-size: 0.75rem;
    transition: all 0.3s;
}
.wc-card:hover .wc-card-bottom-arrow {
    background: var(--accent);
    color: var(--walnut-950);
    transform: translateX(2px);
}
.wc-card::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: inherit;
    background: linear-gradient(145deg, var(--accent-glow), transparent 60%);
    opacity: 0; transition: opacity 0.35s;
    pointer-events: none;
}
.wc-card:hover {
    border-color: rgba(255,255,255,0.14);
    transform: translateY(-6px);
    box-shadow: var(--shd-card-hover), 0 0 40px var(--accent-glow);
}
.wc-card:hover::after { opacity: 1; }

.wc-card-icon {
    width: 48px; height: 48px;
    border-radius: var(--r-md);
    background: var(--accent-dim);
    border: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; line-height: 1;
    color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
    margin-bottom: 4px;
}
.wc-card-title {
    font-family: var(--font-display);
    font-size: 1.1rem; font-weight: 700;
    color: var(--ivory-0);
    position: relative; z-index: 1;
}
.wc-card-desc {
    font-size: 0.82rem; color: var(--ivory-400);
    line-height: 1.5;
    position: relative; z-index: 1;
}

/* Quick prompt chips */
.wc-chips-wrap { width: 100%; }
.wc-chips-label {
    font-size: 0.6rem; font-weight: 700;
    color: var(--ivory-500);
    text-transform: uppercase; letter-spacing: 2.5px;
    margin-bottom: 14px;
}
.wc-chips {
    display: flex; flex-wrap: wrap;
    gap: 8px; justify-content: center;
}
.wc-chip {
    padding: 9px 18px;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: 99px;
    font-size: 0.8rem; font-weight: 500;
    color: var(--ivory-300);
    cursor: pointer;
    transition: all 0.25s var(--ease);
    box-shadow: var(--shd-xs);
}
.wc-chip:hover {
    border-color: var(--accent);
    color: var(--accent-text);
    background: var(--accent-dim);
    transform: translateY(-2px);
    box-shadow: var(--shd-sm), 0 0 16px var(--accent-glow);
}

/* ══════════════════════════════════════════════════════════════
   CHAT VIEW
   ══════════════════════════════════════════════════════════════ */
.view-chat { flex-direction: row !important; overflow: hidden; }
.chat-area {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0; overflow: hidden;
}
.chat-messages {
    flex: 1; min-height: 0;
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 28px 32px;
    display: flex; flex-direction: column; gap: 22px;
    scroll-behavior: smooth;
}

/* Messages */
.msg { display: flex; gap: 14px; max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user { flex-direction: row-reverse; }
.msg-ava {
    width: 36px; height: 36px; flex-shrink: 0;
    border-radius: var(--r-md);
    background: var(--surf-3);
    border: 1px solid var(--border-strong);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; font-weight: 800;
    color: var(--ivory-400);
    font-family: var(--font-mono);
}
.msg.user .msg-ava {
    background: linear-gradient(145deg, var(--walnut-500), var(--walnut-700));
    color: var(--accent);
    border-color: var(--brass-border);
    box-shadow: var(--shd-brass);
}
.msg-body {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 6px;
}
.msg.user .msg-body { align-items: flex-end; }
.msg-bubble {
    padding: 16px 20px;
    border-radius: var(--r-lg);
    font-size: 0.92rem; line-height: 1.8;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    color: var(--ivory-200);
    word-wrap: break-word; max-width: 100%;
    box-shadow: var(--shd-xs);
}
.msg.user .msg-bubble {
    background: var(--walnut-700);
    border-color: var(--walnut-600);
    color: var(--ivory-100);
    border-bottom-right-radius: var(--r-xs);
}
.msg.ai .msg-bubble { border-bottom-left-radius: var(--r-xs); }
.msg-meta {
    display: flex; gap: 10px; align-items: center;
    font-size: 0.64rem; color: var(--ivory-500);
}
.msg-badge {
    font-family: var(--font-mono); font-size: 0.58rem;
    color: var(--accent); font-weight: 600;
    padding: 3px 8px;
    border: 1px solid var(--accent-dim);
    border-radius: 99px;
    background: var(--accent-dim);
}

/* Markdown inside bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    font-family: var(--font-display);
    color: var(--ivory-0); margin: 1rem 0 0.5rem; line-height: 1.3;
}
.msg-bubble h2 {
    font-size: 1.12rem; font-weight: 600;
    border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.msg-bubble h3 { font-size: 0.98rem; font-weight: 600; color: var(--accent-text); }
.msg-bubble p { margin-bottom: 0.75rem; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.4rem; margin-bottom: 0.75rem; }
.msg-bubble li { margin-bottom: 0.35rem; }
.msg-bubble code {
    font-family: var(--font-mono); font-size: 0.82em;
    background: var(--surf-3); padding: 2px 6px;
    border-radius: var(--r-xs); color: var(--accent-text);
}
.msg-bubble pre code { display: block; padding: 12px; overflow-x: auto; }
.msg-bubble strong { color: var(--ivory-0); font-weight: 700; }
.msg-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 14px; color: var(--ivory-300);
    font-style: italic; margin: 0.75rem 0;
    font-family: var(--font-display); font-size: 1.02em;
}

/* Typing indicators */
.typing-cursor {
    display: inline-block; width: 2px; height: 1em;
    background: var(--accent); margin-left: 2px;
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.loading-dots::after { content: ''; display: inline-block; animation: dots 1.4s infinite; }
@keyframes dots {
    0% { content: '…'; } 33% { content: '⋯'; }
    66% { content: '···'; } 100% { content: '…'; }
}

/* ── Research terminal ──────────────────────────────────────── */
.rt {
    margin: 0 24px 20px;
    background: rgba(10, 9, 8, 0.95);
    border: 1px solid var(--border-card);
    border-radius: var(--r-lg);
    overflow: hidden; flex-shrink: 0;
    box-shadow: var(--shd-lg);
}
.rt-head {
    padding: 10px 16px;
    background: rgba(255,255,255,0.02);
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border);
}
.rt-pulse {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    animation: rtpulse 1.5s ease-in-out infinite;
}
@keyframes rtpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.rt-title {
    font-family: var(--font-mono); font-size: 0.64rem;
    color: var(--ivory-500); text-transform: uppercase;
    letter-spacing: 2px; font-weight: 600;
}
.rt-phase {
    margin-left: auto; font-family: var(--font-mono);
    font-size: 0.64rem; color: var(--accent); font-weight: 600;
}
.rt-min {
    background: none; border: none; cursor: pointer;
    color: var(--ivory-500); font-size: 1rem; line-height: 1;
    padding: 2px 6px; transition: color var(--t);
}
.rt-min:hover { color: var(--ivory-200); }
.rt-body {
    max-height: 220px; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    font-family: var(--font-mono); font-size: 0.7rem;
    line-height: 1.75; color: var(--ivory-400);
}
.rt-line { display: flex; gap: 10px; margin-bottom: 3px; }
.rt-ts { color: var(--walnut-600); flex-shrink: 0; }
.rt-prefix { font-weight: 700; flex-shrink: 0; }
.rt-prefix.p-supervisor { color: var(--brass-400); }
.rt-prefix.p-research { color: #5ba3d6; }
.rt-prefix.p-retrieve { color: #8b8cf8; }
.rt-prefix.p-web { color: #5bb87a; }
.rt-prefix.p-reflect { color: #e88bba; }
.rt-prefix.p-synthesis { color: #d68a4a; }
.rt-prefix.p-entity { color: #a07ecc; }
.rt-prefix.p-error { color: #e25656; }
.rt-msg { color: var(--ivory-500); }
.rt-loop-line {
    padding: 6px 0; display: flex; align-items: center; gap: 10px;
    font-size: 0.68rem; font-weight: 700;
    color: var(--walnut-500); font-family: var(--font-mono);
}
.rt-loop-line::before, .rt-loop-line::after {
    content: ''; flex: 1; height: 1px; background: var(--walnut-700);
}
.rt-card {
    margin: 8px 0; padding: 12px 14px;
    background: rgba(255,255,255,0.02);
    border-left: 2px solid var(--accent);
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.rt-card-hdr {
    font-size: 0.62rem; font-weight: 800;
    color: var(--accent); text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 4px;
}
.rt-card-body { font-size: 0.7rem; color: var(--ivory-400); line-height: 1.55; }

/* ── Side panel ─────────────────────────────────────────────── */
.side-panel {
    width: 360px; flex-shrink: 0;
    background: var(--surf-1); border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    animation: panel-in 0.25s var(--ease);
}
@keyframes panel-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: none; }
}
.sp-head {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.sp-tabs { display: flex; gap: 4px; flex: 1; }
.sp-tab {
    padding: 7px 13px; font-size: 0.74rem; font-weight: 700;
    background: none; border: 1px solid transparent;
    cursor: pointer; border-radius: var(--r-sm);
    color: var(--ivory-400); transition: all var(--t);
}
.sp-tab.active {
    background: var(--surf-card);
    color: var(--accent-text);
    border-color: var(--border-card);
    box-shadow: var(--shd-xs);
}
.sp-close {
    background: none; border: none; cursor: pointer;
    color: var(--ivory-500); font-size: 0.85rem;
    padding: 4px; border-radius: var(--r-xs);
    transition: color var(--t);
}
.sp-close:hover { color: var(--ivory-0); }
.sp-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sp-panel { padding: 16px; }
.sp-empty {
    display: flex; flex-direction: column; align-items: center;
    padding: 40px 20px; gap: 12px; text-align: center;
}
.sp-empty-glyph { font-size: 2rem; color: var(--ivory-500); line-height: 1; }
.sp-empty p { font-size: 0.78rem; color: var(--ivory-500); line-height: 1.5; }

.sp-card {
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-lg);
    padding: 14px; margin-bottom: 10px;
    box-shadow: var(--shd-xs);
    transition: border-color var(--t);
}
.sp-card:hover { border-color: var(--border-strong); }
.sp-card-hdr {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.66rem; font-weight: 800;
    color: var(--accent-text);
    text-transform: uppercase; letter-spacing: 1px;
    margin-bottom: 8px;
}
.sp-card-body { font-size: 0.78rem; color: var(--ivory-300); line-height: 1.55; }

.source-item {
    font-size: 0.74rem; color: var(--ivory-400);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    word-break: break-all;
    transition: color var(--t);
}
.source-item:hover { color: var(--accent-text); }

.entity-group { margin-bottom: 14px; }
.entity-group-label {
    font-size: 0.62rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1.5px;
    color: var(--ivory-500); margin-bottom: 8px;
}
.entity-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.entity-tag {
    padding: 4px 10px; border-radius: 99px;
    font-size: 0.68rem; font-weight: 600;
    background: var(--surf-card); color: var(--ivory-300);
    border: 1px solid var(--border-card);
}

/* ── Document view ──────────────────────────────────────────── */
.view-document { overflow: hidden; }
.doc-shell { flex: 1; display: flex; overflow: hidden; }
.doc-upload {
    flex: 1; display: flex; align-items: center;
    justify-content: center; padding: 40px;
}
.doc-drop {
    display: flex; align-items: center; justify-content: center;
    width: 100%; max-width: 520px; min-height: 340px;
    background: var(--surf-card);
    border: 2px dashed var(--border-strong);
    border-radius: var(--r-2xl);
    cursor: pointer;
    transition: all 0.35s var(--ease);
    box-shadow: var(--shd-card);
}
.doc-drop:hover, .doc-drop.dragover {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: var(--shd-card-hover), 0 0 60px var(--accent-glow);
    transform: scale(1.01);
}
.dd-inner {
    display: flex; flex-direction: column; align-items: center;
    gap: 14px; text-align: center; padding: 40px;
    pointer-events: none;
}
.dd-glyph { color: var(--accent); line-height: 1; }
.dd-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; color: var(--ivory-0); }
.dd-sub { font-size: 0.88rem; color: var(--ivory-400); }
.dd-link { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; }
.dd-formats { display: flex; gap: 8px; margin-top: 10px; }
.dd-formats span {
    font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700;
    padding: 5px 12px; border-radius: 99px;
    background: var(--surf-3); border: 1px solid var(--border-card);
    color: var(--ivory-400);
}

/* Doc analysis view */
.doc-analysis { flex: 1; display: flex; overflow: hidden; }
.doc-chat-col {
    flex: 1; display: flex; flex-direction: column;
    border-right: 1px solid var(--border); min-width: 0;
}
.doc-file-bar {
    padding: 14px 20px; background: var(--surf-card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.dfb-icon { color: var(--accent); font-size: 1.2rem; }
.dfb-name { font-size: 0.85rem; font-weight: 700; color: var(--ivory-100); }
.dfb-meta { font-size: 0.72rem; color: var(--ivory-400); }
.doc-messages {
    flex: 1; min-height: 0;
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 20px 24px;
    display: flex; flex-direction: column; gap: 16px;
}
.doc-risk-bar {
    min-height: 0; padding: 0 16px;
    display: flex; flex-wrap: wrap; gap: 6px;
    border-top: 1px solid var(--border);
    transition: padding var(--t);
}
.doc-risk-bar:not(:empty) { padding: 10px 16px; }
.risk-chip {
    padding: 5px 12px; border-radius: 99px;
    font-size: 0.67rem; font-weight: 700;
}
.risk-chip.high { background: rgba(226,86,86,0.12); color: #f5a3a3; border: 1px solid rgba(226,86,86,0.3); }
.risk-chip.medium { background: rgba(219,162,79,0.12); color: #f0d070; border: 1px solid rgba(219,162,79,0.3); }
.risk-chip.low { background: rgba(91,184,122,0.12); color: #8ed6a4; border: 1px solid rgba(91,184,122,0.3); }
.doc-input-wrap {
    padding: 14px 16px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: flex-end;
    background: var(--surf-1);
}
.doc-input-wrap textarea {
    flex: 1; background: var(--surf-card);
    border: 1px solid var(--border-card); border-radius: var(--r-md);
    padding: 10px 14px; font-family: var(--font-ui);
    font-size: 0.88rem; color: var(--ivory-100);
    resize: none; outline: none;
    transition: border-color var(--t); max-height: 120px;
}
.doc-input-wrap textarea:focus { border-color: var(--accent); }
.doc-info-col {
    width: 320px; flex-shrink: 0;
    display: flex; flex-direction: column;
    min-height: 0;
    background: var(--surf-1);
}
.doc-info-tabs {
    display: flex; padding: 12px 12px 0; gap: 4px;
    border-bottom: 1px solid var(--border);
}
.di-tab {
    padding: 8px 14px; font-size: 0.74rem; font-weight: 700;
    background: none; border: none; cursor: pointer;
    color: var(--ivory-400);
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    transition: all var(--t);
    border-bottom: 2px solid transparent;
}
.di-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.di-panel { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.di-empty { font-size: 0.74rem; color: var(--ivory-500); font-style: italic; padding: 8px; }
.di-risk-card {
    padding: 14px; border-radius: var(--r-lg);
    margin-bottom: 10px; font-size: 0.78rem;
    line-height: 1.55; border: 1px solid;
    box-shadow: var(--shd-xs);
}
.di-risk-card.high { background: rgba(226,86,86,0.06); border-color: rgba(226,86,86,0.2); color: #f5a3a3; }
.di-risk-card.medium { background: rgba(219,162,79,0.06); border-color: rgba(219,162,79,0.2); color: #f0d070; }
.di-risk-card.low { background: rgba(91,184,122,0.06); border-color: rgba(91,184,122,0.2); color: #8ed6a4; }
.di-risk-card .risk-label {
    font-size: 0.6rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1px;
    opacity: 0.8; display: block; margin-bottom: 4px;
}

/* ── Draft view ─────────────────────────────────────────────── */
.view-draft { overflow: hidden; }
.draft-shell { flex: 1; display: flex; overflow: hidden; }
.draft-form-col {
    width: 380px; flex-shrink: 0;
    background: var(--surf-1);
    border-right: 1px solid var(--border);
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    padding: 28px 24px;
    display: flex; flex-direction: column; gap: 24px;
}
.df-title {
    font-family: var(--font-display);
    font-size: 1.4rem; font-weight: 600; color: var(--ivory-0);
}
.df-sub { font-size: 0.78rem; color: var(--ivory-400); margin-top: 4px; }
.df-templates { display: flex; flex-wrap: wrap; gap: 6px; }
.df-tpl {
    padding: 8px 14px; font-size: 0.74rem; font-weight: 700;
    background: var(--surf-card); border: 1px solid var(--border-card);
    border-radius: 99px; cursor: pointer;
    color: var(--ivory-400); transition: all var(--t);
    box-shadow: var(--shd-xs);
}
.df-tpl:hover { border-color: var(--accent); color: var(--accent-text); }
.df-tpl.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 0 12px var(--accent-glow);
}
.df-fields { display: flex; flex-direction: column; gap: 16px; }
.df-field { display: flex; flex-direction: column; gap: 7px; }
.df-field label {
    font-size: 0.66rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1.5px;
    color: var(--ivory-500);
}
.df-field input, .df-field textarea {
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-md);
    padding: 11px 14px; font-family: var(--font-ui);
    font-size: 0.88rem; color: var(--ivory-100);
    outline: none; resize: vertical;
    transition: border-color var(--t);
    box-shadow: var(--shd-inset);
}
.df-field input:focus, .df-field textarea:focus { border-color: var(--accent); }
.btn-generate {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 14px 20px;
    background: linear-gradient(145deg, var(--walnut-600), var(--walnut-500));
    border: 1px solid var(--brass-border);
    border-radius: var(--r-md);
    font-family: var(--font-ui); font-size: 0.9rem; font-weight: 800;
    color: var(--accent-text); cursor: pointer;
    transition: all 0.3s var(--ease);
    box-shadow: var(--shd-brass);
}
.btn-generate:hover {
    background: linear-gradient(145deg, var(--walnut-500), var(--walnut-600));
    box-shadow: var(--shd-brass), 0 6px 30px var(--accent-glow);
    transform: translateY(-2px);
}
.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.draft-preview-col {
    flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.dp-header {
    padding: 14px 24px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surf-1);
}
.dp-title {
    font-family: var(--font-display);
    font-size: 1rem; font-weight: 600; color: var(--ivory-0);
}
.dp-actions { display: flex; gap: 8px; }
.dp-act {
    padding: 7px 15px; font-size: 0.74rem; font-weight: 700;
    background: var(--surf-card); border: 1px solid var(--border-card);
    border-radius: var(--r-sm); cursor: pointer;
    color: var(--ivory-300); transition: all var(--t);
    box-shadow: var(--shd-xs);
}
.dp-act:hover { border-color: var(--accent); color: var(--accent-text); }
.dp-act-primary {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent-text);
}
.dp-content { flex: 1; min-height: 0; overflow-y: scroll; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 28px 32px; }
.dp-empty {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; height: 100%; gap: 16px; text-align: center;
}
.dp-empty-glyph { font-size: 3rem; color: var(--ivory-500); line-height: 1; }
.dp-empty p { font-size: 0.88rem; color: var(--ivory-500); }
.dp-status {
    padding: 8px 24px; font-size: 0.7rem;
    color: var(--ivory-500); font-family: var(--font-mono);
    border-top: 1px solid var(--border); min-height: 32px;
}

/* Legal document rendering */
.legal-doc {
    font-family: var(--font-display);
    font-size: 1rem; line-height: 1.9; color: var(--ivory-200);
}
.legal-doc h1 {
    font-size: 1.4rem; font-weight: 600; margin: 0 0 1.5rem;
    color: var(--ivory-0); text-align: center;
}
.legal-doc h2 {
    font-size: 1.1rem; font-weight: 600;
    margin: 2rem 0 0.75rem; color: var(--ivory-0);
}
.legal-doc h3 {
    font-size: 0.95rem; font-weight: 600;
    margin: 1.5rem 0 0.5rem; color: var(--accent-text);
}
.legal-doc p { margin-bottom: 1rem; }
.legal-doc ol, .legal-doc ul { padding-left: 1.5rem; margin-bottom: 1rem; }
.legal-doc li { margin-bottom: 0.5rem; }

/* Draft skeleton */
.draft-skel { display: flex; flex-direction: column; gap: 10px; }
.skel-line {
    height: 14px; border-radius: 99px;
    background: var(--surf-2);
    animation: skel-pulse 1.5s ease-in-out infinite;
}
@keyframes skel-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 0.8; } }

/* ── Global input dock ──────────────────────────────────────── */
.input-dock {
    padding: 0 28px calc(24px + env(safe-area-inset-bottom, 0px));
    background: transparent;
    z-index: 20; flex-shrink: 0;
}
.input-wrap {
    max-width: 820px; margin: 0 auto;
    background: var(--surf-card);
    border: 1px solid var(--border-card);
    border-radius: var(--r-xl);
    padding: 14px 14px 10px 18px;
    box-shadow: var(--shd-card);
    transition: all 0.25s var(--ease);
    display: flex; flex-direction: column; gap: 10px;
}
.input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: var(--shd-card-hover), 0 0 0 4px var(--accent-dim);
}
#user-input {
    width: 100%; background: none; border: none; outline: none;
    font-family: var(--font-ui); font-size: 0.95rem;
    color: var(--ivory-0); resize: none;
    min-height: 24px; max-height: 200px; line-height: 1.6;
}
#user-input::placeholder { color: var(--ivory-500); }
.input-actions {
    display: flex; align-items: center; justify-content: space-between;
}
.input-hint {
    font-family: var(--font-mono); font-size: 0.6rem;
    color: var(--ivory-500); font-weight: 500;
}
.send-btn {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: var(--r-md);
    background: linear-gradient(145deg, var(--walnut-600), var(--walnut-500));
    border: 1px solid var(--brass-border);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: var(--shd-brass);
    transition: all 0.22s;
}
.send-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shd-brass), 0 6px 24px var(--accent-glow);
    border-color: var(--accent);
}
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--walnut-600); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--walnut-500); }

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex !important; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile & Tablet
   ══════════════════════════════════════════════════════════════ */

/* Mobile hamburger — hidden on desktop */
.mob-menu-btn {
    display: none;
    background: none; border: none; cursor: pointer;
    color: var(--ivory-300); padding: 6px;
    border-radius: var(--r-sm);
    transition: color var(--t);
    flex-shrink: 0;
}
.mob-menu-btn:hover { color: var(--ivory-0); }

/* Sidebar backdrop — mobile only */
.sb-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 39;
    background: rgba(15, 14, 12, 0.7);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t) var(--ease);
}
.sb-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

/* ── Desktop sidebar collapse (sb-toggle) ───────────────────── */
.sidebar.collapsed {
    width: 4vw;
    min-width: 3.5rem;
}
.sidebar.collapsed .brand-copy,
.sidebar.collapsed .sb-label,
.sidebar.collapsed .mi-text,
.sidebar.collapsed .mi-hint,
.sidebar.collapsed .sb-section,
.sidebar.collapsed .sb-threads,
.sidebar.collapsed .sb-status-text {
    display: none;
}
.sidebar.collapsed .sb-brand { justify-content: center; padding: 1.25rem 0.75rem; }
.sidebar.collapsed .sb-toggle { margin-left: 0; }
.sidebar.collapsed .sb-nav { padding: 0.875rem 0.5rem; }
.sidebar.collapsed .mode-item { justify-content: center; padding: 0.625rem; }
.sidebar.collapsed .mi-icon { margin: 0; }
.sidebar.collapsed .sb-foot { justify-content: center; padding: 0.875rem 0.75rem; }

/* ── Mobile (< 768px) ───────────────────────────────────────── */
@media (max-width: 767px) {
    /* Show hamburger, hide desktop toggle */
    .mob-menu-btn { display: flex; align-items: center; justify-content: center; }
    .sb-toggle { display: none; }

    /* Sidebar becomes a full-height overlay — 80vw, no clamp */
    .sidebar {
        position: fixed; top: 0; left: 0;
        height: 100%; height: 100dvh;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform var(--t) var(--ease);
        width: 80vw !important;
        box-shadow: var(--shd-xl);
    }
    .sidebar.mob-open { transform: translateX(0); }
    .sb-backdrop { display: block; pointer-events: none; }

    /* Shell — let it fill height normally, no overflow clipping */
    .shell { height: 100%; height: 100dvh; overflow: hidden; }

    /* Topbar */
    .topbar { padding: 0 4vw; }
    .tb-thread { display: none; }
    .sp-toggle { display: inline-flex; }

    /* Input dock — safe-area-aware bottom padding */
    .input-dock {
        padding: 2vw 4vw calc(4vw + env(safe-area-inset-bottom, 0px));
    }
    .input-wrap { border-radius: var(--r-lg); }

    /* Welcome scroll — workspace already excludes dock, just need breathing room */
    .welcome-scroll {
        padding: 5vw 4vw 4vw;
    }

    /* Chat */
    .chat-messages { padding: 4vw; }
    .view-chat { flex-direction: column !important; }
    .chat-area { width: 100%; overflow: hidden; }

    /* Deep Research — RT panel tighter on mobile */
    .rt { margin: 0 3vw 3vw; }
    .rt-body { max-height: 35vw; }

    /* Welcome screen — two columns */
    .wc-cards { grid-template-columns: 1fr 1fr !important; }
    .wc-stats { grid-template-columns: 1fr 1fr !important; }

    /* Side panel — full overlay */
    .side-panel {
        position: fixed; inset: 0; top: var(--topbar-h);
        z-index: 35; border-radius: 0;
        border-left: none;
        border-top: 1px solid var(--border);
        display: flex; flex-direction: column;
        width: 100%;
        max-width: none;
        height: calc(100dvh - var(--topbar-h));
        box-shadow: var(--shd-xl);
        overflow-y: auto;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .sp-body {
        flex: 1; min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    /* Draft — form on top (natural height), preview below (scrollable) */
    .draft-shell {
        flex-direction: column !important;
        overflow-y: auto !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        min-height: 0;
        max-height: calc(100dvh - var(--topbar-h) - var(--dock-h) - 1rem);
    }
    .draft-form-col {
        width: 100% !important; min-width: unset !important;
        height: auto; flex-shrink: 0;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        overflow-y: visible !important;
        padding: 20px 16px;
    }
    .draft-preview-col {
        width: 100% !important; min-width: unset !important;
        flex-shrink: 0;
        height: auto;
        flex: 1;
        display: flex; flex-direction: column;
        overflow: visible;
        max-height: none;
    }
    .dp-content {
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y;
        padding: 16px;
    }
    .dp-header { padding: 12px 16px; flex-shrink: 0; }
    .dp-status { padding: 6px 16px; flex-shrink: 0; }

    /* Doc analysis — chat col on top, info col below */
    .doc-analysis {
        flex-direction: column !important;
        overflow: hidden !important;
        height: 100%;
    }
    .doc-chat-col {
        width: 100% !important; min-width: unset !important;
        height: 58vh; flex-shrink: 0;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        overflow: visible;
        display: flex; flex-direction: column;
    }
    .doc-messages {
        flex: 1; min-height: 0;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    .doc-info-col {
        width: 100% !important; min-width: unset !important;
        height: 38vh; flex-shrink: 0;
        overflow: visible;
        display: flex; flex-direction: column;
    }
    .di-panel {
        flex: 1; min-height: 0;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    .doc-upload { padding: 20px; }
    .doc-drop { min-height: 260px; }
    .dd-inner { padding: 24px; }
}

/* ── Very small (< 420px) ───────────────────────────────────── */
@media (max-width: 419px) {
    .wc-cards { grid-template-columns: 1fr !important; }
    .wc-stats { grid-template-columns: 1fr 1fr !important; }
    .topbar { padding: 0 3vw; }
    .mode-badge { font-size: 0.66rem; padding: 0.3rem 0.6rem; }
}

/* ── Tablet (768px–1024px) ──────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1024px) {
    :root { --sb-w: clamp(180px, 22vw, 260px); }
    .wc-cards { grid-template-columns: repeat(2, 1fr) !important; }
    .wc-stats { grid-template-columns: repeat(2, 1fr) !important; }
    .chat-messages { padding: 2.5vw; }
    .welcome-scroll { padding: 3vw 3vw calc(var(--dock-h) + 2rem); }
}
