/* ══════════════════════════════════════════════════════════════════
   Research Report Tool — UI chrome styles
   ══════════════════════════════════════════════════════════════════ */

:root {
    --brand-50:  #eff6ff;
    --brand-100: #dbeafe;
    --brand-200: #bfdbfe;
    --brand-300: #93c5fd;
    --brand-400: #60a5fa;
    --brand-500: #3b82f6;
    --brand-600: #2563eb;
    --brand-700: #1d4ed8;
    --brand-800: #1e3a5f;
    --brand-900: #0f172a;
    --brand-950: #0b1220;

    --slate-50:  #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-700: #334155;
    --slate-900: #0f172a;

    --topbar-h: 168px;
    --pane-gap: 18px;
    --radius:   16px;
    --radius-sm: 10px;

    --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
    --shadow-md:  0 4px 14px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg:  0 18px 48px rgba(15, 23, 42, 0.14), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-glow: 0 10px 40px rgba(37, 99, 235, 0.5);
    --topbar-shadow: 0 18px 40px rgba(11, 18, 32, 0.35), 0 6px 12px rgba(11, 18, 32, 0.18);
}

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji';
    -webkit-font-smoothing: antialiased;
    background:
        radial-gradient(1200px 600px at 0% -10%, rgba(37, 99, 235, 0.10), transparent 60%),
        radial-gradient(1000px 500px at 100% 110%, rgba(37, 99, 235, 0.06), transparent 60%),
        #eef2f9;
    color: var(--slate-900);
    overflow: hidden;
}

* { box-sizing: border-box; }

/* ─────────────────────── PRELOAD (hide before JS intro) ─────────────────────── */
body.preload .intro-target {
    opacity: 0;
}
body.preload .reveal-up {
    animation: none;
    opacity: 0;
    transform: translateY(14px);
}

/* Basic keyframes retained for non-intro animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes softPulse { 0%,100% {transform:scale(1);opacity:.9;} 50% {transform:scale(1.06);opacity:1;} }
@keyframes dotBlink  { 0%,100% {opacity:.4;} 50% {opacity:1;} }
@keyframes spinSlow  { to { transform: rotate(360deg); } }
@keyframes orbitCCW  { to { transform: rotate(-360deg); } }
@keyframes revealUp {
    to { opacity: 1; transform: translateY(0); }
}
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0;  }
}

/* ════════════════════════ TOP BAR ════════════════════════ */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    padding: 24px 28px;
    display: grid;
    grid-template-columns: 320px 1fr 320px;
    align-items: center;
    gap: 22px;
    z-index: 100;
    color: #fff;
    background:
        linear-gradient(180deg,
            #2563eb 0%,
            #1d4ed8 22%,
            #1e3a8a 50%,
            #1e3a5f 78%,
            #152c4a 100%);
    box-shadow: var(--topbar-shadow);
    overflow: hidden;
}
/* No more radial fog overlays — the constellation canvas provides the
   visual interest, and the radial highlights were creating muddy areas
   near the logo and on the right side. */
.topbar::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent,
        rgba(96, 165, 250, 0.65) 30%,
        rgba(255, 255, 255, 0.4) 50%,
        rgba(96, 165, 250, 0.65) 70%,
        transparent);
    pointer-events: none;
}

/* Constellation canvas — draws behind brand mark */
.topbar-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.9;
    mix-blend-mode: screen;
    z-index: 1;
}

.topbar-left,
.topbar-center,
.topbar-right { position: relative; z-index: 2; }
.topbar-left  { display: flex; justify-content: flex-start; align-items: center; }
.topbar-right { display: flex; justify-content: flex-end;   align-items: center; gap: 8px; }

/* ─────────────────────── BRAND MARK ─────────────────────── */
.brand-mark {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    height: 100%;
    align-self: center;
}
.brand-logo-empty {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 22px;
    background: rgba(255, 255, 255, 0.10);
    border: 1.5px dashed rgba(255, 255, 255, 0.35);
    border-radius: 14px;
    color: rgba(255, 255, 255, 0.85);
    font: 800 11px 'Inter', sans-serif;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.18s;
    backdrop-filter: blur(6px);
}
.brand-logo-empty svg { width: 28px; height: 28px; }
.brand-logo-empty:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-1px);
}
.brand-logo-img {
    max-height: 110px;
    max-width: 320px;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.4));
    cursor: pointer;
}

/* ─────────────────────── TITLE CARD (glassmorphic) ─────────────────────── */
.report-header-card {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    align-self: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 14px;
    padding: 14px 20px 18px;
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    box-shadow:
        0 8px 28px rgba(0, 0, 0, 0.24),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.report-header-eyebrow {
    display: flex;
    align-items: center;
    gap: 8px;
    font: 800 9px 'Inter', sans-serif;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.report-header-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.28);
    animation: dotBlink 2.4s infinite;
}
.report-header-eyebrow-sep { opacity: 0.5; }
.report-header-eyebrow-meta { color: rgba(255, 255, 255, 0.55); font-weight: 700; }
.report-header-row {
    display: flex; align-items: center; gap: 10px;
    min-height: 24px;
}
.report-header-row-split {
    display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 14px; margin-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.18);
    padding-top: 10px;
    align-items: center;
}
.rh-label {
    font-size: 9px; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    min-width: 78px;
}
.rh-input {
    flex: 1;
    border: none;
    background: transparent;
    font: 700 14px 'Inter', sans-serif;
    color: #ffffff;
    padding: 2px 0;
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.15s;
}
.rh-input::placeholder { color: rgba(255, 255, 255, 0.35); font-weight: 500; }
.rh-input:hover { border-bottom-color: rgba(255, 255, 255, 0.3); }
.rh-input:focus { border-bottom-color: var(--brand-300); }
.rh-input-title { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.rh-static { font: 700 13px 'Inter', sans-serif; color: rgba(255, 255, 255, 0.8); }

/* Per-report client logo upload (lives inside the title card row split) */
.rh-client-logo-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    align-self: center;
}
.rh-client-logo-remove {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(239, 68, 68, 0.18);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.15s;
    padding: 0;
}
.rh-client-logo-remove:hover {
    background: #dc2626;
    border-color: #dc2626;
    transform: scale(1.08);
}

.rh-client-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.10);
    border: 1px dashed rgba(255, 255, 255, 0.32);
    border-radius: 9px;
    color: rgba(255, 255, 255, 0.78);
    font: 700 9px 'Inter', sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    align-self: center;
}
.rh-client-logo:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.55);
    color: #ffffff;
}
.rh-client-logo.has-logo {
    border-style: solid;
    background: rgba(255, 255, 255, 0.94);
    padding: 4px 10px 4px 4px;
}
.rh-client-logo.has-logo #client-logo-empty-icon { display: none; }
.rh-client-logo.has-logo #client-logo-label {
    color: var(--brand-700);
    font-size: 9px;
}
.rh-client-logo-img {
    max-height: 26px;
    max-width: 64px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
}

/* Logo uploader inside the settings modal */
.logo-uploader {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--slate-50);
    border: 1px dashed var(--slate-300);
    border-radius: 12px;
    margin-bottom: 6px;
}
.logo-uploader-preview {
    width: 92px;
    height: 64px;
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: 9px;
    display: grid;
    place-items: center;
    overflow: hidden;
    flex-shrink: 0;
}
.logo-uploader-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.logo-uploader-empty {
    text-align: center;
    color: var(--slate-400);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.logo-uploader-empty span { display: block; margin-top: 4px; line-height: 1.3; }
.logo-uploader-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}
.logo-uploader-actions .btn-ghost {
    padding: 8px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}
.setting-hint {
    font-size: 11px;
    color: var(--slate-400);
    line-height: 1.55;
    margin-top: 8px;
}

