/* products/stoa/app/static/style.css
 *
 * Sovereign EidOS Knowledge Substrate (Stoa).
 * Follows the universal Eidolon OS Dark Obsidian Design System.
 */

:root,
:root[data-theme="dark"],
:root:not([data-theme]),
:root[data-theme="auto"] {
    --bg: #07090e;
    --card-bg: #0e1526;
    --card-hover: #162038;
    --fg: #f8fafc;
    --muted: #94a3b8;
    --rule: #1e293b;
    --border-hover: #38bdf8;
    --link: #38bdf8;
    --link-hover: #7dd3fc;
    --accent: #38bdf8;
    --code-bg: #0b1120;
    --sidebar-bg: #090e1b;
    --topbar-bg: #0a0f1d;
    --gold: #f59e0b;
    --green: #10b981;
    --purple: #a855f7;
    --red: #f43f5e;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
    --max-prose: 82ch;
    --sidebar-width: 19rem;
    --topbar-height: 3.5rem;
    --platform-bar-height: 38px;
    --header-offset: calc(var(--platform-bar-height) + var(--topbar-height));
}

/* Explicit light theme — high contrast & WCAG AAA legible */
:root[data-theme="light"] {
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --card-hover: #e2e8f0;
    --fg: #0f172a;
    --muted: #475569;
    --rule: #cbd5e1;
    --border-hover: #0284c7;
    --link: #0369a1;
    --link-hover: #0284c7;
    --accent: #0284c7;
    --code-bg: #f1f5f9;
    --sidebar-bg: #eef2f6;
    --topbar-bg: #ffffff;
    --gold: #b45309;
    --green: #059669;
    --purple: #7c3aed;
    --red: #e11d48;
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

/* Sepia theme — warm editorial contrast */
:root[data-theme="sepia"] {
    --bg: #fbf7ee;
    --card-bg: #ffffff;
    --card-hover: #f4ede2;
    --fg: #291e14;
    --muted: #6b5c4d;
    --rule: #dcd0bf;
    --border-hover: #b45309;
    --link: #b45309;
    --link-hover: #78350f;
    --accent: #b45309;
    --code-bg: #f4ece1;
    --sidebar-bg: #f2e9dc;
    --topbar-bg: #fbf7ee;
    --gold: #b45309;
    --green: #2d6a4f;
    --purple: #6d597a;
    --red: #b91c1c;
    --shadow: 0 4px 16px rgba(45, 36, 30, 0.08);
}

:root[data-theme="light"]  { color-scheme: light; }
:root[data-theme="dark"]   { color-scheme: dark; }
:root[data-theme="sepia"]  { color-scheme: light; }
:root[data-theme="auto"], :root:not([data-theme]) { color-scheme: dark; }

/* Modern standard — Firefox + Chromium 121+. */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--rule) transparent;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-track {
    background: transparent;
}
*::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
}

