:root {
    --lapis-900: #0e1a40;
    --lapis-800: #14275e;
    --lapis-700: #1f3a93;
    --lapis-500: #3a5bc7;
    --lapis-100: #e6ebf8;
    --gold: #c8a24a;
    --gold-soft: #f3e7c6;
    --ink: #1d2433;
    --ink-soft: #4a5368;
    --muted: #7a8194;
    --parchment: #f6f2e8;
    --card: #fffdf8;
    --line: #e7dfcc;
    --line-soft: #efe9da;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --ok: #2e7d4f;
    --warn-bg: #fff4d6;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(20, 39, 94, .06), 0 6px 24px rgba(20, 39, 94, .07);
    --left-sidebar-width: 340px;
    --summary-width: 360px;
    --header-h: 60px;
    --serif: "Noto Serif", Georgia, "Times New Roman", serif;
    --sans: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--parchment);
}
a { color: var(--lapis-700); }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--lapis-800); margin: 0 0 .5em; line-height: 1.3; }
h3 { font-size: 1.02rem; }
h4 { font-size: .95rem; margin-top: 1.1em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input[type="text"], input[type="number"], textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 8px 11px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--lapis-500); box-shadow: 0 0 0 3px rgba(58, 91, 199, .15); }
label { display: block; margin: 0 0 10px; }
label > span, .field-label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
svg { width: 18px; height: 18px; flex: none; }

