html, body { margin: 0; height: 100%; background: var(--bg-dark); color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
#view-library { height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
:root {
    --bg-dark: #0b0f19;
    --sidebar-bg: #111827;
    --panel-bg: #1f2937;
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --accent-blue: #38bdf8;
    --accent-gradient: linear-gradient(135deg, #38bdf8 0%, #818cf8 50%, #c084fc 100%);
    --user-bubble: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
    --bot-bubble: rgba(31, 41, 55, 0.75);
    --editor-bg: #090d16;
    --editor-text: #f9fafb;
    --card-bg: rgba(31, 41, 55, 0.45);
    --popover-bg: #1f2937;
    --popover-btn-bg: rgba(255, 255, 255, 0.08);
    --popover-btn-text: #f9fafb;
    --hover-bg: rgba(255, 255, 255, 0.06);
    --input-bg: rgba(31, 41, 55, 0.7);
    --overlay-soft: rgba(0, 0, 0, 0.05);
    --overlay-mid: rgba(0, 0, 0, 0.15);
    --overlay-strong: rgba(0, 0, 0, 0.25);
    --reference-header-bg: var(--sidebar-bg);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes referenceCitationPulse {
    0%, 100% { background-color: rgba(250, 204, 21, 0.22); }
    50% { background-color: rgba(250, 204, 21, 0.58); }
}
@keyframes referencePdfShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@keyframes referenceNoteTargetPulse {
    0%, 100% { background-color: rgba(250,204,21,0.45); }
    50% { background-color: rgba(250,204,21,0.9); }
}
@keyframes referenceNotePagePulse {
    0%, 100% { outline-color: rgba(245,158,11,0.4); }
    50% { outline-color: rgba(245,158,11,0.95); }
}
:root {
    /* Thread wallpaper (dark) */
    --wa-chat-bg: #0b141a;
    --wa-chat-dot-1: rgba(255, 255, 255, 0.035);
    --wa-chat-dot-2: rgba(255, 255, 255, 0.022);
    --wa-chat-dot-3: rgba(56, 189, 248, 0.04);
    /* Bubbles (dark) */
    --wa-bubble-out: #005c4b;
    --wa-bubble-out-text: #e9fffa;
    --wa-bubble-in: #1f2c34;
    --wa-bubble-in-text: #f9fafb;
    --wa-tail-out: #005c4b;
    --wa-tail-in: #1f2c34;
    /* Meta + ticks */
    --wa-meta-out: rgba(233, 255, 250, 0.55);
    --wa-meta-in: rgba(255, 255, 255, 0.45);
    --wa-tick-seen: #53bdeb;
    /* Pill / notice surfaces */
    --wa-pill-bg: rgba(32, 44, 51, 0.95);
    --wa-pill-text: rgba(255, 255, 255, 0.75);
    --wa-pill-soft-bg: rgba(32, 44, 51, 0.75);
    --wa-pill-soft-text: rgba(255, 255, 255, 0.6);
    /* Hover menus / overlays */
    --wa-menu-bg: rgba(11, 20, 26, 0.92);
    --wa-menu-hover: rgba(255, 255, 255, 0.1);
    --wa-menu-text: #f9fafb;
    /* Attachment + image frames */
    --wa-att-bg: rgba(0, 0, 0, 0.22);
    --wa-att-bg-hover: rgba(0, 0, 0, 0.34);
    --wa-att-border: rgba(255, 255, 255, 0.14);
    --wa-att-name: #53bdeb;
    --wa-att-size: rgba(255, 255, 255, 0.45);
    --wa-image-frame-bg: rgba(0, 0, 0, 0.35);
    --wa-caption-text: rgba(255, 255, 255, 0.75);
    --wa-caption-text-in: rgba(255, 255, 255, 0.65);
    --wa-deleted-text: rgba(255, 255, 255, 0.5);
    /* Avatars */
    --wa-avatar-group: #1f2c34;
    --wa-avatar-text: #ffffff;
    --wa-avatar-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    /* Conversation list */
    --wa-conv-active-bg: rgba(0, 92, 75, 0.25);
    --wa-conv-active-time: #00a884;
    /* Composer */
    --wa-composer-bg: #1f2c34;
    --wa-composer-focus: rgba(0, 168, 132, 0.5);
    --wa-send-bg: #00a884;
    --wa-send-bg-hover: #02c39a;
    /* Bubbles / pills shadow */
    --wa-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
@keyframes waFlash {
    0%, 100% { box-shadow: none; }
    25% { box-shadow: 0 0 0 3px var(--accent-blue), 0 0 25px rgba(56, 189, 248, 0.5); }
}
@keyframes waTypingBlink {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
}
@scope (#view-library) {


html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Full-screen views use inline width plus padding in the markup. Keep the
   padding inside the viewport width so cards never acquire a horizontal
   off-screen coordinate on phone/tablet layouts. */
#landing-page,
#view-portal {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100vw;
}

#landing-page > div,
#view-portal > div {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 900px) {
    #landing-page .project-grid,
    #landing-page .projects-grid,
    #landing-page [style*="grid-template-columns"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    #landing-page > div[style*="grid-template-columns"],
    #view-portal > div[style*="grid-template-columns"] {
        width: 100% !important;
        max-width: 100% !important;
        grid-template-columns: minmax(0, 1fr) !important;
    }
    #landing-page .project-card,
    #view-portal .project-card {
        width: min(100%, 360px) !important;
        min-width: 0 !important;
        margin-inline: auto;
        transform: none !important;
    }
    .app-tab-btn {
        padding-inline: 8px;
        white-space: nowrap;
    }
}

body.light-theme {
    --bg-dark: #f8fafc;
    --sidebar-bg: #ffffff;
    --panel-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent-blue: #0284c7;
    --accent-gradient: linear-gradient(135deg, #0284c7 0%, #4f46e5 100%);
    --user-bubble: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
    --bot-bubble: #f1f5f9;
    --editor-bg: #ffffff;
    --editor-text: #0f172a;
    --card-bg: rgba(255, 255, 255, 0.85);
    --popover-bg: #ffffff;
    --popover-btn-bg: #f1f5f9;
    --popover-btn-text: #0f172a;
    --hover-bg: #e2e8f0;
    --input-bg: #f1f5f9;
    --reference-header-bg: var(--sidebar-bg);
    --overlay-soft: #ffffff;
    --overlay-mid: #f1f5f9;
    --overlay-strong: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
html, body { height: 100%; width: 100%; overflow: hidden; background: var(--bg-dark); color: var(--text-main); }

.hidden { display: none !important; }

.btn-primary { background: var(--accent-gradient); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: transform 0.15s ease, opacity 0.2s; }
.btn-primary:hover { opacity: 0.92; transform: translateY(-1px); }
.btn-secondary { background: var(--hover-bg); color: var(--text-main); border: 1px solid var(--border-color); padding: 6px 12px; border-radius: 6px; cursor: pointer; transition: background 0.2s; }
.btn-secondary:hover { background: rgba(56, 189, 248, 0.15); }
.btn-danger { background: #ef4444; color: #fff; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; }

/* Terminal toolbar buttons (Vibe Coding sandbox terminal).
 * The terminal panel is intentionally dark in BOTH themes (#0a0f1e), so these
 * buttons must not inherit the theme's --text-main / --hover-bg (in light
 * theme the text would turn near-black and vanish against the dark panel).
 * Colors are fixed so they stay readable in either theme. */
.vibe-term-btn {
    background: rgba(255, 255, 255, 0.09);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 2px 10px;
    font-size: 0.72rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.vibe-term-btn:hover {
    background: rgba(56, 189, 248, 0.22);
    border-color: rgba(56, 189, 248, 0.55);
    color: #ffffff;
}
.vibe-term-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Shell / Run Output tabs inside the sandboxed terminal pane. */
.vibe-term-tab {
    background: transparent;
    color: #94a3b8;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 3px 14px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.vibe-term-tab:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}
.vibe-term-tab.active {
    color: #38bdf8;
    border-bottom-color: #38bdf8;
    background: rgba(56, 189, 248, 0.08);
}

.app-container { display: flex; flex-direction: column; width: 100vw; height: 100vh; overflow: hidden; }
.app-topbar { height: 62px; background: var(--sidebar-bg); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; flex-shrink: 0; }

.app-tab-btn { background: transparent; color: var(--text-muted); border: none; padding: 8px 16px; font-weight: 600; cursor: pointer; border-radius: 8px; transition: all 0.2s; position: relative; }
.app-tab-btn.active { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); }

/* Header actions use the same quiet, transparent treatment as workstation
   tabs. Keep their controls visually consistent in both themes. */
.app-topbar-action {
    position: relative;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    padding: 8px 12px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.app-topbar-action:hover,
.app-topbar-action:focus-visible {
    background: var(--hover-bg);
    color: var(--text-main);
    border-color: var(--border-color);
    outline: none;
}
.app-user-menu {
    position: relative;
}
.app-user-menu-trigger {
    color: var(--accent-blue);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-user-menu-dropdown {
    position: absolute;
    z-index: 1200;
    top: calc(100% + 7px);
    right: 0;
    min-width: 150px;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: var(--panel-bg);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
}
.app-user-menu-dropdown button {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-main);
    text-align: left;
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
}
.app-user-menu-dropdown button:hover,
.app-user-menu-dropdown button:focus-visible {
    background: var(--hover-bg);
    color: var(--accent-blue);
    outline: none;
}
.tab-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 0.68rem; font-weight: 700; line-height: 1; vertical-align: middle; }
.chat-unread-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px; padding: 0 5px; margin-left: 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 0.64rem; font-weight: 700; line-height: 1; vertical-align: middle; }
.research-message-ticks { color: var(--text-muted); font-size: 0.72rem; font-weight: 700; letter-spacing: -2px; }
.research-message-ticks.seen { color: #38bdf8; }

.workstation { display: flex; flex: 1; overflow: hidden; }
/* Immersive full-height workspace mode: the global top bar is hidden outside
   the Home Portal, so the active workspace fills the full window height. */
body.immersive-workspace .app-container { height: 100vh; }
body.immersive-workspace .workstation { height: 100vh; height: 100dvh; flex: 1 1 auto; }
body.immersive-workspace .latex-container { height: 100vh; height: 100dvh; flex: 1 1 auto; }
body.immersive-workspace .system-workstation { height: 100vh; height: 100dvh; }

/* Contextual "Return to Home" hover-morph affordance. Markup pattern:
   <button class="home-nav-badge" onclick="switchAppTab('portal')"
     title="Return to Home Portal"><span class="badge-icon">📚</span><span
     class="badge-home" aria-hidden="true">🏠</span><span>Label</span></button>
   Hover swaps .badge-icon -> .badge-home via pure CSS. */
.home-nav-badge { background: transparent; border: 0; padding: 4px 8px; font: inherit; font-weight: 700; font-size: 1rem; color: var(--accent-blue); display: inline-flex; align-items: center; gap: 8px; cursor: pointer; border-radius: 8px; transition: background 0.2s, color 0.2s; white-space: nowrap; }
.home-nav-badge:hover, .home-nav-badge:focus-visible { background: var(--hover-bg); color: var(--text-main); outline: none; }
.home-nav-badge:focus-visible { box-shadow: 0 0 0 2px var(--accent-blue); }
.home-nav-badge .badge-home { display: none; }
.home-nav-badge:hover .badge-icon, .home-nav-badge:focus-visible .badge-icon { display: none; }
.home-nav-badge:hover .badge-home, .home-nav-badge:focus-visible .badge-home { display: inline; }
.system-workstation { display: flex; flex-direction: row; background: var(--bg-dark); flex: 1; min-height: 0; overflow: hidden; width: 100%; }
#system-left-pane { flex: 1 1 50%; min-width: 200px; display: flex; flex-direction: column; overflow: hidden; }
#system-right-pane { flex: 1 1 50%; min-width: 200px; display: flex; flex-direction: column; overflow: hidden; }
#system-resize-handle { flex: 0 0 6px; cursor: col-resize; background: var(--border-color); transition: background 0.15s; user-select: none; -webkit-user-select: none; }
#system-resize-handle:hover { background: var(--accent-blue); }
#system-resize-handle:active { background: var(--accent-blue); }
@media (max-width: 900px) {
    .system-workstation { flex-direction: column; }
    #system-left-pane { flex: 0 0 auto; min-width: 0; max-height: 50%; }
    #system-right-pane { flex: 1; min-height: 200px; }
    #system-resize-handle { flex: 0 0 6px; cursor: row-resize; width: 100%; height: 6px; }
}


.icloud-backdrop {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.25), transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(192, 132, 252, 0.25), transparent 40%),
                var(--bg-dark);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
}

.icloud-card {
    background: rgba(31, 41, 55, 0.65);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 24px;
    padding: 36px 32px;
    width: 100%; max-width: 420px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.4);
    display: flex; flex-direction: column; align-items: center; text-align: center;
}

.icloud-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: var(--accent-gradient);
    display: flex; justify-content: center; align-items: center;
    font-size: 2rem; margin-bottom: 16px;
    box-shadow: 0 8px 24px rgba(56, 189, 248, 0.3);
}

.auth-toggle-bar {
    display: flex; width: 100%; background: rgba(0,0,0,0.25);
    border-radius: 12px; padding: 4px; margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.auth-toggle-btn {
    flex: 1; padding: 8px; font-size: 0.82rem; font-weight: 600;
    border: none; background: transparent; color: var(--text-muted);
    border-radius: 8px; cursor: pointer; transition: all 0.2s;
}

.auth-toggle-btn.active {
    background: var(--accent-gradient); color: #ffffff; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Three tabs (Blank / ZIP / 📁 Folder) must stay on one line. */
#new-project-modal .auth-toggle-btn {
    white-space: nowrap;
}

.icloud-input {
    width: 100%; padding: 12px 14px; margin-top: 10px;
    background: rgba(15, 23, 42, 0.6); border: 1px solid var(--border-color);
    border-radius: 12px; color: var(--text-main); outline: none; font-size: 0.95rem;
    transition: border-color 0.2s;
}
.icloud-input:focus { border-color: var(--accent-blue); }

.auth-secondary-links {
    margin-top: 18px; 
    display: flex; 
    flex-direction: row; 
    justify-content: space-between; 
    align-items: center; 
    width: 100%;
}

.link-btn {
    background: transparent; border: none; color: var(--accent-blue);
    font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: opacity 0.2s;
}
.link-btn:hover { opacity: 0.8; text-decoration: underline; }

.sidebar-left { width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-right { width: 300px; background: var(--sidebar-bg); border-left: 1px solid var(--border-color); padding: 20px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; flex-shrink: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--bg-dark); position: relative; min-width: 0; }
.chat-messages { flex: 1; padding: 24px 10%; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth; min-width: 0; width: 100%;}

.chat-list { flex: 1; overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.chat-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 0.9rem; transition: background 0.2s, color 0.2s; }
.chat-item:hover { background: var(--hover-bg); color: var(--text-main); }
.chat-item.active { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); font-weight: 500; }
.chat-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item-delete { opacity: 0; background: none; border: none; color: #f87171; cursor: pointer; padding: 4px; border-radius: 4px; transition: opacity 0.2s; }
.chat-item:hover .chat-item-delete { opacity: 1; }

.message { max-width: 80%; padding: 16px 20px; border-radius: 18px; font-size: 0.98rem; line-height: 1.65; word-wrap: break-word; overflow-wrap: break-word; animation: fadeIn 0.3s ease-out; }

.message.user {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    align-self: stretch; /* Stretches to full width across the chat */
    background: var(--user-bubble);
    color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(2, 132, 199, 0.25);
    white-space: pre-wrap;
    word-break: break-word;
}
/* Skill badge inside a user bubble. The bubble is a blue gradient in BOTH
 * themes, so this must NOT use theme vars (--text-main / --accent-blue):
 * in light mode those resolve to dark ink that vanishes on the blue
 * background. Fixed white-on-translucent keeps it readable either way. */
.message.user .ai-skill-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.55);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}
.message.user .ai-skill-text {
    width: 100%;
    white-space: pre-wrap;
    color: #ffffff;
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
}
.slash-command-wrap {
    position: relative;
    width: 100% !important;
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
}

#user-input {
    width: 100% !important;
    min-width: 100% !important;
    box-sizing: border-box !important;
}

