/* Interface only. Saved book fonts, --pv-* output settings and canvas engines
   remain owned by their existing modules. Loaded only on authenticated views. */
.app-body {
  --bg-page:#f7f5ef; --bg-card:#fff; --bg-rail:#f1f2eb;
  --bg-rail-hover:#e7ece3; --bg-topbar:#fff; --bg-topbar-soft:#edf2eb;
  --bg-chapter-current:#d6e2d0;
  --ink-1:#27372f; --ink-2:#394a40; --ink-3:#59695f; --ink-4:#69776d;
  --line:#dce1d7; --line-soft:#e9ece4; --line-strong:#bec9bd;
  --accent:#285b47; --accent-soft:#36745c; --accent-bg:#e6eee6;
  --ui-primary:#285b47; --ui-on-primary:#fff;
  background:var(--bg-page); color:var(--ink-1);
}
:root[data-theme="dark"] .app-body {
  --bg-page:#202923; --bg-card:#29342d; --bg-rail:#253128;
  --bg-rail-hover:#35483b; --bg-topbar:#29342d; --bg-topbar-soft:#35483b;
  --bg-chapter-current:#435c49;
  --ink-1:#eef1e8; --ink-2:#d4dfd3; --ink-3:#b3bfb3; --ink-4:#a7b5a7;
  --line:#455248; --line-soft:#39463c; --line-strong:#667b69;
  --accent:#a7d0b5; --accent-soft:#bfdfc9; --accent-bg:#354d3c;
  --ui-primary:#a7d0b5; --ui-on-primary:#183322;
}
.app-body .chapter-item.is-active { background:var(--bg-chapter-current); }
.app-body :is(button,a,input,select,textarea,summary):focus-visible {
  outline:2px solid var(--accent); outline-offset:3px;
}
.app-body :is(.btn,.select,.field input,.field select,.field textarea) { border-radius:7px; }
.app-body .btn-primary { background:var(--ui-primary); color:var(--ui-on-primary); border-color:var(--ui-primary); }
.app-body .btn-primary:hover { background:var(--ui-primary); color:var(--ui-on-primary); filter:brightness(.94); }
.app-body :is(.topbar,.editor-topbar) { background:var(--bg-card); color:var(--ink-1); border-bottom:1px solid var(--line); }
.app-body :is(.topbar-wordmark,.topbar-title-text) { color:var(--ink-1); text-transform:none; letter-spacing:.015em; }
.app-body :is(.topbar-admin-link,.topbar-home,.topbar-iconbtn,.topbar-help-btn,.btn-edit-details,.btn-back-editor,.topbar-signout) {
  color:var(--ink-2); border-color:var(--line); background:transparent;
}
.app-body :is(.topbar-admin-link,.topbar-home,.topbar-iconbtn,.topbar-help-btn,.btn-edit-details,.btn-back-editor):hover {
  color:var(--accent); background:var(--accent-bg); border-color:var(--line-strong);
}
.app-body .topbar-divider { background:var(--line); }
.app-body .user-avatar { background:var(--accent-bg); color:var(--accent); }
.app-body .topbar-export-pill { background:var(--ui-primary); color:var(--ui-on-primary); border-color:var(--ui-primary); }
.app-body .save-status { color:var(--accent); }
.app-body .user-menu-dropdown { background:var(--bg-card); color:var(--ink-1); border-color:var(--line); }
.app-body .user-menu-item { color:var(--ink-2); }
.app-body .user-menu-item:hover { background:var(--accent-bg); color:var(--accent); }

/* Quiet hover surfaces must retain contrast for nested labels and captions.
   --accent-soft is a saturated button color, not a menu highlight. */
.app-body .topbar-back-link { color:var(--ink-2); }
.app-body .topbar-back-link:is(:hover,:focus-visible) { color:var(--accent); text-decoration:underline; text-underline-offset:3px; }
.app-body :is(
  .export-menu-item,.wm-menu-item,.theme-action-pop-item,
  .figure-toolbar-floater button,.tts-btn,.find-snippet.is-jumpable,
  .res-chip,.corkboard-bulk-btn,.corkboard-status-pill,.diff-swap-btn,
  .diff-collapsed-toggle,.outline-open,.outline-hover-beat,.outline-syn,
  .outline-pick-row,.outline-insp-close,.outline-insp-beat,.chapter-caret,
  .emoji-cell,.tf-gear-pop button
):is(:hover,:focus-visible) { background:var(--accent-bg); color:var(--ink-1); }
.app-body :is(.emoji-tab.is-on,.tf-rolebar-btn.is-on),
.app-body .outline-row.is-selected td { background:var(--accent-bg); }
.app-body .tts-btn:is(:hover,:focus-visible) { border-color:var(--line-strong); }