a { color: var(--link); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ── Top bar (Line 2 below Obsidian Global Bar) ───────────────────── */
.topbar {
    position: sticky;
    top: var(--platform-bar-height);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .65rem 1.25rem;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--rule);
    box-shadow: var(--shadow);
    min-height: var(--topbar-height);
    box-sizing: border-box;
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 750;
    color: var(--fg);
    font-size: 1.15rem;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.brand:hover { color: var(--accent); text-decoration: none; }

.brand-logo-e {
    font-size: 1.5rem;
    color: var(--accent);
    font-weight: 800;
    line-height: 1;
}

.topbar-meta {
    margin-left: .5rem;
    white-space: nowrap;
}

.topbar-badge {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    border: 1px solid rgba(56, 189, 248, 0.25);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.topbar-clock {
    color: var(--muted);
    font-size: .85rem;
    margin-left: .75rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Top-level tabs (Docs / Intercomms) */
.topbar-tabs { display: flex; gap: .35rem; margin-left: .5rem; flex-shrink: 0; }
.topbar-tab {
    padding: .35rem .75rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    font-size: .88rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}
.topbar-tab:hover { color: var(--fg); background: var(--card-hover); text-decoration: none; }
.topbar-tab.active {
    color: var(--accent);
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.25);
    text-decoration: none;
}

.topbar-theme {
    background: var(--card-bg);
    color: var(--fg);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.topbar-theme:focus {
    outline: none;
    border-color: var(--accent);
}

/* Intercomms reader */
.ic-count { color: var(--muted); font-size: .8em; font-weight: 400; }
.ic-sub { color: var(--muted); }
.ic-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.ic-table th, .ic-table td {
    text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--rule);
    vertical-align: top;
}
.ic-table th { color: var(--muted); font-weight: 600; }
.ic-date, .ic-from, .ic-to { white-space: nowrap; }
.ic-to { color: var(--muted); }
.ic-badge {
    font-size: .72rem; padding: .1rem .4rem; border-radius: .3rem;
    background: var(--rule); color: var(--muted);
}
.ic-back { margin-bottom: .5rem; }
.ic-meta { color: var(--muted); margin-top: -.4rem; }
.ic-body { margin: 1rem 0 2rem; }
.ic-comments { border-top: 2px solid var(--rule); padding-top: 1rem; }
.ic-comment { border-left: 3px solid var(--accent); padding: .3rem .8rem; margin: .6rem 0; }
.ic-comment-meta { font-size: .82rem; color: var(--muted); }
.ic-comment-form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; max-width: 40rem; }
.ic-comment-form textarea {
    padding: .5rem; border: 1px solid var(--rule); border-radius: .35rem;
    background: var(--bg); color: var(--fg); font: inherit;
}
.ic-comment-form button {
    align-self: flex-start; padding: .4rem 1rem; border: 1px solid var(--accent);
    border-radius: .35rem; background: var(--accent); color: var(--bg); cursor: pointer;
}
.ic-comments-note { color: var(--muted); font-size: .85rem; margin: -.3rem 0 1rem; }
.ic-comment-edit { margin-top: .35rem; }
.ic-comment-edit > summary { cursor: pointer; color: var(--muted); font-size: .8rem; }

/* Intercomms master-detail: message list (left) + inline preview pane (right).
   Kuda 2026-07-19: "message preview + comment addition on the right side of the
   list pane — not a separate page." */
.ic-split { display: flex; gap: 1rem; align-items: flex-start; }
.ic-list-pane { flex: 0 0 38%; max-width: 38%; max-height: calc(100vh - 12rem); overflow-y: auto; }
.ic-preview-pane {
    flex: 1 1 62%; min-width: 0; border-left: 1px solid var(--rule); padding-left: 1rem;
    max-height: calc(100vh - 12rem); overflow-y: auto;
}
.ic-preview-pane.ic-loading { opacity: .5; }
.ic-preview-empty { color: var(--muted); font-style: italic; padding: 1rem 0; }
.ic-msglist { list-style: none; margin: 0; padding: 0; }
.ic-msgrow { border-bottom: 1px solid var(--rule); }
.ic-msglink { display: block; padding: .5rem .6rem; text-decoration: none; color: var(--fg); }
.ic-msglink:hover { background: var(--rule); }
.ic-msgrow.active .ic-msglink { background: var(--rule); border-left: 3px solid var(--accent); }
.ic-msgrow.active { position: relative; }
.ic-subj { display: block; font-weight: 600; font-size: .92rem; }
.ic-rowmeta { display: block; color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.ic-preview-subj { margin: .2rem 0 .3rem; font-size: 1.15rem; }
/* Stack on narrow screens so the preview still shows (no separate page). */
@media (max-width: 900px) {
    .ic-split { flex-direction: column; }
    .ic-list-pane, .ic-preview-pane { flex-basis: auto; max-width: 100%; max-height: none; }
    .ic-preview-pane { border-left: none; border-top: 1px solid var(--rule); padding-left: 0; padding-top: 1rem; }
}

/* Search form embedded in the topbar */
.topbar-search {
    flex: 1;
    margin: 0 .5rem 0 auto;
    max-width: 28rem;
    display: flex;
}
.topbar-search-input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--rule);
    border-radius: .35rem;
    background: var(--bg);
    color: var(--fg);
    font-size: .95rem;
    min-height: 38px;
}
.topbar-search-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
/* On the narrowest screens, shrink the search to keep brand + meta visible */
@media (max-width: 480px) {
    .topbar-search { max-width: none; }
    .topbar-meta { display: none; }
    .topbar-clock { display: none; }
}