.btn-primary, .btn-secondary, .btn-ghost, .btn-small, #apply-filters-btn {
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 8px 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn-primary, #apply-filters-btn { background: var(--lapis-700); color: #fff; }
.btn-primary:hover:not(:disabled), #apply-filters-btn:hover { background: var(--lapis-800); }
.btn-secondary { background: var(--gold-soft); color: var(--lapis-900); border-color: #e3d09c; }
.btn-secondary:hover:not(:disabled) { background: #eedcaa; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--lapis-800); padding: 6px 12px; font-size: .85rem; text-decoration: none; }
.btn-ghost:hover { background: var(--lapis-100); }
.btn-small { padding: 4px 12px; font-size: .82rem; background: var(--lapis-700); color: #fff; }
.wide { width: 100%; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--lapis-800); display: inline-flex; }
.icon-btn:hover { background: var(--lapis-100); }

/* ---------------- Header ---------------- */
.app-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    color: #fff;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='none' stroke='%23c8a24a' stroke-opacity='.13'%3E%3Crect x='18' y='18' width='24' height='24'/%3E%3Crect x='18' y='18' width='24' height='24' transform='rotate(45 30 30)'/%3E%3C/g%3E%3C/svg%3E"),
        linear-gradient(100deg, var(--lapis-900), var(--lapis-800) 55%, var(--lapis-700));
    border-bottom: 2px solid var(--gold);
    position: relative;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-emblem { width: 38px; height: 38px; }
.brand-text strong { display: block; font-family: var(--serif); font-size: 1.2rem; letter-spacing: .02em; }
.brand-text small { display: block; font-size: .74rem; opacity: .78; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.lang-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; }
.lang-switch button { background: transparent; border: 0; color: #fff; padding: 5px 11px; font-size: .75rem; font-weight: 600; opacity: .75; }
.lang-switch button.active { background: var(--gold); color: var(--lapis-900); opacity: 1; }
.av-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,.08); color: #fff;
    border: 1px solid rgba(200,162,74,.6); border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600;
}
.av-toggle:hover, .av-toggle[aria-pressed="true"] { background: rgba(200,162,74,.22); }
.av-toggle .pill { background: var(--gold); color: var(--lapis-900); border-radius: 999px; padding: 0 7px; font-size: .68rem; text-transform: uppercase; }

/* ---------------- Workspace ---------------- */
.app-main { height: calc(100vh - var(--header-h)); }
.chat-workspace {
    height: 100%;
    display: grid;
    grid-template-columns: var(--left-sidebar-width) 5px minmax(0, 1fr) 0;
    transition: grid-template-columns .2s ease;
}
.chat-workspace.summary-open { grid-template-columns: var(--left-sidebar-width) 5px minmax(0, 1fr) var(--summary-width); }
.sidebar-resizer { cursor: col-resize; background: transparent; border-right: 1px solid var(--line); }
.sidebar-resizer:hover { background: var(--gold-soft); }
body.is-resizing-sidebar { user-select: none; cursor: col-resize; }

.workspace-panel { background: var(--card); display: flex; flex-direction: column; min-height: 0; }
.sidebar { border-right: 0; }
.mobile-drawer-header { display: none; }
.sidebar-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); background: #fbf8f0; }
.tab-btn { border: 0; background: transparent; padding: 11px 4px; font-size: .8rem; font-weight: 600; color: var(--ink-soft); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--lapis-800); border-bottom-color: var(--gold); background: var(--card); }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--line); }
.sidebar-footer button { width: 100%; }
.grid.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* persona & modes */
.persona-card { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.persona-card-portrait { width: 64px; height: 64px; border-radius: 50%; box-shadow: var(--shadow); }
.persona-card strong { display: block; font-family: var(--serif); font-size: 1.05rem; color: var(--lapis-800); }
.persona-card small { color: var(--muted); }
.persona-bio { font-size: .86rem; color: var(--ink-soft); margin: 0 0 6px; }
.persona-books { font-size: .82rem; margin: 0 0 16px; }
.mode-list { display: grid; gap: 8px; margin-bottom: 8px; }
.mode-card {
    display: flex; gap: 12px; align-items: flex-start; text-align: left;
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.mode-card svg { width: 26px; height: 26px; color: var(--lapis-700); background: var(--lapis-100); border-radius: 8px; padding: 4px; }
.mode-card strong { display: block; font-size: .9rem; color: var(--lapis-800); }
.mode-card small { display: block; font-size: .78rem; color: var(--muted); line-height: 1.4; }
.mode-card:hover { border-color: var(--lapis-500); box-shadow: var(--shadow); }
.mode-card.is-current { border-color: var(--gold); background: #fffaf0; box-shadow: inset 3px 0 0 var(--gold); }

/* filters */
.facet-checkbox-list { max-height: 170px; overflow-y: auto; border: 1px solid var(--line-soft); border-radius: 10px; padding: 6px 8px; margin-bottom: 12px; background: #fff; }
.facet-checkbox-list.compact { max-height: none; }
.facet-checkbox-list label { display: flex; align-items: center; gap: 8px; margin: 0; padding: 3px 0; font-size: .84rem; }
.facet-checkbox-list label span { margin: 0; font-weight: 400; color: var(--ink); font-size: .84rem; }
.facet-checkbox-empty { color: var(--muted); font-size: .82rem; }
.facet-counter { font-size: .82rem; color: var(--ink-soft); margin: 4px 0; }
.facet-warning { background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; font-size: .82rem; margin-bottom: 8px; }
.facet-select-all-row { display: flex; align-items: center; gap: 8px; font-size: .84rem; margin: 6px 0; }
.facet-select-all-row span { margin: 0; font-weight: 600; }
.facet-book-list { display: grid; gap: 2px; }
.facet-book-row { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; margin: 0; border-radius: 8px; font-size: .84rem; }
.facet-book-row:hover { background: #faf6ec; }
.facet-book-row input { margin-top: 3px; }
.facet-book-row > span { margin: 0; font-weight: 400; color: var(--ink); font-size: .84rem; }
.facet-book-meta { color: var(--muted); font-size: .76rem; }
.layer-badge { display: inline-block; font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 6px; padding: 1px 6px; margin-right: 4px; vertical-align: 1px; }
.layer-primary { background: var(--gold-soft); color: #7a5a14; }
.layer-research { background: var(--lapis-100); color: var(--lapis-800); }
.layer-reference { background: #e6f2ea; color: #2e6b45; }
.layer-fiction { background: #f5e6ef; color: #8a3a66; }

/* chats list */
.sidebar-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sidebar-head-row h3 { margin: 0; }
.chats-list { display: grid; gap: 6px; }
.chat-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; cursor: pointer; position: relative; }
.chat-item:hover { border-color: var(--lapis-500); }
.chat-item.active { border-color: var(--gold); background: #fffaf0; }
.chat-item-title { font-size: .86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 58px; }
.chat-item small { color: var(--muted); font-size: .74rem; }
.chat-item-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; }
.chat-item-tools button { border: 0; background: transparent; padding: 3px; border-radius: 6px; color: var(--muted); }
.chat-item-tools button:hover { background: var(--lapis-100); color: var(--lapis-800); }
.chat-item-tools svg { width: 15px; height: 15px; }
.mode-tag { font-size: .68rem; background: var(--lapis-100); color: var(--lapis-800); border-radius: 5px; padding: 0 5px; margin-right: 4px; }

.help p { font-size: .86rem; color: var(--ink-soft); }

/* ---------------- Chat area ---------------- */
.chat-area { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: rgba(255, 253, 248, .85); backdrop-filter: blur(6px); }
.topbar-mode { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mode-chip { font-family: var(--serif); font-weight: 600; color: var(--lapis-800); }
.scope-info { color: var(--muted); font-size: .8rem; }
.topbar-actions { display: flex; gap: 8px; }
.mobile-only { display: none; }
.chat-notice { margin: 8px 18px 0; background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; font-size: .85rem; }

.chat-messages { flex: 1; overflow-y: auto; padding: 22px max(18px, calc((100% - 860px) / 2)); scroll-behavior: smooth; }
.chat-msg { display: flex; gap: 12px; margin: 0 0 18px; align-items: flex-start; }
.chat-msg.chat-user { justify-content: flex-end; }
.chat-msg .chat-content { max-width: 100%; min-width: 0; }
.chat-user .chat-content { background: var(--lapis-700); color: #fff; padding: 10px 14px; border-radius: 16px 16px 4px 16px; max-width: 78%; white-space: pre-wrap; box-shadow: var(--shadow); }
.chat-assistant .msg-body { flex: 1; min-width: 0; }
.chat-assistant .chat-content { background: var(--card); border: 1px solid var(--line); padding: 14px 18px; border-radius: 4px 16px 16px 16px; box-shadow: var(--shadow); }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; box-shadow: var(--shadow); cursor: pointer; background: var(--lapis-100); }
.chat-avatar.scholar { display: grid; place-items: center; color: var(--lapis-700); }
.chat-avatar.scholar svg { width: 22px; height: 22px; }
.chat-content p { margin: 0 0 .7em; }
.chat-content p:last-child { margin-bottom: 0; }
.chat-content h2, .chat-content h3, .chat-content h4 { margin: .8em 0 .4em; font-size: 1.02rem; }
.chat-content ul, .chat-content ol { margin: .2em 0 .8em; padding-left: 1.4em; }
.chat-content blockquote { margin: .4em 0 .9em; padding: 6px 12px; border-left: 3px solid var(--gold); background: #fffaf0; color: var(--ink-soft); border-radius: 0 8px 8px 0; }
.chat-content code { background: #f1ede2; padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.chat-content pre { background: #1d2433; color: #f6f2e8; padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.chat-content hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.chat-table-wrap { overflow-x: auto; margin: .5em 0 1em; }
.chat-table-wrap table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.chat-table-wrap th, .chat-table-wrap td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.chat-table-wrap th { background: #faf5e8; font-weight: 600; }
.cite-chip { display: inline-block; font-size: .76rem; background: var(--gold-soft); color: #6b4f12; border-radius: 6px; padding: 0 6px; text-decoration: none; margin: 0 1px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: baseline; }
.cite-chip:hover { background: #ecd89f; }
.lesson-question { display: block; margin-top: .6em; padding: 10px 12px; background: var(--lapis-100); border-radius: 10px; }

.chat-sources { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
.chat-sources h4 { font-family: var(--sans); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
.library-source-list, .web-source-list { margin: 0 0 6px; padding-left: 1.1em; font-size: .84rem; }
.library-source-list li { margin-bottom: 4px; }
.library-source-list a { text-decoration: none; background: var(--lapis-100); padding: 0 6px; border-radius: 5px; font-size: .78rem; margin-right: 2px; }
.library-source-list a.cited { background: var(--gold-soft); color: #6b4f12; font-weight: 600; }
.web-source-list small { display: block; color: var(--muted); }

.msg-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 6px; padding-left: 2px; }
.chat-response-time { color: var(--muted); font-size: .76rem; }
.msg-actions { display: inline-flex; gap: 4px; }
.msg-actions button { border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 3px 6px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; }
.msg-actions button:hover { background: var(--lapis-100); color: var(--lapis-800); }
.msg-actions button.active { color: var(--lapis-700); background: var(--lapis-100); border-color: #cdd6f0; }
.msg-actions button.active.down { color: var(--danger); background: var(--danger-bg); border-color: #f3c2bd; }
.msg-actions svg { width: 15px; height: 15px; }
.summary-message-badge { display: inline-block; font-size: .72rem; font-weight: 700; background: var(--gold-soft); color: #6b4f12; border-radius: 6px; padding: 1px 8px; margin-bottom: 6px; }
.mode-badge { display: inline-block; font-size: .7rem; color: var(--muted); margin-bottom: 4px; }
.quote-warning { margin-top: 10px; background: var(--warn-bg); border: 1px solid #f0dc9d; border-radius: 10px; padding: 8px 12px; font-size: .82rem; }
.quote-warning ul { margin: 4px 0 0; padding-left: 1.2em; }
.knowledge-offer { margin-top: 10px; }
.knowledge-answer-btn { background: #fff; border: 1px dashed var(--lapis-500); color: var(--lapis-700); border-radius: 10px; padding: 7px 12px; font-size: .84rem; font-weight: 600; }
.knowledge-answer-btn:hover:not(:disabled) { background: var(--lapis-100); }

.chat-answer-loading { display: flex; gap: 6px; align-items: center; }
.chat-answer-loading span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1.2s infinite ease-in-out; }
.chat-answer-loading span:nth-child(2) { animation-delay: .15s; }
.chat-answer-loading span:nth-child(3) { animation-delay: .3s; }
.chat-answer-loading small { margin-left: 6px; color: var(--muted); }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.request-error { background: var(--danger-bg); border: 1px solid #f3c2bd; border-radius: 10px; padding: 10px 12px; color: var(--danger); }
.request-error p { margin: 0 0 4px; }
.request-error small { display: block; color: var(--ink-soft); margin-bottom: 6px; }
.request-error button { border: 1px solid #e6a7a1; background: #fff; border-radius: 8px; padding: 4px 10px; font-size: .8rem; color: var(--danger); }

/* welcome */
.welcome { text-align: center; max-width: 640px; margin: 4vh auto 0; }
.welcome img { width: 112px; height: 112px; border-radius: 50%; box-shadow: 0 8px 30px rgba(20,39,94,.25); }
.welcome h2 { margin: 14px 0 6px; font-size: 1.45rem; }
.welcome p { color: var(--ink-soft); margin: 0 auto 14px; }
.welcome .disclaimer { font-size: .78rem; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; }
.suggestions button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; font-size: .84rem; color: var(--lapis-800); }
.suggestions button:hover { border-color: var(--gold); background: #fffaf0; }

/* persona banner */
.persona-banner { position: relative; display: flex; gap: 14px; align-items: flex-start; background: linear-gradient(120deg, #fffaf0, #f7f0dc); border: 1px solid #ecdcb0; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; }
.persona-banner img { width: 72px; height: 72px; border-radius: 50%; }
.persona-banner strong { font-family: var(--serif); font-size: 1.1rem; color: var(--lapis-800); }
.persona-banner small { display: block; color: var(--muted); }
.persona-banner p { margin: 6px 0 0; font-size: .86rem; color: var(--ink-soft); }
.persona-banner .panel-close { position: absolute; top: 6px; right: 8px; }

/* progress */
.request-progress { display: flex; align-items: center; gap: 12px; padding: 6px max(18px, calc((100% - 860px) / 2)); font-size: .82rem; color: var(--ink-soft); }
.progress-bar { flex: 1; height: 4px; background: var(--line-soft); border-radius: 4px; overflow: hidden; position: relative; }
.progress-bar span { position: absolute; left: -40%; width: 40%; height: 100%; background: linear-gradient(90deg, var(--lapis-500), var(--gold)); border-radius: 4px; animation: slide 1.3s infinite ease-in-out; }
@keyframes slide { to { left: 100%; } }
.summary-sidebar .request-progress { padding: 8px 0; }

/* composer */
.chat-composer { padding: 10px max(18px, calc((100% - 860px) / 2)) 16px; border-top: 1px solid var(--line); background: var(--card); }
.chat-composer textarea { resize: none; min-height: 52px; max-height: 220px; border-radius: 12px; padding: 11px 14px; font-size: .95rem; }
.composer-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.web-search-toggle { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .84rem; }
.web-search-toggle span { margin: 0; font-weight: 500; font-size: .84rem; color: var(--ink-soft); }
.composer-hint { flex: 1; font-size: .74rem; text-align: right; }

/* ---------------- Summary panel ---------------- */
.summary-sidebar { border-left: 1px solid var(--line); overflow: hidden; }
.summary-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.summary-header h2 { font-size: 1.1rem; margin: 0; }
.plan-label { font-size: .72rem; color: var(--muted); }
.panel-close { border: 0; background: transparent; font-size: 1.5rem; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.panel-close:hover { background: var(--lapis-100); color: var(--lapis-800); }
.summary-scroll { flex: 1; overflow-y: auto; padding: 14px 16px; }
.summary-selection-state { font-size: .84rem; margin-bottom: 6px; }
.summary-selection-state.warning { color: #8a5a00; background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }
.summary-books-list { display: grid; gap: 4px; margin-bottom: 12px; }
.summary-book-item { font-size: .82rem; background: #fff; border: 1px solid var(--line-soft); border-radius: 8px; padding: 5px 8px; }
.summary-controls { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }
.summary-controls legend { font-size: .8rem; font-weight: 600; color: var(--ink-soft); padding: 0 4px; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.segmented-control label { margin: 0; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: .84rem; }
.segmented-control label span { margin: 0; font-weight: 500; color: var(--ink); font-size: .84rem; }
.summary-result { margin-top: 14px; }
.summary-result-content { font-size: .88rem; }
.summary-result-content.muted { color: var(--muted); }
.summary-cap-notice { font-size: .78rem; color: #8a5a00; }
.summary-footer { padding: 12px 16px; border-top: 1px solid var(--line); }

/* ---------------- Audiovisual stub ---------------- */
.av-stage {
    position: relative;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 22px;
    align-items: center;
    margin: 14px max(18px, calc((100% - 900px) / 2)) 0;
    padding: 20px 24px;
    border-radius: 18px;
    color: #f4efe2;
    background:
        radial-gradient(circle at 20% 30%, rgba(200,162,74,.18), transparent 55%),
        linear-gradient(135deg, var(--lapis-900), var(--lapis-800));
    box-shadow: 0 10px 40px rgba(14,26,64,.35);
    border: 1px solid rgba(200,162,74,.45);
}
.av-portrait-wrap { position: relative; width: 200px; height: 200px; margin: 0 auto; }
.av-portrait { position: relative; width: 200px; height: 200px; border-radius: 50%; z-index: 1; }
.av-halo { position: absolute; inset: -12px; border-radius: 50%; background: radial-gradient(circle, rgba(200,162,74,.45), transparent 70%); animation: breathe 4s infinite ease-in-out; }
@keyframes breathe { 0%, 100% { transform: scale(.94); opacity: .6; } 50% { transform: scale(1.05); opacity: 1; } }
.av-wave { position: absolute; left: 50%; bottom: -14px; transform: translateX(-50%); display: flex; gap: 4px; z-index: 2; background: rgba(14,26,64,.85); padding: 6px 10px; border-radius: 999px; border: 1px solid rgba(200,162,74,.5); }
.av-wave i { display: block; width: 4px; height: 14px; background: var(--gold); border-radius: 2px; opacity: .5; }
.av-stage.speaking .av-wave i { animation: wave 1s infinite ease-in-out; opacity: 1; }
.av-wave i:nth-child(2) { animation-delay: .1s; } .av-wave i:nth-child(3) { animation-delay: .2s; } .av-wave i:nth-child(4) { animation-delay: .3s; }
.av-wave i:nth-child(5) { animation-delay: .4s; } .av-wave i:nth-child(6) { animation-delay: .5s; } .av-wave i:nth-child(7) { animation-delay: .6s; }
@keyframes wave { 0%, 100% { transform: scaleY(.4); } 50% { transform: scaleY(1.4); } }
.av-body h3 { color: #fff; font-size: 1.2rem; margin: 6px 0; }
.av-badge { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--gold); color: var(--lapis-900); border-radius: 999px; padding: 2px 10px; }
.av-desc { font-size: .86rem; opacity: .85; margin: 0 0 10px; }
.av-subtitle { background: rgba(0,0,0,.28); border-radius: 10px; padding: 10px 14px; min-height: 48px; font-size: .9rem; font-family: var(--serif); line-height: 1.5; margin-bottom: 12px; max-height: 110px; overflow: hidden; }
.av-subtitle span { opacity: .6; font-family: var(--sans); font-size: .84rem; }
.av-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.av-controls button { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 6px 12px; font-size: .8rem; }
.av-pipeline { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.av-pipeline li { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); border-radius: 10px; padding: 6px 8px; font-size: .74rem; }
.av-pipeline li strong { display: block; color: var(--gold); font-size: .78rem; }
.av-pipeline li.done { border-color: rgba(200,162,74,.7); }
.av-close { position: absolute; top: 8px; right: 10px; color: #fff; }
.av-close:hover { background: rgba(255,255,255,.12); color: #fff; }
body.av-mode .chat-messages { padding-top: 14px; }

/* ---------------- Reader ---------------- */
.reader-page .app-main { height: auto; min-height: calc(100vh - var(--header-h)); }
.reader { max-width: 820px; margin: 0 auto; padding: 22px 18px 60px; }
.reader-crumbs a { text-decoration: none; font-size: .88rem; }
.reader-head { margin: 12px 0 16px; }
.reader-head h1 { font-size: 1.55rem; margin: 6px 0; }
.reader-annotation { font-size: .88rem; color: var(--ink-soft); }
.reader-nav { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--parchment); padding: 10px 0; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.reader-jump { display: flex; align-items: center; gap: 6px; font-size: .88rem; }
.reader-jump input { width: 90px; }
.reader-fragment { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 22px; margin-bottom: 14px; font-family: var(--serif); font-size: 1.02rem; line-height: 1.7; opacity: .6; }
.reader-fragment.is-target { opacity: 1; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(200,162,74,.2), var(--shadow); }
.reader-fragment p { margin: 0 0 .7em; }
.reader-fragment-label { font-family: var(--sans); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.reader-note { margin-top: 20px; }

/* ---------------- Responsive ---------------- */
.chat-panel-overlay { display: none; }
@media (max-width: 1279px) {
    .chat-workspace, .chat-workspace.summary-open { grid-template-columns: minmax(0, 1fr); }
    .sidebar-resizer { display: none; }
    .workspace-panel { position: fixed; top: 0; bottom: 0; z-index: 50; width: min(92vw, 380px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.2); }
    #filters-panel { left: 0; }
    #summary-panel { right: 0; left: auto; transform: translateX(105%); }
    .workspace-panel.is-open { transform: none; }
    .chat-panel-overlay.is-visible { display: block; position: fixed; inset: 0; background: rgba(14,26,64,.35); z-index: 40; }
    .mobile-drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
    .mobile-only { display: inline-flex; }
}
@media (max-width: 760px) {
    .brand-text small, .av-toggle span:not(.pill), .composer-hint { display: none; }
    .av-stage { grid-template-columns: 1fr; text-align: center; }
    .av-pipeline { grid-template-columns: repeat(2, 1fr); }
    .av-controls { justify-content: center; }
    .chat-user .chat-content { max-width: 90%; }
    .chat-avatar { width: 32px; height: 32px; }
    .topbar-actions .btn-ghost { padding: 5px 8px; }
}