/* Compact library with the original sortable groups and card actions. */
.library-page .lib-band {
  --band-ink-1:var(--ink-1); --band-ink-2:var(--ink-2); --band-ink-3:var(--ink-3);
  --band-glass:var(--bg-card); --band-glass-line:var(--line);
  background:var(--bg-page); min-height:0; overflow:visible; z-index:2;
}
.library-page .topbar { z-index:3; }
.library-page .lib-band-bg { display:none; }
.library-page .lib-band-inner { padding:40px 40px 24px; }
.library-page .library-hero { align-items:flex-start; gap:24px; }
.library-page .library-title { font-size:36px; margin-bottom:8px; }
.library-page .lib-band :is(.library-title,.library-sub,.btn,.library-stat) { text-shadow:none; box-shadow:none; }
.library-page .library-actions { max-width:680px; gap:10px; }
.library-page .lib-band .btn { background:var(--bg-card); border-color:var(--line); color:var(--ink-2); }
.library-page .lib-band .btn-primary { background:var(--ui-primary); color:var(--ui-on-primary); border-color:var(--ui-primary); }
.library-page .lib-band .library-actions :is(.library-search-input,.select) { background:var(--bg-card); border-color:var(--line); color:var(--ink-1); }
.library-page .lib-band .library-search-input::placeholder { color:var(--ink-3); }
.library-page .library-stat { border-radius:8px; }
.library-page .lib-shelf { padding:8px 40px 64px; }
.library-page .book-grid { gap:24px; }
.library-page .book-card { padding:14px; border:1px solid var(--line); border-radius:12px; background:var(--bg-card); }
.library-page .book-cover-link::after { display:none; }
.library-page .book-cover-link { box-shadow:none; }
.library-page .book-card:hover { border-color:var(--line-strong); box-shadow:0 6px 20px #20372a0b; }
.library-page .book-progress { overflow:visible; margin-bottom:24px; }
.library-page .book-progress-label { top:8px; right:0; transform:none; font-size:11px; background:transparent; color:var(--ink-3); padding:0; }
.continue-writing { display:flex; align-items:center; justify-content:space-between; gap:24px; margin:0 0 32px; padding:24px; background:var(--accent-bg); border:1px solid var(--line); border-radius:12px; }
.continue-label { color:var(--accent); font:600 11px var(--font-sans); text-transform:uppercase; letter-spacing:.12em; }
.continue-writing h2 { margin:8px 0; font:500 24px var(--font-display); }
.continue-writing p { color:var(--ink-3); margin:0; font-size:13px; }
.continue-writing .btn { flex-shrink:0; }

/* Editor and book details share the header, including its optional utility row.
   Keep both responsive so added controls cannot overflow a fixed-height bar. */
:is(.editor-body,.details-body) .editor-topbar { height:auto; min-height:104px; grid-template-columns:minmax(0,1fr) auto; grid-template-rows:52px 48px; gap:0 16px; padding:0 24px; }
:is(.editor-body,.details-body) .editor-topbar>.topbar-left { grid-area:1/1; min-width:0; width:100%; max-width:100%; }
:is(.editor-body,.details-body) .topbar-title-block { min-width:0; }
:is(.editor-body,.details-body) .topbar-title-text { overflow:hidden; text-overflow:ellipsis; }
:is(.editor-body,.details-body) .editor-topbar>.topbar-right { grid-area:1/2; }
:is(.editor-body,.details-body) .editor-topbar>.topbar-center { grid-area:2/1/3/3; width:100%; justify-content:space-between; border-top:1px solid var(--line-soft); min-width:0; }
:is(.editor-body,.details-body) .view-tabs { background:transparent; border-radius:0; gap:4px; overflow-x:auto; min-width:0; }
:is(.editor-body,.details-body) .view-tab { color:var(--ink-3); padding:9px 18px; border-radius:6px; white-space:nowrap; }
:is(.editor-body,.details-body) .view-tab:hover { background:var(--bg-rail); color:var(--ink-1); }
:is(.editor-body,.details-body) .view-tab.is-active { background:var(--accent-bg); color:var(--accent); box-shadow:none; }
:is(.editor-body,.details-body) .topbar-title-text { max-width:min(40vw,560px); }
.details-body .btn-back-editor { flex-shrink:0; white-space:nowrap; }
.editor-body .sidebar { background:var(--bg-card); }
.editor-body :is(.chapter-sidebar,.rail-panel) { background:var(--bg-card); }
.editor-body .sidebar-footer { background:var(--bg-card); }
.editor-body .icon-rail { background:var(--bg-card); }
.editor-body .rail-btn { color:var(--ink-3); }
.editor-body .rail-btn:hover,.editor-body .rail-btn.is-active { background:var(--accent-bg); color:var(--accent); }
.editor-body .manuscript:not(.has-backdrop) { background-color:var(--bg-rail); }
.app-body :is(.codex-drawer-head,.scratchpad-head,.todo-head) { background:var(--bg-card); color:var(--ink-1); border-color:var(--line); }
.app-body :is(.codex-drawer-tab,.scratchpad-tab,.todo-tab) { background:var(--ui-primary); color:var(--ui-on-primary); border-color:var(--line-strong); box-shadow:0 3px 12px #20372a22; }
.app-body :is(.codex-drawer-close,.scratchpad-close,.todo-close) { color:var(--ink-2); }

/* Existing admin destinations, filters, tables and forms share one palette. */
.admin-body .admin-nav { background:var(--bg-card); color:var(--ink-2); border-right:1px solid var(--line); }
.admin-body :is(.admin-nav-head,.admin-nav-foot) { border-color:var(--line); }
.admin-body :is(.admin-logo,.admin-nav-user,.admin-nav-link,.admin-nav-group-header) { color:var(--ink-3); }
.admin-body .admin-nav-link { margin:2px 10px; border-radius:7px; }
.admin-body .admin-nav-link:hover { background:var(--bg-rail); color:var(--ink-1); }
.admin-body .admin-nav-link.is-active { background:var(--accent-bg); color:var(--accent); border-color:var(--accent); }
.admin-body .admin-nav-link.is-active .admin-nav-icon { color:var(--accent); }
.admin-body :is(.admin-nav-filter input,.admin-nav-signout-btn) { background:var(--bg-page); color:var(--ink-2); border-color:var(--line); }
.admin-body .admin-nav-filter input::placeholder { color:var(--ink-3); }
.admin-body .admin-main { max-width:1500px; }
.admin-body .admin-nav { overflow-x:hidden; }
.admin-body .admin-maintenance-card summary { cursor:pointer; margin:0; }
.admin-body .admin-overview-priorities { grid-template-columns:minmax(0,2fr) minmax(0,1fr); align-items:start; }
@media(max-width:680px) { .admin-body .admin-overview-priorities { grid-template-columns:1fr; } }
.admin-body .admin-card { border-radius:12px; border-color:var(--line); }
.admin-body th { background:var(--bg-rail); color:var(--ink-2); }
.interior-menu { position:relative; }
.interior-menu summary { cursor:pointer; list-style:none; }
.interior-menu summary::-webkit-details-marker { display:none; }
.interior-menu summary::after { content:'⌄'; margin-left:8px; }
.interior-menu-panel { position:absolute; right:0; top:calc(100% + 8px); z-index:350; width:240px; padding:8px; display:flex; flex-direction:column; gap:4px; background:var(--bg-card); border:1px solid var(--line); border-radius:10px; box-shadow:0 12px 32px #14271c22; }
.interior-menu-panel .btn { width:100%; text-align:left; justify-content:flex-start; }
.interior-menu-panel .inline-form { margin:0; }
@media (max-width:700px) {
  .library-page .library-actions { position:relative; }
  .library-page .library-actions .interior-menu { position:static; }
  .library-page .library-actions .interior-menu-panel { right:0; max-width:calc(100vw - 48px); box-sizing:border-box; }
}
.sidebar-footer .interior-menu-panel { top:auto; bottom:calc(100% + 8px); right:auto; left:0; }
.interior-drawer-toggle { display:none; flex-shrink:0; }
@media(max-width:900px) {
  .admin-body .admin-toggle { display:inline-flex; margin-bottom:16px; }
  .admin-body .admin-shell { display:block; }
  .admin-body .admin-nav { display:none; }
  .admin-body .admin-nav.interior-drawer-open { display:block; position:fixed; inset:0 auto 0 0; width:min(300px,85vw); height:100dvh; overflow:auto; z-index:400; box-shadow:10px 0 40px #10241d33; }
  .admin-body .admin-nav-list { display:block; }
  .admin-body :is(.admin-nav-section,.admin-nav-group-items,.admin-nav-group-items li) { display:block; }
  .admin-body .admin-nav-group-header { display:flex; }
  .admin-body .admin-nav-group-items li[hidden] { display:none; }
  .admin-body .admin-nav-filter { display:block; }
  .admin-body .admin-nav-head { padding:20px; }
}
@media(max-width:680px) {
  .editor-body .chapters-toggle { display:inline-flex; padding:7px; font-size:11px; }
  .editor-body .chapter-sidebar.interior-drawer-open { display:flex; position:fixed; left:0; top:104px; bottom:0; width:min(300px,85vw); z-index:220; box-shadow:10px 0 40px #10241d33; }
  .editor-body .editor-body-grid,.editor-body .editor-body-grid.is-panel-open { grid-template-columns:minmax(0,1fr) 44px; }
  .editor-body .icon-rail { display:flex; grid-column:2; width:44px; overflow-y:auto; }
  .editor-body .rail-panel:not([hidden]) { display:flex; position:fixed; top:104px; right:44px; bottom:0; width:min(300px,calc(100vw - 60px)); z-index:210; box-shadow:-8px 0 32px #10241d22; }
  :is(.editor-body,.details-body) .editor-topbar>.topbar-center { gap:6px; }
  :is(.editor-body,.details-body) .topbar-export-pill { padding:7px; font-size:10px; }
  :is(.editor-body,.details-body) .topbar-export-pill .export-caret { display:none; }
}
@media(max-width:1000px) {
  .library-page .library-hero { flex-direction:column; }
  .library-page .library-actions { max-width:none; justify-content:flex-start; }
  :is(.editor-body,.details-body) .view-tab { padding:9px 12px; }
  :is(.editor-body,.details-body) .editor-topbar { padding:0 12px; }
}
@media(max-width:600px) {
  .library-page :is(.lib-band-inner,.lib-shelf) { padding-left:16px; padding-right:16px; }
  .library-page .book-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
  .library-page .book-card { padding:8px; min-width:0; }
  .library-page .library-actions { width:100%; }
  .library-page .library-search-input { width:100%; flex-basis:100%; }
  .continue-writing { align-items:flex-start; flex-direction:column; padding:18px; }
  :is(.editor-body,.details-body) .editor-topbar>.topbar-right { gap:6px; }
  :is(.editor-body,.details-body) .topbar-title-text { max-width:38vw; font-size:14px; }
  :is(.editor-body,.details-body) .editor-topbar>.topbar-left { overflow:hidden; }
  :is(.editor-body,.details-body) .topbar-title-text { max-width:100%; }
  :is(.editor-body,.details-body) .topbar-title-block { gap:4px; }
  .editor-body .btn-edit-details { padding:4px; font-size:10px; }
  :is(.editor-body,.details-body) .view-tab { padding:9px 10px; font-size:12px; }
  .app-body .topbar { padding:0 12px; }
  .app-body .topbar-right { gap:8px; }
}
/* Optional session tools cannot consume the chapter navigator. */
.interior-utility-original { display:none !important; }
.interior-utilities { display:flex; align-items:center; justify-content:space-between; gap:12px; min-width:0; padding:6px 0; background:var(--bg-card); border-top:1px solid var(--line); }
.interior-utilities-left,.interior-utilities-right { display:flex; gap:8px; align-items:center; }
.interior-utilities-right { margin-left:auto; }
.app-body .interior-utility { color:var(--ink-2); background:var(--bg-card); border:1px solid var(--line-strong); padding:6px 12px; min-height:32px; font-size:12px; white-space:nowrap; }
.app-body .interior-utility:is(:hover,[aria-expanded="true"]) { background:var(--accent-bg); color:var(--ink-1); border-color:var(--accent); }
:is(.editor-body,.details-body) .editor-topbar.has-utilities { grid-template-rows:52px 48px auto; }
:is(.editor-body,.details-body) .editor-topbar>.interior-utilities { grid-column:1/-1; grid-row:3; }
.editor-body .editor-shell.is-focus-mode .editor-topbar.has-utilities { display:flex !important; min-height:44px; padding-right:66px; }
.editor-shell.is-focus-mode .editor-topbar.has-utilities>:not(.interior-utilities) { display:none; }
.editor-shell.is-focus-mode .interior-utilities { width:100%; border-top:0; }
.app-body .topbar.has-utilities:not(.editor-topbar) { height:auto; flex-wrap:wrap; }
.topbar:not(.editor-topbar)>.interior-utilities { flex-basis:100%; width:100%; }
.admin-main>.interior-utilities { position:sticky; top:0; z-index:100; margin-bottom:16px; }
/* Open overlays begin below the reserved row, keeping all launchers reachable. */
.app-body:has(.interior-utilities) :is(#codex-drawer,#todo-drawer,#scratchpad) { top:var(--interior-header-bottom,144px); height:calc(100dvh - var(--interior-header-bottom,144px)); }
.app-body:has(.interior-utilities) :is(.codex-drawer-panel,.scratchpad-panel) { max-height:100%; }
@media(max-width:680px) {
  .interior-utilities { gap:6px; }
  .interior-utilities-right { gap:6px; }
  .app-body .interior-utility { padding:6px 10px; }
  .editor-body:has(.interior-utilities) :is(.chapter-sidebar.interior-drawer-open,.rail-panel:not([hidden])) { top:var(--interior-header-bottom,144px); }
}
.sidebar-footer:has(.writing-desk-note),.sidebar-footer:has(.guided-checklist){max-height:45%;overflow-y:auto;flex-shrink:0}
.writing-desk-note summary,.guided-checklist summary{cursor:pointer;color:var(--ink-1)}
.writing-desk-note[open] label{display:block;margin-top:8px}
/* Small launchers leave the chapter list room; expanded tools stay usable. */
.editor-body .sidebar-footer { display:flex; flex-wrap:wrap; align-items:flex-start; gap:6px; padding:8px; }
.editor-body .sidebar-footer .btn-add-chapter { width:30px; min-width:30px; height:30px; padding:0; margin:0; flex:0 0 30px; }
.editor-body .sidebar-footer .btn-add-chapter .plus { font-size:20px; line-height:1; }
.editor-body .sidebar-footer>.writing-desk-note { min-width:0; padding:0; }
.editor-body .sidebar-footer>.writing-desk-note>summary,
.editor-body .sidebar-footer>.interior-menu>summary { box-sizing:border-box; min-height:30px; padding:5px 7px; font-size:11px; line-height:18px; border:1px solid var(--line); border-radius:6px; background:var(--bg-card); cursor:pointer; }
.editor-body .sidebar-footer>.writing-desk-note[open],
.editor-body .sidebar-footer>.interior-menu[open] { flex-basis:100%; }
.editor-body .sidebar-footer>.writing-desk-note[open]>:not(summary) { margin-top:8px; }
.editor-body .sidebar-footer .interior-menu-panel { position:static; width:100%; box-sizing:border-box; margin-top:6px; box-shadow:none; }
.editor-body .topbar-recovery { margin-right:10px; font-size:12px; white-space:nowrap; }
@media(max-width:900px) {
  .editor-body .editor-topbar { grid-template-rows:52px auto; }
  .editor-body .editor-topbar.has-utilities { grid-template-rows:52px auto auto; }
  .editor-body .editor-topbar>.topbar-center { flex-wrap:wrap; min-height:48px; gap:4px; padding:4px 0; }
  .editor-body .topbar-export { flex-wrap:wrap; justify-content:flex-end; gap:4px; }
  .editor-body .topbar-recovery { white-space:normal; max-width:130px; margin-right:4px; }
}
.support-main,.support-card,.support-form{min-width:0;max-width:100%}
.support-form select,.support-form input,.support-form textarea{min-width:0;max-width:100%}
[data-problem-report]{margin:12px 0;padding:16px;border:1px solid var(--line);border-radius:10px}
[data-problem-report] legend{max-width:100%;white-space:normal}

/* ---- Admin: theme-aware surfaces (2026-10-23) ----
   Cards, stat tiles and alerts were typed as literal light colours, so
   dark mode showed white cards with pale text. They now ride the
   .app-body palette above; alerts get their own dark tints. */
.admin-body :is(.admin-card,.admin-stat,.admin-row-edit-panel) { background:var(--bg-card); color:var(--ink-1); }
.admin-body :is(.admin-card .admin-html:focus,.preset-edit-form textarea.admin-html:focus) { background:var(--bg-card); }
.admin-body .admin-page-title { color:var(--ink-1); }
.admin-body .admin-page-sub { color:var(--ink-3); max-width:72ch; }
.admin-body .admin-empty { color:var(--ink-3); }
:root[data-theme="dark"] .admin-body .admin-alert-ok    { background:#24382a; color:#cde6c7; }
:root[data-theme="dark"] .admin-body .admin-alert-error { background:#44261f; color:#f2c6bc; }
:root[data-theme="dark"] .admin-body :is(.admin-alert-warn,.admin-log-truncated) { background:#3d3519; color:#f0dfa8; }
:root[data-theme="dark"] .admin-body .admin-announce-pill-info    { background:#22343f; color:#c4dcec; }
:root[data-theme="dark"] .admin-body .admin-announce-pill-success { background:#24382a; color:#cde6c7; }
.admin-body .admin-legacy-card > summary { cursor:pointer; margin:0; color:var(--ink-3); }
.admin-body .admin-legacy-card[open] > summary { margin-bottom:12px; }