/* ─────────────────────── ICON BUTTONS ─────────────────────── */
.icon-btn {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.9);
    display: grid; place-items: center;
    cursor: pointer;
    transition: all 0.15s;
    backdrop-filter: blur(8px);
}
.icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.icon-btn { position: relative; }
.icon-btn-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px #152c4a, 0 0 0 4px rgba(239, 68, 68, 0.25);
    animation: dotBlink 1.6s infinite;
}

/* ════════════════════════ LOCK ALERT TOAST ════════════════════════ */
.lock-alert {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translateX(-50%) translateY(-12px);
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px 14px 18px;
    background: linear-gradient(135deg, #fef2f2, #fff);
    border: 1px solid #fecaca;
    border-left: 4px solid #dc2626;
    border-radius: 12px;
    box-shadow: 0 18px 48px rgba(220, 38, 38, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    max-width: 520px;
}
.lock-alert.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.lock-alert-icon {
    font-size: 22px;
    line-height: 1;
    color: #dc2626;
    flex-shrink: 0;
}
.lock-alert-body { flex: 1; min-width: 0; }
.lock-alert-title {
    font-size: 13px;
    font-weight: 800;
    color: #7f1d1d;
    letter-spacing: -0.01em;
}
.lock-alert-sub {
    font-size: 12px;
    color: #b91c1c;
    margin-top: 2px;
    line-height: 1.4;
}
.lock-alert-btn {
    background: #dc2626;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    font: 800 10px 'Inter', sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    flex-shrink: 0;
}
.lock-alert-btn:hover { background: #b91c1c; }
.lock-alert-close {
    background: transparent;
    border: none;
    color: #b91c1c;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    padding: 4px 8px;
    flex-shrink: 0;
}

.topbar-divider {
    width: 1px; height: 26px;
    background: rgba(255, 255, 255, 0.22);
    margin: 0 6px;
}

/* ════════════════════════ SPLIT LAYOUT ════════════════════════ */
.split-layout {
    position: fixed;
    top: var(--topbar-h); left: 0; right: 0; bottom: 0;
    display: grid;
    grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr);
    gap: var(--pane-gap);
    padding: var(--pane-gap);
}

/* ════════════════════════ CHAT PANE ════════════════════════ */
.chat-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    min-height: 0;
}

.chat-pane-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: #152c4a;
    position: relative;
    color: #fff;
}
.chat-pane-header::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
}
.chat-pane-title {
    display: flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 13px;
    color: #ffffff;
    text-transform: uppercase; letter-spacing: 0.08em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.chat-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.3);
    animation: dotBlink 2s infinite;
}
.chat-pane-meta {
    font-size: 11px; color: rgba(255,255,255,0.78); font-weight: 600;
    display: flex; align-items: center; gap: 10px;
}
.chat-meta-sep { margin: 0 2px; color: rgba(255,255,255,0.3); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 26px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Empty state */
.chat-empty {
    margin: auto;
    text-align: center;
    padding: 40px 24px;
    max-width: 440px;
}
.chat-empty-icon {
    width: 82px; height: 82px;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.10), rgba(37, 99, 235, 0.02));
    border: 1px solid rgba(37, 99, 235, 0.18);
    color: rgba(37, 99, 235, 0.55);
    display: grid; place-items: center;
    margin: 0 auto 28px;
    position: relative;
}
.chat-empty-icon::before,
.chat-empty-icon::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(37, 99, 235, 0.26);
    pointer-events: none;
}
.chat-empty-icon::before {
    inset: -20px;
    animation: emptyRing 3s ease-in-out infinite;
}
.chat-empty-icon::after {
    inset: -40px;
    border-color: rgba(37, 99, 235, 0.14);
    animation: emptyRing 3s ease-in-out infinite 0.6s;
}
@keyframes emptyRing {
    0%, 100% { opacity: 0.2; transform: scale(0.92); }
    50%      { opacity: 0.75; transform: scale(1.04); }
}
.chat-empty-title {
    font-size: 19px; font-weight: 800; color: var(--slate-900);
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}
.chat-empty-sub {
    font-size: 13px; line-height: 1.65; color: var(--slate-500);
}

/* Loading skeleton (intro only) */
.skeleton-wrap {
    display: flex; flex-direction: column; gap: 14px;
    padding: 30px 20px;
}
.skeleton-line {
    height: 14px;
    background: linear-gradient(
        90deg,
        var(--slate-100) 0%,
        var(--slate-200) 40%,
        var(--brand-50) 50%,
        var(--slate-200) 60%,
        var(--slate-100) 100%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.4s linear infinite;
}
.skeleton-line.sk-w-70 { width: 70%; }
.skeleton-line.sk-w-50 { width: 50%; }
.skeleton-line.sk-w-90 { width: 90%; }
.skeleton-block {
    height: 60px;
    border-radius: 10px;
    background: linear-gradient(
        90deg,
        var(--slate-100) 0%,
        var(--slate-200) 40%,
        var(--brand-50) 50%,
        var(--slate-200) 60%,
        var(--slate-100) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}

/* ══════════════════════════════════════════════════════════════════
   MESSAGE BUBBLES — polished, editorial typography.
   No avatars, no "YOU"/"AI" labels — alignment + treatment tells who.
   Typography mirrors the PDF report template for a unified look.
   ══════════════════════════════════════════════════════════════════ */
.msg {
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(8px);
    animation: revealUp 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.msg-user      { align-items: flex-end; }
.msg-assistant { align-items: flex-start; }

/* Avatars retired */
.msg-avatar { display: none; }

.msg-bubble {
    max-width: 86%;
    padding: 14px 18px;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji';
    font-size: 13.5px;
    line-height: 1.65;
    letter-spacing: -0.005em;
    color: var(--slate-700);
    position: relative;
}

/* ─── USER BUBBLE — deep cool gradient, tight corner cut ─── */
.msg-user .msg-bubble {
    background:
        radial-gradient(280px 120px at 20% 0%, rgba(255,255,255,0.14), transparent 60%),
        linear-gradient(135deg, #2563eb 0%, #1d4ed8 45%, #1e3a8a 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px 16px 4px 16px;
    box-shadow:
        0 10px 28px rgba(37, 99, 235, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

/* ─── ASSISTANT BUBBLE — clean editorial card with brand accent ─── */
.msg-assistant .msg-bubble {
    background: #ffffff;
    color: var(--slate-700);
    border: 1px solid var(--slate-200);
    border-radius: 4px 16px 16px 16px;
    padding: 16px 20px 16px 22px;
    box-shadow:
        0 4px 14px rgba(15, 23, 42, 0.06),
        0 1px 2px rgba(15, 23, 42, 0.04);
    max-width: 92%;
}
.msg-assistant .msg-bubble::before {
    content: '';
    position: absolute;
    left: 0; top: 14px; bottom: 14px;
    width: 3px;
    background: linear-gradient(180deg, var(--brand-500), var(--brand-700));
    border-radius: 0 2px 2px 0;
}

/* ─── TYPOGRAPHY INSIDE BUBBLES ─── */
.msg-bubble p {
    margin: 0 0 10px;
}
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3 {
    margin: 14px 0 8px;
    color: var(--slate-900);
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.015em;
    line-height: 1.3;
}
.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child { margin-top: 0; }

.msg-bubble h1 { font-size: 15px; font-weight: 800; }
.msg-bubble h2 {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand-700);
    margin-top: 16px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--slate-100);
}
.msg-bubble h3 { font-size: 13px; font-weight: 700; }

.msg-user .msg-bubble h1,
.msg-user .msg-bubble h3 { color: #fff; }
.msg-user .msg-bubble h2 {
    color: rgba(255,255,255,0.78);
    border-bottom-color: rgba(255,255,255,0.18);
}

.msg-bubble strong {
    font-weight: 700;
    color: var(--slate-900);
}
.msg-user .msg-bubble strong { color: #ffffff; }

.msg-bubble em {
    font-style: italic;
    color: var(--slate-500);
}
.msg-user .msg-bubble em { color: rgba(255,255,255,0.85); }

/* ─── CUSTOM BULLET LISTS — brand-blue discs, tight spacing ─── */
.msg-bubble ul {
    list-style: none;
    padding: 0;
    margin: 8px 0 12px;
}
.msg-bubble ul li {
    position: relative;
    padding-left: 18px;
    margin-bottom: 6px;
    line-height: 1.6;
}
.msg-bubble ul li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 9px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-600);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}
.msg-user .msg-bubble ul li::before {
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.28);
}

.msg-bubble ol {
    padding-left: 22px;
    margin: 8px 0 12px;
}
.msg-bubble ol li {
    margin-bottom: 6px;
    padding-left: 4px;
}
.msg-bubble ol li::marker {
    color: var(--brand-600);
    font-weight: 800;
    font-size: 12px;
}
.msg-user .msg-bubble ol li::marker { color: rgba(255, 255, 255, 0.9); }

/* ─── CODE, LINKS ─── */
.msg-bubble code {
    font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
    font-size: 11.5px;
    background: var(--slate-100);
    color: var(--slate-900);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--slate-200);
}
.msg-user .msg-bubble code {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}

/* ─── Rendered HTML tables in chat messages ─── */
.msg-bubble .rendered-html {
    margin: 12px 0;
    overflow-x: auto;
}
.msg-bubble .rendered-html table,
.msg-bubble .md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 8px 0;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--slate-200);
}
.msg-bubble .rendered-html th,
.msg-bubble .md-table th {
    background: var(--brand-600);
    color: #fff;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.msg-bubble .rendered-html td,
.msg-bubble .md-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--slate-100);
    color: var(--slate-700);
    vertical-align: top;
}
.msg-bubble .rendered-html tr:nth-child(even) td,
.msg-bubble .md-table tr:nth-child(even) td {
    background: var(--slate-50);
}
.msg-bubble .rendered-html tr:hover td,
.msg-bubble .md-table tr:hover td {
    background: rgba(37, 99, 235, 0.04);
}