.message.bot { align-self: flex-start; background: var(--bot-bubble); color: var(--text-main); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; width: 100%; max-width: 88%; min-width: 0; }
.message.bot p { margin-bottom: 12px; }
.message.bot p:last-child { margin-bottom: 0; }
.message.bot h1, .message.bot h2, .message.bot h3 { color: var(--accent-blue); margin: 16px 0 8px 0; }
.message.bot ul, .message.bot ol { margin-left: 20px; margin-bottom: 12px; }
.message.bot code { background: rgba(15, 23, 42, 0.8); color: var(--accent-blue); padding: 3px 7px; border-radius: 6px; font-family: "SF Mono", Monaco, monospace; font-size: 0.88rem; }
.message.bot pre { background: #090d16; padding: 16px; border-radius: 12px; overflow-x: auto; margin: 14px 0; border: 1px solid var(--border-color); max-width: 100%; }

.activity-log { align-self: flex-start; font-size: 0.82rem; color: #fbbf24; background: rgba(30, 27, 75, 0.6); padding: 8px 16px; border-radius: 20px; border: 1px solid rgba(99, 102, 241, 0.4); display: flex; align-items: center; gap: 8px; }

.chat-header-bar { 
    padding: 16px 24px; 
    background: var(--panel-bg); 
    backdrop-filter: blur(12px); 
    border-bottom: 1px solid var(--border-color); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-wrap: nowrap;
    height: 56px;
    box-sizing: border-box;
    gap: 16px;
}

.chat-header-bar > div:first-child {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

#chat-title-display { 
    font-size: 1.1rem !important; 
    font-weight: 600 !important; 
    background: var(--accent-gradient) !important; 
    -webkit-background-clip: text !important; 
    -webkit-text-fill-color: transparent !important; 
    
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    
    display: inline-block !important;
    max-width: 400px !important; 
    height: 24px !important;      
    line-height: 24px !important; 
    margin: 0 !important;
    flex-shrink: 1 !important;
}

#chat-stop-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #ef4444;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}
#chat-stop-btn:hover {
    background: #dc2626;
}

/* Expandable Thinking Block Styles */
details.thought-container {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

details.thought-container summary {
    cursor: pointer;
    font-weight: 600;
    user-select: none;
    color: var(--accent-blue);
    outline: none;
}

details.thought-container[open] {
    border-color: rgba(56, 189, 248, 0.4);
    background: rgba(56, 189, 248, 0.02);
}

.thought-content {
    margin-top: 10px;
    border-top: 1px dashed var(--border-color);
    padding-top: 8px;
    font-style: italic;
    line-height: 1.5;
    color: var(--text-muted);
}

.chat-input-wrapper { padding: 16px 10% 24px 10%; background: linear-gradient(to top, var(--bg-dark) 80%, transparent); flex-shrink: 0; transition: background 0.2s; }
.chat-input-wrapper.drag-over { background: rgba(56, 189, 248, 0.15); }
.research-dropzone { transition: border-color 0.15s, background 0.15s; }
.research-dropzone.drag-over { border-color: var(--accent-blue) !important; background: rgba(56, 189, 248, 0.08); }
.input-container { position: relative; background: var(--panel-bg); backdrop-filter: blur(16px); border: 1px solid var(--border-color); border-radius: 20px; padding: 20px 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08); transition: border-color 0.3s; }
.input-container:focus-within { border-color: rgba(56, 189, 248, 0.6); }

.attachment-badge-list { display: flex; gap: 6px; flex-wrap: wrap; }
.attachment-chip { background: rgba(56, 189, 248, 0.2); color: var(--accent-blue); font-size: 0.78rem; padding: 3px 10px; border-radius: 12px; display: flex; align-items: center; gap: 6px; }

textarea#user-input { flex: 1; background: transparent; border: none; color: var(--text-main); font-size: 0.98rem; outline: none; resize: none; max-height: 200px; min-height: 28px; line-height: 1.5; padding: 2px 0; }
textarea#user-input::placeholder { color: var(--text-muted); }

.setting-group { display: flex; flex-direction: column; gap: 8px; }
.setting-group label { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.setting-group textarea, .setting-group input[type="text"], .setting-group input[type="number"] { background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; color: var(--text-main); font-size: 0.9rem; outline: none; }
.slider-wrapper { display: flex; align-items: center; gap: 12px; }
.slider-wrapper input[type="range"] { flex: 1; accent-color: var(--accent-blue); }
.slider-val { font-size: 0.85rem; color: var(--accent-blue); font-weight: 600; width: 30px; }

.toggle-container { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-muted); background: var(--bg-dark); padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border-color); }
.switch { position: relative; display: inline-block; width: 32px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #4b5563; transition: .3s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 3px; bottom: 3px; background-color: white; transition: .3s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 50%; }
input:checked + .slider { background: linear-gradient(135deg, #38bdf8, #818cf8); }
input:checked + .slider:before { transform: translateX(14px); }

.latex-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.latex-dashboard { flex: 1; padding: 30px; overflow-y: auto; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-top: 16px; }
.project-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 18px; cursor: pointer; transition: border-color 0.2s; max-width: 100%; box-sizing: border-box; }
.project-card:hover { border-color: var(--accent-blue); }

.latex-workspace { flex: 1; display: flex; flex-direction: row; height: 100%; overflow: hidden; background: var(--bg-dark); position: relative; }
.resizer { width: 6px; background: var(--border-color); cursor: col-resize; transition: background 0.2s; z-index: 10; }
.resizer:hover { background: var(--accent-blue); }
.latex-workspace-tree { width: 260px; min-width: 200px; max-width: 400px; flex-shrink: 0; background: var(--sidebar-bg); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; padding: 6px 10px 10px 10px; gap: 0; overflow: hidden; min-height: 0; }
.latex-workspace-tree.drag-over { background: rgba(56, 189, 248, 0.15); border: 2px dashed var(--accent-blue); }
.latex-sidebar-files { flex: 1 1 50%; display: flex; flex-direction: column; gap: 8px; min-height: 100px; overflow: hidden; }
/* FILES sidebar pieces, extracted from inline styles for easier theming.
   The header treatment (padding + border-bottom) matches the DOCUMENT OUTLINE
   and COMMENTS section headers, and the drop hint is left-aligned. */
.latex-sidebar-header { display: flex; justify-content: space-between; align-items: center; gap: 4px; padding: 6px 2px 4px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.latex-sidebar-title { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }
.latex-sidebar-actions { display: flex; align-items: center; gap: 4px; }
.latex-sidebar-drop-hint { font-size: 0.68rem; color: var(--text-muted); text-align: left; }
.latex-upload-progress { margin-top: 8px; background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); border-radius: 8px; padding: 6px 8px; }
.latex-upload-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.latex-upload-label { font-size: 0.7rem; color: var(--text-muted); flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latex-upload-pct { font-size: 0.7rem; font-weight: 700; color: var(--accent-blue); flex-shrink: 0; }
.latex-upload-track { height: 6px; background: rgba(255,255,255,0.1); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.latex-upload-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-blue), #10b981); border-radius: 4px; transition: width 0.15s; }
.latex-file-tree { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
/* Outline sidebar: never compresses away when panes are squeezed. Long
   section titles ellipsize in place (never wrap, never scroll the pane), so
   the sidebar width alone decides how much of a title is shown. */
.latex-sidebar-outline { flex: 1 1 50%; flex-shrink: 0; min-width: 200px; display: flex; flex-direction: column; overflow: hidden; background: var(--sidebar-bg); border-top: 1px solid var(--border-color); min-height: 80px; max-height: 60%; }
#latex-file-tree, #latex-document-outline { flex: 1; min-height: 0; overflow-y: auto; overflow-x: auto; }
.latex-sidebar-outline.collapsed { flex: 0 0 32px !important; min-height: 32px; max-height: 32px; overflow: hidden; }
.latex-sidebar-outline.collapsed #latex-document-outline, .latex-sidebar-outline.collapsed #latex-outline-placeholder { display: none !important; }
.latex-sidebar-splitter { height: 6px; min-height: 6px; background: var(--border-color); cursor: row-resize; transition: background 0.2s; flex-shrink: 0; border-radius: 2px; }
.latex-sidebar-splitter:hover, .latex-sidebar-splitter.dragging { background: var(--accent-blue); }
#latex-document-outline { scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; overflow-x: hidden; }
#latex-document-outline::-webkit-scrollbar { width: 6px; }
#latex-document-outline::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
/* Long section names stay on ONE line and ellipsize instead of wrapping or
   forcing the sidebar to scroll horizontally. The ellipsis lives on the inner
   `.outline-title`, never on the row, so the row keeps a real line box.
   Note: `overflow: hidden` on a flex child zeroes its automatic minimum size,
   so the row also pins `flex: 0 0 auto` + an explicit `min-height` — otherwise
   a short, column-flex pane shrinks rows into each other (visible overlap). */
.latex-outline-item { display: flex; align-items: center; width: 100%; box-sizing: border-box; flex: 0 0 auto; min-height: 28px; gap: 6px; padding: 4px 8px; font-size: 0.78rem; color: var(--text-muted); cursor: pointer; border-left: 2px solid transparent; white-space: nowrap; min-width: 0; overflow: hidden; position: relative; border-radius: 0 4px 4px 0; transition: background 0.15s, color 0.15s, border-color 0.15s; line-height: 1.4; }
.latex-outline-item:hover { background: rgba(56, 189, 248, 0.08); color: var(--text-main); }
.latex-outline-item.active { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); border-left-color: var(--accent-blue); font-weight: 600; }
.latex-outline-item .outline-icon { font-size: 0.72rem; flex-shrink: 0; opacity: 0.85; }
.latex-outline-item .outline-title, .latex-outline-item .latex-outline-item-title, .latex-outline-item-title { display: block; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latex-outline-item.level-part { font-weight: 700; color: var(--text-main); }
.latex-outline-item.level-chapter { font-weight: 700; }
.latex-outline-item.level-section { font-weight: 600; }
.latex-outline-item.level-subsection { opacity: 0.92; }
.latex-outline-item.level-subsubsection { opacity: 0.85; font-size: 0.75rem; }
.latex-outline-item.level-paragraph { opacity: 0.78; font-size: 0.74rem; font-style: italic; }
/* Subfile provenance: a subtle right-aligned chip names the chapter a section
   lives in, so a project-wide outline stays readable at a glance. */
.latex-outline-item .outline-file-chip { flex: 0 0 auto; margin-left: auto; padding: 0 5px; border-radius: 999px; background: rgba(148, 163, 184, 0.16); color: var(--text-muted); font-size: 0.62rem; font-weight: 600; letter-spacing: 0.02em; opacity: 0.9; }
/* Rows that live in the file currently open in the editor. */
.latex-outline-item.in-active-file { color: var(--text-main); }
.latex-editor-panel { flex: 1 1 0%; min-width: 300px; display: flex; flex-direction: column; position: relative; background: var(--editor-bg); }
.latex-preview-panel { flex: 1 1 0%; min-width: 300px; display: flex; flex-direction: column; background: #1e293b; position: relative; overflow: hidden; }

.editor-toolbar { height: 42px; background: var(--sidebar-bg); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }

/* Fallback if the CodeMirror CDN is unavailable. In the normal path
   CodeMirror hides this textarea and replaces it with its own editor. */
#latex-code-editor {
    flex: 1;
    width: 100%;
    min-width: 0;
    border: 0;
    padding: 10px;
    background: var(--editor-bg);
    color: var(--editor-text);
    font: 0.95rem/1.5 "JetBrains Mono", Menlo, Monaco, "Courier New", monospace;
    font-variant-ligatures: none;
    resize: none;
    outline: none;
    tab-size: 4;
}

/* LaTeX uses the same CodeMirror editor as Vibe Coding. CodeMirror owns the
   line-number gutter and viewport, so no hidden full-document mirror is needed. */
#panel-editor .CodeMirror {
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--editor-bg);
    color: var(--editor-text);
    font-family: "JetBrains Mono", Menlo, Monaco, "Courier New", monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    font-variant-ligatures: none;
}
/* Darcula styles stex control sequences (``\command``, ``\\``, ``\%`` — the
   backslash included) as ``cm-tag`` with ``font-style: italic``. Only upright
   JetBrains Mono faces are shipped, so the browser *synthesizes* the oblique
   and shears the left-leaning backslash nearly vertical (``\verb`` reads as
   ``|verb``). Darcula also underlines ``cm-tag``, which visually merges with
   subscripts (``\beta_i`` reads as ``\beta`` underlined into the ``_``).
   Neutralize the slant AND the underline on tags — color/bold stay, since
   underlines are reserved for spellcheck/error markers — so every backslash
   keeps its true diagonal. Scoped to #panel-editor so the Vibe editor and
   comment italics elsewhere are untouched. */
#panel-editor .CodeMirror span.cm-tag {
    font-style: normal;
    text-decoration: none;
}
#panel-editor .CodeMirror-gutters {
    background: rgba(0, 0, 0, 0.15);
    border-right: 1px solid var(--border-color);
}
#panel-editor .CodeMirror-linenumber {
    color: var(--text-muted);
}
#panel-editor .CodeMirror-cursor {
    border-left: 1px solid var(--accent-blue);
}
#panel-editor .CodeMirror-selected {
    background: rgba(56, 189, 248, 0.25) !important;
}
#panel-editor .CodeMirror-activeline-background {
    background: rgba(128, 128, 128, 0.08);
}
#panel-editor .CodeMirror-linebackground.cm-latex-error-line {
    background: rgba(239, 68, 68, 0.18) !important;
}
.cm-latex-warning-marker {
    color: #fbbf24;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0 3px;
    cursor: pointer;
}
#panel-editor .CodeMirror-matchingbracket {
    color: #4ade80 !important;
    text-decoration: underline;
}

/* VS Code-style active-file Find & Replace widget. */
.latex-find-replace {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 5px;
    padding: 7px 9px;
    background: var(--panel-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-top: 0;
    border-radius: 0 0 8px 8px;
}
.latex-find-row,
.latex-replace-row {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}
.latex-find-input {
    flex: 1 1 auto;
    width: 0;
    min-width: 70px;
    height: 30px;
    box-sizing: border-box;
    padding: 4px 8px;
    color: var(--text-main);
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.78rem;
    outline: none;
}
.latex-find-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-blue) 28%, transparent);
}
.latex-find-count {
    flex: 0 0 auto;
    min-width: 66px;
    padding: 4px 7px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-muted);
    background: color-mix(in srgb, var(--text-main) 5%, transparent);
    font-size: 0.68rem;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
}
.latex-find-count.has-results { color: var(--text-main); }
.latex-find-count.has-error { color: #ef4444; border-color: color-mix(in srgb, #ef4444 55%, var(--border-color)); }
.latex-find-icon-btn,
.latex-find-toggle,
.latex-find-action {
    flex: 0 0 auto;
    height: 30px;
    padding: 3px 8px;
    color: var(--text-main);
    background: color-mix(in srgb, var(--text-main) 5%, transparent);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font: inherit;
    font-size: 0.73rem;
    cursor: pointer;
    white-space: nowrap;
}
.latex-find-icon-btn { min-width: 30px; font-size: 0.85rem; }
.latex-find-toggle { min-width: 32px; color: var(--text-muted); }
.latex-find-icon-btn:hover,
.latex-find-action:hover,
.latex-find-toggle:hover { border-color: var(--accent-blue); color: var(--text-main); }
.latex-find-toggle[aria-pressed="true"] {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: color-mix(in srgb, var(--accent-blue) 15%, transparent);
}
.latex-find-action-primary { border-color: color-mix(in srgb, var(--accent-blue) 55%, var(--border-color)); }
.latex-find-match {
    background: rgba(250, 204, 21, 0.22);
    border-bottom: 1px solid rgba(250, 204, 21, 0.6);
}
.latex-find-match-active {
    background: rgba(56, 189, 248, 0.34);
    box-shadow: inset 0 -2px 0 var(--accent-blue);
}
body.light-theme .latex-find-match {
    background: rgba(234, 179, 8, 0.25);
    border-bottom-color: rgba(161, 98, 7, 0.7);
}
body.light-theme .latex-find-match-active {
    background: rgba(14, 165, 233, 0.25);
    box-shadow: inset 0 -2px 0 #0284c7;
}
@media (max-width: 640px) {
    .latex-find-replace { padding: 6px; gap: 4px; }
    .latex-find-row, .latex-replace-row { gap: 3px; }
    .latex-find-count { min-width: 52px; padding-inline: 4px; font-size: 0.62rem; }
    .latex-find-icon-btn, .latex-find-toggle, .latex-find-action { padding-inline: 5px; }
    .latex-find-toggle { min-width: 28px; }
    .latex-find-input { min-width: 0; }
}

.selection-popover {
    position: absolute;
    z-index: 600;
    background: var(--popover-bg);
    border: 1px solid var(--accent-blue);
    border-radius: 12px;
    padding: 6px 8px;
    display: flex;
    gap: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(12px);
}
.selection-popover button {
    background: var(--popover-btn-bg);
    color: var(--popover-btn-text);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.selection-popover button:hover {
    background: var(--accent-blue);
    color: #ffffff;
    border-color: var(--accent-blue);
}

/* ---- Inline review comments ---- */
.latex-comment-highlight {
    background: rgba(250, 204, 21, 0.22) !important;
    border-bottom: 1px dashed rgba(250, 204, 21, 0.75);
    cursor: pointer;
}
.latex-comment-highlight.resolved {
    background: rgba(148, 163, 184, 0.18) !important;
    border-bottom-color: rgba(148, 163, 184, 0.6);
}
.CodeMirror-gutter.latex-comments-gutter,
.latex-comments-gutter {
    width: 14px;
    cursor: pointer;
    pointer-events: auto;
}
.latex-comment-gutter-mark {
    display: inline-block;
    color: #facc15;
    font-size: 11px;
    line-height: 1;
    pointer-events: auto;
    cursor: pointer;
    opacity: 0.9;
}
.latex-comment-gutter-mark.resolved { color: #94a3b8; opacity: 0.6; }
.latex-comment-gutter-mark:hover { opacity: 1; }

.latex-comments-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    margin-left: 4px;
    border-radius: 999px;
    background: #facc15;
    color: #1f2937;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
}
#latex-comments-toggle-btn.active {
    background: rgba(56, 189, 248, 0.18);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.latex-sidebar-comments {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    background: var(--sidebar-bg);
}
.latex-comment-file-group { display: flex; flex-direction: column; gap: 4px; }
.latex-comment-file-group-head {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px 6px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.latex-comment-list-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 7px 9px;
    border: 1px solid var(--border-color);
    border-left: 3px solid #facc15;
    border-radius: 6px;
    background: var(--panel-bg);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.latex-comment-list-item:hover { background: rgba(56, 189, 248, 0.08); border-color: var(--accent-blue); }
.latex-comment-list-item.resolved { border-left-color: #94a3b8; opacity: 0.75; }
.latex-comment-list-item.other-file { opacity: 0.68; }
.latex-comment-list-meta { display: flex; align-items: center; gap: 6px; }
.latex-comment-list-body { font-size: 0.78rem; color: var(--text-main); line-height: 1.35; word-break: break-word; }
.latex-comment-list-time { font-size: 0.66rem; color: var(--text-muted); }
.latex-comment-line-tag {
    font-size: 0.64rem;
    color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.14);
    border-radius: 4px;
    padding: 1px 4px;
}

/* Thread / compose popover (fixed-positioned from the anchor's char coords) */
#latex-comment-thread-popover {
    position: fixed;
    z-index: 650;
    width: 340px;
    max-width: calc(100vw - 24px);
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    background: var(--popover-bg);
    border: 1px solid var(--accent-blue);
    border-radius: 12px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    backdrop-filter: blur(12px);
}
#latex-comment-thread-popover.hidden { display: none !important; }
.latex-comment-thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-blue);
}
.latex-comment-thread-body {
    flex: 1;
    min-height: 40px;
    max-height: 42vh;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.latex-comment-compose-hint { font-size: 0.76rem; color: var(--text-muted); line-height: 1.4; word-break: break-word; }
.latex-comment-card {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 7px 9px;
    background: var(--input-bg);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.latex-comment-card.root { border-left: 3px solid #facc15; }
.latex-comment-card-head { display: flex; align-items: center; gap: 6px; }
.latex-comment-author { font-size: 0.74rem; font-weight: 700; color: var(--text-main); }
.latex-comment-time { font-size: 0.64rem; color: var(--text-muted); }
.latex-comment-resolved-tag {
    font-size: 0.62rem;
    color: #4ade80;
    background: rgba(74, 222, 128, 0.14);
    border-radius: 4px;
    padding: 1px 4px;
}
.latex-comment-head-spacer { flex: 1; }
.latex-comment-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
}
.latex-comment-menu-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.latex-comment-body { font-size: 0.78rem; color: var(--text-main); line-height: 1.4; word-break: break-word; }
.latex-comment-menu {
    position: absolute;
    top: 26px;
    right: 8px;
    z-index: 5;
    min-width: 120px;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.latex-comment-menu.hidden { display: none !important; }
.latex-comment-menu button {
    background: transparent;
    border: none;
    text-align: left;
    padding: 7px 10px;
    font-size: 0.75rem;
    color: var(--text-main);
    cursor: pointer;
}
.latex-comment-menu button:hover { background: var(--hover-bg); }
.latex-comment-menu button.danger { color: #f87171; }
.latex-comment-edit-input {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    background: var(--bg-dark, #0b0f19);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.78rem;
}
.latex-comment-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.latex-comment-thread-reply {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--border-color);
}
.latex-comment-thread-reply textarea {
    flex: 1;
    resize: none;
    background: var(--bg-dark, #0b0f19);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.78rem;
    line-height: 1.4;
}

.tree-item-menu {
    position: relative;
    display: inline-block;
}

.tree-item-dots {
    padding: 2px 6px;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
}
.tree-item-dots:hover {
    background: var(--hover-bg);
    color: var(--text-main);
}

.tree-dropdown-content {
    position: absolute;
    right: 0;
    top: 24px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    z-index: 100;
    display: flex;
    flex-direction: column;
    min-width: 120px;
    padding: 4px 0;
}

.tree-dropdown-item {
    padding: 6px 12px;
    font-size: 0.8rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}
.tree-dropdown-item:hover {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blue);
}

.latex-insert-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 230px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.55);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1500;
}
.latex-insert-menu-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px 10px;
    letter-spacing: 0.04em;
}
.latex-insert-menu button {
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-main);
    font-size: 0.82rem;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.latex-insert-menu button:hover {
    background: rgba(56, 189, 248, 0.14);
    color: var(--accent-blue);
}
.latex-insert-menu code {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
}

.latex-insert-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    background: rgba(0,0,0,0.15);
    transition: border-color 0.12s, background 0.12s;
}
.latex-insert-item:hover {
    border-color: var(--accent-blue);
}
.latex-insert-item.keyboard-hover {
    border-color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.10);
    box-shadow: inset 0 0 0 1px var(--accent-blue);
}
.latex-insert-item.selected {
    border-color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.12);
}
.latex-insert-item .insert-key {
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-blue);
    white-space: nowrap;
}
.latex-insert-item .insert-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.4;
    word-break: break-word;
}
.latex-insert-type-chip {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
}
.latex-insert-type-chip.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

.latex-inline-suggest {
    position: absolute;
    z-index: 1600;
    min-width: 280px;
    max-width: 460px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.55);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.latex-inline-list {
    max-height: 264px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.latex-inline-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    border-radius: 7px;
    cursor: pointer;
    background: transparent;
}
.latex-inline-item:hover,
.latex-inline-item.active {
    background: rgba(56, 189, 248, 0.14);
}
.latex-inline-item .inline-primary {
    font-family: 'Fira Code', monospace;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-blue);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.latex-inline-item .inline-secondary {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55%;
}
.latex-inline-hint {
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 3px 10px 4px;
    letter-spacing: 0.02em;
    border-top: 1px solid var(--border-color);
}

