/* Diligence: design tokens and base components. A copy of Lyceum's styles.css (apps\lyceum\ui\styles.css, itself made
   from Ledger's): the same fonts, warm paper colours, spacing and components, with Diligence's own accent, a deep
   indigo, in place of Lyceum's green-blue. Plain CSS, no build step.
   Rule for every file: never a coloured side-stripe (no border-left or border-right wider than 1px on cards, rows,
   callouts or selected items). Selection is a background fill (--sel); a state is a chip with a word and an icon.
   The UI harness runs a self-check for this in the app, and common.js runs it in the browser preview. */@font-face { font-family: "Instrument Serif"; src: url("fonts/instrument-serif-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("fonts/instrument-serif-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Inter Tight"; src: url("fonts/inter-tight-latin-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Inter Tight"; src: url("fonts/inter-tight-latin-wght-italic.woff2") format("woff2"); font-weight: 100 900; font-style: italic; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }

/* ---------- tokens (light) ----------
   The accent #3B3F86 on the cream panel #FBF6EA has a contrast of about 8.7 to 1 (text and buttons); in the dark
   theme the accent fill #4B50A3 under cream text about 6.5 to 1, and the link colour #AEB2F2 on #1B1714 about 8.9 to 1. */
:root {
  --dil: #3B3F86; --ink: #1B1714; --beige: #F3ECDC; --cream: #FBF6EA; --hairline: #D8CDB6;
  --body: #3A332C; --grey: #675E52; --grey-faint: #857A6B; --gold: #B08A2E; --sand: #EADFC9;

  --bg: var(--beige); --panel: var(--cream); --card: var(--cream); --text: var(--ink); --soft: var(--body);
  --muted: var(--grey); --faint: var(--grey-faint); --rule: var(--hairline); --rule-soft: rgba(216, 205, 182, .6);
  --accent: var(--dil); --accent-soft: rgba(59, 63, 134, .10); --on-accent: var(--cream);
  --link: var(--dil); --mark: rgba(176, 138, 46, .28); --mark-line: var(--gold);
  --chip: var(--sand); --sel: #E4E0EE; --sel-text: #23265A; --hover: rgba(234, 223, 201, .55); --flash: rgba(176, 138, 46, .22);
  --page: #FFFDF8; --input: #FFFDF8;
  /* status tones: always paired with a word and an icon, never colour alone */
  --t-good: #3F6B3A;  --t-good-bg: rgba(63, 107, 58, .12);
  --t-warn: #84641A;  --t-warn-bg: rgba(176, 138, 46, .18);
  --t-bad: #9B362A;   --t-bad-bg: rgba(155, 54, 42, .11);
  --t-info: #3B3F86;  --t-info-bg: rgba(59, 63, 134, .11);
  --t-plain: #675E52; --t-plain-bg: rgba(103, 94, 82, .10);
  --shadow: 0 1px 2px rgba(27, 23, 20, .08); --shadow-lg: 0 20px 60px rgba(0, 0, 0, .28);
  --sans: "Inter Tight", "Segoe UI", system-ui, sans-serif;
  --serif: "Instrument Serif", Cambria, Georgia, serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
/* ---------- tokens (dark): by the system setting unless the person picked light, or when the person picked dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1714; --panel: #221D19; --card: #2A241F; --text: #F3ECDC; --soft: #E3D9C4; --muted: #B3A893; --faint: #978B78;
    --rule: #3A332C; --rule-soft: rgba(58, 51, 44, .7); --accent: #4B50A3; --accent-soft: rgba(174, 178, 242, .14); --on-accent: #FBF6EA;
    --link: #AEB2F2; --mark: rgba(217, 180, 90, .30); --mark-line: #D9B45A;
    --chip: #342D27; --sel: #2D2E4A; --sel-text: #E8E8FA; --hover: rgba(52, 45, 39, .7); --flash: rgba(217, 180, 90, .18); --page: #FBF6EA; --input: #221D19;
    --t-good: #9CC48F; --t-good-bg: rgba(156, 196, 143, .13); --t-warn: #D9B45A; --t-warn-bg: rgba(217, 180, 90, .15);
    --t-bad: #E8907A; --t-bad-bg: rgba(224, 122, 95, .15); --t-info: #B4B7F0; --t-info-bg: rgba(174, 178, 242, .14);
    --t-plain: #B3A893; --t-plain-bg: rgba(179, 168, 147, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1B1714; --panel: #221D19; --card: #2A241F; --text: #F3ECDC; --soft: #E3D9C4; --muted: #B3A893; --faint: #978B78;
  --rule: #3A332C; --rule-soft: rgba(58, 51, 44, .7); --accent: #4B50A3; --accent-soft: rgba(174, 178, 242, .14); --on-accent: #FBF6EA;
  --link: #AEB2F2; --mark: rgba(217, 180, 90, .30); --mark-line: #D9B45A;
  --chip: #342D27; --sel: #2D2E4A; --sel-text: #E8E8FA; --hover: rgba(52, 45, 39, .7); --flash: rgba(217, 180, 90, .18); --page: #FBF6EA; --input: #221D19;
  --t-good: #9CC48F; --t-good-bg: rgba(156, 196, 143, .13); --t-warn: #D9B45A; --t-warn-bg: rgba(217, 180, 90, .15);
  --t-bad: #E8907A; --t-bad-bg: rgba(224, 122, 95, .15); --t-info: #B4B7F0; --t-info-bg: rgba(174, 178, 242, .14);
  --t-plain: #B3A893; --t-plain-bg: rgba(179, 168, 147, .12);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; }
.serif { font-family: var(--serif); font-weight: 400; }
a, .linkish { color: var(--link); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.linkish { border: 0; background: none; padding: 0; font: inherit; }
svg.i { width: 14px; height: 14px; flex: none; vertical-align: -2px; }

/* ---------- the window ---------- */
.app { display: grid; height: 100vh; width: 100vw; grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "side top" "side banner" "side main"; }

/* ---------- left panel ---------- */
.sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 12px 18px; }
.brand { font-family: var(--serif); font-size: 26px; font-weight: 400; letter-spacing: .01em; color: var(--text); display: flex; align-items: center; gap: 9px; }
.brand svg { width: 24px; height: 24px; color: var(--accent); }
.icon-btn { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 7px; cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:hover { background: var(--chip); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn[disabled] { opacity: .35; cursor: default; background: transparent; }
.nav { flex: 1; overflow: auto; padding: 4px 8px 12px; display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--soft); font-weight: 500; transition: background .12s; }
.nav-item svg { width: 16px; height: 16px; color: var(--faint); flex: none; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--sel); color: var(--sel-text); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
:root[data-theme="dark"] .nav-item.active svg { color: var(--link); }
.nav-item .count { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 20px; text-align: right; }

/* the "now reading" panel and the service line, always visible */
.reading-panel { border-top: 1px solid var(--rule); padding: 12px 14px 14px; display: grid; gap: 5px; font-size: 12.5px; }
.rp-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rp-title { color: var(--text); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.rp-doc { color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-sub { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 18px; }
.rp-bar { height: 3px; border-radius: 2px; background: var(--chip); overflow: hidden; }
.rp-bar i { display: block; height: 100%; width: 30%; background: var(--accent); border-radius: 2px; animation: qslide 1.6s ease-in-out infinite; }
:root[data-theme="dark"] .rp-bar i { background: var(--link); }
.rp-bar.idle i { animation: none; width: 0; }
@keyframes qslide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.dot.on { background: var(--t-good); } .dot.busy { background: var(--t-info); animation: pulse 1.4s ease-in-out infinite; }
.dot.off { background: transparent; outline: 1.5px solid var(--faint); outline-offset: -1.5px; } .dot.bad { background: var(--t-bad); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.service-line { color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 4px; min-width: 0; }
.service-line > span:not(.dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-line .linkish { font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar { grid-area: top; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px;
  padding: 10px 24px; border-bottom: 1px solid var(--rule); background: var(--bg); min-height: 58px; }
.where { min-width: 0; display: flex; align-items: center; gap: 12px; }
.title { font-family: var(--serif); font-weight: 400; font-size: 26px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- banner (service not running) ---------- */
.banner { grid-area: banner; display: flex; gap: 14px; align-items: center; padding: 9px 24px; background: var(--t-warn-bg); border-bottom: 1px solid var(--rule); font-size: 13px; color: var(--text); }
.banner.bad { background: var(--t-bad-bg); }
.banner .grow { flex: 1; }
.banner svg { width: 16px; height: 16px; color: var(--t-warn); flex: none; }
.banner:empty { display: none; }

/* ---------- content ---------- */
.content { grid-area: main; min-height: 0; min-width: 0; overflow: hidden; position: relative; }
.screen { height: 100%; }
.pad { padding: 20px 24px 40px; }
.section-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 18px 0 8px; }
.section-label .aside { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
.center-empty { height: 100%; min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 32px; }
.empty-title { font-family: var(--serif); font-size: 26px; line-height: 1.2; }
.empty-sub { color: var(--muted); max-width: 440px; }
.notice { border: 1px dashed var(--rule); border-radius: 10px; padding: 9px 14px; color: var(--muted); font-size: 13px; }
.callout { background: var(--chip); border-radius: 10px; padding: 10px 14px; color: var(--text); font-size: 13.5px; }
.callout.warn { background: var(--t-warn-bg); } .callout.bad { background: var(--t-bad-bg); } .callout.good { background: var(--t-good-bg); } .callout.info { background: var(--t-info-bg); }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--rule); background: var(--card); padding: 6px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.4; transition: background .12s, border-color .12s, filter .12s; color: var(--text); }
.btn:hover { border-color: var(--faint); }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--t-bad); }
.btn.danger-fill { background: var(--t-bad); border-color: var(--t-bad); color: #fff; }
:root[data-theme="dark"] .btn.danger-fill { background: #A8432F; border-color: #A8432F; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--soft); }
.btn.ghost:hover { background: var(--chip); }
.btn.small { padding: 3px 9px; font-size: 12.5px; border-radius: 7px; }
.btn[disabled] { opacity: .5; cursor: default; filter: none; }
kbd { font: 500 10.5px/1 var(--mono); padding: 2px 5px; border-radius: 4px; border: 1px solid var(--rule); background: var(--card); color: var(--muted); }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 9px 1px 7px; font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap;
  background: var(--t-plain-bg); color: var(--t-plain); }
.chip svg { width: 12px; height: 12px; }
.chip.good { background: var(--t-good-bg); color: var(--t-good); }
.chip.warn { background: var(--t-warn-bg); color: var(--t-warn); }
.chip.bad { background: var(--t-bad-bg); color: var(--t-bad); }
.chip.info { background: var(--t-info-bg); color: var(--t-info); }
.chip.plain { background: var(--t-plain-bg); color: var(--t-plain); }
.chip.outline { background: transparent; outline: 1px solid var(--rule); outline-offset: -1px; color: var(--muted); }
.chip.busy svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fchip { border: 1px solid var(--rule); background: var(--card); color: var(--soft); border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.fchip:hover { border-color: var(--faint); }
.fchip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.fchip .n { font-variant-numeric: tabular-nums; color: var(--faint); }
.fchip.on .n { color: inherit; opacity: .75; }

/* ---------- forms ---------- */
.field { display: grid; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; }
.field i { font-weight: 400; color: var(--muted); font-style: normal; }
.input, .field input, .field select, .field textarea, select.input {
  padding: 7px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--input); color: var(--text); min-width: 0; }
.field textarea { resize: vertical; min-height: 70px; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-size: 13.5px; color: var(--soft); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ---------- dialog ---------- */
.overlay { position: fixed; inset: 0; background: rgba(27, 23, 20, .38); display: flex; align-items: center; justify-content: center; padding: 28px; z-index: 30; }
.modal { background: var(--panel); border-radius: 16px; width: min(520px, 100%); padding: 22px 24px 18px; box-shadow: var(--shadow-lg); display: grid; gap: 14px; max-height: 100%; overflow: auto; }
.modal.wide { width: min(680px, 100%); }
.modal-title { font-family: var(--serif); font-size: 28px; font-weight: 400; line-height: 1.15; overflow-wrap: anywhere; }
.modal-sub { margin: -6px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal .error { color: var(--t-bad); font-size: 13px; }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; justify-items: end; }
.toast { max-width: 480px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); display: flex; gap: 12px; align-items: center; font-size: 13.5px; animation: toastin .18s ease-out; overflow-wrap: anywhere; }
.toast.bad { background: var(--t-bad); color: #fff; }
:root[data-theme="dark"] .toast.bad { background: #A8432F; }
.toast .linkish { color: inherit; font-weight: 600; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* drop veil, for files and folders dragged onto the window */
.drop-veil { position: fixed; inset: 0; background: rgba(59, 63, 134, .08); outline: 3px dashed var(--accent); outline-offset: -10px; z-index: 40; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-veil div { background: var(--card); padding: 16px 24px; border-radius: 12px; font-size: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); max-width: 520px; text-align: center; }

/* ---------- finishing ---------- */
::selection { background: rgba(59, 63, 134, .22); }
:focus-visible { outline: 2px solid rgba(59, 63, 134, .6); outline-offset: 2px; border-radius: 6px; }
:root[data-theme="dark"] :focus-visible { outline-color: rgba(174, 178, 242, .75); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(140, 129, 114, .35); border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(140, 129, 114, .6); }
.skeleton { display: inline-block; height: 10px; max-width: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--chip) 0%, var(--hover) 50%, var(--chip) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; vertical-align: middle; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- the page viewer (pageview.js) ---------- */
.pv { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.pv-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 8px; background: var(--panel); border-bottom: 1px solid var(--rule); }
.pv-pages, .pv-zoom { display: flex; align-items: center; gap: 2px; }
.pv-pageno { font-size: 12.5px; color: var(--soft); min-width: 92px; text-align: center; }
.pv-pct { border: 0; background: transparent; font-size: 12.5px; color: var(--soft); min-width: 52px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.pv-pct:hover { background: var(--chip); }
.pv-main { flex: 1; min-height: 0; display: flex; }
.pv-scroll { flex: 1; min-width: 0; overflow: auto; padding: 14px; outline: none; background: var(--bg); }
.pv-scroll.grabbing { cursor: grabbing; }
.pv-sheet { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .18); min-height: 160px; transition: width .12s; }
.pv-img { display: block; width: 100%; height: auto; user-select: none; }
.pv-boxes { position: absolute; inset: 0; pointer-events: none; }
.hlbox { position: absolute; background: rgba(176, 138, 46, .26); outline: 2px solid var(--gold); outline-offset: 1px; border-radius: 2px; }
.pv-loading, .pv-error { padding: 40px 20px; text-align: center; color: #675E52; font-size: 13px; background: #fff; }