/* ─── Fenced code blocks with copy button ─── */
.msg-bubble .code-block {
    margin: 12px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--slate-200);
    background: var(--slate-900);
}
.msg-bubble .code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.msg-bubble .code-lang {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(148, 163, 184, 0.7);
}
.msg-bubble .code-copy-btn {
    font-size: 11px;
    font-weight: 600;
    color: var(--brand-400);
    background: transparent;
    border: 1px solid rgba(96, 165, 250, 0.25);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.msg-bubble .code-copy-btn:hover {
    background: rgba(96, 165, 250, 0.1);
    border-color: rgba(96, 165, 250, 0.5);
}
.msg-bubble .code-block pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.6;
    color: #e2e8f0;
    font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}
.msg-bubble .code-block code {
    background: transparent;
    border: 0;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.msg-bubble a {
    color: var(--brand-600);
    text-decoration: underline;
    text-decoration-color: rgba(37, 99, 235, 0.35);
    text-underline-offset: 3px;
    font-weight: 600;
    transition: text-decoration-color 0.15s;
}
.msg-bubble a:hover { text-decoration-color: var(--brand-600); }
.msg-user .msg-bubble a {
    color: #ffffff;
    text-decoration-color: rgba(255, 255, 255, 0.55);
}
.msg-user .msg-bubble a:hover { text-decoration-color: #ffffff; }

/* ─── Blockquote ─── */
.msg-bubble blockquote {
    margin: 10px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--brand-500);
    background: var(--slate-50);
    border-radius: 0 8px 8px 0;
    color: var(--slate-700);
    font-style: italic;
}
.msg-user .msg-bubble blockquote {
    border-left-color: rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.92);
}

/* ─── ATTACHMENTS INSIDE BUBBLES ─── */
.msg-attachments {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.msg-user .msg-attachments { border-top-color: rgba(255,255,255,0.2); }

.msg-attachment {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 10px 5px 5px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 8px;
    font-size: 11px; font-weight: 600;
    color: var(--slate-700);
}
.msg-user .msg-attachment {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}
.msg-attachment-thumb {
    width: 28px; height: 28px; border-radius: 5px;
    object-fit: cover;
}

/* ─────────────────────── DROP OVERLAY ─────────────────────── */
.drop-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.94), rgba(15, 23, 42, 0.94));
    color: #fff;
    display: grid; place-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s;
    z-index: 20;
    border-radius: var(--radius);
}
.drop-overlay.active { opacity: 1; pointer-events: auto; }
.drop-overlay-inner {
    text-align: center;
    border: 2px dashed rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    padding: 48px 64px;
    background: rgba(255, 255, 255, 0.06);
}
.drop-title  { font-size: 22px; font-weight: 800; margin-top: 14px; }
.drop-sub    { font-size: 13px; opacity: 0.85; margin-top: 6px; }

/* ─────────────────────── CHAT INPUT ─────────────────────── */
.chat-input-wrap {
    padding: 18px 18px 22px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: #152c4a;
    position: relative;
    color: #fff;
}

.attachment-tray {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-bottom: 12px;
    max-height: 150px;
    overflow-y: auto;
    padding: 2px;
}
.attachment-tray.hidden { display: none; }
.attachment-tray::-webkit-scrollbar { width: 8px; }
.attachment-tray::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 8px; }
.attach-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px 6px 6px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    font-size: 12px; font-weight: 600; color: var(--slate-700);
    max-width: 220px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    animation: revealUp 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.attach-chip > span:not(.attach-chip-thumb) {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attach-chip-thumb {
    width: 26px; height: 26px; border-radius: 6px;
    background: var(--brand-50); color: var(--brand-600);
    display: grid; place-items: center; font-size: 10px; font-weight: 800;
    text-transform: uppercase;
    object-fit: cover;
}
.attach-chip-close {
    width: 18px; height: 18px;
    border-radius: 4px;
    background: transparent;
    border: none;
    color: var(--slate-400);
    cursor: pointer;
    display: grid; place-items: center;
}
.attach-chip-close:hover { background: var(--slate-100); color: var(--slate-700); }

.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.97);
    border: 1.5px solid rgba(255, 255, 255, 0.38);
    border-radius: 14px;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
}
.chat-input-bar:focus-within {
    background: #fff;
    border-color: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.22), 0 16px 40px rgba(0, 0, 0, 0.38);
}
.attach-btn {
    width: 38px; height: 38px;
    border-radius: 9px;
    border: none;
    background: var(--slate-100);
    color: var(--slate-500);
    display: grid; place-items: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.attach-btn:hover { background: var(--brand-50); color: var(--brand-600); }
.chat-textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font: 500 14px 'Inter', sans-serif;
    line-height: 1.5;
    color: var(--slate-900);
    max-height: 160px;
    padding: 8px 4px;
    background: transparent;
}
.chat-textarea::placeholder { color: var(--slate-400); }
.send-btn {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 9px;
    border: none;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700) 55%, var(--brand-900));
    color: #fff;
    display: grid; place-items: center;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.32);
    transition: transform 0.18s, box-shadow 0.18s, background 0.18s;
    flex-shrink: 0;
    overflow: hidden;
    isolation: isolate;
}
.send-btn svg { position: relative; z-index: 2; }
.send-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,0.55) 50%, transparent 70%);
    transform: translateX(-150%);
    transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}