/* Search results page */
.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: 1rem 0 1.5rem;
}
.search-input {
    flex: 1;
    min-width: 60%;
    padding: .65rem 1rem;
    border: 1px solid var(--rule);
    border-radius: .4rem;
    background: var(--bg);
    color: var(--fg);
    font-size: 1rem;
    min-height: 44px;
}
.search-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
.search-section {
    padding: .5rem .75rem;
    border: 1px solid var(--rule);
    border-radius: .4rem;
    background: var(--bg);
    color: var(--fg);
    font-size: .95rem;
    min-height: 44px;
}
.search-meta {
    color: var(--muted);
    margin: 1rem 0;
}
.search-hits {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}
.search-hit {
    padding: .9rem 0;
    border-bottom: 1px solid var(--rule);
}
.search-hit:last-child { border-bottom: 0; }
.hit-title {
    display: block;
    font-size: 1.08rem;
    font-weight: 600;
    margin-bottom: .35rem;
}
.hit-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: center;
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: .35rem;
}
.hit-meta .score, .hit-meta .mtime { font-variant-numeric: tabular-nums; }
.hit-snippet {
    margin: .3rem 0 0;
    color: var(--fg);
    opacity: .85;
    font-size: .94rem;
    line-height: 1.5;
}
.search-empty { color: var(--muted); padding: 2rem 0; text-align: center; }
.search-tip { color: var(--muted); margin: .9rem 0; }

/* ── Chat page ────────────────────────────────────────────────────── */
.topbar-chat {
    display: inline-flex;
    align-items: center;
    padding: .35rem .75rem;
    margin-left: .25rem;
    border-radius: .35rem;
    background: var(--accent);
    color: white;
    font-size: .9rem;
    font-weight: 600;
    min-height: 38px;
    text-decoration: none;
}
.topbar-chat:hover {
    background: var(--link-hover);
    color: white;
    text-decoration: none;
}

.chat-page {
    /* /chat page — fit the chat experience into the viewport so
       lower buttons + the prompt textarea are always visible.
       Flex column: lead + log + form + meta share the available
       height; chat-log is the only thing that scrolls internally. */
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);  /* topbar + a little breathing room */
    max-width: 60rem;
    margin: 0 auto;
}
.chat-page > h1, .chat-page > .lead, .chat-page > .chat-form,
.chat-page > .chat-meta {
    flex: 0 0 auto;
}
.chat-page > #chat-log {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}
.chat-page .lead {
    color: var(--muted);
    margin: 0 0 1rem;
    font-size: 1rem;
}

.chat-log {
    border: 1px solid var(--rule);
    border-radius: .5rem;
    background: var(--bg);
    padding: 1rem;
    margin: 1rem 0;
    min-height: 45vh;
    max-height: 65vh;
    overflow-y: auto;
}

.chat-turn {
    margin: 0 0 1rem;
    padding: 0;
}
.chat-turn.role-user .chat-bubble {
    background: var(--code-bg);
    color: var(--fg);
    border-radius: 1rem 1rem .25rem 1rem;
    padding: .75rem 1rem;
    margin-left: auto;
    max-width: 80%;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chat-turn.role-user {
    display: flex;
    justify-content: flex-end;
}
.chat-turn.role-assistant .chat-bubble {
    background: transparent;
    color: var(--fg);
    border-radius: 1rem 1rem 1rem .25rem;
    padding: .25rem 0;
    max-width: 95%;
    line-height: 1.55;
}
.chat-turn.role-assistant .chat-bubble p {
    margin: .5em 0;
}

/* Chat bubbles never scroll horizontally — the pane is too narrow
 * for horizontal scrolling to be ergonomic. Long lines wrap with
 * padding via `overflow-wrap: anywhere` (handles long URLs and
 * unbreakable tokens that `word-wrap: break-word` alone misses).
 * Code blocks inside chat trade their natural line preservation
 * for in-bubble readability. */
.chat-bubble {
    overflow-wrap: anywhere;
    word-break: break-word;
    overflow-x: hidden;
}
.chat-bubble pre,
.chat-bubble code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}
.chat-bubble pre {
    overflow-x: visible;
}
.chat-bubble table {
    /* Tables in chat: wrap content cells rather than horizontally
     * scroll the table block (which the prose-table rule would do).
     * Tables in chat are usually small enough that compressed cells
     * are more readable than a sideways-scrolling block. */
    display: table;
    overflow-x: visible;
    width: 100%;
    max-width: 100%;
}