#latex-dashboard-view.drag-over,
#panel-tree.drag-over {
    outline: 2px dashed var(--accent-blue) !important;
    outline-offset: -4px;
    background: rgba(56, 189, 248, 0.06) !important;
}
#latex-dashboard-dropzone.drag-over {
    border-color: var(--accent-blue) !important;
    color: var(--accent-blue) !important;
    background: rgba(56, 189, 248, 0.08) !important;
}

.history-drawer {
    position: absolute;
    top: 0;
    right: 0;
    width: 380px;
    height: 100%;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    z-index: 550;
}

.history-item {
    padding: 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.82rem;
}

.inline-ai-dialog {
    position: absolute;
    top: 50px;
    right: 20px;
    width: 380px;
    background: var(--panel-bg);
    border: 1px solid var(--accent-blue);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    padding: 16px;
    z-index: 700;
    display: flex;
    flex-direction: column;
    gap: 12px;
    backdrop-filter: blur(16px);
}

.inline-ai-header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--accent-blue); font-size: 0.9rem; }
.inline-ai-body { max-height: 200px; overflow-y: auto; background: var(--bg-dark); border: 1px solid var(--border-color); padding: 12px; border-radius: 10px; font-size: 0.88rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; color: var(--text-main); }
.inline-ai-actions { display: flex; justify-content: flex-end; gap: 8px; }

.tree-file-item { padding: 6px 10px; border-radius: 6px; font-size: 0.85rem; color: var(--text-muted); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.tree-file-item.active { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); font-weight: 600; }
.tree-file-item:hover { color: var(--text-main); }
.tree-folder-item { user-select: none; }
.tree-folder-item:hover { background: rgba(56, 189, 248, 0.08); }
.tree-folder-label { font-weight: 600; }
.latex-tree-children { display: flex; flex-direction: column; gap: 4px; }
.latex-main-file-badge { flex-shrink: 0; font-size: 0.75rem; margin-left: 4px; }
.latex-compile-target { position: relative; z-index: 1001; display: inline-flex; align-items: center; align-self: stretch; }
.latex-compile-target-divider { height: 1px; margin: 4px 6px; background: var(--border-color); }
.latex-compile-target-menu { left: auto; right: 0; min-width: 230px; z-index: 1002; }
.latex-insert-menu .latex-compile-target-option { box-sizing: border-box; }
.latex-insert-menu .latex-compile-target-option[aria-checked="true"] { color: var(--accent-blue, #38bdf8); font-weight: 700; }

.pdf-toolbar { height: 38px; background: var(--sidebar-bg); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; padding: 0 10px; font-size: 0.8rem; flex-shrink: 0; }
.pdf-viewport { flex: 1; width: 100%; height: calc(100% - 38px); overflow-x: hidden; overflow-y: auto; position: relative; background: #525659; display: flex; flex-direction: column; align-items: center; padding: 10px 0; }
#pdf-preview-frame { width: 100%; min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pdf-js-page { position: relative; background: #ffffff; box-shadow: 0 4px 15px rgba(0,0,0,0.3); line-height: 0; }
.pdf-js-page canvas { display: block; cursor: default; }
/* PDF.js text layer: transparent glyphs remain selectable/copyable while the
   canvas below supplies the visible page. */
.pdf-text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; user-select: text; -webkit-user-select: text; }
.pdf-text-layer span, .pdf-text-layer br { position: absolute; color: transparent; white-space: pre; transform-origin: 0% 0%; cursor: text; user-select: text; -webkit-user-select: text; }
.pdf-text-layer ::selection, .pdf-text-layer span::selection { background: rgba(56, 189, 248, 0.35); color: transparent; }
/* PDF.js annotation layer: transparent link/destination boxes painted above
   the canvas so a Table of Contents, \cite or \ref is clickable. The layer
   itself ignores the pointer so text selection still works; only links opt in. */
.pdf-annotation-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; line-height: 1; }
.pdf-annotation-layer section { position: absolute; text-align: initial; pointer-events: none; }
.pdf-annotation-layer .linkAnnotation { pointer-events: auto; }
.pdf-annotation-layer .linkAnnotation > a { position: absolute; top: 0; left: 0; width: 100%; height: 100%; font-size: 1em; cursor: pointer; }
.pdf-annotation-layer .linkAnnotation > a:hover { background: rgba(56, 189, 248, 0.25); box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7); border-radius: 2px; }
.pdf-js-empty { color: #d1d5db; padding: 48px 20px; text-align: center; font-size: 0.9rem; line-height: 1.5; }
.pdf-js-page.pdf-sync-target { outline: 3px solid var(--accent-blue); outline-offset: 4px; }

.ai-chat-draggable { position: absolute; top: 80px; right: 80px; width: 380px; height: 500px; background: var(--panel-bg); border: 1px solid var(--accent-blue); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.5); display: flex; flex-direction: column; z-index: 999; overflow: hidden; backdrop-filter: blur(12px); }
.ai-drawer-header { padding: 12px 16px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.ai-drawer-messages { flex: 1; padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; font-size: 0.88rem; }

textarea#ai-drawer-input {
    width: 100%; background: var(--bg-dark); border: 1px solid var(--border-color); color: var(--text-main); padding: 8px; border-radius: 8px; font-size: 0.88rem; outline: none; resize: none; max-height: 120px; min-height: 38px; line-height: 1.4;
}

.latex-log-drawer { position: absolute; bottom: 0; left: 0; width: 100%; height: 220px; background: #0d1117; color: #f87171; font-family: monospace; font-size: 0.82rem; padding: 12px; border-top: 2px solid var(--border-color); overflow-y: auto; white-space: pre-wrap; z-index: 400; }
.latex-conversion-report { max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; padding: 9px; border: 1px solid var(--border-color); border-radius: 7px; background: rgba(0,0,0,0.2); color: var(--text-muted); font: 0.72rem/1.45 "SF Mono", Monaco, monospace; }

.mdt-sidebar { width: 420px; min-height: 0; display: flex; flex-direction: column; gap: 16px; flex-shrink: 0; }
.mdt-main-content { flex: 1; min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; }
.mdt-dashboard { display: flex; align-items: stretch; gap: 24px; padding: 24px; height: 100%; min-height: 0; overflow-y: auto; width: 100%; box-sizing: border-box; }
.mdt-st-tabs { display: flex; gap: 16px; border-bottom: 1px solid var(--border-color); margin-bottom: 16px; }
.mdt-st-tab { padding: 8px 16px; cursor: pointer; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid transparent; }
.mdt-st-tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }
.mdt-cfg-section { background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; margin-bottom: 16px; }.mdt-command-preview-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 0 0 12px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: color-mix(in srgb, var(--panel-bg) 88%, var(--accent-blue));
    font-size: 0.78rem;
    overflow-x: auto;
}

.mdt-command-preview-label {
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

#mdt-command-preview {
    color: var(--accent-blue);
    white-space: pre;
    user-select: text;
}

.mdt-task-label {
 display: flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; }
.mdt-task-cb { width: 16px; height: 16px; accent-color: var(--accent-blue); }
.terminal-window-wrapper { background: #0b0f19; border: 1px solid var(--border-color); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; flex: 1; min-height: 380px; }
#view-mdt .terminal-window-wrapper { flex: 1 1 auto; min-height: 0; max-height: none; }
.terminal-title-bar { background: #111827; padding: 8px 16px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border-color); }
.terminal-dot { width: 12px; height: 12px; border-radius: 50%; }
.terminal-dot.red { background: #ef4444; }
.terminal-dot.yellow { background: #f59e0b; }
.terminal-dot.green { background: #10b981; }
.terminal-title { font-family: monospace; font-size: 0.8rem; color: var(--text-muted); }
#mdt-terminal-container { flex: 1; min-height: 0; height: 100%; width: 100%; box-sizing: border-box; padding: 8px 12px; font-family: monospace; font-size: 0.85rem; color: #10b981; overflow: hidden; white-space: pre-wrap; background: #0b0f19; }
#view-mdt .terminal-window-wrapper .xterm { height: 100%; }
#view-mdt .terminal-window-wrapper .xterm-viewport { overflow-y: auto !important; }
.mdt-workspace-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 8px; font-size: 0.82rem; }

.mdt-input-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    width: 100%;
}
.mdt-input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.mdt-input-group:focus-within {
    border-color: var(--accent-blue);
}
.mdt-input-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted) !important;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.mdt-input-group input, 
.mdt-input-group select {
    margin: 0 !important;
    padding: 8px 12px !important;
    background: var(--bg-dark) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    color: var(--text-main) !important;
    width: 100% !important;
    font-size: 0.88rem !important;
    outline: none !important;
} 

/* WinSCP Style Admin File Grid Rows */
.admin-fs-row {
    display: grid;
    grid-template-columns: 35px minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.2fr) 128px;
    align-items: center;
    padding: 8px 12px;
    font-size: 0.85rem;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background 0.15s ease, border-left 0.1s ease;
    user-select: none;
    border-left: 3px solid transparent;
}

.admin-fs-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Active Row Selection Visual States */
.admin-fs-row.selected {
    background: rgba(56, 189, 248, 0.12) !important;
    border-left: 3px solid var(--accent-blue);
    color: #ffffff;
}

/* Row Content Alignment Details */
.fs-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 8px;
}

.fs-check {
    display: flex;
    align-items: center;
    justify-content: center;
}

.fs-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fs-size, .fs-time {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
}

/* Action buttons must never be clipped by the row's overflow at the
   pane divider; the grid track is sized to fit all four icons. */
.fs-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    overflow: visible;
    padding-right: 0;
}

/* Drag-and-Drop Active States */
.admin-fs-row.dragging {
    opacity: 0.4;
    background: rgba(56, 189, 248, 0.05);
}

/* Hovering over Directory targets */
.admin-fs-row.dir-node.drag-hover {
    background: rgba(166, 227, 161, 0.15) !important; /* Greenish pastel highlight */
    border-left-color: #a6e3a1 !important;
    transform: scale(1.005);
}

/* Parent folder row (..) spacing and visibility */
.admin-fs-row.parent-node {
    background: rgba(255, 255, 255, 0.015);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.admin-fs-row.parent-node:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* Backward Drag Over indicators */
.admin-fs-row.parent-node.drag-hover-parent {
    background: rgba(56, 189, 248, 0.15) !important;
    border-left-color: var(--accent-blue) !important;
    transform: scale(1.002);
}

/* Code editor text alignments */
#admin-file-editor::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
#admin-file-editor::-webkit-scrollbar-track {
    background: transparent;
}
#admin-file-editor::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
#admin-file-editor::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Form checkboxes styling override */
.fs-row-cb, #admin-fs-select-all {
    cursor: pointer;
    accent-color: var(--accent-blue);
    width: 14px;
    height: 14px;
}

.admin-fs-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    transition: border-color 0.15s, background 0.15s;
}
.admin-fs-item:hover {
    border-color: var(--accent-blue);
    background: var(--hover-bg);
}

.always-scroll-container {
    scrollbar-color: var(--accent-blue) rgba(0, 0, 0, 0.1);
    scrollbar-width: thin;
}

.always-scroll-container::-webkit-scrollbar {
    width: 8px;
    display: block !important;
}

.always-scroll-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.always-scroll-container::-webkit-scrollbar-thumb {
    background: var(--accent-blue);
    border-radius: 4px;
    border: 2px solid transparent;
}

.admin-window-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 82%;
    max-width: 1000px;
    height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.75);
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                height 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                bottom 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                right 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.15s ease;
}

/* MAXIMIZED WINDOW (fills viewport) */
.admin-window-card.maximized {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0px !important;
    border: none !important;
}

/* MINIMIZED WINDOW (docked compact bar) */
.admin-window-card.minimized {
    width: 320px !important;
    height: 48px !important; /* Locks and shows only header title bar */
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 10000 !important;
    border-radius: 8px !important;
    border-color: var(--accent-blue) !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6) !important;
}

/* Disable background dimming overlay when minimized to allow command input in the terminal below */
#admin-file-modal.minimized-backdrop {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    pointer-events: none !important; /* Directs inputs to underlying workspace */
}

#admin-file-modal.minimized-backdrop .admin-window-card {
    pointer-events: auto !important; /* Keeps minimized header bar interactive */
}

/* Light Theme window styling */
body.light-theme .admin-window-card {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
}

body.light-theme #admin-file-modal-body {
    background: #ffffff !important;
}

body.light-theme #admin-file-editor {
    color: #0f172a !important; /* Dark charcoal text color */
    background: #ffffff !important;
}

body.light-theme #admin-file-modal .modal-header,
body.light-theme #admin-file-modal > div > div:first-child {
    background: #f8fafc !important;
    border-bottom: 1px solid #cbd5e1 !important;
}

body.light-theme #admin-file-modal h3,
body.light-theme #admin-file-modal span {
    color: #0f172a !important;
}

body.light-theme .icloud-card {
    background: rgba(255, 255, 255, 0.95) !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #0f172a !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12) !important;
}

body.light-theme #admin-fs-items-container {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
}

body.light-theme .admin-fs-row {
    color: #0f172a !important;
    border-bottom: 1px solid #cbd5e1 !important;
}

body.light-theme .admin-fs-row:hover {
    background: #f1f5f9 !important;
}

body.light-theme .admin-fs-row.parent-node {
    background: #f8fafc !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

body.light-theme .fs-size,
body.light-theme .fs-time {
    color: #475569 !important;
}

body.light-theme .admin-fs-row.selected {
    background: rgba(2, 132, 199, 0.08) !important;
    border-left: 3px solid #0284c7 !important;
    color: #0284c7 !important;
}

body.light-theme .admin-fs-row.selected .fs-name-text {
    color: #0284c7 !important;
}

body.light-theme .admin-fs-row.selected .fs-size,
body.light-theme .admin-fs-row.selected .fs-time {
    color: #0284c7 !important;
}

/* Hover indicators for drag target folder in light theme */
body.light-theme .admin-fs-row.dir-node.drag-hover {
    background: rgba(16, 185, 129, 0.1) !important;
    border-left-color: #10b981 !important;
}

body.light-theme .admin-fs-row.parent-node.drag-hover-parent {
    background: rgba(2, 132, 199, 0.1) !important;
    border-left-color: #0284c7 !important;
}

body.light-theme .icloud-input,
body.light-theme .admin-fs-item,
body.light-theme .setting-group input,
body.light-theme .setting-group textarea {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}
body.light-theme .icloud-card h2,
body.light-theme .icloud-card h3,
body.light-theme .icloud-card h4,
body.light-theme .icloud-card p,
body.light-theme .icloud-card label,
body.light-theme #collaborators-list span {
    color: #0f172a !important;
}

body.light-theme #jupyter-cells-container textarea {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

.editor-popup-medium {
    width: 70%;
    height: 75%;
    max-width: 1000px;
    max-height: 800px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.editor-popup-fullscreen {
    width: 95vw !important;
    height: 92vh !important;
    max-width: none !important;
    max-height: none !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body.light-theme #editor-popup-card {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
}

body.light-theme #editor-popup-textarea {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.light-theme #editor-popup-title {
    color: #0f172a !important;
}

/* ==========================================================
   1. LOGIN MODAL CARD HOVER GLOW (NON-SHIFTING)
========================================================== */
.icloud-card {
    transition: border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.icloud-card:hover {
    border-color: rgba(56, 189, 248, 0.55) !important;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5), 
                0 0 30px rgba(56, 189, 248, 0.25) !important;
}

body.light-theme .icloud-card:hover {
    border-color: rgba(2, 132, 199, 0.5) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12), 
                0 0 25px rgba(2, 132, 199, 0.2) !important;
}

.project-card {
    transition: border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.project-card.card-ai:hover,
.project-card[onclick*="ai"]:hover {
    border-color: rgba(56, 189, 248, 0.55) !important;
    box-shadow: 0 0 25px rgba(37, 99, 235, 0.35) !important;
}

.project-card.card-chat:hover {
    border-color: rgba(45, 212, 191, 0.55) !important;
    box-shadow: 0 0 25px rgba(13, 148, 136, 0.35) !important;
}

.project-card.card-research:hover {
    border-color: rgba(52, 211, 153, 0.55) !important;
    box-shadow: 0 0 25px rgba(5, 150, 105, 0.35) !important;
}

.project-card.card-latex:hover,
.project-card[onclick*="latex"]:hover {
    border-color: rgba(129, 140, 248, 0.55) !important;
    box-shadow: 0 0 25px rgba(99, 102, 241, 0.35) !important;
}

.project-card.card-jupyter:hover,
.project-card[onclick*="jupyter"]:hover {
    border-color: rgba(245, 158, 11, 0.55) !important;
    box-shadow: 0 0 25px rgba(234, 88, 12, 0.35) !important;
}

.project-card.card-mdt:hover,
.project-card[onclick*="mdt"]:hover,
.project-card[onclick*="mdtransport"]:hover {
    border-color: rgba(16, 185, 129, 0.55) !important;
    box-shadow: 0 0 25px rgba(5, 150, 105, 0.35) !important;
}

.project-card.card-hpc:hover {
    border-color: rgba(34, 211, 238, 0.55) !important;
    box-shadow: 0 0 25px rgba(2, 132, 199, 0.35) !important;
}

.project-card.card-ref:hover {
    border-color: rgba(244, 114, 182, 0.55) !important;
    box-shadow: 0 0 25px rgba(219, 39, 119, 0.35) !important;
}

.project-card.card-setup:hover {
    border-color: rgba(250, 204, 21, 0.55) !important;
    box-shadow: 0 0 25px rgba(202, 138, 4, 0.35) !important;
}

.project-card.card-visualizer:hover {
    border-color: rgba(192, 132, 252, 0.55) !important;
    box-shadow: 0 0 25px rgba(124, 58, 237, 0.35) !important;
}

.project-card:not(.card-ai):not([onclick*="ai"]):not(.card-chat):not(.card-research):not(.card-latex):not([onclick*="latex"]):not(.card-jupyter):not([onclick*="jupyter"]):not(.card-mdt):not([onclick*="mdt"]):not([onclick*="mdtransport"]):not(.card-hpc):not(.card-ref):not(.card-setup):not(.card-visualizer):hover {
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.22) !important;
}

/* Apply custom typography specifically to XTerm terminal canvases */
#admin-terminal-container .xterm-rows,
#mdt-terminal-container .xterm-rows,
.xterm {
    font-family: "Berkeley Mono", "JetBrains Mono", "Courier New", monospace !important;
    font-variant-ligatures: normal;
    text-rendering: optimizeLegibility;
}

/* Keep Reference Manager answers readable after Markdown is rendered. */
#ref-chat-messages .reference-chat-assistant > *:first-child { margin-top: 0; }
#ref-chat-messages .reference-chat-assistant > *:last-child { margin-bottom: 0; }
#ref-chat-messages .reference-chat-assistant p {
    margin: 0 0 0.75rem;
}
#ref-chat-messages .reference-chat-assistant h1,
#ref-chat-messages .reference-chat-assistant h2,
#ref-chat-messages .reference-chat-assistant h3,
#ref-chat-messages .reference-chat-assistant h4,
#ref-chat-messages .reference-chat-assistant h5,
#ref-chat-messages .reference-chat-assistant h6 {
    margin: 1rem 0 0.25rem;
    font-weight: 600;
    line-height: 1.3;
}
#ref-chat-messages .reference-chat-assistant strong {
    font-weight: 600;
}
#ref-chat-messages .reference-chat-assistant ul,
#ref-chat-messages .reference-chat-assistant ol {
    margin: 0.5rem 0 0.75rem;
    padding-left: 1.25rem;
    list-style-position: outside;
}
#ref-chat-messages .reference-chat-assistant ul { list-style-type: disc; }
#ref-chat-messages .reference-chat-assistant ol { list-style-type: decimal; }
#ref-chat-messages .reference-chat-assistant li {
    margin: 0.2rem 0;
    line-height: 1.5;
    word-break: break-word;
}

/* Keep the same structure for the other Markdown chat surfaces. */
.response-content ol,
.response-content ul {
    margin: 0.5rem 0 0.75rem;
    padding-left: 1.25rem;
}
.response-content li {
    margin-top: 4px;
    line-height: 1.5;
    word-break: break-word;
}

#admin-panel-terminal, #hpc-right-terminal-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: #0b0f19; 
}