.send-btn:hover {
    background: linear-gradient(135deg, var(--brand-400), var(--brand-600) 55%, var(--brand-800));
    transform: translateY(-2px) scale(1.06);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.5), 0 0 0 1px rgba(255,255,255,0.15) inset;
}
.send-btn:hover::before {
    transform: translateX(150%);
}
.send-btn:active { transform: translateY(0) scale(1); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn:disabled::before { display: none; }

/* Start Analysis sticky CTA */
.start-analysis-btn {
    position: relative;
    width: 100%;
    margin-top: 16px;
    padding: 15px 20px;
    background: linear-gradient(135deg, #60a5fa 0%, #2563eb 50%, #1d4ed8 100%);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 12px;
    font: 800 14px 'Inter', sans-serif;
    letter-spacing: 0.02em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255,255,255,0.38);
    overflow: hidden;
    transition: transform 0.22s, box-shadow 0.22s, background 0.22s, border-color 0.22s, color 0.22s;
    text-transform: uppercase;
}
.start-analysis-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #93c5fd 0%, #60a5fa 35%, #3b82f6 70%, #1d4ed8 100%);
    border-color: rgba(255, 255, 255, 0.65);
    transform: translateY(-3px);
    box-shadow: 0 26px 60px rgba(96, 165, 250, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.3) inset, inset 0 1px 0 rgba(255, 255, 255, 0.55);
    color: #ffffff;
}
.start-analysis-btn:active:not(:disabled) {
    transform: translateY(-1px);
}
.start-analysis-btn:disabled {
    background: rgba(255, 255, 255, 0.09);
    color: rgba(255, 255, 255, 0.42);
    border-color: rgba(255, 255, 255, 0.14);
    box-shadow: none;
    cursor: not-allowed;
}
.start-glow {
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
    transform: translateX(-100%);
    pointer-events: none;
}
.start-analysis-btn:not(:disabled) .start-glow {
    animation: shine 2.6s infinite;
}
@keyframes shine {
    0%   { transform: translateX(-100%); }
    50%  { transform: translateX(100%);  }
    100% { transform: translateX(100%);  }
}
.start-hint {
    position: absolute;
    bottom: -20px; left: 50%;
    transform: translateX(-50%);
    font-size: 10px; font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.06em;
    white-space: nowrap;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.start-analysis-btn:not(:disabled) .start-hint { display: none; }

/* ════════════════════════ PREVIEW PANE ════════════════════════ */
.preview-pane {
    display: flex;
    flex-direction: column;
    background: #eef2f9;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    min-height: 0;
    position: relative;
}
.preview-pane-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: #152c4a;
    position: relative;
    color: #fff;
}
.preview-pane-header::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
}
.preview-pane-title {
    display: flex; align-items: center; gap: 8px;
    font-weight: 800; font-size: 13px;
    color: #ffffff;
    text-transform: uppercase; letter-spacing: 0.08em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.preview-zoom {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 800; color: rgba(255,255,255,0.9);
}
.zoom-btn {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: rgba(255,255,255,0.14);
    border: 1px solid rgba(255,255,255,0.24);
    color: #ffffff;
    cursor: pointer;
    font-size: 16px;
    font-weight: 800;
    transition: all 0.15s;
}
.zoom-btn:hover { background: rgba(255,255,255,0.25); border-color: rgba(255,255,255,0.4); }

.preview-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 32px 28px 60px;
    background:
        radial-gradient(800px 400px at 50% 0%, rgba(37, 99, 235, 0.07), transparent 70%),
        #e8edf6;
}

.report-preview {
    max-width: 760px;
    margin: 0 auto;
    transform-origin: top center;
    transition: transform 0.2s;
}

/* Preview skeleton (intro only) */
.preview-skeleton {
    max-width: 760px;
    margin: 0 auto;
    aspect-ratio: 210 / 297;
    background:
        linear-gradient(90deg,
            rgba(255,255,255,0.6) 0%,
            rgba(37, 99, 235, 0.12) 40%,
            rgba(255,255,255,0.8) 50%,
            rgba(37, 99, 235, 0.12) 60%,
            rgba(255,255,255,0.6) 100%);
    background-size: 220% 100%;
    animation: shimmer 1.6s linear infinite;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.1);
    position: relative;
    overflow: hidden;
}
.preview-skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(180deg, rgba(15,23,42,0.08), transparent 30%),
        linear-gradient(0deg, rgba(15,23,42,0.06), transparent 30%);
}

/* ════════════════════════ LIGHTBOX ════════════════════════ */
.lightbox {
    position: fixed; inset: 0;
    display: none;
    z-index: 1000;
}
.lightbox.active {
    display: block;
    animation: fadeIn 0.25s ease;
}
.lightbox-bg {
    position: absolute; inset: 0;
    background:
        radial-gradient(1200px 800px at 50% 40%, rgba(59, 130, 246, 0.4), transparent 60%),
        linear-gradient(165deg, var(--brand-500) 0%, var(--brand-700) 30%, var(--brand-900) 70%, var(--brand-950) 100%);
}
.lightbox-particles { position: absolute; inset: 0; overflow: hidden; }
.lb-particle {
    position: absolute;
    bottom: -20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.65);
    animation: floatUp linear infinite;
}
@keyframes floatUp {
    0%   { transform: translateY(0) translateX(0);     opacity: 0; }
    10%  { opacity: var(--p-opacity, 0.6); }
    90%  { opacity: var(--p-opacity, 0.6); }
    100% { transform: translateY(-110vh) translateX(var(--p-drift, 0px)); opacity: 0; }
}

.lightbox-content {
    position: relative;
    max-width: 560px;
    margin: 0 auto;
    padding: 72px 32px 40px;
    text-align: center;
    color: #fff;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.lb-orbit { position: relative; width: 240px; height: 240px; margin-bottom: 36px; }
.lb-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.16);
    animation: softPulse 3s ease-in-out infinite;
}
.lb-ring-1 { inset: 0;   border-color: rgba(255, 255, 255, 0.3);  animation-delay: 0s;   }
.lb-ring-2 { inset: 24px; border-color: rgba(255, 255, 255, 0.18); animation-delay: 0.6s; }
.lb-ring-3 { inset: 48px; border-color: rgba(255, 255, 255, 0.12); animation-delay: 1.2s; }
.lb-ring::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: rgba(255, 255, 255, 0.9);
    animation: spinSlow 2.4s linear infinite;
}
.lb-ring-2::before { animation: orbitCCW 3.2s linear infinite; }
.lb-ring-3::before { animation: spinSlow 4s linear infinite; }
.lb-core {
    position: absolute;
    inset: 0;
    display: grid; place-items: center;
    color: #fff;
    filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.55));
    animation: softPulse 2.4s ease-in-out infinite;
}

.lb-title {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: -0.01em;
    margin-bottom: 10px;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}
.lb-sub {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.78);
    margin-bottom: 32px;
    max-width: 460px;
    min-height: 1.6em;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
    font-style: italic;
    line-height: 1.55;
}
.lb-sub.visible {
    opacity: 1;
    transform: translateY(0);
}

.lb-phases {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}
.lb-phase {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    font-size: 13px; font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    text-align: left;
    opacity: 0;
    transform: translateY(8px);
    animation: revealUp 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.lb-phase.active {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}
.lb-phase.done { color: rgba(255, 255, 255, 0.9); }
.lb-phase-icon {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    display: grid; place-items: center;
    flex-shrink: 0;
}
.lb-phase.active .lb-phase-icon {
    border-color: #fff;
    border-top-color: transparent;
    animation: spinSlow 1s linear infinite;
}
.lb-phase.done .lb-phase-icon {
    background: #fff;
    border-color: #fff;
    color: var(--brand-700);
}
.lb-phase.done .lb-phase-icon::after { content: '✓'; font-size: 12px; font-weight: 900; }

.lb-ticker {
    display: flex; align-items: center; gap: 10px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 700;
    transition: opacity 0.6s ease, transform 0.6s ease;
}
.lb-ticker-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #fff;
    animation: softPulse 1.4s ease-in-out infinite;
}