.chat-sources {
    margin: .35rem 0 0;
    font-size: .85rem;
    color: var(--muted);
    line-height: 1.5;
    padding-left: 0;
}
.chat-sources strong { color: var(--fg); margin-right: .35rem; }
.chat-sources .doc-link { margin-right: .15rem; }

.chat-form {
    display: flex;
    gap: .65rem;
    align-items: flex-end;
    margin: 1rem 0 .5rem;
    flex: 0 0 auto;
}
.chat-input {
    flex: 1;
    padding: .75rem 1rem;
    border: 1px solid var(--rule);
    border-radius: .5rem;
    background: var(--bg);
    color: var(--fg);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 44px;
    max-height: 30vh;
}
.chat-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
#chat-send {
    min-width: 5rem;
}
#chat-send:disabled {
    opacity: .6;
    cursor: not-allowed;
}
.chat-meta {
    color: var(--muted);
    font-size: .85rem;
    margin: .5rem 0 1.5rem;
}
.chat-meta button {
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: .25rem;
    padding: .15rem .55rem;
    cursor: pointer;
    font-size: .82rem;
    color: var(--fg);
}
.chat-meta button:hover { background: var(--code-bg); }

/* Chat model picker — small, inline with footer buttons */
.chat-model-select {
    padding: .35rem .55rem;
    border: 1px solid var(--rule);
    border-radius: .35rem;
    background: var(--bg);
    color: var(--fg);
    font-size: .82rem;
    min-height: 30px;
    max-width: 14rem;
}
.chat-model-select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

/* "+ New thread" — sibling to .chat-model-select in the chat panel
   header (and in the read-view side panel header). Visually quiet
   so it reads as a secondary control next to the model picker;
   click feedback handled in JS (label flips to "✓ New thread"
   briefly after click). */
.chat-new-thread {
    padding: .35rem .55rem;
    border: 1px solid var(--rule);
    border-radius: .35rem;
    background: var(--bg);
    color: var(--fg);
    font-size: .78rem;
    cursor: pointer;
    min-height: 30px;
    white-space: nowrap;
}
.chat-new-thread:hover { background: var(--code-bg); }
.chat-new-thread:disabled {
    opacity: .65;
    cursor: default;
}
.chat-panel-foot {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    padding-top: .5rem;
    border-top: 1px solid var(--rule);
    margin-top: .5rem;
    /* Pinned at the bottom of the flex column — doesn't grow/shrink
       so the chat-log between header + form/foot is the only thing
       that scrolls. */
    flex: 0 0 auto;
}

/* Mobile: chat log shrinks slightly, form stacks tighter */
@media (max-width: 600px) {
    .chat-log { max-height: 55vh; }
    .chat-turn.role-user .chat-bubble { max-width: 90%; }
}

/* ── Read view: side-by-side reader + chat ────────────────────────── */
.read-layout {
    display: flex;
    gap: 1rem;
    align-items: stretch;
    margin: -1.25rem -1rem 0; /* eat the .content padding for full-width */
    padding: 1.25rem 1rem 0;
}

.read-pane {
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    transition: flex .25s ease, max-width .25s ease;
}