#admin-terminal-container, #hpc-terminal-container {
    flex-grow: 1;
    height: 100%;
    width: 100%;
    min-height: 0; 
    min-width: 0;
    padding: 12px; 
    box-sizing: border-box;
    overflow: hidden;
}

#admin-terminal-container .xterm, #hpc-terminal-container .xterm, #mdt-terminal-container .xterm,
#vibe-shell-container .xterm {
    height: 100%;
    width: 100%;
}

#admin-terminal-container .xterm-viewport, #hpc-terminal-container .xterm-viewport, #mdt-terminal-container .xterm-viewport,
#vibe-shell-container .xterm-viewport {
    height: 100% !important;
    width: 100% !important;
}

/* The Vibe sandbox shell fills its pane the same way the System/MDT terminals
   do. Without a stretched .xterm/.xterm-viewport the canvas sits at its natural
   (initial-fit) size, so the pane looked short and narrow until a manual
   fit/resize. min-height:0 lets the flex child actually shrink. */
#vibe-shell-container {
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}
#vibe-shell-container .xterm,
#vibe-shell-container .xterm-viewport {
    box-sizing: border-box;
}

.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(120, 120, 120, 0.3);
    transition: .3s;
    border-radius: 18px;
    border: 1px solid var(--border-color);
}
.switch .slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background-color: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: #2ea043;
    border-color: #2ea043;
}
input:checked + .slider:before {
    transform: translateX(16px); 
}

/* ------------------------------------------------------------------
   HPC Workspace: MD Studio sub-tabs
------------------------------------------------------------------ */
.hpc-subtab-bar {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--panel-bg);
    flex-shrink: 0;
    overflow-x: auto;
}
.hpc-subtab-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s;
}
.hpc-subtab-btn:hover { color: var(--text-main); border-color: var(--accent-blue); }
.hpc-subtab-btn.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(16, 185, 129, 0.18));
    color: var(--accent-blue);
    border-color: rgba(56, 189, 248, 0.55);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.2);
}
.hpc-subtab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.hpc-subtab-panel.active { display: flex; }

.md-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.10), rgba(16, 185, 129, 0.08));
    flex-wrap: wrap;
}
.md-banner h2 { font-size: 1.25rem; font-weight: 800; margin: 0; color: var(--text-main); }
.md-banner p { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0 0; }
.md-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid rgba(52, 211, 153, 0.4);
    background: rgba(52, 211, 153, 0.10);
    color: #34d399;
    white-space: nowrap;
}
.md-status-pill.offline {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.10);
    color: #f87171;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}
.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
}
.kpi-card::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--kpi-accent, #38bdf8);
    opacity: 0.9;
}
.kpi-card.running { --kpi-accent: #34d399; }
.kpi-card.queued { --kpi-accent: #f59e0b; }
.kpi-card.completed { --kpi-accent: #38bdf8; }
.kpi-card.targets { --kpi-accent: #a855f7; }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--text-main); line-height: 1; }
.kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.kpi-sub { font-size: 0.7rem; color: var(--text-muted); opacity: 0.8; }

.md-runs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.md-runs-table th {
    text-align: left;
    padding: 9px 12px;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color);
    background: var(--overlay-soft);
}
.md-runs-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}
.md-runs-table tbody tr { cursor: pointer; transition: background 0.15s; }
.md-runs-table tbody tr:hover { background: rgba(56, 189, 248, 0.08); }

.status-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}
.status-tag.running { background: rgba(52,211,153,0.14); color: #34d399; border: 1px solid rgba(52,211,153,0.35); }
.status-tag.queued { background: rgba(245,158,11,0.14); color: #fbbf24; border: 1px solid rgba(245,158,11,0.35); }
.status-tag.completed { background: rgba(56,189,248,0.14); color: #38bdf8; border: 1px solid rgba(56,189,248,0.35); }
.status-tag.failed { background: rgba(239,68,68,0.14); color: #f87171; border: 1px solid rgba(239,68,68,0.35); }
.status-tag.paused { background: rgba(168,85,247,0.14); color: #c084fc; border: 1px solid rgba(168,85,247,0.35); }
.status-tag.custom { background: rgba(16,185,129,0.14); color: #34d399; border: 1px solid rgba(16,185,129,0.35); }

.progress-track {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 180px;
}
.progress-bar {
    height: 7px;
    background: rgba(255,255,255,0.08);
    border-radius: 99px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, #38bdf8, #10b981);
    transition: width 0.5s ease;
}
.progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.66rem;
    color: var(--text-muted);
}

.launcher-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.launcher-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    cursor: pointer;
    transition: all 0.16s;
    text-align: left;
}
.launcher-card:hover {
    border-color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0,0,0,0.25);
}
.launcher-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}
.launcher-card h4 { font-size: 0.88rem; font-weight: 700; margin: 0 0 3px; color: var(--text-main); }
.launcher-card p { font-size: 0.74rem; margin: 0; color: var(--text-muted); line-height: 1.45; }

.md-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}

/* Multi-Stage Phase Durations: widen each option so headers fit on one line */
#md-phase-durations-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
#md-phase-durations-grid .md-form-field label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#md-phase-durations-grid .md-form-field input {
    width: 100%;
    box-sizing: border-box;
}

/* Annealing Temperature / Time fields: both 1.4x wider than siblings */
#md-em-anneal-grid {
    grid-template-columns: minmax(120px, 1fr) minmax(168px, 1.4fr) minmax(168px, 1.4fr);
}
#md-em-anneal-grid .md-form-field input {
    width: 100%;
    box-sizing: border-box;
}
@media (max-width: 1300px) {
    #md-em-anneal-grid { grid-template-columns: 1fr 1fr; }
    #md-em-anneal-grid .md-form-field.anneal-wide { grid-column: span 2; }
}

/* Dynamic 3D Box & Packing Inspector: square viewers */
#setup-dynamic-3d-mol,
#setup-dynamic-3d-config {
    aspect-ratio: 1 / 1;
    width: 100%;
}
.md-form-field { display: flex; flex-direction: column; gap: 5px; }
.md-output-group { display: flex; flex-direction: column; gap: 8px; }
.md-output-group-title { font-size: 0.72rem; font-weight: 600; color: var(--text-main); }
.md-output-group-title strong { color: var(--accent-blue); }
.md-output-divider { height: 1px; background: var(--border-color); }
.md-form-field label { font-size: 0.74rem; font-weight: 600; color: var(--text-muted); }
.md-form-field input, .md-form-field select {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.82rem;
    outline: none;
}
.md-form-field input:focus, .md-form-field select:focus { border-color: var(--accent-blue); }

.molecule-row {
    display: grid;
    grid-template-columns: 1fr 90px 70px 70px 70px 34px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}
.molecule-row input {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    min-width: 0;
}
.molecule-row input.mol-dims { width: 100%; box-sizing: border-box; }

/* Per-molecule box dimensions are hidden when "use same box" is toggled on */
#md-molecules-card.uniform .mol-dims,
#md-molecules-card.uniform .mol-dims-col { display: none !important; }
#md-molecules-card.uniform .molecule-row { grid-template-columns: 1fr 90px 34px; }

/* HPC remote/local item rows: full width in light mode */
#md-setup-remote-items,
#md-setup-local-items,
#hpc-remote-items-container,
#hpc-local-items-container {
    background: var(--bg-dark);
}
.molecule-remove {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.35);
    color: #f87171;
    border-radius: 8px;
    cursor: pointer;
    padding: 7px 0;
    font-size: 0.8rem;
}

.md-panel-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.md-panel-card h3 { font-size: 0.95rem; font-weight: 700; color: var(--accent-blue); margin: 0; }
.md-panel-card h4 { font-size: 0.8rem; font-weight: 700; color: var(--text-main); margin: 0; }

.file-chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--overlay-mid);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: 'JetBrains Mono', monospace;
}

.viz-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 10px 10px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    /* The square viewports are as wide as the panel, so they can be taller
       than the visible area — scroll instead of clipping them. */
    overflow-y: auto;
}
/* OVITO/VMD-style horizontal control toolbar: one row of cards that stretch
   to fill the FULL panel width, above the viewport canvas.  The row height is
   content-driven — every card grows to show ALL of its content with no
   internal scrolling; the whole .viz-grid scrolls instead. */
.viz-toolbar {
    display: flex;
    flex-direction: row;
    gap: 10px;
    overflow-x: auto;
    overflow-y: visible;
    flex-shrink: 0;
    height: auto;
    padding-bottom: 4px;
    align-items: stretch;
}
.viz-toolbar-card {
    flex: 1 1 0;
    min-width: 240px;
    height: auto;
    overflow-y: visible;
}
.viz-viewers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    gap: 10px;
    flex: 0 0 auto;
    /* Leave ~14% free space on each side (so the mouse wheel can scroll the
       page instead of zooming the structure) — the two square viewports
       occupy the centered 72% (1.2x the previous 60%) and stay square. */
    width: 72%;
    max-width: 1080px;
    margin: 0 auto;
    overflow: visible;
}
.viz-pane {
    display: flex;
    flex-direction: column;
    gap: 0;
    aspect-ratio: 1 / 1;
    width: 100%;
    max-width: 100%;
    height: auto;
    overflow: hidden;
    background: #090d16;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}
.viz-pane .viz-title { font-size: 0.8rem; font-weight: 700; color: var(--text-main); display: flex; justify-content: space-between; align-items: center; background: var(--overlay-mid); padding: 6px 12px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
/* Medium / full / minimize window controls on each viewport (like the
   Reference Manager PDF viewer). */
.viz-size-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 5px;
    cursor: pointer;
}
.viz-size-btn:hover { color: var(--accent-blue); border-color: var(--accent-blue); }
/* Minimized: title bar only, stage hidden. */
.viz-pane.viz-min { aspect-ratio: auto; height: 38px; overflow: hidden; }
.viz-pane.viz-min .viz-stage { display: none; }
/* Full size: span the whole viewport row; the sibling pane is tucked away. */
.viz-pane.viz-full { grid-column: 1 / -1; }
.viz-pane.viz-hidden { display: none; }
.viz-stage { flex: 1; min-height: 0; background: #070a12; overflow: hidden; position: relative; }
.viz-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 0.8rem; text-align: center; padding: 20px;
}
.viz-upload { display: flex; flex-direction: column; gap: 8px; }
.viz-upload label { font-size: 0.74rem; font-weight: 600; color: var(--text-muted); }
.viz-select {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    width: 100%;
}

.md-2d-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: auto;
}

/* Research Updates composer: give rendered preview lists room for their
   bullets/markers — without left padding the markers get clipped at the
   container edge. */
#research-content-preview ul,
#research-content-preview ol,
.research-feed-content ul,
.research-feed-content ol {
    margin-left: 22px;
    padding-left: 4px;
}
#research-content-preview li,
.research-feed-content li {
    list-style-position: outside;
    margin-bottom: 4px;
}
#research-content-preview p,
.research-feed-content p {
    margin: 0 0 10px 0;
}

/* ---------------------------------------------------------------------------
 * Vibe Coding studio — CodeMirror editor
 * ---------------------------------------------------------------------------
 * The CodeMirror wrapper replaces the <textarea> in place; give it the same
 * flex sizing the textarea had so it fills the center panel, and tint it to
 * the app's dark theme (darcula tokens on the app background).
 */
#vibe-editor-wrap .CodeMirror {
    flex: 1;
    height: 100%;
    width: 100%;
    background: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}
#vibe-editor-wrap .CodeMirror-gutters {
    background: rgba(0, 0, 0, 0.15);
    border-right: 1px solid var(--border-color);
}
#vibe-editor-wrap .CodeMirror-linenumber {
    color: var(--text-muted);
}
#vibe-editor-wrap .CodeMirror-cursor {
    border-left: 1px solid var(--accent-blue);
}
#vibe-editor-wrap .CodeMirror-selected {
    background: rgba(56, 189, 248, 0.25) !important;
}
#vibe-editor-wrap .CodeMirror-activeline-background {
    background: rgba(128, 128, 128, 0.08);
}
#vibe-editor-wrap .CodeMirror-matchingbracket {
    color: #4ade80 !important;
    text-decoration: underline;
}
.vibe-file-preview {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: var(--editor-bg);
    color: var(--editor-text);
}
.vibe-file-preview-header {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    min-width: 0;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.72rem;
}
.vibe-file-preview-header > span {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vibe-file-preview-header button {
    flex: 0 0 auto;
    padding: 4px 8px;
    font-size: 0.68rem;
}
.vibe-file-preview-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #ffffff;
}
.vibe-file-preview-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    margin: auto;
    object-fit: contain;
    background: #ffffff;
}
.vibe-file-preview-media {
    display: block;
    width: min(100%, 720px);
    max-height: 100%;
    margin: auto;
}
.vibe-file-preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-height: 100px;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-align: center;
}
.vibe-csv-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}
.vibe-csv-toolbar {
    flex-wrap: wrap;
}
.vibe-csv-filter {
    flex: 0 1 190px;
    min-width: 120px;
    padding: 4px 7px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.7rem;
}
.vibe-csv-count {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}
.vibe-csv-table {
    width: max-content;
    min-width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-family: "Berkeley Mono", "JetBrains Mono", monospace;
    font-size: 0.72rem;
}
.vibe-csv-sort-button {
    display: block;
    width: 100%;
    padding: 0 14px 0 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vibe-csv-sort-button:hover {
    color: var(--text-main);
}
.vibe-csv-column-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    touch-action: none;
}
.vibe-csv-column-resizer:hover,
.vibe-csv-table th:active .vibe-csv-column-resizer {
    background: var(--accent-blue);
}
.vibe-csv-table th {
    position: relative;
}
.vibe-csv-table th,
.vibe-csv-table td {
    max-width: 300px;
    padding: 6px 8px;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.vibe-csv-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel-bg);
    color: var(--accent-blue);
    font-weight: 700;
}
.vibe-csv-table td {
    color: var(--text-main);
}
.vibe-csv-table tr:nth-child(even) td {
    background: rgba(128,128,128,0.05);
}

.vibe-pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    min-width: 0;
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--panel-bg);
}
.vibe-pdf-toolbar button {
    flex: 0 0 auto;
    min-width: 28px;
    padding: 4px 7px;
    font-size: 0.7rem;
}
.vibe-pdf-zoom-label,
.vibe-pdf-search-status {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}
.vibe-pdf-search {
    flex: 1 1 150px;
    min-width: 90px;
    padding: 4px 7px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.7rem;
}
.vibe-pdf-body {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #525659;
}
.vibe-pdf-thumbnails {
    display: flex;
    flex: 0 0 92px;
    flex-direction: column;
    gap: 7px;
    min-height: 0;
    padding: 8px 6px;
    overflow-y: auto;
    background: #1e2530;
    border-right: 1px solid rgba(255,255,255,0.12);
}
.vibe-pdf-thumbnail {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: #d1d5db;
    cursor: pointer;
    font-size: 0.64rem;
}
.vibe-pdf-thumbnail:hover,
.vibe-pdf-thumbnail.active {
    border-color: var(--accent-blue);
    background: rgba(56,189,248,0.14);
}
.vibe-pdf-thumbnail-canvas {
    display: block;
    width: 72px;
    min-height: 28px;
    background: #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.vibe-pdf-pages {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 12px;
    overflow: auto;
}
.vibe-pdf-page {
    position: relative;
    flex: 0 0 auto;
    min-width: 240px;
    min-height: 180px;
    background: #ffffff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    line-height: 0;
}
.vibe-pdf-page canvas {
    display: block;
}
.vibe-pdf-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    min-height: 100px;
    padding: 20px;
    color: #d1d5db;
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: center;
}
.vibe-pdf-text-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    line-height: 1;
    user-select: text;
    -webkit-user-select: text;
}
.vibe-pdf-text-layer span,
.vibe-pdf-text-layer br {
    position: absolute;
    color: transparent;
    white-space: pre;
    transform-origin: 0 0;
    cursor: text;
}
.vibe-pdf-text-layer span::selection {
    background: rgba(56,189,248,0.35);
    color: transparent;
}

/* Keep Vibe assistant controls reachable while the response thread grows. */
.vibe-ai-sidebar,
.vibe-ai-sidebar-header,
.vibe-ai-thread,
.vibe-ai-composer {
    min-height: 0;
}
.vibe-ai-sidebar {
    flex: 0 0 26%;
    height: 100%;
}

/* Vibe four-pane layout: file tree | editor | AI assistant | terminal. */
.vibe-main-layout {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
/* The assistant is a full-height right column. Files, editor, and terminal
   share the left column so the terminal never spans beneath the assistant. */
.vibe-left-workspace {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-dark);
}
.vibe-code-layout {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.vibe-pane {
    min-width: 0;
    min-height: 0;
}
.vibe-files-pane {
    flex: 0 0 240px;
    width: 240px;
    min-width: 165px;
    max-width: 42vw;
}
.vibe-editor-pane {
    flex: 1 1 auto;
    min-width: 180px;
}
.vibe-ai-sidebar {
    flex: 0 0 360px;
    width: 360px;
    height: 100%;
    min-width: 270px;
    max-width: 52vw;
}
.vibe-terminal-pane {
    width: 100%;
    height: 30%;
    min-height: 130px;
    max-height: 65%;
    min-width: 0;
    overflow: hidden;
}
.vibe-resize-handle {
    flex: 0 0 7px;
    z-index: 5;
    background: rgba(128,128,128,0.08);
    transition: background 0.15s ease;
}
.vibe-resize-handle:hover,
body.vibe-resizing .vibe-resize-handle {
    background: var(--accent-blue);
}
.vibe-resize-handle-horizontal {
    cursor: col-resize;
}
.vibe-resize-handle-vertical {
    cursor: row-resize;
}
.vibe-resizing,
.vibe-resizing * {
    user-select: none !important;
}
.vibe-resizing iframe,
.vibe-resizing textarea {
    pointer-events: none;
}
@media (max-width: 900px) {
    .vibe-files-pane { flex-basis: 190px; }
    .vibe-ai-sidebar { flex-basis: 300px; min-width: 245px; }
}
.vibe-terminal-toolbar > div:last-child {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}
@media (max-width: 900px) {
    .vibe-terminal-toolbar {
        align-items: flex-start !important;
        gap: 6px;
    }
    .vibe-terminal-toolbar > div:last-child {
        justify-content: flex-start;
    }
}
@media (max-width: 760px) {
    .vibe-main-layout {
        flex-direction: column;
    }
    .vibe-left-workspace {
        flex: 1 1 58%;
        min-height: 260px;
    }
    .vibe-resize-handle-horizontal#vibe-ai-resizer {
        flex: 0 0 7px;
        width: 100%;
        cursor: row-resize;
    }
    .vibe-ai-sidebar {
        flex: 1 1 42%;
        width: 100%;
        min-width: 0;
        min-height: 260px;
    }
}
@media (max-width: 650px) {
    .vibe-files-pane { flex-basis: 155px; min-width: 145px; }
    .vibe-ai-sidebar { flex-basis: 250px; min-width: 220px; }
    .vibe-mode-btn { padding-inline: 5px; }
    .vibe-settings-menu { min-width: 0; }
}
@media (max-width: 1100px) {
    .vibe-studio-toolbar { align-items: flex-start !important; }
    .vibe-studio-toolbar > div:last-child {
        justify-content: flex-end;
        row-gap: 5px;
    }
}
@media (max-width: 760px) {
    .vibe-studio-toolbar {
        flex-wrap: wrap;
    }
    .vibe-studio-toolbar > div:last-child {
        width: 100%;
    }
}
.vibe-ai-sidebar-header {
    flex: 0 0 auto;
}
.vibe-ai-thread {
    flex: 1 1 auto !important;
    overflow-y: auto;
}
.vibe-ai-composer {
    flex: 0 0 auto !important;
    width: 100%;
    box-sizing: border-box;
}
#vibe-attachment-label,
#vibe-skill-button {
    height: 28px;
    min-height: 28px;
    box-sizing: border-box;
}
.vibe-skill-picker {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 28px;
}
.vibe-skill-button {
    width: 100%;
    padding: 4px 8px;
    border-radius: 7px;
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    font-size: 0.68rem;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vibe-skill-button:hover,
.vibe-skill-button[aria-expanded="true"] {
    border-color: var(--accent-blue);
}
.vibe-skill-menu {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 10000;
    max-height: 420px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}
.vibe-skill-menu-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 7px;
    border-radius: 5px;
    color: var(--text-main);
    font-size: 0.7rem;
    cursor: pointer;
    user-select: none;
}
.vibe-skill-menu-item:hover {
    background: rgba(56,189,248,0.14);
}
.vibe-skill-menu-item input {
    margin: 0;
    accent-color: var(--accent-blue);
}
.vibe-skill-menu-empty {
    padding: 7px;
    color: var(--text-muted);
    font-size: 0.7rem;
}
.vibe-skill-menu-save {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 7px;
    border: 0;
    border-top: 1px solid var(--border-color);
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.68rem;
    text-align: left;
    cursor: pointer;
}
.vibe-skill-menu-save:hover {
    background: rgba(56,189,248,0.14);
    color: var(--text-main);
}
.vibe-skill-select-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
/* Retain theme styling for code that reads the hidden compatibility select. */
#vibe-skill-select {
    line-height: 18px;
    /* Let the browser render native form controls in the page's color
       scheme so the dropdown list, checkboxes, and option backgrounds
       match dark mode instead of forcing a white popup. */
    color-scheme: dark;
}
body.light-theme #vibe-skill-select {
    color-scheme: light;
}
/* <option> elements ignore the parent <select> background on most
   browsers and fall back to the OS default (white), which makes the
   skill list invisible in dark mode. Force the option background and
   text color to the theme variables. */
