/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #f7f7f8;
    color: #1e293b;
    height: 100vh;
    overflow: hidden;
    display: flex;
    transition: background 0.3s, color 0.3s;
}
body.dark { background: #0f172a; color: #e2e8f0; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: 260px;
    height: 100vh;
    background: #fff;
    border-right: 1px solid #e9edf2;
    padding: 16px 12px;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
    position: relative;
}
body.dark .sidebar { background: #1e293b; border-right-color: #334155; }
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
.sidebar-clock {
    font-size: 0.68rem;
    color: #94a3b8;
    padding: 2px 4px 4px 4px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.2px;
}
body.dark .sidebar-clock { color: #64748b; }
.sidebar-logo {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 8px 4px 12px 4px;
    background: linear-gradient(145deg, #1e293b, #0f172a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}
body.dark .sidebar-logo { background: linear-gradient(145deg, #f1f5f9, #94a3b8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.sidebar-logo span { font-size: 1.2rem; -webkit-text-fill-color: initial; color: #1e293b; }
body.dark .sidebar-logo span { color: #e2e8f0; }
.new-chat-btn {
    background: #0f172a; color: white; border: none; padding: 8px 16px; border-radius: 99px;
    font-weight: 600; font-size: 0.85rem; cursor: pointer; width: 100%; text-align: center; margin-bottom: 16px; transition: 0.2s;
}
body.dark .new-chat-btn { background: #3b82f6; }
.new-chat-btn:hover { opacity: 0.9; }
.sidebar-sections { flex: 1; overflow-y: auto; }
.sidebar-section .heading { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px; color: #94a3b8; font-weight: 600; padding: 4px 4px 6px 4px; }
.sidebar-item {
    padding: 6px 8px 6px 10px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: 0.15s;
    display: flex; justify-content: space-between; align-items: center; color: #1e293b;
    position: relative;
}
body.dark .sidebar-item { color: #e2e8f0; }
.sidebar-item:hover { background: #f1f5f9; }
body.dark .sidebar-item:hover { background: #334155; }
.sidebar-item .time { font-size: 0.6rem; color: #94a3b8; margin-left: 6px; flex-shrink: 0; }
.sidebar-item.active { background: #eef2ff; }
body.dark .sidebar-item.active { background: #334155; }
.sidebar-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Per-chat "⋮" menu — always visible (not hover-only), so it works on
   touch devices too. Opens a small Pin / Rename / Delete dropdown. */
.item-menu-btn {
    background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 1rem;
    padding: 0 6px; border-radius: 6px; flex-shrink: 0; line-height: 1;
}
.item-menu-btn:hover { background: #e2e8f0; color: #1e293b; }
body.dark .item-menu-btn:hover { background: #475569; color: #e2e8f0; }
.item-menu {
    display: none; position: fixed; z-index: 260;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.14);
    min-width: 130px; overflow: hidden; font-size: 0.8rem;
}
body.dark .item-menu { background: #1e293b; border-color: #334155; }
.item-menu.open { display: block; }
.item-menu div { padding: 8px 12px; cursor: pointer; color: #1e293b; white-space: nowrap; }
body.dark .item-menu div { color: #e2e8f0; }
.item-menu div:hover { background: #f1f5f9; }
body.dark .item-menu div:hover { background: #334155; }

/* Sits between the scrollable chat list and the plan/login footer —
   its own flex row, so it naturally takes a bit of the height that
   used to belong entirely to the scrollable list (.sidebar-sections
   is flex:1, so it just shrinks to make room). */
.sidebar-feedback-btn {
    display: flex; align-items: center; gap: 8px; width: 100%; flex-shrink: 0;
    background: none; border: 1px solid #e2e8f0; border-radius: 10px;
    padding: 8px 12px; margin: 8px 0 4px 0; font-size: 0.78rem; font-weight: 600;
    color: #475569; cursor: pointer; transition: 0.15s; text-align: left;
}
.sidebar-feedback-btn:hover { background: #f1f5f9; border-color: #cbd5e1; color: #1e293b; }
body.dark .sidebar-feedback-btn { border-color: #334155; color: #cbd5e1; }
body.dark .sidebar-feedback-btn:hover { background: #334155; border-color: #475569; color: #f1f5f9; }

.sidebar-footer {
    border-top: 1px solid #e9edf2; padding: 12px 4px 4px 4px; margin-top: 8px; flex-shrink: 0;
}
.sidebar-plan-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; margin-bottom: 4px; border-radius: 8px; cursor: pointer;
    font-size: 0.78rem; color: #64748b; transition: 0.15s;
}
.sidebar-plan-row:hover { background: #f1f5f9; }
body.dark .sidebar-plan-row:hover { background: #334155; }
#sidebarPlanBadge { font-weight: 600; color: #1e293b; }
body.dark #sidebarPlanBadge { color: #e2e8f0; }
.sidebar-upgrade-cta {
    font-size: 0.66rem; font-weight: 700; color: #3b82f6; background: #eef2ff;
    padding: 2px 8px; border-radius: 99px;
}
body.dark .sidebar-upgrade-cta { background: #1e3a5f; }
body.dark .sidebar-footer { border-top-color: #334155; }
.sidebar-footer .login-btn {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px;
    cursor: pointer; transition: 0.2s; width: 100%; border: none; background: none; font-size: 0.9rem; color: #1e293b;
}
body.dark .sidebar-footer .login-btn { color: #e2e8f0; }
.sidebar-footer .login-btn:hover { background: #f1f5f9; }
body.dark .sidebar-footer .login-btn:hover { background: #334155; }
.sidebar-footer .login-btn .avatar {
    background: #3b82f6; color: white; width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; font-size: 0.75rem;
}

/* ===== MAIN CONTENT ===== */
.main {
    flex: 1; display: flex; align-items: stretch; height: 100vh; min-width: 0; overflow: hidden; padding: 0;
}
.chat-wrapper {
    max-width: 880px; width: 100%; margin-left: 24px; margin-right: auto;
    display: flex; flex-direction: column; height: 100vh; min-width: 0;
    transition: margin-right 0.3s ease;
}
/* Right Panel - Notepad */
.right-panel {
    width: calc(160px + 1in);
    flex-shrink: 0;
    background: #f8fafc;
    border-left: 1px solid #e9edf2;
    padding: 16px 12px;
    display: none; /* hidden by default, shown for paid/dev */
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    z-index: 50;
}
body.dark .right-panel { background: #1e293b; border-left-color: #334155; }
.right-panel.show { display: flex; }
.right-panel.expanded {
    width: 50vw !important;
    box-shadow: -4px 0 30px rgba(0,0,0,0.15);
    z-index: 999;
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    border-left: 1px solid #e9edf2;
    padding: 24px;
}
body.dark .right-panel.expanded { border-left-color: #334155; }

.notepad-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    background: white;
    border: 1px solid #e2e8f0;
    padding: 12px;
    height: 100%;
    overflow: hidden;
}
body.dark .notepad-container { background: #0f172a; border-color: #475569; }
.notepad-container .note-heading {
    font-size: 1.1rem;
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    color: #1e293b;
    padding: 4px 0;
    margin-bottom: 8px;
    width: 100%;
    resize: none;
    font-family: inherit;
}
body.dark .notepad-container .note-heading { color: #e2e8f0; }
.notepad-container .note-heading::placeholder {
    color: #94a3b8;
    font-weight: 700;
    opacity: 0.6;
}
.notepad-container .note-details {
    flex: 1;
    border: none;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.6;
    background: transparent;
    color: #1e293b;
    padding: 4px 0;
    width: 100%;
}
body.dark .notepad-container .note-details { color: #e2e8f0; }
.notepad-container .note-details::placeholder {
    color: #94a3b8;
    opacity: 0.6;
}
.notepad-container .pdf-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}
.notepad-container .pdf-actions button {
    background: #0f172a;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}
body.dark .notepad-container .pdf-actions button { background: #3b82f6; }
.notepad-container .pdf-actions button:hover { opacity: 0.9; }
.notepad-container .pdf-actions .new-note-btn {
    background: transparent;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    margin-right: auto;
}
body.dark .notepad-container .pdf-actions .new-note-btn { color: #e2e8f0; border-color: #475569; }
.notepad-container .pdf-actions .new-note-btn:hover { background: #f1f5f9; opacity: 1; }
body.dark .notepad-container .pdf-actions .new-note-btn:hover { background: #1e293b; }
.saved-pdfs {
    margin-top: 12px;
    border-top: 1px solid #e9edf2;
    padding-top: 8px;
    max-height: 150px;
    overflow-y: auto;
}
body.dark .saved-pdfs { border-top-color: #334155; }
.saved-pdfs .pdf-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.75rem;
    color: #475569;
}
body.dark .saved-pdfs .pdf-item { color: #94a3b8; }
.saved-pdfs .pdf-item .menu {
    cursor: pointer;
    padding: 0 6px;
    font-weight: 600;
    position: relative;
}
.saved-pdfs .pdf-item .dropdown {
    display: none;
    position: absolute;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
    min-width: 120px;
}
body.dark .saved-pdfs .pdf-item .dropdown { background: #1e293b; border-color: #475569; }
.saved-pdfs .pdf-item .dropdown.show { display: block; }
.saved-pdfs .pdf-item .dropdown div {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.7rem;
    color: #1e293b;
}
body.dark .saved-pdfs .pdf-item .dropdown div { color: #e2e8f0; }
.saved-pdfs .pdf-item .dropdown div:hover { background: #f1f5f9; }
body.dark .saved-pdfs .pdf-item .dropdown div:hover { background: #334155; }

.notepad-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.6);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    cursor: pointer;
    z-index: 10;
    color: #64748b;
    font-weight: 500;
    font-size: 0.85rem;
    text-align: center;
    padding: 20px;
}
body.dark .notepad-overlay { background: rgba(15,23,42,0.7); color: #94a3b8; }
.notepad-overlay .lock-icon { font-size: 1.5rem; display: block; margin-bottom: 6px; }
.right-panel.insight .notepad-overlay { display: flex; }
.right-panel.synthesis .notepad-overlay { display: none; }
.right-panel.dev .notepad-overlay { display: none; }

/* ===== CHAT UI ===== */
.chat-header {
    display: flex; justify-content: space-between; align-items: center; padding: 10px 0; gap: 16px;
    border-bottom: 1px solid #e9edf2; flex-shrink: 0;
}
body.dark .chat-header { border-bottom-color: #334155; }
.chat-header .hamburger {
    display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer;
    padding: 4px 8px; border-radius: 8px; color: #1e293b; flex-shrink: 0;
}
body.dark .chat-header .hamburger { color: #e2e8f0; }
.chat-header .hamburger:hover { background: #e9edf2; }
body.dark .chat-header .hamburger:hover { background: #334155; }
.chat-header .right-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.dark-toggle { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 99px; }
.dark-toggle:hover { background: #e9edf2; }
body.dark .dark-toggle:hover { background: #334155; }
/* Bot selector now lives inside .chat-header (merged with the top row
   instead of taking its own row underneath it) — needs its own flex
   rule since it's no longer nested inside .top-controls. */
#botSelectorRow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* TOP CONTROLS */
.top-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #e9edf2;
    margin-bottom: 8px;
}
body.dark .top-controls { border-bottom-color: #334155; }
.top-controls.hidden { display: none !important; }
.top-controls .row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.plan-toggle {
    display: flex; background: #e9edf2; border-radius: 99px; padding: 2px; border: 1px solid #cbd5e1;
}
body.dark .plan-toggle { background: #1e293b; border-color: #475569; }
.plan-toggle button {
    background: transparent; border: none; padding: 4px 14px; border-radius: 99px;
    font-weight: 600; font-size: 0.7rem; cursor: pointer; color: #64748b; transition: 0.2s;
}
.plan-toggle button.active { background: #0f172a; color: white; }
body.dark .plan-toggle button.active { background: #3b82f6; }
#planStatus {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-left: auto;
}
/* Bot / Judge / Rounds selector (no persona lens — plain numbered slots) */
#botSelector {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
#botSelector .slot {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #64748b;
}
body.dark #botSelector .slot { color: #94a3b8; }
#botSelector .slot.hidden { display: none; }
#botSelector select {
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    font-size: 0.7rem;
    background: white;
    color: #1e293b;
    cursor: pointer;
    max-width: 120px;
}
body.dark #botSelector select { background: #0f172a; color: #e2e8f0; border-color: #475569; }
#botSelector select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
#botSelector .slot .label {
    font-weight: 600;
    min-width: 44px;
}

.shared-view-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px;
    background: #eef2ff;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: #334155;
}
body.dark .shared-view-banner { background: #1e2a4a; border-color: #334155; color: #cbd5e1; }
.shared-view-banner button {
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 99px;
    padding: 4px 12px;
    font-size: 0.75rem;
    cursor: pointer;
    color: inherit;
}
.shared-view-banner button:hover { background: rgba(0,0,0,0.05); }
.share-link-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.share-link-row input {
    flex: 1;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    font-size: 0.8rem;
    background: #f8fafc;
    color: #1e293b;
}
body.dark .share-link-row input { background: #0f172a; border-color: #475569; color: #e2e8f0; }

.chat-feed {
    flex: 1; overflow-y: auto; padding: 24px 0 0; display: flex; flex-direction: column; gap: 18px; min-width: 0;
}
.chat-feed::-webkit-scrollbar { width: 4px; }
.chat-feed::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

.user-msg {
    align-self: flex-end; background: #0f172a; color: white; padding: 10px 16px;
    border-radius: 18px 18px 4px 18px; max-width: 85%; font-size: 0.95rem; word-wrap: break-word;
}
body.dark .user-msg { background: #2563eb; }

/* ---- message actions: edit/retry on a user question, copy on bot/judge boxes ---- */
.user-msg-row { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.user-msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.user-msg-row:hover .user-msg-actions, .user-msg-row:focus-within .user-msg-actions { opacity: 1; }
.msg-action-btn {
    background: none; border: none; cursor: pointer; font-size: 0.78rem; line-height: 1;
    padding: 4px 7px; border-radius: 6px; color: #64748b;
}
.msg-action-btn:hover { background: rgba(0,0,0,0.06); color: #1e293b; }
body.dark .msg-action-btn { color: #94a3b8; }
body.dark .msg-action-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

.copy-icon-btn {
    background: none; border: none; cursor: pointer; font-size: 0.75rem; line-height: 1;
    padding: 3px 6px; border-radius: 5px; color: inherit; opacity: 0.55; margin-left: 8px; vertical-align: middle;
}
.copy-icon-btn:hover { opacity: 1; background: rgba(0,0,0,0.06); }
body.dark .copy-icon-btn:hover { background: rgba(255,255,255,0.1); }

.file-attach-badge {
    align-self: flex-end; background: #eef2ff; padding: 4px 12px; border-radius: 12px;
    font-size: 0.75rem; color: #1e293b; border: 1px solid #cbd5e1; display: inline-block; margin-top: -8px; margin-bottom: 4px;
}
body.dark .file-attach-badge { background: #1e293b; color: #cbd5e1; border-color: #475569; }

.debate-block { background: white; border-radius: 16px; padding: 14px 16px; border: 1px solid #e9edf2; }
body.dark .debate-block { background: #1e293b; border-color: #334155; }
.debate-grid { display: grid; gap: 12px; margin-bottom: 12px; min-width: 0; }
.debate-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.debate-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.bot-card {
    padding: 10px 12px; border-radius: 12px; background: #f8fafc; border: 1px solid #e9edf2;
    /* A 1fr grid track won't shrink below its content's natural
       width by default — a wide code block or long unbroken token
       (a URL, a long variable name) inside a bot's answer was
       forcing the whole debate-grid, and everything containing it
       (chat-wrapper, .main, the page), wider than the viewport
       instead of scrolling inside its own card. min-width:0 lets
       the card actually shrink to its grid track's real width, so
       .md pre's own overflow-x:auto (below) can do its job. */
    min-width: 0; overflow-wrap: break-word;
}
body.dark .bot-card { background: #0f172a; border-color: #334155; }
.bot-card .name {
    font-weight: 600; font-size: 0.8rem; margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.bot-card .content { font-size: 0.85rem; line-height: 1.5; color: #1e293b; }
body.dark .bot-card .content { color: #e2e8f0; }
.bot-card .revised { border-top: 2px dashed #94a3b8; padding-top: 8px; margin-top: 8px; font-size: 0.8rem; color: #3b82f6; }
body.dark .bot-card .revised { color: #60a5fa; border-top-color: #475569; }

/* Small uppercase label placed above each judge/review section
   ("Bot 1 Analysis", "Judge's own answer", "Peer Review", etc.) so
   these read as distinct headed blocks instead of running together —
   color is intentionally NOT set here; each parent block below
   already has its own text color, and the label just inherits it. */
.section-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; opacity: 0.9; }

/* ===== Rendered markdown (headings, bold, lists, hr, code) coming
   from bot/judge answers via marked+DOMPurify — see renderMarkdown()
   in app.js. Sized down to fit compact chat cards; colors inherit
   from whichever container (light bot-card vs dark judge-box) this
   ends up in rather than being hardcoded here. ===== */
.md p { margin: 0 0 8px 0; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-size: 0.95em; font-weight: 700; margin: 10px 0 6px; line-height: 1.3; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 20px; }
.md li { margin-bottom: 3px; }
.md hr { border: none; border-top: 1px dashed currentColor; opacity: 0.25; margin: 10px 0; }
.md code { font-family: ui-monospace, Consolas, monospace; font-size: 0.85em; background: rgba(128,128,128,0.15); padding: 1px 5px; border-radius: 4px; }
.md pre { background: rgba(128,128,128,0.12); padding: 8px 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.md pre code { background: none; padding: 0; }

/* Copy-code button — floats over the top-right corner of every
   fenced code block. Uses a neutral gray/alpha background rather
   than a light- or dark-specific color, since the same code block
   can end up on a light .bot-card or a dark .judge-box; color:inherit
   picks up whichever text color that context already uses. */
.code-block-wrapper { position: relative; }
.code-block-wrapper pre { padding-top: 30px; }
.code-block-wrapper .copy-code-btn {
    position: absolute; top: 6px; right: 6px; z-index: 2;
    background: rgba(128,128,128,0.25); border: 1px solid rgba(128,128,128,0.35);
    color: inherit; border-radius: 6px; padding: 3px 8px; font-size: 0.72rem;
    cursor: pointer; opacity: 0.8; transition: opacity 0.15s ease, background 0.15s ease;
    font-family: inherit; line-height: 1.4;
}
.code-block-wrapper .copy-code-btn:hover { opacity: 1; background: rgba(128,128,128,0.4); }
.code-block-wrapper .copy-code-btn.copied {
    opacity: 1; background: rgba(34,197,94,0.3); border-color: rgba(34,197,94,0.5); color: #16a34a;
}
body.dark .code-block-wrapper .copy-code-btn.copied { color: #4ade80; }
.md blockquote { border-left: 3px solid currentColor; opacity: 0.9; padding-left: 10px; margin: 6px 0; font-style: italic; }
.md strong { font-weight: 700; }
.md a { color: #3b82f6; text-decoration: underline; }

.judge-box {
    background: #0f172a; border-radius: 12px; padding: 12px 16px; color: white; overflow-wrap: break-word;
}
body.dark .judge-box { background: #0f172a; border: 1px solid #334155; }
.judge-box .label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 1px; color: #94a3b8; }
.judge-box .judge-content {
    font-size: 0.85rem;
    line-height: 1.5;
    color: #e2e8f0;
}
.judge-box .judge-content .analysis-item { margin-bottom: 10px; }
.judge-box .judge-content .analysis-item .section-label { color: #facc15; }
.judge-box .judge-content .better-answer { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #334155; color: #93c5fd; }
.judge-box .judge-content .verdict {
    font-weight: 700;
    color: #facc15;
    border-top: 1px solid #334155;
    padding-top: 8px;
    margin-top: 6px;
}
.judge-box .judge-content .verdict .md { font-size: 1rem; font-weight: 700; }
.judge-box .conf { background: #1e293b; display: inline-block; padding: 2px 14px; border-radius: 99px; font-size: 0.7rem; color: #cbd5e1; margin-top: 6px; }
.judge-box .ai-disclaimer { display: block; margin-top: 8px; font-size: 0.68rem; color: #64748b; font-style: italic; }
/* Shown instead of a verdict when no judge was selected for the debate */
.judge-box.judge-missing .judge-content .verdict { color: #fca5a5; }
.judge-box.judge-missing .conf { display: none; }
.judge-box.judge-missing .ai-disclaimer { display: none; }

/* ===== INPUT AREA ===== */
.input-area {
    border-top: 1px solid #e9edf2; padding: 24px 0 14px; flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; background: inherit;
}
body.dark .input-area { border-top-color: #334155; }
.input-row { display: flex; gap: 10px; align-items: flex-end; }
.input-wrap {
    flex: 1; background: white; border-radius: 24px; border: 1px solid #e2e8f0;
    padding: 4px 4px 4px 16px; display: flex; flex-direction: column; gap: 4px; transition: border 0.2s;
}
body.dark .input-wrap { background: #0f172a; border-color: #475569; }
.input-wrap:focus-within { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12); }
.input-wrap textarea {
    border: none; background: transparent; font-size: 0.95rem; outline: none; resize: none;
    font-family: inherit; min-height: 24px; max-height: 120px; line-height: 1.4; color: inherit; padding: 6px 0; width: 100%;
}
.input-wrap textarea::placeholder { color: #94a3b8; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 4px 0; }
.file-chip {
    background: #f1f5f9; padding: 2px 10px 2px 12px; border-radius: 99px; font-size: 0.7rem;
    display: flex; align-items: center; gap: 6px; border: 1px solid #e2e8f0; color: #334155;
}
body.dark .file-chip { background: #1e293b; border-color: #475569; color: #cbd5e1; }
.file-chip .remove { cursor: pointer; font-weight: 700; color: #dc2626; font-size: 0.8rem; margin-left: 2px; }
.input-actions { display: flex; align-items: center; gap: 4px; padding-bottom: 2px; }
.attach-btn { background: none; border: none; font-size: 1.3rem; cursor: pointer; padding: 6px 8px; border-radius: 99px; color: #64748b; transition: 0.2s; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.attach-btn:hover { background: #f1f5f9; color: #1e293b; }
body.dark .attach-btn:hover { color: #e2e8f0; }
.send-btn {
    background: #0f172a; color: white; border: none; padding: 0 20px; border-radius: 99px;
    font-weight: 600; cursor: pointer; font-size: 0.9rem; height: 40px; flex-shrink: 0; transition: 0.2s;
}
body.dark .send-btn { background: #3b82f6; }
.send-btn:hover { opacity: 0.9; }
#statusMsg { font-size: 0.7rem; color: #94a3b8; padding-left: 4px; min-height: 1.2rem; }

/* cap-badge (usage) and powered-by now share ONE row instead of two —
   cap-badge stays left, powered-by is pinned to the far right via
   margin-left:auto (see .powered-by below), so it always ends up
   flush with the chat area's own right edge regardless of what else
   is in this row. */
.input-footer-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.cap-badge {
    display: flex; align-items: center; gap: 10px; font-size: 0.75rem; color: #64748b; flex-wrap: wrap;
}
body.dark .cap-badge { color: #94a3b8; }
.cap-badge .used { background: #e9edf2; padding: 2px 12px; border-radius: 99px; font-weight: 600; color: #1e293b; }
body.dark .cap-badge .used { background: #334155; color: #e2e8f0; }
.cap-badge .limit-reached { color: #dc2626; font-weight: 700; }
.cap-badge .notice { color: #d97706; font-weight: 600; }

.powered-by {
    font-size: 0.65rem;
    color: #94a3b8;
    margin-left: auto;
    white-space: nowrap;
}
body.dark .powered-by { color: #64748b; }

/* ===== MODALS ===== */
.modal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; justify-content: center; align-items: center;
}
.modal.active { display: flex; }
.modal-content {
    background: white; padding: 2rem; border-radius: 24px; max-width: 620px; width: 95%; box-shadow: 0 20px 60px rgba(0,0,0,0.3); position: relative;
}
body.dark .modal-content { background: #1e293b; color: #e2e8f0; }
.modal-content .close { position: absolute; top: 12px; right: 20px; font-size: 1.6rem; cursor: pointer; color: #94a3b8; }
.modal-content h2 { margin-bottom: 0.5rem; font-size: 1.4rem; }
.modal-content p.sub { color: #94a3b8; font-size: 0.85rem; margin-bottom: 1.5rem; }
.modal-content .g_id_signin { display: flex; justify-content: center; }

/* ===== FEEDBACK MODAL ===== */
.feedback-modal { max-width: 480px !important; }
.feedback-type-tabs {
    display: flex; gap: 6px; margin: 4px 0 18px 0; background: #f1f5f9; padding: 4px; border-radius: 10px;
}
body.dark .feedback-type-tabs { background: #0f172a; }
.feedback-type-tabs button {
    flex: 1; padding: 8px 6px; border: none; background: none; border-radius: 8px;
    font-size: 0.78rem; font-weight: 600; color: #64748b; cursor: pointer; transition: 0.15s;
}
.feedback-type-tabs button.active { background: #fff; color: #0f172a; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
body.dark .feedback-type-tabs button.active { background: #1e293b; color: #e2e8f0; }
.feedback-type-tabs button:hover:not(.active) { color: #1e293b; }
body.dark .feedback-type-tabs button:hover:not(.active) { color: #e2e8f0; }

.feedback-field { margin-bottom: 14px; text-align: left; }
.feedback-field label { display: block; font-size: 0.75rem; font-weight: 600; color: #475569; margin-bottom: 5px; }
body.dark .feedback-field label { color: #94a3b8; }
.feedback-field label .optional { font-weight: 400; color: #94a3b8; }
.feedback-field input, .feedback-field textarea {
    width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid #cbd5e1;
    font-size: 0.85rem; font-family: inherit; background: #fff; color: #0f172a; resize: vertical; box-sizing: border-box;
}
body.dark .feedback-field input, body.dark .feedback-field textarea { background: #0f172a; border-color: #334155; color: #e2e8f0; }
.feedback-field input:focus, .feedback-field textarea:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }

.feedback-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 6px; }
.feedback-status { font-size: 0.78rem; color: #16a34a; font-weight: 600; flex: 1; text-align: left; }
.feedback-status.error { color: #dc2626; }

.upgrade-modal { max-width: 700px !important; }
.plan-card {
    flex: 1; min-width: 160px; padding: 16px; border-radius: 16px; background: #f8fafc; border: 1px solid #e2e8f0; text-align: center; transition: 0.2s;
}
body.dark .plan-card { background: #0f172a; border-color: #334155; }
.plan-card.synthesis { border: 2px solid #3b82f6; background: #eef2ff; position: relative; }
body.dark .plan-card.synthesis { background: #1e293b; border-color: #3b82f6; }
.plan-card .popular {
    position: absolute; top: -10px; right: -10px; background: #3b82f6; color: white; padding: 2px 12px; border-radius: 99px; font-size: 0.6rem; font-weight: 600;
}
.plan-card ul { list-style: none; padding: 0; font-size: 0.8rem; color: #475569; text-align: left; margin: 12px 0; }
body.dark .plan-card ul { color: #94a3b8; }
.plan-card ul li { padding: 4px 0; }

/* ===== DESKTOP SIDEBAR: hover-to-peek, click-to-pin =====
   Collapsed by default (off-screen). Hovering the left edge or the
   sidebar itself peeks it open as an overlay (page content doesn't
   shift). Clicking the hamburger pins it open — that DOES reserve
   layout space — until clicked again. Pin state persists via
   localStorage (see app.js: initDesktopSidebarCollapse). */
.sidebar-hover-zone { display: none; }
@media (min-width: 701px) {
    .chat-header .hamburger { display: inline-flex; }
    .sidebar-hover-zone {
        display: block; position: fixed; top: 0; left: 0; width: 14px; height: 100vh; z-index: 240;
    }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; z-index: 250;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.14);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .sidebar.sb-visible { transform: translateX(0); }
    body.sidebar-pinned .sidebar { box-shadow: none; }
    .main { margin-left: 0; transition: margin-left 0.2s ease; }
    body.sidebar-pinned .main { margin-left: 260px; }

    /* Chat area always stretches to fill the freed-up width, stopping
       exactly 24px before the notepad panel (or the viewport edge if
       the notepad isn't shown) — regardless of whether the sidebar is
       pinned open or collapsed. (Earlier this only applied when
       collapsed, with pinned reverting to the old fixed 880px
       centered layout — that was the wrong call; a consistent 24px
       gap from the notepad is what's wanted either way.)
       width:auto below is required, not decorative — the base
       .chat-wrapper rule sets width:100%, and leaving that in place
       here fights flex-basis for space against .right-panel (the
       notepad), which has flex-shrink:0 and can't yield. That
       mismatch is what caused the notepad to vanish and a stray
       horizontal scrollbar to appear: chat-wrapper was demanding
       100% of .main's width AND flex-growing into whatever the
       notepad left over, instead of sharing the row properly. */
    .chat-wrapper {
        width: auto;
        flex: 1 1 auto;
        max-width: none;
        margin-left: 24px;
        margin-right: 24px;
    }
}

.sidebar-overlay { display: none; }
@media (max-width: 700px) {
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 150; }
    .sidebar-overlay.active { display: block; }
    .chat-header .hamburger { display: block; }
    .chat-header .right-actions .badge { display: none; }
    .input-area { padding: 10px 0 12px; }
    .input-wrap { padding-left: 12px; }
    .send-btn { padding: 0 14px; font-size: 0.8rem; height: 36px; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0,0,0,0.1); z-index: 200; width: 280px; border-right: 1px solid #e9edf2;
    }
    .sidebar.open { transform: translateX(0); }
    .right-panel { display: none !important; }
    .chat-wrapper { margin-left: 12px; margin-right: 12px; max-width: 100%; }
    .debate-grid.cols-2 { grid-template-columns: 1fr; }
    .debate-grid.cols-3 { grid-template-columns: 1fr; }
    .top-controls .row { flex-wrap: wrap; }
    #botSelector select { max-width: 100px; }
}

/* ---- Maths (KaTeX) in bot / judge answers ---- */
.math-block {
    overflow-x: auto;          /* long formulas scroll sideways instead of overflowing the card */
    overflow-y: hidden;
    margin: 6px 0;
    padding: 2px 0;
}
.math-block .katex-display { margin: 0.4em 0; }
p > .math-block { display: block; }
.katex { font-size: 1.08em; }