/* Doc pane — gets most of the width by default */
.read-doc {
    flex: 1 1 65%;
    max-width: 100%;
}
.read-doc .pane-body {
    flex: 1 1 auto;
    max-width: var(--max-prose);
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

/* Chat pane — narrower than doc by default but still substantial.
   `position: sticky` so the chat stays in view as the user scrolls
   the doc body. `align-self: flex-start` is required for sticky
   inside a flex container so the pane doesn't stretch to the
   container's full height (which would make sticky a no-op).
   `max-height: calc(100vh - 3rem)` keeps the chat within the
   viewport below the topbar; the chat-log scrolls internally. */
.read-chat {
    flex: 1 1 35%;
    min-width: 22rem;
    max-width: 40rem;
    border-left: 1px solid var(--rule);
    padding-left: 1rem;
    margin-left: 1rem;
    position: sticky;
    top: var(--topbar-height);
    align-self: flex-start;
    max-height: calc(100vh - var(--topbar-height));
    display: flex;
    flex-direction: column;
}

/* Collapsed states — narrow strip with click-to-expand. Cursor
   pointer signals interactivity; rotated label is the "expand"
   affordance. */
.read-layout.doc-collapsed .read-doc,
.read-layout.chat-collapsed .read-chat {
    flex: 0 0 3rem;
    min-width: 3rem;
    max-width: 3rem;
    overflow: hidden;
    cursor: pointer;
    opacity: .85;
    background: var(--code-bg);
    border-radius: .5rem;
}
.read-layout.doc-collapsed .read-doc:hover,
.read-layout.chat-collapsed .read-chat:hover {
    opacity: 1;
    background: var(--bg);
}
.read-layout.doc-collapsed .read-doc .pane-body,
.read-layout.doc-collapsed .read-doc .pane-header-meta,
.read-layout.doc-collapsed .read-doc .btn-edit,
.read-layout.chat-collapsed .read-chat .chat-log,
.read-layout.chat-collapsed .read-chat .chat-form,
.read-layout.chat-collapsed .read-chat .chat-panel-foot,
.read-layout.chat-collapsed .read-chat .chat-fullscreen-link,
.read-layout.chat-collapsed .read-chat .pane-title {
    display: none;
}
.read-layout.doc-collapsed .read-doc .pane-collapse,
.read-layout.chat-collapsed .read-chat .pane-collapse {
    transform: rotate(180deg);
    margin: 0 auto;
}

.read-layout.doc-collapsed .read-chat,
.read-layout.chat-collapsed .read-doc {
    flex: 1 1 auto;
    max-width: 100%;
}

/* Pane header — toolbar at the top of each pane. Explicit
   ``flex: 0 0 auto`` so it doesn't grow OR shrink in a flex-column
   container — keeps the chat header pinned while the chat-log
   between it and the form scrolls. */
.pane-header {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding-bottom: .65rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--rule);
    flex-wrap: wrap;
    flex: 0 0 auto;
}

/* Doc pane header — STICKY so the toolbar (section pill, mtime,
   Edit button) stays visible as the user scrolls the doc body.
   The chat pane's header doesn't need this — that whole pane is
   already sticky-positioned in the read-layout. */
.read-doc > .pane-header {
    position: sticky;
    top: var(--topbar-height);  /* below the global topbar */
    z-index: 3;
    background: var(--bg);
    margin: 0;
    padding: .65rem 0;
    border-bottom: 1px solid var(--rule);
}
/* Push the doc body slightly so it doesn't crash into the sticky
   header. */
.read-doc > .pane-body {
    padding-top: 1rem;
}
.pane-header-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: center;
    font-size: .85rem;
    color: var(--muted);
    flex: 1;
}
.pane-title {
    margin: 0;
    font-size: 1.05rem;
    color: var(--fg);
    flex: 1;
}
.pane-collapse {
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: .35rem;
    padding: .25rem .55rem;
    font-size: .9rem;
    color: var(--fg);
    cursor: pointer;
    min-height: 32px;
    min-width: 32px;
}
.pane-collapse:hover { background: var(--code-bg); }

.chat-fullscreen-link {
    color: var(--muted);
    font-size: 1.05rem;
    text-decoration: none;
    padding: 0 .35rem;
}
.chat-fullscreen-link:hover { color: var(--accent); text-decoration: none; }