#vibe-skill-select option {
    background: var(--input-bg);
    color: var(--text-main);
}
#vibe-skill-select option:checked {
    background: var(--accent-blue);
    color: #ffffff;
}

/* Compact Vibe configuration popover. Settings stay available without
   consuming the project toolbar width on small laptop screens. */
.vibe-settings-picker {
    position: relative;
    flex: 0 0 auto;
}
.vibe-settings-button {
    font-size: 0.76rem;
    padding: 5px 11px;
    white-space: nowrap;
}
.vibe-settings-menu {
    position: fixed;
    z-index: 12000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    min-width: 280px;
    max-width: calc(100vw - 16px);
    overflow-y: auto;
    background: var(--panel-bg);
    color: var(--text-main);
    border: 1px solid var(--accent-blue);
    border-radius: 10px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.48);
}
.vibe-settings-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-blue);
    font-size: 0.82rem;
    font-weight: 700;
}
.vibe-settings-close {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 5px;
    cursor: pointer;
}
.vibe-settings-close:hover {
    color: var(--text-main);
}
.vibe-settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 7px 8px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    cursor: pointer;
}
.vibe-settings-toggle:hover {
    background: var(--hover-bg);
}
.vibe-settings-toggle span {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.vibe-settings-toggle b {
    font-size: 0.74rem;
    font-weight: 600;
}
.vibe-settings-toggle small {
    color: var(--text-muted);
    font-size: 0.66rem;
    line-height: 1.25;
}
.vibe-settings-toggle input {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--accent-blue);
}
.vibe-settings-section {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.vibe-settings-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
}
.vibe-settings-section #vibe-model-select {
    width: 100%;
    max-width: none;
    padding: 5px 8px;
    border-radius: 7px;
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    font-size: 0.74rem;
}
.vibe-cloud-empty-state {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 7px 8px;
    border: 1px dashed rgba(251, 191, 36, 0.55);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.35;
}
.vibe-cloud-empty-state button {
    align-self: flex-start;
    padding: 4px 8px;
    font-size: 0.68rem;
}
.vibe-cloud-badge {
    display: none;
    color: #34d399;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.vibe-settings-health {
    font-size: 0.68rem;
    color: var(--text-muted);
    padding: 0 2px;
    line-height: 1.4;
}
.vibe-lint-error-line {
    background: rgba(248, 113, 113, 0.13);
    border-left: 3px solid #f87171;
}
.CodeMirror-hints {
    background: var(--panel-bg, #1e2430);
    border: 1px solid var(--border-color);
    font-family: "Fira Code", "JetBrains Mono", monospace;
    font-size: 0.8rem;
}
.CodeMirror-hint {
    color: var(--text-main);
}
li.CodeMirror-hint-active {
    background: rgba(56, 189, 248, 0.25);
    color: #fff;
}
.vibe-provider-button {
    width: 100%;
    font-size: 0.74rem;
    padding: 6px 10px;
}

/* Visible Local/Cloud mode control in the Vibe settings popover. Cloud opens
   the provider setup when no cloud key has been configured yet. */
.vibe-model-mode-picker {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(128,128,128,0.08);
}
.vibe-mode-btn {
    border: 0;
    border-radius: 6px;
    padding: 4px 7px;
    color: var(--text-muted);
    background: transparent;
    font-size: 0.72rem;
    cursor: pointer;
    white-space: nowrap;
}
.vibe-mode-btn:hover,
.vibe-mode-btn.active {
    color: var(--text-main);
    background: rgba(56,189,248,0.16);
}
#vibe-mode-cloud-btn.active {
    color: #34d399;
    background: rgba(16,185,129,0.16);
}

#skills-modal .icloud-card {
    align-items: stretch;
    width: min(960px, 95vw);
    max-width: min(960px, 95vw);
    max-height: 90vh;
    box-sizing: border-box;
    overflow: hidden;
}
#skills-list {
    flex: 0 0 168px !important;
    height: 168px !important;
    max-height: 22vh !important;
    min-height: 140px !important;
    overflow-y: auto !important;
}
#skills-list,
#skills-modal .skills-metadata-grid {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.skills-metadata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}
.skills-metadata-grid .icloud-input {
    font-size: 0.72rem;
    padding: 6px 8px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}
#skills-modal .icloud-input,
#skills-modal #skills-content,
#skills-modal #skills-name,
#skills-modal #skills-description,
#skills-modal #skills-triggers,
#skills-modal #skills-applies-to,
#skills-modal #skills-verification,
#skills-modal #skills-python-deps,
#skills-modal #skills-node-deps {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}
#skills-modal #skills-content {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}
@media (max-width: 560px) {
    .skills-metadata-grid {
        grid-template-columns: 1fr;
    }
}

.vibe-ai-sidebar-options {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-top: 2px;
}
.vibe-ai-sidebar-options label {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.3;
    cursor: pointer;
    user-select: none;
}
.vibe-ai-sidebar-options label span {
    color: var(--text-muted);
}
.vibe-ai-sidebar-options input {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--accent-blue);
    cursor: pointer;
}
.vibe-ai-composer {
    overflow-y: auto;
}
.vibe-ai-composer > textarea {
    flex: 0 0 auto !important;
    min-height: 64px;
    height: 88px;
    max-height: 28vh;
}

/* Rendered Markdown in the Vibe AI assistant. */
.vibe-ai-markdown {
    white-space: normal;
}
.vibe-ai-markdown h1,
.vibe-ai-markdown h2,
.vibe-ai-markdown h3,
.vibe-ai-markdown h4,
.vibe-ai-markdown h5,
.vibe-ai-markdown h6 {
    margin: 0.55em 0 0.3em;
    color: var(--accent-blue);
    line-height: 1.25;
}
.vibe-ai-markdown h1 { font-size: 1.2rem; }
.vibe-ai-markdown h2 { font-size: 1.08rem; }
.vibe-ai-markdown h3 { font-size: 0.98rem; }
.vibe-ai-markdown p { margin: 0 0 0.65em; }
.vibe-ai-markdown p:last-child { margin-bottom: 0; }
.vibe-ai-markdown ul,
.vibe-ai-markdown ol {
    margin: 0.35em 0 0.7em 1.25em;
    padding-left: 0.9em;
}
.vibe-ai-markdown li { margin: 0.2em 0; }
.vibe-ai-markdown blockquote {
    margin: 0.55em 0;
    padding: 0.35em 0.75em;
    border-left: 3px solid var(--accent-blue);
    color: var(--text-muted);
    background: rgba(56, 189, 248, 0.06);
}
.vibe-ai-markdown pre {
    margin: 0.65em 0;
    padding: 0.7em;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.3);
    white-space: pre;
}
.vibe-ai-markdown code {
    padding: 0.08em 0.28em;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.22);
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 0.92em;
}
.vibe-ai-markdown pre code { padding: 0; background: transparent; }
.vibe-ai-markdown a { color: var(--accent-blue); text-decoration: underline; }
.vibe-ai-markdown hr { border: 0; border-top: 1px solid var(--border-color); margin: 0.8em 0; }
.vibe-ai-markdown table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 0.65em 0;
}
.vibe-ai-markdown th,
.vibe-ai-markdown td {
    padding: 4px 7px;
    border: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}
.vibe-ai-markdown th { background: rgba(56, 189, 248, 0.1); }
.vibe-ai-provenance {
    margin-top: 10px;
    padding-top: 7px;
    border-top: 1px dashed var(--border-color);
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.4;
}
.vibe-ai-sources {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.67rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.vibe-plan-panel {
    flex: 0 0 auto;
    max-height: 30%;
    overflow-y: auto;
    margin: 8px 12px 0;
    padding: 7px 9px;
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.05);
    font-size: 0.69rem;
    line-height: 1.45;
}
.vibe-plan-title { color: var(--accent-blue); font-weight: 700; margin-bottom: 4px; }
.vibe-plan-step { display: flex; gap: 6px; color: var(--text-muted); }
.vibe-plan-step.done { color: #4ade80; }.vibe-ai-sources a { color: var(--accent-blue); text-decoration: underline; }
.latex-diagnostics-header { display:flex; justify-content:space-between; align-items:center; padding:8px 10px; border-bottom:1px solid var(--border-color); color:var(--accent-blue); font-size:0.78rem; }
.latex-diagnostic-row { width:100%; display:flex; gap:8px; align-items:flex-start; text-align:left; border:0; border-bottom:1px solid var(--border-color); background:transparent; color:var(--text-main); padding:8px 10px; cursor:pointer; font-size:0.74rem; line-height:1.4; }
.latex-diagnostic-row:hover { background:rgba(56,189,248,0.10); }
.latex-diagnostic-row.error { color:#fca5a5; }
.latex-diagnostic-row.warning { color:#fcd34d; }
.latex-raw-log { margin:0; padding:10px; white-space:pre-wrap; overflow:auto; font-size:0.7rem; color:var(--text-muted); max-height:220px; }
.latex-diagnostics-header + details { border-top:1px solid var(--border-color); padding:6px 10px; font-size:0.72rem; color:var(--text-muted); }
.latex-conflict-notice { padding:6px 10px; border:1px solid rgba(248,113,113,0.45); background:rgba(248,113,113,0.10); color:#fca5a5; font-size:0.72rem; line-height:1.4; }
.latex-setting-row { display:flex; justify-content:space-between; align-items:center; gap:12px; color:var(--text-main); font-size:0.8rem; }
.latex-setting-row select, .latex-setting-row input[type="number"] { min-width:150px; padding:6px 8px; border-radius:7px; background:var(--input-bg); color:var(--text-main); border:1px solid var(--border-color); }
.latex-setting-row input[type="checkbox"] { width:16px; height:16px; accent-color:var(--accent-blue); }
.ai-diff-title { color:var(--accent-blue); font-weight:700; margin-bottom:8px; }
.ai-diff-remove, .ai-diff-add { white-space:pre-wrap; font-family:'JetBrains Mono',monospace; font-size:0.78rem; padding:2px 6px; }
.latex-conflict-diff { font-family:'JetBrains Mono', 'Fira Code', monospace; font-size:0.76rem; line-height:1.45; }
.latex-conflict-diff-row { display:grid; grid-template-columns:42px minmax(0, 1fr) 22px minmax(0, 1fr); align-items:stretch; min-height:1.45em; }
.latex-conflict-diff-row code { white-space:pre-wrap; overflow-wrap:anywhere; padding:1px 6px; color:var(--text-main); }
.latex-conflict-line-number { color:var(--text-muted); text-align:right; padding:1px 6px 1px 0; user-select:none; }
.latex-conflict-divider { color:var(--text-muted); text-align:center; user-select:none; }
.latex-conflict-same { background:transparent; }
.latex-conflict-local-change { color:#fecaca !important; background:rgba(239,68,68,0.20); }
.latex-conflict-server-change { color:#bbf7d0 !important; background:rgba(16,185,129,0.20); }
.latex-conflict-empty { background:rgba(148,163,184,0.10); }
.latex-conflict-diff-empty { color:var(--text-muted); font-style:italic; padding:8px; }
.ai-diff-remove { color:#fca5a5; background:rgba(239,68,68,0.10); }
.ai-diff-add { color:#86efac; background:rgba(16,185,129,0.10); }
.ai-diff-same { white-space:pre-wrap; font-family:'JetBrains Mono',monospace; font-size:0.78rem; padding:2px 6px; color:var(--text-muted); }
.ai-diff-changed { white-space:pre-wrap; font-family:'JetBrains Mono',monospace; font-size:0.78rem; padding:2px 6px; color:var(--text-main); }
.ai-diff-word-del { color:#fca5a5; background:rgba(239,68,68,0.28); border-radius:3px; padding:0 2px; text-decoration:line-through; }
.ai-diff-word-add { color:#bbf7d0; background:rgba(16,185,129,0.30); border-radius:3px; padding:0 2px; }
body.light-theme .ai-diff-remove { color:#b91c1c; background:rgba(239,68,68,0.08); }
body.light-theme .ai-diff-add { color:#15803d; background:rgba(16,185,129,0.12); }
body.light-theme .ai-diff-word-del { color:#b91c1c; background:rgba(239,68,68,0.20); }
body.light-theme .ai-diff-word-add { color:#15803d; background:rgba(16,185,129,0.25); }
.vibe-skill-checklist {
    margin-top: 6px;
    padding: 5px 7px;
    border-left: 2px solid #a78bfa;
    color: var(--text-muted);
    font-size: 0.66rem;
    line-height: 1.35;
}

/* Reference Manager uses a fixed 70/30 split on wide screens. On narrow
   screens the panes stack without allowing either child to overflow. */
.reference-manager .ref-library-pane,
.reference-manager .ref-assistant-pane {
    min-width: 0;
}
.reference-manager .ref-main-view {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
}
.reference-manager .ref-main-view.hidden {
    display: none !important;
}
.reference-manager #ref-pdf-inline-container {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #525659;
}
.reference-manager #ref-pdf-inline-container.hidden {
    display: none !important;
}
.reference-manager .ref-library-pane.pdf-active {
    padding: 0 !important;
    gap: 0 !important;
    overflow: hidden;
}
.reference-manager .ref-library-pane.pdf-active #ref-pdf-inline-container {
    border: 0;
    border-radius: 0;
    flex: 1 1 0;
}
/* Maximize: the viewer borrows the Reference Assistant column, so the fixed
   70/30 split collapses to a full-width PDF viewer. Below the stacking
   breakpoint the panes are full-width already and there is no column to
   reclaim, so the control is hidden instead (see the 760px media query). */
@media (min-width: 761px) {
    .reference-manager.ref-assistant-collapsed .ref-library-pane {
        width: 100% !important;
        border-right: 0;
    }
    .reference-manager.ref-assistant-collapsed .ref-assistant-pane {
        display: none !important;
    }
}
.reference-manager #ref-pdf-inline-container.minimized {
    flex: 0 0 48px;
    min-height: 48px;
}
.reference-manager #ref-pdf-inline-container.minimized .reference-pdf-viewer {
    min-height: 48px;
}
.ref-minimized-pdf-dock {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 0;
    min-height: 46px;
    padding: 8px 10px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.14), var(--panel-bg));
    box-shadow: 0 5px 18px rgba(0,0,0,0.22);
}
.ref-minimized-pdf-dock.hidden {
    display: none !important;
}
.ref-minimized-pdf-icon {
    flex: 0 0 auto;
    font-size: 1.05rem;
}
.ref-minimized-pdf-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--text-main);
    font-size: 0.78rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-minimized-pdf-restore,
.ref-minimized-pdf-close {
    flex: 0 0 auto;
    padding: 5px 9px;
    font-size: 0.7rem;
}
.reference-pdf-header,
.ref-assistant-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 40px;
    min-height: 40px;
    height: 40px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--reference-header-bg);
}
.reference-pdf-header .reference-pdf-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text-main);
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: normal;
}
.reference-pdf-context {
    flex: 0 1 auto;
    margin-left: auto;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.68rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reference-pdf-window-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}
.reference-pdf-window-button {
    width: 28px;
    padding: 3px 6px;
    font-size: 0.7rem;
}
.ref-assistant-header {
    flex: 0 0 40px;
    height: 40px;
    min-height: 40px;
    padding: 0 16px;
}
.ref-assistant-shell {
    min-width: 0;
}
.ref-assistant-status {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #60a5fa;
    box-shadow: 0 0 8px #60a5fa;
}
.ref-assistant-context {
    margin-left: auto;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.68rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-assistant-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px 0;
    border-bottom: 1px solid var(--border-color);
}
.ref-assistant-tab {
    padding: 7px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
}
.ref-assistant-tab.active,
.ref-assistant-tab:hover {
    border-bottom-color: var(--accent-blue);
    color: var(--accent-blue);
}
.ref-assistant-panel {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}
.ref-assistant-panel.hidden {
    display: none !important;
}
.reference-chat-welcome,
.reference-chat-user,
.reference-chat-assistant {
    max-width: 85%;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}
.reference-chat-welcome,
.reference-chat-assistant {
    align-self: flex-start;
    border: 1px solid var(--border-color);
    background: var(--panel-bg);
    color: var(--text-main);
}
.reference-chat-user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: #fff;
}
.reference-citation-badge {
    position: relative;
    display: inline-block;
    margin: 0 2px;
    padding: 1px 7px;
    border: 1px solid rgba(245, 158, 11, 0.65);
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.16);
    color: var(--accent-blue);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    line-height: 1.25;
    vertical-align: baseline;
}
.reference-citation-badge[data-match-status="exact"] {
    border-color: rgba(34, 197, 94, 0.72);
    background: rgba(34, 197, 94, 0.14);
}
.reference-citation-badge[data-match-status="ocr-fuzzy"],
.reference-citation-badge[data-match-status="document-search"],
.reference-citation-badge[data-match-status="document-search-ocr"] {
    border-color: rgba(250, 204, 21, 0.75);
}
.reference-citation-badge:hover,
.reference-citation-badge:focus-visible {
    background: rgba(245, 158, 11, 0.3);
    border-color: #f59e0b;
    outline: 2px solid rgba(245, 158, 11, 0.25);
    outline-offset: 1px;
}
.reference-citation-group {
    display: inline-flex;
    align-items: baseline;
    gap: 1px;
    white-space: nowrap;
}
.reference-citation-separator {
    color: var(--text-muted);
    font-size: 0.72em;
    user-select: none;
}
.reference-source-popover {
    position: fixed;
    z-index: 100001;
    width: min(320px, calc(100vw - 16px));
    padding: 8px 10px;
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    background: var(--panel-bg);
    color: var(--text-main);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
    font-size: 0.74rem;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    pointer-events: none;
}
.reference-source-popover small {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 0.68rem;
}
.reference-pdf-text-layer span.reference-pdf-search-highlight,
.reference-pdf-text-layer mark.reference-pdf-search-highlight {
    background: rgba(56, 189, 248, 0.42);
    border-radius: 2px;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25), 0 0 10px rgba(56, 189, 248, 0.45);
    color: inherit;
}
.reference-pdf-text-layer span.reference-pdf-citation-highlight {
    color: transparent;
    background: rgba(250, 204, 21, 0.34);
    border-radius: 2px;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.22), 0 0 13px rgba(245, 158, 11, 0.5);
    animation: referenceCitationPulse 1.35s ease-in-out 2;
}

.ref-assistant-panel .reference-pdf-notes-list {
    background: transparent;
}

/* Stable Reference Manager PDF reader. The page canvas, selectable text layer,
   and annotation layer share one positioned coordinate system. */