/* ════════════════════ COMPLETION + FADE-OUT STATES ════════════════════ */
/* When chat.js receives the SSE 'done' event, the lightbox flips into
   .complete state: phase rows fade away, core icon pulses celebratory,
   title morphs to "Your research is ready". After ~1.7s, .fading-out
   is added and the entire overlay fades out over ~0.9s. The report
   has already been rendered into the preview pane behind the lightbox,
   so the slow fade-out reveals it gracefully. */
.lightbox.complete .lb-phases {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}
.lightbox.complete .lb-ticker {
    opacity: 0.5;
    transform: translateY(-6px);
}
.lightbox.complete .lb-title {
    animation: lbTitleCelebrate 1.05s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: linear-gradient(135deg, #ffffff, #c7e0ff 60%, #ffffff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 28px rgba(255, 255, 255, 0.3);
}
@keyframes lbTitleCelebrate {
    0%   { transform: translateY(8px) scale(0.96); opacity: 0.6; }
    60%  { transform: translateY(-3px) scale(1.04); opacity: 1; }
    100% { transform: translateY(0)    scale(1);    opacity: 1; }
}
.lightbox.complete .lb-core {
    animation: lbCoreCelebrate 1.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes lbCoreCelebrate {
    0%   { transform: scale(1);    filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.55)); }
    35%  { transform: scale(1.45); filter: drop-shadow(0 0 70px rgba(255, 255, 255, 1)) drop-shadow(0 0 32px rgba(147, 197, 253, 0.9)); }
    100% { transform: scale(1.12); filter: drop-shadow(0 0 44px rgba(255, 255, 255, 0.85)); }
}
.lightbox.complete .lb-ring {
    border-color: rgba(255, 255, 255, 0.45);
    transition: border-color 0.6s ease;
}

/* The slow fade-out at the end of the ceremony — reveals the report
   that's already rendered behind the lightbox in the preview pane. */
.lightbox.fading-out {
    opacity: 0;
    transition: opacity 0.9s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}
.lightbox.fading-out .lb-core {
    transform: scale(1.45);
    transition: transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ════════════════════════ SETTINGS MODAL ════════════════════════ */
.modal { position: fixed; inset: 0; display: none; z-index: 1100; }
.modal.active { display: block; animation: fadeIn 0.2s ease; }
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
}
.modal-card {
    position: relative;
    width: 480px; max-width: calc(100vw - 48px);
    max-height: calc(100vh - 80px);
    margin: 40px auto;
    background: #fff;
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: revealUp 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.modal-head {
    padding: 20px 24px 14px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--slate-200);
}
.modal-title { font-size: 16px; font-weight: 800; }

/* Close button visibility override — the global .icon-btn is white-on-dark
   for the topbar; inside a modal head we need dark-on-light so the X is
   actually visible against the white card background. */
.modal-head .icon-btn,
.library-head-actions .icon-btn[data-close-modal] {
    background: var(--slate-100);
    border: 1px solid var(--slate-200);
    color: var(--slate-700);
    width: 36px;
    height: 36px;
    border-radius: 9px;
    font-size: 22px;
    font-weight: 600;
    line-height: 1;
}
.modal-head .icon-btn:hover,
.library-head-actions .icon-btn[data-close-modal]:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.35);
    color: #dc2626;
    transform: translateY(-1px);
}
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-foot {
    padding: 14px 24px;
    display: flex; justify-content: flex-end; gap: 10px;
    border-top: 1px solid var(--slate-200);
    background: #fafbfd;
}
.setting-group { margin-bottom: 18px; }
.setting-label {
    display: block;
    font-size: 11px; font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--slate-500);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.setting-group input[type="text"],