/* Side-panel mode toggle (Chat / Decks). Sits flush-left in the
   pane-header; segmented-control style. The mode itself is set via
   a data-side-mode attribute on the parent .read-chat section,
   which drives the .side-chat-only / .side-decks-only show/hide
   rules below. */
.side-mode-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: .35rem;
    overflow: hidden;
    margin-right: auto;
}
.side-mode-toggle button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: .8rem;
    font-weight: 600;
    padding: .3rem .65rem;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.side-mode-toggle button:not(.active):hover {
    background: var(--code-bg);
    color: var(--fg);
}
.side-mode-toggle button.active {
    background: var(--code-bg);
    color: var(--accent);
    cursor: default;
}

/* Show/hide based on the parent's data-side-mode. !important to
   beat any inherited display from the original chat-pane CSS. */
.read-chat[data-side-mode="chat"]  .side-decks-only { display: none !important; }
.read-chat[data-side-mode="decks"] .side-chat-only  { display: none !important; }

/* Decks-mode list. Uses ARIA list/listitem roles instead of ul/li
   so the Jinja loop tokens don't trip strict HTML linters. */
.side-decks {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: .25rem 0;
}
.side-decks-list {
    display: flex;
    flex-direction: column;
}
.side-decks-item {
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--border);
}
.side-decks-link {
    display: block;
    font-weight: 600;
    line-height: 1.3;
    color: var(--link);
    text-decoration: none;
}
.side-decks-link:hover {
    color: var(--link-hover);
    text-decoration: underline;
}
/* Title is no longer a link in v0.2 (2026-05-14): the View / Present
 * action buttons below carry the navigation, the title is a plain
 * heading so users don't accidentally lose their reading context by
 * clicking it. */
.side-decks-title {
    font-weight: 600;
    line-height: 1.3;
    color: var(--fg);
    overflow-wrap: anywhere;
}
.side-decks-actions {
    display: flex;
    gap: .35rem;
    margin-top: .35rem;
}
.side-decks-action {
    font-size: .8rem;
    padding: .2rem .5rem;
}
.side-decks-meta {
    display: flex;
    gap: .4rem;
    align-items: center;
    margin-top: .2rem;
    font-size: .75rem;
    color: var(--muted);
}
.side-decks-mtime {
    font-variant-numeric: tabular-nums;
}
.side-decks-empty {
    padding: 1rem .75rem;
    color: var(--muted);
    font-size: .9rem;
    line-height: 1.45;
}

/* In the side-column chat, the log auto-grows + has its own scroll.
   With the chat pane sticky-positioned, the log fills whatever
   vertical space is left after the header and form, so the
   conversation scrolls internally while the chat stays in the
   viewport. */
.chat-log-panel {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
}
.chat-form-panel {
    margin: .5rem 0;
    flex: 0 0 auto;
}

/* Mobile: stack panes vertically; each is full-width. Sticky
   positioning disabled because the side-by-side layout no longer
   applies — chat scrolls below doc naturally on mobile. */
@media (max-width: 900px) {
    .read-layout {
        flex-direction: column;
        gap: .65rem;
        margin: -1.25rem -1rem 0;
        padding: 1rem 1rem 0;
    }
    .read-chat {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
        border-left: 0;
        border-top: 1px solid var(--rule);
        padding-left: 0;
        margin-left: 0;
        padding-top: 1rem;
        position: static;
        max-height: none;
    }
    .read-layout.doc-collapsed .read-doc,
    .read-layout.chat-collapsed .read-chat {
        flex: 0 0 auto;
        min-width: 0;
        max-width: 100%;
        height: 3rem;
        padding: .5rem 1rem;
    }
}

/* ── Hamburger (mobile only; hidden on desktop) ───────────────────── */
.nav-toggle { display: none; }

.hamburger {
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 22px;
    cursor: pointer;
    padding: 4px 0;
}
.hamburger span {
    display: block;
    height: 2px;
    background: var(--fg);
    border-radius: 1px;
    transition: transform .2s ease, opacity .2s ease;
}

/* ── Sidebar — mobile default = off-canvas drawer ─────────────────── */
.sidebar {
    position: fixed;
    top: var(--header-offset);
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), 85vw);
    height: calc(100vh - var(--header-offset));
    overflow-y: auto;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--rule);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 5;
    padding: 1rem;
}