.reference-pdf-viewer {
    /* The floating panels are positioned against the viewer, so a panel can
       never escape into the manager's own layout. */
    position: relative;
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: #525659;
}
.reference-pdf-viewer.minimized .reference-pdf-toolbar,
.reference-pdf-viewer.minimized .reference-pdf-workspace,
.reference-pdf-viewer.minimized .reference-pdf-selection-popover {
    display: none !important;
}
/* The row wraps. The controls are compact clusters, and a pane too narrow to
   hold them all moves the last cluster onto the next line instead of pushing
   buttons off the screen (or hiding them behind a horizontal scrollbar, where
   nothing on the bar advertises that there is more to the right). A cluster
   never splits across lines: the wrap points are the cluster boundaries. */
.reference-pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    flex-wrap: wrap;
    min-width: 0;
    padding: 5px 8px;
    /* A single cluster wider than the pane still scrolls rather than being
       clipped: kept as the last resort, not the normal case. */
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    border-bottom: 1px solid var(--border-color);
    background: var(--panel-bg);
}
/* The full-width scrollbar is taller than the row it would sit in. */
.reference-pdf-toolbar::-webkit-scrollbar {
    height: 4px;
}
.reference-pdf-toolbar::-webkit-scrollbar-thumb {
    border-radius: 2px;
    background: var(--border-color);
}
/* A cluster of related controls. The groups carry the separators, and nothing
   inside one may wrap either. */
.reference-pdf-toolgroup {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 3px;
    min-width: 0;
}
.reference-pdf-toolgroup + .reference-pdf-toolgroup {
    margin-left: 2px;
    padding-left: 5px;
    border-left: 1px solid var(--border-color);
}
.reference-pdf-button {
    flex: 0 0 auto;
    min-width: 30px;
    padding: 4px 8px;
    font-size: 0.7rem;
}
/* Icon-only controls: square and compact, with the name in title/aria-label. */
.reference-pdf-icon-button {
    min-width: 26px;
    padding: 3px 5px;
    font-size: 0.78rem;
    line-height: 1;
}
/* A word button that has to fit in the row: the same control, tighter padding,
   so a label like "Extract" cannot force the toolbar to scroll. */
.reference-pdf-compact {
    padding: 3px 7px;
    font-size: 0.68rem;
}
.reference-pdf-button[disabled] {
    cursor: not-allowed;
    opacity: 0.4;
}
/* The annotate switch and the enabled undo/redo buttons read as "on" rather
   than merely enabled. */
.reference-pdf-button.active {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}
.reference-pdf-zoom-label {
    flex: 0 0 auto;
    min-width: 40px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    white-space: nowrap;
}
.reference-pdf-search-status {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reference-pdf-search-nav {
    flex: 0 0 auto;
    min-width: 24px;
    padding: 3px 6px;
    font-size: 0.78rem;
    line-height: 1;
}
.reference-pdf-search-nav:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}
/* Floating layers. The find bar, the Tools menu and the text composer open as
   panels *below* their trigger, in the viewer's own layer rather than in the
   toolbar. That is the whole fix for the jitter: the row is a horizontal scroll
   container whose children are laid out left to right, so a panel that grew
   inside it moved every button after it. A panel here shares no flow with the
   row and cannot move a single control. */
.reference-pdf-float-panel {
    position: absolute;
    z-index: 100;
    max-width: min(420px, calc(100% - 12px));
    overflow: auto;
    padding: 9px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--panel-bg);
    box-shadow: 0 12px 30px rgba(0,0,0,0.45);
    font-size: 0.72rem;
}
.reference-pdf-search-popover {
    width: min(360px, calc(100% - 12px));
}
.reference-pdf-tools-menu {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: min(240px, calc(100% - 12px));
    padding: 6px;
}
.reference-pdf-menu-section {
    padding: 5px 6px 2px;
    color: var(--text-muted);
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.reference-pdf-menu-item {
    display: block;
    width: 100%;
    padding: 5px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-main);
    font-size: 0.72rem;
    text-align: left;
    cursor: pointer;
}
.reference-pdf-menu-item:hover,
.reference-pdf-menu-item:focus-visible {
    border-color: var(--accent-blue);
    background: rgba(56,189,248,0.16);
}
.reference-pdf-menu-item[disabled] {
    cursor: not-allowed;
    opacity: 0.45;
}
/* The page tools keep their single-line cluster inside the menu, one row per
   operation, because the menu is a column. */
.reference-pdf-tools-menu .reference-pdf-pageops,
.reference-pdf-tools-menu .reference-pdf-library {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding-left: 0;
    border-left: none;
}
/* The find controls stay one small row inside the panel: the panel is as wide as
   it wants to be, so unlike the toolbar it has room for them. */
.reference-pdf-search-box {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}
/* Text insertion: where the composer is and what it is for. */
.reference-pdf-text-hint {
    position: absolute;
    z-index: 100;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    padding: 6px 12px;
    border: 1px solid var(--accent-blue);
    border-radius: 999px;
    background: rgba(15,23,42,0.92);
    color: #e2e8f0;
    font-size: 0.7rem;
    /* It floats over the canvas: it is a hint, never a click target. */
    pointer-events: none;
}
.reference-pdf-text-composer {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: min(280px, calc(100% - 12px));
}
.reference-pdf-text-where {
    color: var(--text-muted);
    font-size: 0.66rem;
}
.reference-pdf-text-input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 7px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.74rem;
    resize: vertical;
}
.reference-pdf-text-field {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.66rem;
}
.reference-pdf-text-field select,
.reference-pdf-text-field input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 3px 5px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.7rem;
}
.reference-pdf-text-field input[type="color"] {
    padding: 0;
    height: 22px;
}
.reference-pdf-text-actions {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 2px;
}
/* Both drawing modes (text placement and box redaction) make the page itself the
   target, so the selectable text layer steps aside while either is armed. */
.reference-pdf-pages.text-mode,
.reference-pdf-pages.redact-box-mode,
.reference-pdf-pages.image-place-mode {
    cursor: crosshair;
}
.reference-pdf-pages.text-mode .reference-pdf-text-layer,
.reference-pdf-pages.text-mode .reference-pdf-text-layer span,
.reference-pdf-pages.redact-box-mode .reference-pdf-text-layer,
.reference-pdf-pages.redact-box-mode .reference-pdf-text-layer span,
.reference-pdf-pages.image-place-mode .reference-pdf-text-layer,
.reference-pdf-pages.image-place-mode .reference-pdf-text-layer span {
    cursor: crosshair;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}
/* The rectangle the reader drags for a redaction: in the viewer's layer, above
   the pages and below the floating panels, and never a click target itself. */
.reference-pdf-redact-box {
    position: absolute;
    z-index: 90;
    border: 1px dashed #f43f5e;
    border-radius: 1px;
    background: rgba(244, 63, 94, 0.28);
    pointer-events: none;
}
.reference-pdf-search {
    flex: 0 1 180px;
    min-width: 96px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.72rem;
}
/* A selection badge is a count, not a placeholder: it exists only while there
   is something to count. */
.reference-pdf-selection-status,
.reference-pdf-pageop-status {
    flex: 0 0 auto;
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}
.reference-pdf-selection-status:empty,
.reference-pdf-pageop-status:empty {
    display: none;
}
.reference-pdf-outline {
    background: var(--panel-bg);
    color: var(--text-main);
}
.reference-pdf-workspace {
    display: flex;
    flex: 1 1 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    overflow-y: hidden;
    flex-direction: row;
    align-items: stretch;
}
#admin-file-modal-body > .reference-pdf-viewer {
    width: 100%;
    height: 100%;
}
.reference-pdf-thumbnails {
    display: flex;
    position: relative;
    flex: 0 0 96px;
    flex-direction: column;
    gap: 7px;
    min-height: 0;
    padding: 8px 6px;
    overflow-y: auto;
    background: #202630;
    border-right: 1px solid rgba(255,255,255,0.12);
}
.reference-pdf-thumbnail {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: #d1d5db;
    font-size: 0.64rem;
}
.reference-pdf-thumbnail:hover {
    border-color: var(--accent-blue);
    background: rgba(56,189,248,0.14);
}
.reference-pdf-thumbnail.selected {
    border-color: var(--accent-blue);
    background: rgba(56,189,248,0.22);
}
/* The page being read: a ring of its own, so it never reads as a selection
   (that is blue) and the rail can show both at once. */
.reference-pdf-thumbnail.active-page {
    box-shadow: inset 0 0 0 2px #facc15;
}
/* Native drag reordering of the rail. The thumbnails in flight fade so the gap
   they will leave is visible, and the hovered edge carries the insertion line
   the drop will land on. The rail itself picks up a dashed outline so it reads
   as the drop zone before a thumbnail is hovered. */
.reference-pdf-thumbnails.drop-active {
    outline: 1px dashed var(--accent-blue);
    outline-offset: -3px;
}
.reference-pdf-thumbnail {
    cursor: grab;
}
.reference-pdf-thumbnail.dragging {
    opacity: 0.4;
    cursor: grabbing;
}
.reference-pdf-thumbnail.drop-before,
.reference-pdf-thumbnail.drop-after {
    position: relative;
}
.reference-pdf-thumbnail.drop-before::before,
.reference-pdf-thumbnail.drop-after::after {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 2px;
    background: var(--accent-blue);
    box-shadow: 0 0 6px rgba(56,189,248,0.8);
    /* The line is a landmark, never a target: it must not swallow the drop, and
       it must not swallow the clicks on the tools it sits beside. */
    pointer-events: none;
    content: "";
}
.reference-pdf-thumbnail.drop-before::before {
    top: -5px;
}
.reference-pdf-thumbnail.drop-after::after {
    bottom: -5px;
}
.reference-pdf-thumbnail-jump {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    text-align: center;
    cursor: pointer;
    user-select: none;
}
.reference-pdf-thumbnail-canvas {
    display: block;
    width: 76px;
    min-height: 28px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
/* The per-page tools sit in a cross, one slot each: Insert above the centre,
   Rotate in it, ▲/▼ either side, Blank page below. Five controls per page is a lot
   of ink over a long document, so the row is dimmed until the thumbnail is
   hovered, one of its tools has focus, or the page is selected — and it is a
   layout, never a hidden layer: every control stays in the DOM, reachable by
   keyboard and by touch, at the same place every time. */
.reference-pdf-thumbnail-tools {
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: repeat(3, 1fr);
    align-items: center;
    justify-items: center;
    gap: 1px;
    width: 100%;
    opacity: 0.55;
    transition: opacity 0.12s ease;
}
.reference-pdf-thumbnail:hover .reference-pdf-thumbnail-tools,
.reference-pdf-thumbnail.selected .reference-pdf-thumbnail-tools,
.reference-pdf-thumbnail-tools:focus-within {
    opacity: 1;
}
.reference-pdf-thumbnail-tool[data-slot="insert"] { grid-area: 1 / 2 / 2 / 3; }
.reference-pdf-thumbnail-tool[data-slot="up"] { grid-area: 2 / 1 / 3 / 2; }
.reference-pdf-thumbnail-tool[data-slot="rotate"] { grid-area: 2 / 2 / 3 / 3; }
.reference-pdf-thumbnail-tool[data-slot="down"] { grid-area: 2 / 3 / 3 / 4; }
.reference-pdf-thumbnail-tool[data-slot="blank"] { grid-area: 3 / 2 / 4 / 3; }
/* Bringing pages in reads as the opposite of ▲/▼ moving *this* page, so it is
   tinted like the other additive tools. */
.reference-pdf-thumbnail-tool.reference-pdf-thumbnail-insert {
    border-color: rgba(56,189,248,0.45);
}
.reference-pdf-thumbnail-tool {
    flex: 0 0 auto;
    min-width: 18px;
    padding: 1px 3px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--panel-bg);
    color: #d1d5db;
    font-size: 0.62rem;
    line-height: 1.3;
    cursor: pointer;
}
.reference-pdf-thumbnail-tool:hover {
    border-color: var(--accent-blue);
    color: #fff;
}
.reference-pdf-thumbnail-tool[aria-pressed="true"] {
    border-color: var(--accent-blue);
    background: rgba(56,189,248,0.28);
    color: #fff;
}
/* The thumbnail rail stays dark in light theme, but its tool buttons use the
   light panel background. Give their icons enough contrast in every state. */
body.light-theme .reference-pdf-thumbnail-tools {
    opacity: 1;
}
body.light-theme .reference-pdf-thumbnail-tool,
body.light-theme .reference-pdf-thumbnail-tool:hover,
body.light-theme .reference-pdf-thumbnail-tool[aria-pressed="true"] {
    color: #0f172a;
}
body.light-theme .reference-pdf-thumbnail-tool[aria-pressed="true"] {
    background: #dbeafe;
}
/* Page operations (rotate / move / extract / insert / delete). A cluster like
   the others: one line, never wrapped. */
.reference-pdf-pageops {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 3px;
    min-width: 0;
}
/* The primary tools, standalone on the bar: Add text, Optimize, Burn notes and
   Stamp. One line, like every other cluster — the row wraps around clusters,
   never inside one. Redaction is not here: the selected passage is redacted from
   the floating card over it, and the drawn box from Tools ▾. */
.reference-pdf-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 3px;
    min-width: 0;
}
.reference-pdf-pageops.busy {
    opacity: 0.6;
}
/* .reference-pdf-pageop-status is styled with the other selection badge above
   (the two report the same kind of thing and were drifting apart). */
/* Library housekeeping inside the Tools menu (metadata sync and friends). Kept
   visually apart from the page tools because it does not act on the thumbnail
   selection. */
.reference-pdf-library {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 3px;
    min-width: 0;
}
.reference-pdf-optimize {
    border-color: var(--accent-blue);
}
.reference-pdf-maintenance-status {
    /* Last in the row and shrinkable: a status line can only ever appear at the
       end of it, never push a control the reader is aiming at. */
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.7rem;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.reference-pdf-maintenance-status:empty {
    display: none;
}
/* The metadata sync reports under the inspector, where the button lives. */
.ref-metadata-sync-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}
.ref-metadata-sync-status {
    display: block;
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.3;
}
.ref-metadata-sync-status:empty {
    display: none;
}
/* The library-insert panel that used to float over the rail is gone: inserting
   a PDF now happens on the thumbnail of the page it goes after, through the
   reader's own file picker. */
/* Annotation burn-in and stamping (Phase 3). Each button is tinted for what it
   does to the file: burn is additive and marked with the highlight yellow it
   draws and stamping is a normal edit. Redaction destroys text instead of adding
   it, so its one non-card control — the menu entry that arms the drag box — is
   tinted red to say so. */
.reference-pdf-burn {
    border-color: rgba(250,204,21,0.55);
}
.reference-pdf-stamp {
    border-color: var(--accent-blue);
}
.reference-pdf-redact-area {
    color: #f87171;
}
.reference-pdf-stamp-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* Same floating shape as the insert panel: the rail is far too narrow to
       hold a form, so the dialog overlays the page column. */
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 40;
    width: min(280px, 60vw);
    padding: 10px;
    border: 1px solid var(--accent-blue);
    border-radius: 6px;
    background: var(--panel-bg);
    color: var(--text-main);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    font-size: 0.72rem;
}
.reference-pdf-stamp-title {
    font-weight: 600;
    color: var(--accent-blue);
}
.reference-pdf-stamp-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.reference-pdf-stamp-field > span {
    color: var(--text-muted);
    font-size: 0.68rem;
}
.reference-pdf-stamp-field input,
.reference-pdf-stamp-field select {
    min-width: 0;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: rgba(128,128,128,0.08);
    color: var(--text-main);
    font-size: 0.72rem;
}
.reference-pdf-stamp-check {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;
    cursor: pointer;
}
.reference-pdf-stamp-hint {
    color: var(--text-muted);
    line-height: 1.35;
}
.reference-pdf-stamp-actions {
    display: flex;
    gap: 6px;
}
.reference-pdf-pages {
    display: flex;
    flex: 1 1 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 18px;
    overflow: auto;
    overflow-y: auto;
    /* Reserve the scrollbar so fit-width math stays stable when the content
       height (and therefore the scrollbar) appears or disappears. */
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}
.reference-pdf-page {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    /* Width/height are set in px by the viewer's zoom so the canvas and its
       wrapper always match: a cap here (or an inline max-width) would let the
       canvas be clipped by overflow:hidden. */
    min-width: 240px;
    aspect-ratio: 210 / 297;
    background: #fff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    line-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reference-pdf-skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    z-index: 1;
}
.reference-pdf-skeleton-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #94a3b8;
    font-size: 0.78rem;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.reference-pdf-skeleton-shimmer {
    width: 220px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: referencePdfShimmer 1.5s infinite;
}

.reference-pdf-page canvas {
    display: block;
}
.reference-pdf-text-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    line-height: 1;
    user-select: text;
    -webkit-user-select: text;
    pointer-events: auto;
}
.reference-pdf-text-layer span,
.reference-pdf-text-layer br {
    position: absolute;
    color: transparent;
    white-space: pre;
    transform-origin: 0 0;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    pointer-events: auto;
}
.reference-pdf-text-layer span::selection {
    background: rgba(56,189,248,0.35);
    color: transparent;
}
.reference-pdf-annotation-layer {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}
.reference-pdf-highlight {
    position: absolute;
    padding: 0;
    border: 1px solid rgba(245,158,11,0.8);
    background: rgba(250,204,21,0.32);
    cursor: pointer;
    pointer-events: auto;
}
.reference-pdf-scan-notice {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 4;
    padding: 6px 8px;
    border: 1px solid rgba(245,158,11,0.45);
    border-radius: 5px;
    background: rgba(30,30,30,0.86);
    color: #fde68a;
    font-size: 0.66rem;
    line-height: 1.25;
    text-align: center;
    pointer-events: none;
}
.reference-pdf-highlight.reference-pdf-note-target {
    z-index: 2;
    background: rgba(250,204,21,0.72);
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245,158,11,0.35), 0 0 18px rgba(245,158,11,0.78);
    animation: referenceNoteTargetPulse 1.3s ease-in-out 2;
}
.reference-pdf-page.reference-pdf-note-target {
    outline: 3px solid rgba(245,158,11,0.72);
    outline-offset: 4px;
    animation: referenceNotePagePulse 1.3s ease-in-out 2;
}


.reference-pdf-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    min-height: 100px;
    padding: 20px;
    color: #d1d5db;
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: center;
}
.reference-pdf-message.error {
    color: #fca5a5;
}
.reference-pdf-notes {
    display: flex;
    flex: 0 0 220px;
    min-width: 160px;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
}
.reference-pdf-notes-title {
    flex: 0 0 auto;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-blue);
    font-size: 0.75rem;
    font-weight: 700;
}
.reference-pdf-notes-toolbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    padding: 7px 8px 0;
}
.reference-pdf-notes-filter-label {
    color: var(--text-muted);
    font-size: 0.66rem;
    white-space: nowrap;
}
.reference-pdf-notes-filter,
.reference-pdf-notes-sort {
    min-width: 0;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--input-bg, var(--panel-bg));
    color: var(--text-main);
    font-size: 0.66rem;
}
.reference-pdf-notes-list {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    gap: 7px;
    padding: 8px;
    overflow-y: auto;
}
.reference-pdf-empty-notes {
    padding: 10px 4px;
    color: var(--text-muted);
    font-size: 0.7rem;
    line-height: 1.4;
}
.reference-pdf-note {
    flex: 0 0 auto;
    padding: 7px;
    border: 1px solid var(--border-color);
    border-left: 3px solid rgba(250,204,21,0.75);
    border-radius: 6px;
    background: rgba(128,128,128,0.07);
}
.reference-pdf-note.active {
    border-color: var(--accent-blue);
}
/* A note whose page a page operation removed. It is deliberately kept and
   merely marked, so the quote and comment are never thrown away by accident. */