.setting-group input[type="email"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font: 600 13px 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.15s;
}
.setting-group input:focus { border-color: var(--brand-500); }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] {
    width: 48px; height: 32px;
    border: 1px solid var(--slate-200);
    border-radius: 6px;
    padding: 0;
    cursor: pointer;
}
.color-row code { font: 700 13px 'JetBrains Mono', ui-monospace, monospace; color: var(--slate-700); }
.setting-note {
    font-size: 11px;
    color: var(--slate-400);
    margin-top: 18px;
    line-height: 1.5;
}
.setting-note code {
    font-size: 11px;
    background: var(--slate-100);
    padding: 1px 6px;
    border-radius: 4px;
}
.btn-primary {
    background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font: 700 13px 'Inter', sans-serif;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost {
    background: transparent;
    color: var(--slate-500);
    border: 1px solid var(--slate-200);
    padding: 10px 14px;
    border-radius: 8px;
    font: 700 13px 'Inter', sans-serif;
    cursor: pointer;
}
.btn-ghost:hover { background: var(--slate-100); color: var(--slate-900); }

/* Scrollbars */
.chat-messages::-webkit-scrollbar,
.preview-scroll::-webkit-scrollbar { width: 10px; }
.chat-messages::-webkit-scrollbar-thumb,
.preview-scroll::-webkit-scrollbar-thumb {
    background: var(--slate-200);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* ════════════════════════ LIBRARY MODAL ════════════════════════ */
.library-modal .modal-card {
    width: 1080px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 60px);
}
.library-head-title {
    display: flex; align-items: center; gap: 10px;
    color: var(--slate-900);
}
.library-head-actions {
    display: flex; align-items: center; gap: 8px;
}
.library-head-actions .btn-ghost {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.library-body {
    padding: 24px;
    background: #eef2f9;
    max-height: 72vh;
    overflow-y: auto;
}
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}
.library-empty {
    grid-column: 1 / -1;
    padding: 80px 30px;
    text-align: center;
    color: var(--slate-400);
    font-size: 13px;
}
.library-empty strong { color: var(--slate-600); font-weight: 700; }
.library-loading {
    grid-column: 1 / -1;
    padding: 60px;
    text-align: center;
    color: var(--slate-500);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.lib-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: 14px;
    overflow: hidden;
    transition: all 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
    opacity: 0;
    transform: translateY(12px);
    animation: revealUp 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.lib-card:hover {
    border-color: var(--brand-300);
    transform: translateY(-3px);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.14);
}

.lib-card-cover {
    aspect-ratio: 210 / 120;
    background:
        radial-gradient(500px 300px at 50% 0%, rgba(255,255,255,0.14), transparent 60%),
        linear-gradient(145deg, #1d4ed8 0%, #1e3a8a 40%, #1e3a5f 75%, #152c4a 100%);
    color: #ffffff;
    padding: 18px 20px 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}
.lib-card-cover-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.lib-card-vis {
    display: inline-block;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.28);
}
.vis-public  { background: rgba(16, 185, 129, 0.25); color: #d1fae5; border-color: rgba(16, 185, 129, 0.4); }
.vis-private { background: rgba(0, 0, 0, 0.32); color: rgba(255, 255, 255, 0.7); }

.lib-card-chatbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--slate-50);
    border-bottom: 1px solid var(--slate-100);
    flex-wrap: wrap;
}
.lib-card-cost {
    display: inline-flex; align-items: center;
    font: 800 9px 'Inter', sans-serif;
    letter-spacing: 0.06em;
    padding: 4px 9px;
    border-radius: 100px;
    border: 1px solid;
}
.cost-green  { background: rgba(16, 185, 129, 0.10);  color: #059669;  border-color: rgba(16, 185, 129, 0.3); }
.cost-yellow { background: rgba(245, 158, 11, 0.10); color: #d97706;  border-color: rgba(245, 158, 11, 0.3); }
.cost-orange { background: rgba(249, 115, 22, 0.10); color: #ea580c;  border-color: rgba(249, 115, 22, 0.35); }
.cost-red    { background: rgba(239, 68, 68, 0.10);  color: #dc2626;  border-color: rgba(239, 68, 68, 0.4); font-weight: 900; }

.lib-card-lock {
    display: inline-flex; align-items: center;
    font: 800 9px 'Inter', sans-serif;
    letter-spacing: 0.06em;
    color: #dc2626;
    text-transform: uppercase;
}
.lib-card-unlock {
    margin-left: auto;
    background: #dc2626;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 6px;
    font: 800 9px 'Inter', sans-serif;
    letter-spacing: 0.08em;
    cursor: pointer;
    text-transform: uppercase;
}
.lib-card-unlock:hover { background: #b91c1c; }
.lib-card-cover::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 24px 24px;
    mask-image: radial-gradient(ellipse at 50% 40%, #000 40%, transparent 80%);
    -webkit-mask-image: radial-gradient(ellipse at 50% 40%, #000 40%, transparent 80%);
    pointer-events: none;
}
.lib-card-cover > * { position: relative; z-index: 2; }
.lib-card-pill {
    display: inline-block;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    padding: 3px 9px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 100px;
    align-self: flex-start;
    color: rgba(255, 255, 255, 0.9);
}
.lib-card-title {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: -0.015em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.lib-card-for {
    font-size: 9px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lib-card-meta {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--slate-100);
    font-size: 10px;
}
.lib-card-status {
    font-weight: 800;
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 4px 9px;
    border-radius: 100px;
}
.status-ready     { background: rgba(16, 185, 129, 0.12); color: #059669;  border: 1px solid rgba(16, 185, 129, 0.25); }
.status-draft     { background: rgba(100, 116, 139, 0.12); color: #64748b; border: 1px solid rgba(100, 116, 139, 0.25); }
.status-analyzing { background: rgba(245, 158, 11, 0.12); color: #d97706;  border: 1px solid rgba(245, 158, 11, 0.25); }
.status-error     { background: rgba(239, 68, 68, 0.12); color: #dc2626;   border: 1px solid rgba(239, 68, 68, 0.25); }
.lib-card-date {
    color: var(--slate-500);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.lib-card-actions {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: var(--slate-100);
}
.lib-card-actions button {
    background: #ffffff;
    border: none;
    padding: 12px 4px;
    font: 800 9px 'Inter', sans-serif;
    color: var(--slate-500);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.lib-card-actions button svg { width: 12px; height: 12px; }
.lib-card-actions button:hover {
    background: var(--brand-50);
    color: var(--brand-700);
}
.lib-card-actions button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.lib-card-actions button.danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

/* ════════════════════════ MODEL PICKER (custom dropdown) ════════════════════════ */
/* Hidden native select keeps existing chat.js + mobile-drawer code working */
.model-select-hidden { display: none !important; }

.model-picker {
    position: relative;
    display: inline-block;
}
.model-picker-btn {
    appearance: none;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 9px;
    color: #ffffff;
    font: 700 10px 'Inter', sans-serif;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 7px 12px 7px 12px;
    cursor: pointer;
    outline: none;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 240px;
    backdrop-filter: blur(6px);
}
.model-picker-btn::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.25);
    flex-shrink: 0;
}
.model-picker-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.45);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.model-picker.open .model-picker-btn {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.14);
}
.model-picker-current {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.model-picker-arrow {
    flex-shrink: 0;
    transition: transform 0.2s;
    opacity: 0.85;
}
.model-picker.open .model-picker-arrow {
    transform: rotate(180deg);
}

.model-picker-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    background:
        linear-gradient(165deg, var(--brand-700) 0%, var(--brand-800) 40%, var(--brand-900) 80%, #0a1020 100%);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 14px;
    padding: 6px;
    box-shadow:
        0 24px 60px rgba(11, 18, 32, 0.55),
        0 8px 20px rgba(0, 0, 0, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    z-index: 200;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transform-origin: top center;
    pointer-events: none;
    transform: translateY(-4px);
    transition:
        opacity 0.18s ease-out,
        max-height 0.55s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.model-picker.open .model-picker-menu {
    opacity: 1;
    max-height: 70vh;
    overflow-y: auto;
    pointer-events: auto;
    transform: translateY(0);
}
@keyframes mp-option-in {
    0% {
        opacity: 0;
        transform: translateX(-22px);
        filter: blur(2px);
    }
    60% {
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
        filter: blur(0);
    }
}
@keyframes mp-option-shine {
    0%   { background-position: -160% 0; opacity: 0; }
    18%  { opacity: 1; }
    100% { background-position: 260% 0; opacity: 0; }
}
.model-picker-option {
    position: relative;
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 14px;
    color: #ffffff;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    margin-bottom: 2px;
    overflow: hidden;
}
.model-picker.open .model-picker-option {
    opacity: 0;
    animation: mp-option-in 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.model-picker.open .model-picker-option::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
        110deg,
        transparent 30%,
        rgba(255, 255, 255, 0.0) 38%,
        rgba(255, 255, 255, 0.55) 50%,
        rgba(255, 255, 255, 0.0) 62%,
        transparent 70%
    );
    background-size: 220% 100%;
    background-position: -160% 0;
    mix-blend-mode: screen;
    opacity: 0;
    animation: mp-option-shine 0.95s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
/* Stagger — open delay = 380ms (after slide) + 70ms per item */
.model-picker.open .model-picker-option:nth-child(1)  { animation-delay: 0.38s, 0.52s; }
.model-picker.open .model-picker-option:nth-child(2)  { animation-delay: 0.45s, 0.59s; }
.model-picker.open .model-picker-option:nth-child(3)  { animation-delay: 0.52s, 0.66s; }
.model-picker.open .model-picker-option:nth-child(4)  { animation-delay: 0.59s, 0.73s; }
.model-picker.open .model-picker-option:nth-child(5)  { animation-delay: 0.66s, 0.80s; }
.model-picker.open .model-picker-option:nth-child(6)  { animation-delay: 0.73s, 0.87s; }
.model-picker.open .model-picker-option:nth-child(7)  { animation-delay: 0.80s, 0.94s; }
.model-picker.open .model-picker-option:nth-child(8)  { animation-delay: 0.87s, 1.01s; }
.model-picker.open .model-picker-option:nth-child(9)  { animation-delay: 0.94s, 1.08s; }
.model-picker.open .model-picker-option:nth-child(10) { animation-delay: 1.01s, 1.15s; }
.model-picker.open .model-picker-option:nth-child(n+11) { animation-delay: 1.08s, 1.22s; }
@media (prefers-reduced-motion: reduce) {
    .model-picker-menu,
    .model-picker.open .model-picker-menu { transition: opacity 0.15s; transform: none; }
    .model-picker.open .model-picker-option { animation: none; opacity: 1; }
    .model-picker.open .model-picker-option::after { animation: none; display: none; }
}
.model-picker-option:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.18);
}
.model-picker-option.selected {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.32);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.model-picker-option.selected::before {
    content: '✓ ';
    color: #34d399;
    font-weight: 900;
    margin-right: 4px;
}
.mp-name {
    font: 800 12px 'Inter', sans-serif;
    letter-spacing: -0.005em;
    color: #ffffff;
    margin-bottom: 2px;
}
.mp-desc {
    font: 500 10px 'Inter', sans-serif;
    color: rgba(255, 255, 255, 0.65);
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
}
.model-picker-menu::-webkit-scrollbar { width: 6px; }
.model-picker-menu::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 6px; }

/* ════════════════════════ EMAIL MODAL ════════════════════════ */
.email-card { width: 560px !important; }
.email-head-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
    margin-right: 10px;
}
.modal-title {
    display: flex;
    align-items: center;
}
.email-field {
    margin-bottom: 14px;
}
.email-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 14px;
}
.email-field-row .email-field { margin-bottom: 0; }
.email-field label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font: 800 10px 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--slate-500);
    margin-bottom: 6px;
}
.email-field-hint {
    font-weight: 600;
    color: var(--slate-400);
    text-transform: none;
    letter-spacing: 0.02em;
    font-size: 10px;
}
.email-field input[type="email"],
.email-field input[type="text"] {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--slate-200);
    border-radius: 10px;
    font: 600 13px 'Inter', sans-serif;
    color: var(--slate-900);
    outline: none;
    transition: all 0.15s;
    background: #ffffff;
}
.email-field input:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
.email-preview {
    margin-top: 18px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--brand-50), #ffffff);
    border: 1px solid var(--brand-100);
    border-left: 3px solid var(--brand-500);
    border-radius: 0 10px 10px 0;
}
.email-preview-label {
    font: 800 10px 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand-700);
    margin-bottom: 4px;
}
.email-preview-text {
    font-size: 12px;
    color: var(--slate-700);
    line-height: 1.55;
}

/* Spin animation for download button progress indicator */
.spin {
    animation: spin360 1s linear infinite;
}
@keyframes spin360 { to { transform: rotate(360deg); } }

/* Disabled button helpful tooltip — use the native title attribute styling
   but make the visual state clearer */
.icon-btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
    position: relative;
}
.icon-btn:disabled::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 8px;
    background: repeating-linear-gradient(45deg,
        rgba(255, 255, 255, 0.04),
        rgba(255, 255, 255, 0.04) 4px,
        transparent 4px,
        transparent 8px);
    pointer-events: none;
}