.nav-toggle:checked ~ .sidebar { transform: translateX(0); }

.nav-toggle:checked ~ main.content::before {
    content: "";
    position: fixed;
    inset: var(--header-offset) 0 0 0;
    background: rgba(0,0,0,.6);
    z-index: 4;
}

.nav-section {
    margin-bottom: .85rem;
}
.nav-section > summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--fg);
    padding: .35rem 0;
    list-style: none;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::before {
    content: "▸ ";
    color: var(--accent);
    transition: transform .15s;
    display: inline-block;
    margin-right: 4px;
}
.nav-section[open] > summary::before {
    content: "▾ ";
}
.nav-section .count {
    color: var(--muted);
    font-weight: 600;
    font-size: .75em;
    margin-left: auto;
    background: var(--code-bg);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--rule);
}
.nav-section ul {
    list-style: none;
    padding: 0;
    margin: .25rem 0 .25rem .5rem;
}

.nav-subgroup {
    margin: .35rem 0 .35rem .35rem;
}
.nav-subgroup-label {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    padding: .25rem .5rem .15rem;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
}
.nav-subgroup-label::-webkit-details-marker { display: none; }
.nav-subgroup-label::before {
    content: "▸ ";
    color: var(--muted);
    transition: transform .15s;
    display: inline-block;
    font-size: .9em;
    margin-right: 4px;
}
.nav-subgroup[open] > .nav-subgroup-label::before {
    content: "▾ ";
    color: var(--accent);
}
.nav-subgroup ul {
    margin: 0 0 .15rem .25rem;
}
.nav-section li a {
    display: block;
    padding: .45rem .6rem;
    border-radius: 6px;
    font-size: .88rem;
    line-height: 1.35;
    color: var(--muted);
    min-height: 36px;
    transition: all 0.15s ease;
}
.nav-section li a:hover {
    background: var(--card-hover);
    color: var(--fg);
    text-decoration: none;
}
.nav-section li a.active {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    border-left: 3px solid var(--accent);
    font-weight: 600;
    text-decoration: none;
}

/* ── Content area ─────────────────────────────────────────────────── */
.content {
    padding: 1.5rem 1.25rem 4rem;
}

.prose {
    max-width: var(--max-prose);
    margin: 0 auto;
}

.prose h1 { font-size: 2.1rem; font-weight: 800; line-height: 1.25; margin-top: .5rem; color: var(--fg); letter-spacing: -0.02em; }
.prose h2 { font-size: 1.45rem; font-weight: 750; line-height: 1.3; margin-top: 2.2rem; padding-top: .65rem; border-top: 1px solid var(--rule); color: var(--fg); }
.prose h3 { font-size: 1.2rem; font-weight: 700; margin-top: 1.5rem; color: var(--fg); }
.prose h4 { font-size: 1.05rem; font-weight: 650; margin-top: 1.25rem; color: var(--fg); }
.prose p, .prose ul, .prose ol, .prose blockquote { margin: 0.85em 0; color: var(--fg); line-height: 1.65; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.25em 0; }
.prose blockquote {
    border-left: 4px solid var(--accent);
    padding: .65rem 1rem;
    color: var(--fg);
    background: var(--code-bg);
    border-radius: 0 8px 8px 0;
    border-top: 1px solid var(--rule);
    border-right: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
}
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }

.prose a.doc-link {
    color: var(--accent);
    border-bottom: 1px dashed rgba(56, 189, 248, 0.5);
    text-decoration: none;
    font-weight: 500;
}
.prose a.doc-link:hover {
    border-bottom-style: solid;
    text-decoration: none;
    color: var(--link-hover);
}

.prose code {
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: .88em;
    background: var(--code-bg);
    color: var(--accent);
    padding: .15em .4em;
    border-radius: 4px;
    border: 1px solid var(--rule);
}
.prose pre {
    background: var(--code-bg);
    border: 1px solid var(--rule);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: .9rem;
    line-height: 1.5;
    box-shadow: var(--shadow);
}
.prose pre code {
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--fg);
}