.reference-pdf-note.orphaned {
    border-left-color: rgba(148,163,184,0.75);
}
.reference-pdf-note.orphaned .reference-pdf-note-page {
    color: var(--text-muted);
    cursor: default;
}
.reference-pdf-note-page {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 0.68rem;
    font-weight: 700;
}
.reference-pdf-note-quote,
.reference-pdf-note-comment {
    margin-top: 4px;
    color: var(--text-main);
    font-size: 0.7rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.reference-pdf-note-quote {
    color: var(--text-muted);
}
.reference-pdf-note-edit,
.reference-pdf-note-delete {
    margin-top: 6px;
    margin-right: 4px;
    padding: 2px 5px;
    border: 1px solid rgba(56,189,248,0.35);
    border-radius: 4px;
    background: rgba(56,189,248,0.1);
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 0.64rem;
}
.reference-pdf-note-delete {
    margin-top: 6px;
    padding: 2px 5px;
    border: 1px solid rgba(239,68,68,0.35);
    border-radius: 4px;
    background: rgba(239,68,68,0.1);
    color: #f87171;
    cursor: pointer;
    font-size: 0.64rem;
}
.reference-pdf-note-comment-editor {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 6px;
}
.reference-pdf-note-comment-input {
    width: 100%;
    min-height: 58px;
    box-sizing: border-box;
    padding: 5px 6px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--input-bg, var(--panel-bg));
    color: var(--text-main);
    font: inherit;
    font-size: 0.7rem;
    line-height: 1.35;
    resize: vertical;
}
.reference-pdf-note-title {
    margin-bottom: 4px;
    color: var(--text-main);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.reference-pdf-note-open {
    margin-top: 6px;
    margin-right: 4px;
    padding: 2px 5px;
    border: 1px solid rgba(16, 185, 129, 0.4);
    border-radius: 4px;
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    cursor: pointer;
    font-size: 0.64rem;
    font-weight: 700;
}
.reference-pdf-note-edit-actions {
    display: flex;
    gap: 5px;
}
.reference-pdf-note-edit-actions button {
    padding: 3px 6px;
    font-size: 0.64rem;
}
.reference-pdf-selection-popover {
    position: fixed;
    z-index: 10020;
    pointer-events: auto;
    width: min(320px, calc(100vw - 16px));
    padding: 9px;
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    background: var(--panel-bg);
    box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}
/* `.hidden` is globally `display:none !important`; this explicit state is
   required when a PDF selection opens the action card. */
.reference-pdf-selection-popover:not(.hidden) {
    display: block !important;
    visibility: visible !important;
}
.reference-pdf-selection-label {
    max-height: 34px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.3;
}
.reference-pdf-selection-popover input {
    width: 100%;
    box-sizing: border-box;
    margin-top: 6px;
    padding: 5px 7px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.7rem;
}
.reference-pdf-selection-actions {
    display: flex;
    /* Four actions now (Highlight / Comment / Redact / Cancel) in a card that is
       at most 320px wide, so they wrap rather than squeezing to nothing. */
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}
.reference-pdf-popover-redact {
    border-color: #f43f5e;
    color: #fda4af;
}
.reference-pdf-selection-actions button {
    padding: 4px 7px;
    font-size: 0.68rem;
}
/* Darker semantic colors remain readable on light panels and button fills. */
body.light-theme .reference-pdf-button.active {
    color: #075985;
}
body.light-theme .reference-pdf-redact-area,
body.light-theme .reference-pdf-popover-redact,
body.light-theme .reference-pdf-note-delete {
    color: #b91c1c;
}
body.light-theme .reference-pdf-note-delete {
    background: #fee2e2;
}
body.light-theme .reference-pdf-note-open {
    background: #dcfce7;
    color: #166534;
}
body.light-theme .reference-pdf-skeleton-inner {
    color: #475569;
}
@media (max-width: 820px) {
    .reference-pdf-thumbnails { flex-basis: 78px; }
    .reference-pdf-thumbnail-canvas { width: 62px; }
}
@media (max-width: 760px) {
    .reference-manager { flex-direction: column !important; overflow-y: auto !important; }
    .reference-manager .ref-library-pane,
    .reference-manager .ref-assistant-pane { width: 100% !important; flex: 0 0 auto !important; }
    .reference-manager .ref-library-pane { min-height: 56vh; }
    .reference-manager .ref-assistant-pane { min-height: 44vh; }
    .reference-manager #ref-pdf-inline-container { min-height: 240px; }
    /* Stacked layout: maximizing has nothing to reclaim and hiding the
       assistant would strand the AI answers, so drop the control. */
    .reference-pdf-window-button-maximize { display: none !important; }
}
@media (max-width: 620px) {
    /* The toolbar never wraps (see the nowrap rule above): a narrow viewer
       scrolls it, and the find bar stays collapsed behind its button until it
       is wanted. Only the spacing tightens here. */
    .reference-pdf-toolbar { gap: 3px; padding: 4px 6px; }
    .reference-pdf-toolgroup + .reference-pdf-toolgroup { padding-left: 4px; }
}

/* Legacy file-window sizing remains available for non-reference files. */
#admin-file-modal.reference-pdf-modal {
    padding: 48px;
    align-items: center;
    justify-content: center;
}
#admin-file-modal.reference-pdf-modal .reference-pdf-modal-card,
#admin-file-modal.reference-pdf-modal .admin-window-card {
    width: min(1180px, 92vw);
    height: min(820px, 88vh);
    max-width: 1180px;
    max-height: 88vh;
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
}
#admin-file-modal.reference-pdf-modal #admin-file-modal-body {
    align-items: stretch;
    justify-content: stretch;
}
/* The maximize control owns the full-screen transition for Reference PDFs;
   the normal state above remains a centered, usable reading window. */
#admin-file-modal.reference-pdf-modal.reference-pdf-maximized {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
}
#admin-file-modal.reference-pdf-modal.reference-pdf-maximized .admin-window-card.maximized {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
}
#admin-file-modal.reference-pdf-modal.minimized-backdrop {
    padding: 0;
}
#admin-file-modal.reference-pdf-modal.minimized-backdrop .admin-window-card.minimized {
    width: 320px !important;
    height: 48px !important;
}
.reference-pdf-page-count {
    flex: 0 0 auto;
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}
.reference-pdf-pages {
    width: 100%;
    align-items: center;
}
.reference-pdf-page {
    margin-inline: auto;
}

/* Dropdown Menu Styling */
.latex-insert-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--panel-bg, #1e1e2e);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
    border-radius: 8px;
    padding: 6px 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    z-index: 9999;
    display: flex;
    flex-direction: column;
}

.latex-insert-menu.hidden {
    display: none !important;
}

.latex-insert-menu-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #a1a1aa);
    padding: 4px 12px 6px 12px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    margin-bottom: 4px;
}

.latex-insert-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 7px 12px;
    font-size: 0.82rem;
    color: var(--text-main, #e4e4e7);
    cursor: pointer;
    transition: background 0.12s ease;
    white-space: nowrap;
}

.latex-insert-menu button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent-blue, #38bdf8);
}

/* ==========================================================================
   Toolbar dropdown flyout menus (hover-retained, zero dead-zone).
   Wrappers carry `.latex-dropdown` (see index.html action bar). The menu sits
   flush under its trigger (top: 100%, no gap) and an invisible ::before
   bridge covers the seam so the pointer never leaves hover bounds moving
   from button into the list. JS toggles `.visible` alongside `.hidden`;
   either state works standalone.
   ========================================================================== */
.latex-dropdown {
    position: relative;
    display: inline-block;
}
.latex-dropdown > .latex-insert-menu {
    top: 100%;
    margin-top: 0;
    padding-top: 6px;
    background-clip: padding-box;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    border-radius: 6px;
    z-index: 1000;
}
.latex-dropdown > .latex-insert-menu::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
    background: transparent;
}
.latex-insert-menu.visible {
    display: flex !important;
}
.toolbar-dropdown-btn.active,
#latex-insert-btn.active,
#latex-layout-btn.active {
    outline: 1px solid var(--accent-blue, #38bdf8);
    outline-offset: -1px;
}

/* ==========================================================================
   💬 Chat tab — WhatsApp-style thread, bubbles, and conversation list
   Scoped to #view-chat so other tabs (AI agent, research) are untouched.
   Fully themed: all colors resolve through --wa-* custom properties, which
   the body.light-theme block below redefines for the bright theme.
   ========================================================================== */



/* Thread background: "doodle" dot pattern like WhatsApp's chat wallpaper */
#view-chat #chat-messages {
    background-color: var(--wa-chat-bg);
    background-image:
        radial-gradient(var(--wa-chat-dot-1) 1.1px, transparent 1.4px),
        radial-gradient(var(--wa-chat-dot-2) 1.1px, transparent 1.4px),
        radial-gradient(var(--wa-chat-dot-3) 1.4px, transparent 1.7px);
    background-size: 34px 34px, 22px 22px, 58px 58px;
    background-position: 0 0, 11px 17px, 6px 29px;
    padding: 18px 7% 24px;
}

/* Bubbles */
.wa-row { display: flex; margin-bottom: 3px; align-items: flex-end; }
.wa-row.mine { justify-content: flex-end; }
.wa-row.theirs { justify-content: flex-start; }
.wa-row.has-avatar { margin-top: 10px; }

.wa-avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700;
    color: var(--wa-avatar-text);
    margin: 0 8px 2px 0; user-select: none;
    box-shadow: var(--wa-avatar-shadow);
}

.wa-bubble {
    position: relative;
    max-width: 65%;
    min-width: 92px;
    padding: 6px 9px 8px;
    border-radius: 9px;
    font-size: 0.92rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: var(--wa-shadow);
    color: var(--wa-bubble-in-text);
}
.wa-row.theirs .wa-bubble { background: var(--wa-bubble-in); border-top-left-radius: 0; }
.wa-row.mine  .wa-bubble { background: var(--wa-bubble-out); border-top-right-radius: 0; color: var(--wa-bubble-out-text); }

/* Speech-bubble tails (only on the first bubble of a group) */
.wa-bubble.tail-left::before,
.wa-bubble.tail-right::before {
    content: "";
    position: absolute;
    top: 0;
    width: 10px;
    height: 14px;
}
.wa-bubble.tail-left::before {
    left: -9px;
    background: var(--wa-tail-in);
    clip-path: polygon(100% 0, 100% 100%, 0 0);
    border-top-left-radius: 3px;
}
.wa-bubble.tail-right::before {
    right: -9px;
    background: var(--wa-tail-out);
    clip-path: polygon(0 0, 0 100%, 100% 0);
    border-top-right-radius: 3px;
}

/* Sender name inside group bubbles */
.wa-sender {
    display: block;
    font-size: 0.76rem;
    font-weight: 700;
    margin-bottom: 1px;
    color: var(--accent-blue);
}

/* Inline meta (time + ticks) inside the bubble tail */
.wa-meta {
    float: right;
    margin: 8px 0 -4px 10px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.64rem;
    color: var(--wa-meta-out);
    user-select: none;
    line-height: 1;
    transform: translateY(4px);
}
.wa-row.theirs .wa-meta { color: var(--wa-meta-in); }
.wa-meta .wa-ticks { font-weight: 700; letter-spacing: -2px; font-size: 0.72rem; }
.wa-meta .wa-ticks.seen { color: var(--wa-tick-seen); }
.wa-meta .wa-edited { font-style: italic; letter-spacing: 0; }

/* Hover action menu — floating pill just above the bubble's top corner so it
   never overlaps the message text (top-right for own messages, top-left
   for others'). */
.wa-actions {
    position: absolute;
    top: -16px;
    display: none;
    gap: 2px;
    background: var(--wa-menu-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1px 3px;
    z-index: 5;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.wa-row:hover .wa-actions { display: inline-flex; }
.wa-actions button {
    background: transparent; border: none; cursor: pointer;
    font-size: 0.68rem; padding: 2px 4px; border-radius: 8px; line-height: 1;
    color: var(--wa-menu-text);
}
.wa-actions button:hover { background: var(--wa-menu-hover); }
.wa-row.mine .wa-actions { right: -4px; left: auto; }
.wa-row.theirs .wa-actions { left: -4px; right: auto; }

/* Date divider pills */
.wa-date {
    align-self: center;
    margin: 14px 0 10px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--wa-pill-bg);
    color: var(--wa-pill-text);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    box-shadow: var(--wa-shadow);
    user-select: none;
}
.wa-date.today { color: var(--wa-tick-seen); }

/* System / deleted notices */
.wa-system {
    align-self: center;
    margin: 10px 0;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--wa-pill-soft-bg);
    color: var(--wa-pill-soft-text);
    font-size: 0.78rem;
    font-style: italic;
}

/* Deleted-message body inside a bubble */
.wa-deleted { font-style: italic; color: var(--wa-deleted-text) !important; font-size: 0.86rem; }

/* Attachment chip inside bubbles */
.wa-attachment {
    margin-top: 6px;
    padding: 7px 10px;
    border-radius: 8px;
    background: var(--wa-att-bg);
    border: 1px solid var(--wa-att-border);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    clear: both;
}
.wa-attachment:hover { background: var(--wa-att-bg-hover); }
.wa-attachment .wa-att-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: 0.8rem; color: var(--wa-att-name);
}
.wa-attachment .wa-att-size,
.wa-image-caption .wa-att-size {
    font-size: 0.66rem; color: var(--wa-att-size); flex-shrink: 0;
}
.wa-attachment .wa-att-dl {
    background: none;
    border: none;
    color: var(--wa-att-size);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 6px;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}
.wa-attachment .wa-att-dl:hover { background: var(--wa-menu-hover); color: var(--wa-att-name); }

/* Quoted reply block inside bubbles (WhatsApp style) */
.wa-quote {
    margin: 2px 0 6px;
    padding: 6px 10px;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.18);
    border-left: 3px solid var(--accent-blue);
    cursor: pointer;
    clear: both;
}
.wa-quote-sender { font-size: 0.7rem; font-weight: 700; color: var(--accent-blue); }
.wa-quote-text {
    font-size: 0.76rem; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px;
}

/* Forwarded label above forwarded message content */
.wa-forwarded { font-size: 0.7rem; font-style: italic; color: var(--text-muted); margin-bottom: 2px; }

/* Jump-to-quote flash on the target row */
.wa-row.wa-flash .wa-bubble { animation: waFlash 1.6s ease; }


/* Image bubbles — WhatsApp-style inline photo */
.wa-bubble.wa-bubble-image { padding: 4px; min-width: 140px; }
.wa-image { position: relative; width: min(320px, 52vw); }
.wa-image-frame {
    position: relative;
    border-radius: 7px;
    overflow: hidden;
    background: var(--wa-image-frame-bg);
    cursor: zoom-in;
    min-height: 90px;
}
.wa-image-frame img {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.wa-image-frame img.loaded { opacity: 1; }
.wa-image-loading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center; gap: 5px;
}
.wa-image-loading span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--wa-att-size);
    animation: waTypingBlink 1.2s infinite ease-in-out;
}
.wa-image-loading span:nth-child(2) { animation-delay: 0.2s; }
.wa-image-loading span:nth-child(3) { animation-delay: 0.4s; }
.wa-image-frame img.loaded + .wa-image-loading { display: none; }
.wa-image-caption {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 6px 2px;
    font-size: 0.72rem;
}
.wa-image-caption .wa-att-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--wa-caption-text);
}
.wa-row.theirs .wa-image-caption .wa-att-name { color: var(--wa-caption-text-in); }
.wa-image-actions {
    position: absolute; top: 8px; right: 8px;
    display: none; gap: 2px;
    background: var(--wa-menu-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1px 3px;
    z-index: 5;
}
.wa-image:hover .wa-image-actions { display: inline-flex; }
.wa-image-actions button {
    background: transparent; border: none; cursor: pointer;
    font-size: 0.72rem; padding: 2px 5px; border-radius: 8px; line-height: 1;
    color: var(--wa-menu-text);
}
.wa-image-actions button:hover { background: var(--wa-menu-hover); }

/* Right sidebar — Files / Members tab bar (same 56px header height and
   button styling as the 💬 Chats header on the left) */
.wa-side-tabs { flex-shrink: 0; }
.wa-side-tab {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    background: var(--accent-gradient);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.2s;
    white-space: nowrap;
}
.wa-side-tab:hover { opacity: 0.92; transform: translateY(-1px); }
.wa-side-tab.active { opacity: 1; transform: none; }
.wa-side-tab:not(.active) {
    background: var(--hover-bg);
    color: var(--text-main);
    border-color: var(--border-color);
}
.wa-side-tab:not(.active):hover {
    background: rgba(56, 189, 248, 0.15);
    transform: none;
    opacity: 1;
}
.wa-side-panel { display: none; }
.wa-side-panel.active { display: flex; }

/* Files-panel drop target: dashed inner outline + tinted surface while a
   drag hovers over it. Also used briefly as an "uploading" indicator. */
#chat-side-tab-files-panel.wa-drop-active {
    outline: 2px dashed var(--accent-blue);
    outline-offset: -6px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.08);
}
#chat-side-tab-files-panel.wa-drop-active::after {
    content: "Drop to share with this chat";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--wa-menu-bg);
    color: var(--wa-menu-text);
    font-size: 0.78rem;
    font-weight: 600;
    box-shadow: var(--wa-shadow);
    pointer-events: none;
    white-space: nowrap;
    z-index: 3;
}

/* Conversation list — WhatsApp-like rows */
#view-chat .chat-item { padding: 10px 12px; gap: 2px; }
#view-chat .chat-item .wa-conv-name {
    font-weight: 600; font-size: 0.88rem; color: var(--text-main);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#view-chat .chat-item .wa-conv-snippet {
    font-size: 0.74rem; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#view-chat .chat-item .wa-conv-time {
    font-size: 0.66rem; color: var(--text-muted); flex-shrink: 0;
    align-self: flex-start; margin-top: 2px;
}
#view-chat .chat-item.active { background: var(--wa-conv-active-bg); }
#view-chat .chat-item.active .wa-conv-time { color: var(--wa-conv-active-time); }

/* Typing indicator — animated dots */
.wa-typing-dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.wa-typing-dots span {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--text-muted);
    animation: waTypingBlink 1.2s infinite ease-in-out;
}
.wa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }


/* Composer — rounded pill like WhatsApp's input */
#view-chat #chat-input {
    border-radius: 999px !important;
    background: var(--wa-composer-bg) !important;
    border: 1px solid transparent !important;
    padding: 10px 16px !important;
}
#view-chat #chat-input:focus { border-color: var(--wa-composer-focus) !important; outline: none; }
#view-chat #chat-composer .btn-primary {
    border-radius: 50% !important;
    width: 42px; height: 42px;
    padding: 0 !important;
    font-size: 1.05rem !important;
    background: var(--wa-send-bg) !important;
    border-color: var(--wa-send-bg) !important;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
#view-chat #chat-composer .btn-primary:hover { background: var(--wa-send-bg-hover) !important; }

/* ==========================================================================
   ☀️ Light theme — bright-mode variants for every chat surface.
   body.light-theme redefines the --wa-* custom properties only; the layout
   rules above never change. Greens darken for contrast on white, and the
   incoming bubble / wallpaper flip to light grays with dark ink.
   ========================================================================== */
body.light-theme {
    /* Wallpaper: WhatsApp's classic warm-gray light paper */
    --wa-chat-bg: #efeae2;
    --wa-chat-dot-1: rgba(11, 20, 26, 0.05);
    --wa-chat-dot-2: rgba(11, 20, 26, 0.035);
    --wa-chat-dot-3: rgba(2, 132, 199, 0.05);
    /* Bubbles: dark ink on pale green out, white in */
    --wa-bubble-out: #d9fdd3;
    --wa-bubble-out-text: #111b21;
    --wa-bubble-in: #ffffff;
    --wa-bubble-in-text: #111b21;
    --wa-tail-out: #d9fdd3;
    --wa-tail-in: #ffffff;
    /* Meta: readable gray ink on the pale bubbles */
    --wa-meta-out: rgba(17, 27, 33, 0.45);
    --wa-meta-in: rgba(17, 27, 33, 0.45);
    --wa-tick-seen: #0284c7;
    /* Pills: solid light-surface chips with dark text */
    --wa-pill-bg: rgba(255, 255, 255, 0.96);
    --wa-pill-text: #54656f;
    --wa-pill-soft-bg: rgba(255, 255, 255, 0.88);
    --wa-pill-soft-text: #667781;
    /* Menus: white popover surfaces */
    --wa-menu-bg: rgba(255, 255, 255, 0.97);
    --wa-menu-hover: rgba(0, 0, 0, 0.06);
    --wa-menu-text: #111b21;
    /* Attachments: subtle gray recesses */
    --wa-att-bg: rgba(0, 0, 0, 0.05);
    --wa-att-bg-hover: rgba(0, 0, 0, 0.09);
    --wa-att-border: rgba(17, 27, 33, 0.1);
    --wa-att-name: #0284c7;
    --wa-att-size: rgba(17, 27, 33, 0.45);
    --wa-image-frame-bg: rgba(0, 0, 0, 0.06);
    --wa-caption-text: rgba(17, 27, 33, 0.7);
    --wa-caption-text-in: rgba(17, 27, 33, 0.7);
    --wa-deleted-text: rgba(17, 27, 33, 0.5);
    /* Avatars: soften shadow on light surfaces */
    --wa-avatar-group: #e2e8f0;
    --wa-avatar-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
    /* Conversation list: pale green active row */
    --wa-conv-active-bg: rgba(0, 168, 132, 0.12);
    --wa-conv-active-time: #0284c7;
    /* Composer: white pill, green send */
    --wa-composer-bg: #ffffff;
    --wa-composer-focus: rgba(0, 168, 132, 0.45);
    --wa-send-bg: #00a884;
    --wa-send-bg-hover: #029877;
    /* Softer shadow for light surfaces */
    --wa-shadow: 0 1px 1.5px rgba(15, 23, 42, 0.18);
}