/* Default visibility helpers — desktop shows desktop-only, hides mobile-only */
.desktop-only { }
.mobile-only  { display: none !important; }

/* ════════════════════════════════════════════════════════════════════
   MOBILE LAYOUT  (≤ 768px) — tab-based, drawer menu, single pane visible
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root { --topbar-h: 60px; }
    .desktop-only { display: none !important; }
    .mobile-only  { display: inherit !important; }
    .mobile-only.icon-btn { display: grid !important; }

    /* ─── Topbar collapses ─── */
    .topbar {
        grid-template-columns: auto 1fr auto;
        height: var(--topbar-h);
        padding: 8px 14px;
        gap: 10px;
    }
    .topbar-center { display: none; }
    .brand-mark { max-height: 50px; }
    .brand-logo-img { max-height: 44px; max-width: 160px; }
    .brand-logo-empty { padding: 8px 12px; font-size: 9px; }
    .brand-logo-empty svg { width: 18px; height: 18px; }
    .topbar-canvas { display: none; }   /* save battery on mobile */

    /* ─── Mobile tabs ─── */
    .mobile-tabs {
        display: flex !important;
        position: fixed;
        top: var(--topbar-h);
        left: 0; right: 0;
        height: 48px;
        background: #ffffff;
        border-bottom: 1px solid var(--slate-200);
        z-index: 90;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    }
    .mobile-tab {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        background: transparent;
        border: none;
        font: 800 11px 'Inter', sans-serif;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--slate-500);
        cursor: pointer;
        position: relative;
        transition: color 0.15s;
    }
    .mobile-tab.active {
        color: var(--brand-700);
    }
    .mobile-tab.active::after {
        content: '';
        position: absolute;
        left: 22%; right: 22%;
        bottom: 0;
        height: 3px;
        background: linear-gradient(90deg, var(--brand-500), var(--brand-700));
        border-radius: 3px 3px 0 0;
    }
    .mobile-tab svg { flex-shrink: 0; }
    .mobile-tab-badge {
        background: var(--brand-600);
        color: #fff;
        font-size: 9px;
        font-weight: 800;
        padding: 2px 6px;
        border-radius: 100px;
        letter-spacing: 0.06em;
    }

    /* ─── Split layout becomes single-pane ─── */
    .split-layout {
        position: fixed;
        top: calc(var(--topbar-h) + 48px);
        left: 0; right: 0; bottom: 0;
        display: block;
        padding: 0;
        gap: 0;
    }
    .chat-pane,
    .preview-pane {
        position: absolute;
        inset: 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
        display: none;
        flex-direction: column;
    }
    .chat-pane.mobile-active,
    .preview-pane.mobile-active {
        display: flex;
    }

    /* ─── Chat pane mobile tweaks ─── */
    .chat-pane-header {
        padding: 10px 16px;
    }
    .chat-pane-title { font-size: 11px; }
    .chat-pane-meta {
        font-size: 10px;
        gap: 6px;
    }
    .model-select {
        max-width: 140px;
        font-size: 9px;
        padding: 5px 22px 5px 9px;
    }
    .chat-messages {
        padding: 18px 16px;
        gap: 16px;
    }
    .chat-empty {
        padding: 24px 16px;
    }
    .chat-empty-icon {
        width: 64px; height: 64px;
        margin-bottom: 18px;
    }
    .chat-empty-title { font-size: 16px; }
    .chat-empty-sub { font-size: 12px; }

    .msg-bubble {
        max-width: 92%;
        font-size: 13px;
        padding: 12px 14px;
    }
    .msg-assistant .msg-bubble {
        max-width: 95%;
        padding: 13px 16px 13px 18px;
    }

    /* ─── Chat input mobile (handles iOS keyboard properly) ─── */
    .chat-input-wrap {
        padding: 12px 12px 14px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
    .chat-input-bar {
        padding: 8px;
        gap: 8px;
        border-radius: 12px;
    }
    .chat-textarea {
        font-size: 16px;  /* prevents iOS auto-zoom on focus */
    }
    .attach-btn { width: 34px; height: 34px; }
    .send-btn { width: 34px; height: 34px; }
    .start-analysis-btn {
        margin-top: 12px;
        padding: 13px 18px;
        font-size: 13px;
    }

    /* ─── Preview pane mobile tweaks ─── */
    .preview-pane-header { padding: 10px 16px; }
    .preview-pane-title { font-size: 11px; }
    .preview-zoom { display: none; }   /* let pinch-zoom handle it on mobile */
    .preview-scroll { padding: 16px 12px 40px; }
    .report-preview { transform: none !important; }

    /* ─── Drop overlay ─── */
    .drop-overlay-inner { padding: 32px 24px; }
    .drop-title { font-size: 18px; }
    .drop-sub { font-size: 11px; }

    /* ─── All modals become full-screen sheets ─── */
    .modal-card {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        height: 100vh;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    .modal-body { padding: 18px 18px 24px; }
    .library-body { padding: 16px; }
    .library-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .lib-card-cover { aspect-ratio: 16 / 8; padding: 14px 16px; }
    .lib-card-title { font-size: 14px; }
    .lib-card-actions button { padding: 14px 4px; font-size: 9px; }

    /* ─── Library modal head — full width refresh button ─── */
    .library-head-actions .btn-ghost {
        padding: 7px 10px;
        font-size: 10px;
    }

    /* ─── Lightbox (analysis) mobile ─── */
    .lightbox-content { padding: 60px 24px 30px; }
    .lb-orbit { width: 180px; height: 180px; margin-bottom: 28px; }
    .lb-title { font-size: 22px; }
    .lb-sub { font-size: 12px; }
    .lb-phases { max-width: 100%; }
}

/* ════════════════════════ MOBILE DRAWER ════════════════════════ */
.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: none;
}
.mobile-drawer.active {
    display: block;
}
.mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    animation: mDrawerFade 0.25s ease forwards;
}
@keyframes mDrawerFade { to { opacity: 1; } }

.mobile-drawer-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(360px, 88vw);
    background: #ffffff;
    box-shadow: -16px 0 48px rgba(11, 18, 32, 0.36);
    overflow-y: auto;
    transform: translateX(100%);
    animation: mDrawerSlide 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}
@keyframes mDrawerSlide { to { transform: translateX(0); } }