.prose table {
    display: block;
    overflow-x: auto;
    border-collapse: collapse;
    max-width: 100%;
    margin: 1.25rem 0;
    background: var(--card-bg);
    border: 1px solid var(--rule);
    border-radius: 8px;
}
.prose table th, .prose table td {
    border: 1px solid var(--rule);
    padding: .65rem .85rem;
    text-align: left;
    font-size: .92rem;
    color: var(--fg);
}
.prose table th { background: var(--code-bg); color: var(--fg); font-weight: 700; }

.prose img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--rule); }

/* ── Doc toolbar (read + edit view) ───────────────────────────────── */
.doc-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: center;
    margin: -.25rem 0 1.25rem;
    padding-bottom: .65rem;
    border-bottom: 1px solid var(--rule);
}
.doc-meta { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; font-size: .85rem; color: var(--muted); }
.section-pill {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    border: 1px solid rgba(56, 189, 248, 0.25);
    padding: .15rem .6rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: .78rem;
}
.mtime, .size, .path { font-variant-numeric: tabular-nums; }
.path { font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; word-break: break-all; }

.doi-badge {
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 11px;
    color: var(--gold);
    background: var(--code-bg);
    border: 1px solid var(--rule);
    padding: 2px 8px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
}
.doi-badge:hover {
    border-color: var(--gold);
    text-decoration: none;
}

.btn-edit, .btn-save {
    margin-left: auto;
    padding: .45rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #ffffff;
    font-weight: 750;
    cursor: pointer;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    font-size: .88rem;
    transition: all 0.15s ease;
}
.btn-edit:hover, .btn-save:hover {
    background: var(--link-hover);
    border-color: var(--link-hover);
    color: #ffffff;
    text-decoration: none;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

.btn-cancel, .btn-cancel-inline {
    margin-left: auto;
    padding: .45rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--rule);
    background: var(--card-bg);
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    font-size: .88rem;
    transition: all 0.15s ease;
}
.btn-cancel:hover, .btn-cancel-inline:hover {
    background: var(--card-hover);
    color: var(--fg);
    border-color: var(--border-hover);
    text-decoration: none;
}

/* ── Editor ───────────────────────────────────────────────────────── */
.editor-form { display: flex; flex-direction: column; gap: 1rem; }
.editor {
    width: 100%;
    min-height: 60vh;
    padding: 1.25rem;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--fg);
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
}
.editor:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}
.editor-actions { display: flex; gap: .65rem; }

/* ── Index page section grid ──────────────────────────────────────── */
.lead { font-size: 1.15rem; color: var(--muted); margin-top: 0; line-height: 1.5; }
.section-grid { list-style: none; padding: 0; display: grid; gap: 1.25rem; }
.section-grid > li {
    padding: 1.25rem 1.4rem;
    border: 1px solid var(--rule);
    border-radius: 10px;
    background: var(--card-bg);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.section-grid > li:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    background: var(--card-hover);
    box-shadow: var(--shadow);
}
.section-grid strong { display: block; font-size: 1.08rem; font-weight: 750; color: var(--fg); }
.count-inline { color: var(--muted); font-size: .82rem; font-weight: 600; }
.recent { list-style: none; padding: .65rem 0 0; margin: 0; }
.recent li { padding: .25rem 0; font-size: .9rem; }
.recent li a { color: var(--link); }
.recent li a:hover { color: var(--link-hover); }
.recent .more { color: var(--muted); font-style: italic; font-size: 0.82rem; margin-top: 4px; }

/* ── Desktop layout ───────────────────────────────────────────────── */
@media (min-width: 900px) {
    .hamburger { display: none; }
    .sidebar {
        position: fixed;
        top: var(--header-offset);
        transform: translateX(0);
        border-right: 1px solid var(--rule);
    }
    .content {
        margin-left: var(--sidebar-width);
        padding: 2rem 2.5rem 5rem;
    }
    .nav-toggle:checked ~ main.content::before { display: none; }
    .section-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }
}

@media (min-width: 1200px) {
    body { font-size: 16px; }
}