/* Light-theme-only refinements that variables can't express */

/* Sender names need the darker accent for contrast on white bubbles */
body.light-theme .wa-sender { color: #0284c7; }

/* A hairline inset keeps photos defined on the pale frame */
body.light-theme .wa-image-frame { box-shadow: inset 0 0 0 1px rgba(17, 27, 33, 0.08); }

/* Composer input is a white pill in light mode; keep ink dark */
body.light-theme #view-chat #chat-input { color: var(--text-main); }

/* Typing dots sit on the pale wallpaper in light mode */
body.light-theme .wa-typing-dots span { background: #667781; }

/* Files drop zone: blue tint works on both wallpapers; pill follows theme */
body.light-theme #chat-side-tab-files-panel.wa-drop-active {
    background: rgba(2, 132, 199, 0.06);
}

/* Side tabs: active = accent gradient (white ink, both themes); inactive =
   btn-secondary look which follows the theme's --hover-bg / --border-color. */

/* Collapsible group bubble (folder drops): one message, N files */
#view-chat .wa-group {
    background: var(--wa-bubble-in);
    border-radius: 12px;
    padding: 8px 10px;
    max-width: 320px;
    overflow: hidden;
}
#view-chat .wa-group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 2px 2px 6px 2px;
    user-select: none;
}
#view-chat .wa-group-caret {
    font-size: 0.7rem;
    color: var(--wa-meta-in);
    transition: transform 0.15s ease;
}
#view-chat .wa-group-title {
    font-weight: 600;
    font-size: 0.86rem;
    color: var(--wa-att-name);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#view-chat .wa-group-count {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--wa-meta-in);
    white-space: nowrap;
}
#view-chat .wa-group-list {
    border-top: 1px solid var(--wa-meta-in);
    border-top-color: color-mix(in srgb, var(--wa-meta-in) 30%, transparent);
    max-height: 260px;
    overflow-y: auto;
}
#view-chat .wa-group-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid color-mix(in srgb, var(--wa-meta-in) 18%, transparent);
    cursor: pointer;
}
#view-chat .wa-group-item:hover { background: var(--wa-menu-hover); }
#view-chat .wa-group-item:last-child { border-bottom: none; }
#view-chat .wa-group-item-icon { font-size: 0.9rem; }
#view-chat .wa-group-item .wa-att-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
    color: var(--wa-att-name);
}
#view-chat .wa-group-item .wa-att-size {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--wa-meta-in);
    white-space: nowrap;
}
#view-chat .wa-group-item-dl {
    background: none;
    border: none;
    color: var(--wa-meta-in);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
}
#view-chat .wa-group-item:hover .wa-group-item-dl { opacity: 1; }
#view-chat .wa-group-item-dl:hover { background: var(--wa-menu-hover); }
/* Nested folder row inside a grouped bubble's tree (folder uploads). */
#view-chat .wa-group-dir {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid color-mix(in srgb, var(--wa-meta-in) 18%, transparent);
    cursor: pointer;
    user-select: none;
}
#view-chat .wa-group-dir:hover { background: var(--wa-menu-hover); }
#view-chat .wa-group-dir .wa-group-caret {
    flex-shrink: 0;
    width: 10px;
    text-align: center;
}
#view-chat .wa-group-dir .wa-group-item-icon { font-size: 0.85rem; }
#view-chat .wa-group-dir .wa-att-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--wa-att-name);
}
#view-chat .wa-group-dir .wa-att-size {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--wa-meta-in);
    white-space: nowrap;
}
#view-chat .wa-group-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 6px;
}
#view-chat .wa-group-actions button {
    background: none;
    border: 1px solid color-mix(in srgb, var(--wa-meta-in) 40%, transparent);
    color: var(--wa-att-name);
    border-radius: 14px;
    font-size: 0.72rem;
    padding: 3px 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}
#view-chat .wa-group-actions button:hover { background: var(--wa-menu-hover); }

/* "Connecting…" status pill (chat thread) — shown only while the chat
   WebSocket is down/reconnecting. Styled like WhatsApp's subtle in-chat
   status line: quiet gray text with animated dots, no alarm styling. */
#view-chat #chat-ws-status {
    flex-shrink: 0;
    padding: 4px 22px;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--text-muted);
    background: var(--hover-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 2px;
}

/* ==========================================================================
   LaTeX Studio — Integrations modal (GitHub, Git, Dropbox, ReadCube, Zotero,
   Mendeley). The card grid is rendered generically from GET /api/integrations.
   ========================================================================== */
.integrations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    min-height: 80px;
}
.integrations-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.integrations-card.active { border-color: var(--accent-blue); }
.integrations-card-head { display: flex; align-items: center; gap: 10px; }
.integrations-card-icon { width: 30px; height: 30px; flex: 0 0 30px; }
.integrations-card-titles { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.integrations-card-title { font-size: 0.9rem; font-weight: 700; color: var(--text-main); }
.integrations-card-desc { margin: 0; font-size: 0.76rem; line-height: 1.45; color: var(--text-muted); flex: 1; }
.integrations-card-action { align-self: flex-start; padding: 5px 14px; font-size: 0.78rem; border-radius: 8px; }
.integrations-badge {
    display: inline-block;
    align-self: flex-start;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
}
.integrations-badge-off { color: #9ca3af; background: rgba(148, 163, 184, 0.14); border-color: rgba(148, 163, 184, 0.35); }
.integrations-badge-connected { color: #34d399; background: rgba(16, 185, 129, 0.14); border-color: rgba(16, 185, 129, 0.42); }
.integrations-badge-configured { color: #fbbf24; background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.42); }
.integrations-empty { padding: 18px; text-align: center; font-size: 0.82rem; color: var(--text-muted); grid-column: 1 / -1; }

.integrations-detail {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    background: var(--overlay-mid);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.integrations-detail-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.92rem; font-weight: 700; color: var(--text-main); }
.integrations-detail-provider { display: inline-flex; align-items: center; gap: 8px; }
.integrations-detail-icon { width: 24px; height: 24px; flex: 0 0 24px; }
.integrations-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.integrations-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.76rem; color: var(--text-muted); }
.integrations-field input,
.integrations-field select,
.integrations-field textarea {
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.82rem;
}
.integrations-field textarea {
    min-height: 90px;
    resize: vertical;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 0.76rem;
    line-height: 1.5;
}
.integrations-field-wide { grid-column: 1 / -1; }
.integrations-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.integrations-note {
    font-size: 0.74rem;
    line-height: 1.5;
    color: var(--text-muted);
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--overlay-soft);
    border: 1px solid var(--border-color);
}
.integrations-msg { font-size: 0.76rem; line-height: 1.45; color: #34d399; }
.integrations-msg-error { color: #f87171; }

body.light-theme .integrations-badge-off { color: #475569; background: rgba(100, 116, 139, 0.12); border-color: rgba(100, 116, 139, 0.3); }
body.light-theme .integrations-badge-connected { color: #047857; background: rgba(16, 185, 129, 0.14); border-color: rgba(16, 185, 129, 0.4); }
body.light-theme .integrations-badge-configured { color: #b45309; background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.42); }
body.light-theme .integrations-msg { color: #047857; }
body.light-theme .integrations-msg-error { color: #dc2626; }

.integrations-git-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--overlay-soft);
}
.integrations-git-status {
    font-size: 0.76rem;
    line-height: 1.5;
    color: var(--text-muted);
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    word-break: break-word;
}
.integrations-clone {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.integrations-clone input {
    flex: 1;
    min-width: 160px;
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.82rem;
}
.integrations-detail-actions button[disabled] { opacity: 0.55; cursor: not-allowed; }

/* Outbound connectivity diagnostics. */
.integrations-diagnostics {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--overlay-soft);
}
.integrations-diagnostics button[disabled] { opacity: 0.55; cursor: not-allowed; }
/* Backup action loading state. */
#admin-r2-backup-btn.r2-syncing { opacity: 0.65; cursor: wait; }
.integrations-diagnostics-summary { font-size: 0.74rem; color: var(--text-muted); line-height: 1.45; }
.integrations-diagnostics-results {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 2px;
}
.integrations-diag-row {
    display: grid;
    grid-template-columns: 120px minmax(140px, 1fr) auto auto minmax(120px, 1.4fr);
    gap: 8px;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
}
.integrations-diag-service { color: var(--text-main); font-weight: 600; }
.integrations-diag-host { font-family: 'Fira Code', 'JetBrains Mono', monospace; word-break: break-all; }
.integrations-diag-latency { text-align: right; white-space: nowrap; }
.integrations-diag-msg { word-break: break-word; }
.integrations-diag-chip {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: capitalize;
    white-space: nowrap;
    border: 1px solid transparent;
}
.integrations-diag-ok { color: #34d399; background: rgba(16, 185, 129, 0.14); border-color: rgba(16, 185, 129, 0.42); }
.integrations-diag-blocked { color: #fbbf24; background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.42); }
.integrations-diag-down { color: #f87171; background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.42); }
.integrations-diag-alert {
    font-size: 0.74rem;
    line-height: 1.55;
    color: var(--text-muted);
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid rgba(245, 158, 11, 0.42);
    background: rgba(245, 158, 11, 0.1);
}
.integrations-diag-alert code {
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    color: var(--text-main);
}
.integrations-diag-env {
    margin: 8px 0 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    user-select: all;
}
body.light-theme .integrations-diag-ok { color: #047857; background: rgba(16, 185, 129, 0.14); border-color: rgba(16, 185, 129, 0.4); }
body.light-theme .integrations-diag-blocked { color: #b45309; background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.42); }
body.light-theme .integrations-diag-down { color: #dc2626; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); }
body.light-theme .integrations-diag-alert { color: #7c2d12; background: rgba(245, 158, 11, 0.12); }

/* Persistent Reference Manager banner for background imports/syncs that keep
   running after the Integrations modal closes. */
.ref-task-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    background: var(--overlay-soft);
    color: var(--text-main);
    font-size: 0.8rem;
    text-align: left;
}
.ref-task-banner .ref-task-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ref-task-banner .ref-task-text {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* How far along the run is. Counters alone read as stalled when a task spends
   its time in a phase that reports no progress. */
.ref-task-progress {
    height: 4px;
    border-radius: 999px;
    background: var(--input-bg);
    overflow: hidden;
}
.ref-task-progress.hidden { display: none; }
.ref-task-progress-fill {
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--accent-blue);
    transition: width 0.25s ease;
}
.ref-task-banner #ref-task-cancel {
    flex: 0 0 auto;
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 8px;
}
body.light-theme .ref-task-banner { background: rgba(2, 132, 199, 0.08); }

/* Reference Manager filter row: the search-field, folder, sort and tag
   dropdowns share one width so the row stays aligned whatever their option
   labels are. 0.7x of the original 170px — the search box gets the room. */
.ref-filter-select {
    width: 119px;
    margin-top: 0;
    padding: 6px;
    font-size: 0.8rem;
    background: var(--input-bg);
    color: var(--text-main);
}

/* "My Library" tab: folder management plus moving the ticked references. The
   rows are buttons, so a folder can be opened in the library filter, while
   rename/delete only appear on the folders the user created. */
.ref-folder-manager-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 6px;
}
.ref-folder-manager-title {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.ref-folder-manager-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px 10px;
}
.ref-folder-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--panel-bg);
}
.ref-folder-row.active {
    border-color: var(--accent-blue);
}
.ref-folder-open {
    flex: 1 1 auto;
    min-width: 0;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--text-main);
    font-size: 0.78rem;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-folder-open:hover {
    color: var(--accent-blue);
}
.ref-folder-count {
    flex: 0 0 auto;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--text-muted);
    font-size: 0.68rem;
}
.ref-folder-row-action {
    flex: 0 0 auto;
    padding: 3px 7px;
    border-radius: 6px;
    font-size: 0.7rem;
}
.ref-folder-move {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}
.ref-folder-move-label {
    flex: 0 0 auto;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.ref-folder-move select {
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
    padding: 5px;
    font-size: 0.74rem;
}
body.light-theme .ref-folder-row { background: #ffffff; }

/* An actionable toast (the move's Undo) keeps the message and the button on one
   line, with the button reading as the affordance rather than as body text. */
.ref-toast-action {
    flex: 0 0 auto;
    padding: 4px 10px;
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    background: transparent;
    color: var(--accent-blue);
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
}
.ref-toast-action:hover {
    background: var(--accent-blue);
    color: #ffffff;
}

/* Dragging library rows onto a folder. The manager announces itself as a drop
   zone while a row is in flight, and the hovered folder takes the highlight. */
.ref-library-item.ref-dragging {
    opacity: 0.45;
    cursor: grabbing;
}
/* The chip that follows the pointer. It replaces the browser's snapshot of the
   whole card, which covered the folder list the pointer has to aim at. */
.ref-drag-ghost {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 0.8rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.ref-drag-ghost-count {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-blue);
}
.ref-folder-manager-list.drop-active .ref-folder-row {
    border-style: dashed;
    border-color: var(--accent-blue);
}
.ref-folder-row.drop-target {
    border-style: solid;
    border-color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.12);
}
body.light-theme .ref-folder-row.drop-target { background: rgba(2, 132, 199, 0.12); }

/* LaTeX math hover preview and action menu. */
.latex-math-hover {
    position: fixed;
    z-index: 1400;
    width: max-content;
    max-width: min(460px, calc(100vw - 24px));
    max-height: min(60vh, 520px);
    overflow: visible;
    color: var(--text-main);
    background: var(--popover-bg);
    border: 1px solid var(--accent-blue);
    border-radius: 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
}
.latex-math-hover-menu-wrap {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 10;
}
.latex-math-hover-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-main);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.latex-math-hover-menu-button:hover,
.latex-math-hover-menu-button:focus-visible {
    border-color: var(--border-color);
    background: var(--hover-bg);
    outline: none;
}
.latex-math-hover-menu {
    position: absolute;
    z-index: 1;
    top: calc(100% + 5px);
    right: 0;
    display: flex;
    flex-direction: column;
    min-width: 190px;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--popover-bg);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
}
.latex-math-hover-menu button {
    padding: 8px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text-main);
    font-size: 0.78rem;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}
.latex-math-hover-menu button:hover,
.latex-math-hover-menu button:focus-visible { background: var(--hover-bg); outline: none; }
.latex-math-hover-preview {
    box-sizing: border-box;
    font-family: "KaTeX_Main", "Times New Roman", serif;
    font-synthesis: none;
    max-width: 100%;
    max-height: min(48vh, 420px);
    overflow-x: auto;
    overflow-y: auto;
    padding: 10px 36px 10px 12px;
    color: var(--text-main);
    font-size: 0.9em;
    white-space: nowrap;
    scroll-behavior: smooth;
}
.latex-math-hover-preview.display { min-width: 180px; text-align: left; }
.latex-math-hover-preview.display .katex-display { padding-right: 24px; }
.latex-math-hover-preview .katex-display,
.latex-math-hover-export .katex-display { margin: 0; text-align: left; }
.latex-math-hover-preview .katex,
.latex-math-hover-export .katex {
    font-family: "KaTeX_Main", "Times New Roman", serif !important;
    font-synthesis: none;
    font-kerning: normal;
    text-rendering: auto;
}
.latex-math-hover-preview .katex .mathnormal,
.latex-math-hover-preview .katex .mathit,
.latex-math-hover-export .katex .mathnormal,
.latex-math-hover-export .katex .mathit { font-family: "KaTeX_Math", "Times New Roman", serif !important; }
.latex-math-hover-preview .katex .amsrm,
.latex-math-hover-preview .katex .mathbb,
.latex-math-hover-export .katex .amsrm,
.latex-math-hover-export .katex .mathbb { font-family: "KaTeX_AMS", "Times New Roman", serif !important; }
.latex-math-hover-export {
    position: fixed;
    z-index: 0;
    top: 0;
    left: 0;
    opacity: 0;
    visibility: visible;
    pointer-events: none;
    width: max-content;
    max-width: none;
    isolation: isolate;
    padding: 16px;
    overflow: visible;
    color: #111827;
    background: transparent;
    font-size: 20px;
}
.latex-math-hover-export .katex-display { margin: 0; }
@media (max-width: 520px) {
    .latex-math-hover { max-width: calc(100vw - 24px); }
    .latex-math-hover-menu { right: 0; max-width: calc(100vw - 32px); }
    .latex-math-hover-preview { max-width: calc(100vw - 26px); padding: 9px 34px 9px 10px; }
}

}

/* ------------------------------------------------------------------------
   Unscoped overrides.

   The PDF viewer moves its selection card to <body>, where @scope
   (#view-library) no longer matches it — without these rules the card had no
   background and its Highlight / Comment / Redact labels rendered as default
   black text on the dark page.
   ------------------------------------------------------------------------ */
.reference-pdf-selection-popover {
    position: fixed;
    z-index: 10020;
    width: min(320px, calc(100vw - 16px));
    padding: 9px;
    border: 1px solid #38bdf8;
    border-radius: 8px;
    background: #1f2937;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    color: #f9fafb;
    font-size: 0.72rem;
}
.reference-pdf-selection-popover.hidden {
    display: none !important;
}
.reference-pdf-selection-label {
    max-height: 34px;
    overflow: hidden;
    color: #9ca3af;
    font-size: 0.68rem;
    line-height: 1.3;
}
.reference-pdf-selection-popover input {
    width: 100%;
    box-sizing: border-box;
    margin-top: 6px;
    padding: 5px 7px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 5px;
    background: #111827;
    color: #f9fafb;
    font-size: 0.7rem;
}
.reference-pdf-selection-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}
.reference-pdf-selection-actions button {
    padding: 4px 7px;
    border-radius: 6px;
    font-size: 0.68rem;
    line-height: 1.2;
    cursor: pointer;
}
#reference-pdf-highlight-btn {
    border: none;
    background: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
    color: #0b1220;
    font-weight: 600;
}
#reference-pdf-comment-btn,
#reference-pdf-cancel-btn {
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.07);
    color: #f9fafb;
}

/* The backend rewrites PDFs for these tools, which this Worker does not do:
   page tools, text/image stamps, redaction and edit history. Hiding them keeps
   dead controls (and their 404s) out of the reader. */
#reference-pdf-undo-btn,
#reference-pdf-redo-btn,
#reference-pdf-tools-toggle,
#reference-pdf-tools-menu,
#reference-pdf-popover-redact,
#reference-pdf-insert-image,
#reference-pdf-text-composer,
[id^="reference-pdf-text-edit"],
.reference-pdf-popover-redact {
    display: none !important;
}

/* PDF text editing needs the file rewritten on the server: Add text, Optimize,
   Burn notes and Stamp all post page operations this Worker does not have. */
#reference-pdf-add-text-btn,
#reference-pdf-optimize-btn,
#reference-pdf-burn-btn,
#reference-pdf-stamp-btn,
.reference-pdf-thumbnail-tools {
    display: none !important;
}