.mobile-drawer-head {
    padding: 18px 22px 14px;
    background: linear-gradient(180deg,
        #2563eb 0%, #1d4ed8 30%, #1e3a5f 80%, #152c4a 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.mobile-drawer-title {
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.mobile-drawer-close {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.mobile-drawer-section {
    padding: 18px 22px 12px;
    border-bottom: 1px solid var(--slate-100);
}
.mobile-drawer-section:last-child {
    border-bottom: none;
}
.mobile-drawer-label {
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--slate-400);
    margin-bottom: 12px;
}

.mobile-drawer-field {
    margin-bottom: 12px;
}
.mobile-drawer-field label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}
.mobile-drawer-field input,
.mobile-drawer-select {
    width: 100%;
    padding: 11px 14px;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: 9px;
    font: 600 14px 'Inter', sans-serif;  /* 14px+ avoids iOS zoom */
    color: var(--slate-900);
    outline: none;
    transition: all 0.15s;
}
.mobile-drawer-field input:focus,
.mobile-drawer-select:focus {
    background: #fff;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.mobile-drawer-static {
    padding: 11px 14px;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: 9px;
    font: 600 14px 'Inter', sans-serif;
    color: var(--slate-700);
}

.mobile-drawer-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 14px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: 11px;
    font: 700 13px 'Inter', sans-serif;
    color: var(--slate-900);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    position: relative;
}
.mobile-drawer-btn:hover {
    background: var(--brand-50);
    border-color: var(--brand-200);
    color: var(--brand-700);
}
.mobile-drawer-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #fff;
    color: var(--slate-400);
}
.mobile-drawer-btn svg {
    color: var(--brand-600);
    flex-shrink: 0;
}
.mobile-drawer-btn:disabled svg {
    color: var(--slate-300);
}
.mobile-drawer-btn span:not(.mobile-drawer-dot) {
    flex: 1;
}
.mobile-drawer-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
    animation: dotBlink 1.6s infinite;
}

/* ════════════════════════════════════════════════════════════════════
   APP MODAL — branded replacement for native confirm / alert / prompt.
   Smaller cousin of the analysis lightbox: brand gradient card, orbital
   animation behind the content, white text + buttons.
   ════════════════════════════════════════════════════════════════════ */
.app-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.app-modal.active {
    display: flex;
    animation: appModalFade 0.22s ease;
}
@keyframes appModalFade { from { opacity: 0; } to { opacity: 1; } }

.app-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(11, 18, 32, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.app-modal-card {
    position: relative;
    width: 100%;
    max-width: 460px;
    background:
        radial-gradient(800px 500px at 50% 0%, rgba(255, 255, 255, 0.16), transparent 55%),
        linear-gradient(165deg, var(--brand-500) 0%, var(--brand-700) 32%, var(--brand-800) 60%, var(--brand-900) 85%, #0a1020 100%);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow:
        0 32px 80px rgba(11, 18, 32, 0.55),
        0 8px 24px rgba(0, 0, 0, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
    overflow: hidden;
    color: #fff;
    transform: scale(0.7) translateY(40px);
    opacity: 0;
    animation: appModalSpring 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes appModalSpring {
    0%   { transform: scale(0.7) translateY(40px); opacity: 0; }
    60%  { transform: scale(1.04) translateY(-4px); opacity: 1; }
    100% { transform: scale(1) translateY(0); }
}

/* ─── Background atomic orbital animation ─── */
.app-modal-anim {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    perspective: 800px;
}
.app-modal-orbit-wrap {
    position: absolute;
    top: 50%; left: 50%;
    transform-style: preserve-3d;
}
.orbit-wrap-1 { transform: translate(-50%, -50%) rotateX(72deg); }
.orbit-wrap-2 { transform: translate(-50%, -50%) rotateY(72deg); }
.orbit-wrap-3 { transform: translate(-50%, -50%) rotateX(38deg) rotateZ(48deg); }

.app-modal-orbit {
    position: relative;
    width: 320px; height: 320px;
    margin: -160px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    animation: appModalSpin 18s linear infinite;
}
.orbit-wrap-2 .app-modal-orbit {
    width: 380px; height: 380px;
    margin: -190px;
    animation-duration: 26s;
    animation-direction: reverse;
    border-color: rgba(255, 255, 255, 0.14);
}
.orbit-wrap-3 .app-modal-orbit {
    width: 460px; height: 460px;
    margin: -230px;
    animation-duration: 36s;
    border-color: rgba(255, 255, 255, 0.10);
}
.app-modal-orbit::before {
    content: '';
    position: absolute;
    top: -5px; left: 50%;
    width: 9px; height: 9px;
    margin-left: -4.5px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.85), 0 0 32px rgba(255, 255, 255, 0.4);
}
.orbit-wrap-2 .app-modal-orbit::before { width: 6px; height: 6px; margin-left: -3px; top: -3.5px; }
.orbit-wrap-3 .app-modal-orbit::before { width: 7px; height: 7px; margin-left: -3.5px; top: -4px; }

@keyframes appModalSpin {
    to { transform: rotate(360deg); }
}

.app-modal-core {
    position: absolute;
    top: 50%; left: 50%;
    width: 8px; height: 8px;
    margin: -4px 0 0 -4px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 22px rgba(255, 255, 255, 0.85), 0 0 44px rgba(255, 255, 255, 0.45);
    animation: appModalCorePulse 2.4s ease-in-out infinite;
}
@keyframes appModalCorePulse {
    0%, 100% { opacity: 0.55; transform: scale(1); }
    50%      { opacity: 1;    transform: scale(1.55); }
}

/* ─── Content ─── */
.app-modal-content {
    position: relative;
    padding: 38px 36px 30px;
    text-align: center;
    z-index: 2;
}
.app-modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 22px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.32);
    display: grid;
    place-items: center;
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.app-modal-icon.danger {
    background: rgba(239, 68, 68, 0.22);
    border-color: rgba(254, 202, 202, 0.55);
    color: #fff5f5;
}
.app-modal-icon.success {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(167, 243, 208, 0.55);
    color: #ecfdf5;
}
.app-modal-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.015em;
    margin: 0 0 10px;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.app-modal-message {
    font-size: 13.5px;
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.85);
    margin: 0 0 24px;
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
}
.app-modal-input {
    width: 100%;
    padding: 13px 16px;
    background: rgba(255, 255, 255, 0.12);
    border: 1.5px solid rgba(255, 255, 255, 0.32);
    border-radius: 11px;
    font: 600 14px 'Inter', sans-serif;
    color: #ffffff;
    margin-bottom: 22px;
    outline: none;
    transition: all 0.15s;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.app-modal-input::placeholder { color: rgba(255, 255, 255, 0.5); }
.app-modal-input:focus {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.75);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.14);
}

.app-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.app-modal-btn {
    padding: 12px 24px;
    border-radius: 11px;
    font: 800 11px 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
    min-width: 110px;
    border: 1px solid;
}
.app-modal-btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.32);
    color: #ffffff;
}
.app-modal-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}
.app-modal-btn-confirm {
    background: #ffffff;
    border-color: #ffffff;
    color: var(--brand-700);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.app-modal-btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.36);
}
.app-modal-btn-confirm.danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: #dc2626;
    color: #ffffff;
    box-shadow: 0 8px 24px rgba(220, 38, 38, 0.4);
}

@media (max-width: 480px) {
    .app-modal { padding: 16px; }
    .app-modal-card { max-width: 100%; }
    .app-modal-content { padding: 30px 22px 22px; }
    .app-modal-title { font-size: 18px; }
    .app-modal-message { font-size: 13px; }
    .app-modal-actions { flex-direction: column-reverse; }
    .app-modal-btn { width: 100%; padding: 14px 20px; }
    .orbit-wrap-3 { display: none; }
}

/* ════════════════════════ EXTRA-NARROW (≤ 480px) ════════════════════════ */
@media (max-width: 480px) {
    .brand-text { display: none; }
    .topbar { padding: 8px 12px; }
    .mobile-drawer-panel { width: 100vw; }
    .lib-card-cover { aspect-ratio: 16 / 9; }
}
