/* PumaLorum — styles */

/* ── §1 Design tokens ─────────────────────────────────── */
/* @puma-tokens-begin v0.1 */
:root {
  /* surfaces */
  --bg:        #0e0f11;
  --surface:   #16181c;
  --surface2:  #1e2128;
  --border:    #2a2d35;
  --border2:   #363a45;
  --scrim:     rgba(0,0,0,.55);

  /* text */
  --text:       #e8eaf0;
  --text-dim:   #9aa0b0;
  --text-faint: #bbc0d0;   /* AA-passing on --bg (4.5:1) */

  /* brand */
  --accent:         #5b8af0;   /* PumaWorx blue */
  --accent-dim:     #1e2d4a;
  --text-on-accent: #ffffff;
  --logo-accent:    #e07828;   /* the orange in every Puma* favicon */

  /* status */
  --danger: #d42b2b;
  --warn:   #d9a973;
  --ok:     #5ecc94;

  /* categorical palette (for tags, charts, node fills) */
  --color-blue:   #5b8af0;
  --color-green:  #5ecc94;
  --color-amber:  #d9a973;
  --color-red:    #d97373;
  --color-violet: #b07ce0;
  --color-teal:   #6ec9b8;
  --color-orange: #e07828;

  /* motion */
  --ease-out: cubic-bezier(0.25, 1, 0.5, 1);
  --dur-fast: 160ms;
  --dur-mid:  280ms;

  /* elevation */
  --shadow-panel:   0 24px 64px rgba(0,0,0,.50);
  --shadow-overlay: 0 8px  32px rgba(0,0,0,.40);

  /* sizing */
  --touch-min: 36px;
  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;

  /* type */
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
/* @puma-tokens-end */

/* Per-app brand + additions (below the sentinel — the canon block is locked).
   PumaLorum's accent is amber, so text-on-accent flips dark for contrast. */
:root {
  --accent:         #f59e0b;
  --accent-dim:     rgba(245,158,11,.15);
  --logo-accent:    #f59e0b;
  --text-on-accent: #0e0f11;
  color-scheme: dark;
}

/* ── §39 Light theme base ─────────────────────────────── */
/* @puma-lighttheme-css-begin v0.1 */
/* PumaWorx light-theme base — universal token overrides for
   the html[data-theme="light"] selector. Mirrors the §1 :root
   vocabulary (dark defaults) with light-mode values that every
   app shares. Per-app brand overrides (--accent / --accent-dim
   / --logo-accent / app-specific palettes) live in a separate
   html[data-theme="light"] { … } block placed immediately
   below the canon sentinel block, where they inherit canon's
   specificity and order. */
html[data-theme="light"] {
  --bg:         #f4f5f7;
  --surface:    #ffffff;
  --surface2:   #eceef2;
  --border:     #d4d7de;
  --border2:    #c0c4cc;
  --text:       #1a1c22;
  --text-dim:   #5a5e6e;
  --text-faint: #4d5260;
  --shadow-panel:   0 16px 48px rgba(0,0,0,.15);
  --shadow-overlay: 0 4px  16px rgba(0,0,0,.12);
  color-scheme: light;
}
/* @puma-lighttheme-css-end */

/* Per-app light-mode brand extensions */
html[data-theme="light"] {
  --accent:      #d97706;
  --accent-dim:  rgba(217,119,6,.12);
  --logo-accent: #d97706;
  --scrim:       rgba(0,0,0,.35);
  --ok:          #16a34a;
  --warn:        #c07a10;
  --danger:      #dc2626;
  --text-on-accent: #ffffff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

/* ── §9 icon-btn (local alias) ───────────────────────── */
.icon-btn {
  width: var(--touch-min); height: var(--touch-min);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-family: inherit; font-size: 1.05rem; line-height: 1;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn.text { width: auto; padding: 0 12px; font-size: .86rem; }

/* ── §33 Topbar action cluster ───────────────────────── */
/* @puma-topbar-css-begin v0.1 */
/* PumaWorx topbar action cluster — the right-edge button strip
   (Import / Export / save-pip / theme / help / gear) plus a single
   hamburger that takes over on phone widths. Member ids are part of
   the contract; see §33 prose for the full table. */
.topbar-actions { display:flex; align-items:center; gap:6px; margin-left:auto; flex-shrink:0; }
.topbar #topbar-overflow { display:none; }
@media (max-width:768px) {
  .topbar-actions { gap:4px; }
}
@media (max-width:600px) {
  .topbar #btn-import,
  .topbar #btn-export,
  .topbar #storage-pie,
  .topbar #btn-theme,
  .topbar #btn-help,
  .topbar #settings-btn { display:none; }
  .topbar #topbar-overflow { display:inline-flex; }
}
/* @puma-topbar-css-end */

/* ── §17 Save-status pip ─────────────────────────────── */
/* @puma-savepip-css-begin v0.3 */
/* Save-status pip — small color dot at the topbar reporting autosave
   state. Green (--ok) = saved, blue (--accent) pulse = saving, red
   (--danger) = error, bright red (#ff3b30) = nostore (localStorage
   unavailable per §44 — the app is running in memory only). The .flash
   class re-triggers a halo pulse after each successful write. */
.save-pip {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  margin: 0 4px; flex-shrink: 0;
  transition: background var(--dur-fast);
}
.save-pip[data-state="saving"] { background: var(--accent); animation: pip-pulse 0.9s ease-in-out infinite; }
.save-pip[data-state="error"]  { background: var(--danger); animation: none; }
.save-pip[data-state="nostore"] { background: #ff3b30; animation: none; }
.save-pip.flash { animation: pip-flash 540ms var(--ease-out); }
@keyframes pip-pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
@keyframes pip-flash {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); }
  100% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--ok) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .save-pip[data-state="saving"] { animation: none; }
  .save-pip.flash { animation: none; }
}
/* @puma-savepip-css-end */

/* ── §27 Stats pip ───────────────────────────────────── */
/* @puma-statspip-css-begin v0.3 */
/* PumaWorx stats pip — a small conic-gradient donut around the canonical
   §17 save-pip showing localStorage consumption. Clickable to open a stats
   modal. The wedge is green up to ~80% of the configured cap, yellow at
   80–94%, red at 95%+. The save-pip sits in the centre and continues to
   report save state independently. Markup contract:
       <span class="puma-statspip"><span class="save-pip">…</span></span>
   JS sets --usage-pct and --pie-color via pumaStatsPipRefresh(el, opts).
   Modal body class names below (.puma-stats-*) are used by the canon
   helper pumaStatsModalBody(opts) but are layout-only — apps supply the
   data. When localStorage is unavailable (§44) the pip carries
   data-store="off": a solid --danger ring around the bright-red nostore
   save-pip, and the stats modal shows a disabled notice in place of the
   usage bar. */
.puma-statspip {
  --usage-pct: 0;
  --pie-color: var(--ok);
  width: 16px; height: 16px; border-radius: 50%;
  margin: 0 4px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle, var(--surface) 4.5px, transparent 4.5px),
    conic-gradient(
      var(--pie-color) 0% calc(var(--usage-pct) * 1%),
      color-mix(in srgb, var(--text-faint) 28%, transparent) calc(var(--usage-pct) * 1%) 100%
    );
  cursor: pointer;
  transition: background var(--dur-fast), transform 100ms;
}
.puma-statspip:hover { transform: scale(1.1); }
.puma-statspip[data-store="off"] {
  background:
    radial-gradient(circle, var(--surface) 4.5px, transparent 4.5px),
    conic-gradient(var(--danger) 0% 100%);
}
/* Bright-red centre, driven by the pie's off-state so it survives the
   app's own markSaved/markSaving churn (higher specificity than the
   dot's own data-state rules). */
.puma-statspip[data-store="off"] .save-pip { background: #ff3b30; animation: none; }
.puma-statspip .save-pip { margin: 0; pointer-events: none; }

.puma-stats-body {
  display: flex; flex-direction: column; gap: 18px;
  padding: 14px 18px 6px;
  max-height: min(70vh, 640px); overflow-y: auto;
}
.puma-stats-section { display: flex; flex-direction: column; gap: 6px; }
.puma-stats-section-title {
  margin: 0 0 4px; font-size: .68rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint);
}
.puma-stats-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--border) 60%, transparent);
}
.puma-stats-row:last-child { border-bottom: none; }
.puma-stats-row-key { color: var(--text-dim); font-size: .82rem; }
.puma-stats-row-val { color: var(--text); font-size: .82rem; font-variant-numeric: tabular-nums; }
.puma-stats-row.muted .puma-stats-row-key,
.puma-stats-row.muted .puma-stats-row-val { color: var(--text-faint); font-style: italic; }
.puma-stats-mono { font-family: var(--font-mono); font-size: .76rem; }
.puma-stats-storage-summary { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.puma-stats-storage-disabled {
  padding: 12px 14px; border: 1px solid var(--danger); border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--text); font-size: .85rem; line-height: 1.5;
}
.puma-stats-storage-disabled code { font-family: var(--font-mono); font-size: .82em; }
.puma-stats-storage-bar {
  position: relative; width: 100%; height: 8px;
  background: color-mix(in srgb, var(--text-faint) 18%, transparent);
  border-radius: 4px; overflow: hidden;
}
.puma-stats-storage-bar > span {
  display: block; height: 100%;
  background: var(--ok);
  transition: width 240ms var(--ease-out, ease-out);
}
.puma-stats-storage-meta { display: flex; align-items: baseline; gap: 6px; }
.puma-stats-storage-used { color: var(--text); font-weight: 600; font-size: .9rem; }
.puma-stats-storage-cap { color: var(--text-faint); font-size: .76rem; font-family: var(--font-mono); }
.puma-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.puma-stats-cell {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--surface2) 30%, transparent);
  border: 1px solid var(--border); border-radius: 6px;
}
.puma-stats-num { color: var(--text); font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.puma-stats-lbl { color: var(--text-faint); font-size: .7rem; }
@media (max-width: 600px) {
  .puma-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
/* @puma-statspip-css-end */

/* ── §15 Help modal CSS ──────────────────────────────── */
/* @puma-help-css-begin v0.2 */
.help-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  margin: -4px 0 16px; border-bottom: 1px solid var(--border);
}
.help-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: .7rem; letter-spacing: .08em; text-transform: uppercase;
  padding: 8px 14px; cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.help-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.help-tab:hover:not(.active) { color: var(--text); }
.help-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.help-content { display: none; }
.help-content.active { display: block; }
.help-content h3 {
  font-size: .92rem; font-weight: 600; color: var(--text); margin: 0 0 8px;
}
.help-content h3:not(:first-child) { margin-top: 18px; }
.help-content p { font-size: .85rem; color: var(--text-dim); line-height: 1.6; margin: 0 0 10px; }
.help-content ul { padding-left: 18px; margin: 0 0 12px; }
.help-content li { font-size: .85rem; color: var(--text-dim); line-height: 1.6; margin: 4px 0; }
.help-content li strong, .help-content p strong { color: var(--text); font-weight: 600; }
.help-content a { color: var(--accent); text-decoration: none; }
.help-content a:hover { text-decoration: underline; }
.help-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; align-items: center; }
.help-grid > div { padding: 2px 0; }
.help-grid > div:nth-child(odd) { color: var(--text); font-size: .82rem; }
.help-grid > div:nth-child(even) { color: var(--text-dim); }
.help-note {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 8px; padding: 12px 14px; margin: 12px 0;
  font-size: .82rem; color: var(--text-dim); line-height: 1.55;
}
.help-note strong { color: var(--text); }
.help-note.danger {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.help-note.danger > p { margin: 0 0 8px; }
.help-note.danger strong { color: var(--danger); }
.help-clear-stage1 { margin-top: 8px; }
.help-clear-stage2 p { margin: 0 0 6px; }
.help-clear-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.help-clear-input {
  flex: 1; min-width: 0;
  background: var(--surface2); border: 1px solid var(--border2); color: var(--text);
  font-family: var(--font-mono); font-size: .78rem;
  padding: 6px 10px; border-radius: 5px; outline: none;
}
.help-clear-input:focus { border-color: var(--accent); }
.help-clear-btn, .help-clear-reveal-btn {
  background: var(--danger); border: 1px solid var(--danger); color: #fff;
  font: inherit; font-size: .78rem; font-weight: 600;
  padding: 6px 12px; border-radius: 5px; cursor: pointer; white-space: nowrap;
  transition: filter var(--dur-fast), opacity var(--dur-fast);
}
.help-clear-btn:disabled { opacity: .35; cursor: not-allowed; }
.help-clear-btn:not(:disabled):hover, .help-clear-reveal-btn:hover { filter: brightness(1.12); }
.help-about {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--border); text-align: center;
}
.help-about a { font-weight: 600; font-size: .9rem; }
.help-version {
  font-family: var(--font-mono);
  font-size: .72rem; color: var(--text-faint); margin-bottom: 8px;
}
/* @puma-help-css-end */

/* ── Modal shell ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--scrim);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay[hidden], .modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  width: 100%; max-width: 520px;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: .95rem; font-weight: 600; flex: 1;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}

/* ── Export modal ────────────────────────────────────── */
.export-scope {
  font-size: .82rem; color: var(--text-dim);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 18px;
  line-height: 1.45;
}
.export-scope strong { color: var(--text); font-weight: 600; }
.export-scope .export-scope-kind {
  display: inline-block; font-size: .66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); background: var(--accent-dim);
  border-radius: 3px; padding: 1px 6px; margin-right: 7px; vertical-align: 1px;
}

.export-group { margin-bottom: 18px; }
.export-group-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-faint); margin-bottom: 9px;
}

.export-formats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.export-radio, .export-check {
  display: flex; align-items: center; gap: 9px;
  font-size: .85rem; color: var(--text); cursor: pointer;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.export-radio:hover, .export-check:hover { border-color: var(--border2); }
.export-radio input, .export-check input { accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.export-radio:has(input:checked) { border-color: var(--accent); background: var(--accent-dim); }
.export-check { margin-bottom: 8px; }
.export-check small { color: var(--text-faint); }
.export-radio code, .export-check code {
  font-family: var(--font-mono); font-size: .8em; color: var(--text-faint);
}

.export-note {
  font-size: .78rem; color: var(--text-dim); line-height: 1.45;
  padding: 10px 12px; margin-bottom: 16px;
  background: var(--bg); border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.export-actions { display: flex; gap: 10px; }
.export-act-btn {
  flex: 1; padding: 10px 12px; font-size: .85rem; font-weight: 600;
  border: 1px solid var(--border2); border-radius: var(--radius);
  background: var(--surface2); color: var(--text); cursor: pointer;
  transition: filter var(--dur-fast), border-color var(--dur-fast), opacity var(--dur-fast);
}
.export-act-btn:hover { border-color: var(--accent); color: var(--accent); }
.export-act-btn.primary {
  background: var(--accent); color: var(--text-on-accent); border-color: var(--accent);
}
.export-act-btn.primary:hover { filter: brightness(1.1); color: var(--text-on-accent); }
.export-act-btn:disabled {
  opacity: .45; cursor: not-allowed; border-color: var(--border);
  color: var(--text-dim); background: var(--surface2);
}
.export-act-btn:disabled:hover { filter: none; border-color: var(--border); color: var(--text-dim); }

.export-status {
  font-size: .8rem; color: var(--ok); min-height: 1.2em;
  margin-top: 10px; text-align: center;
}
.export-status.error { color: var(--danger); }

@media (max-width: 480px) {
  .export-formats { grid-template-columns: 1fr; }
}

/* ── Disclaimer overlay ──────────────────────────────── */
#disclaimer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 24px;
}
#disclaimer-overlay.hidden { display: none; }

.disclaimer-box {
  background: #1a1200;
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  max-width: 580px; width: 100%;
  padding: 32px;
}
html[data-theme="light"] .disclaimer-box { background: #fff8e6; }

.disclaimer-box .disclaimer-icon { font-size: 36px; margin-bottom: 12px; display: block; }

.disclaimer-box h2 {
  color: var(--accent);
  font-size: 1.2rem; font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase;
  margin-bottom: 16px;
}

.disclaimer-box p {
  color: #e5c97a;
  font-size: .92rem; line-height: 1.65;
  margin-bottom: 14px;
}
html[data-theme="light"] .disclaimer-box p { color: #7a5000; }

.disclaimer-box p strong { color: #fff; }
html[data-theme="light"] .disclaimer-box p strong { color: #1a1c22; }

.disclaimer-box .disclaimer-footer {
  margin-top: 24px;
  display: flex; align-items: center; gap: 12px;
}

.disclaimer-box label {
  display: flex; align-items: center; gap: 8px;
  color: #e5c97a; font-size: .85rem;
  cursor: pointer; flex: 1;
}
html[data-theme="light"] .disclaimer-box label { color: #7a5000; }

.disclaimer-box input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px; height: 16px; cursor: pointer;
}

#disclaimer-accept {
  background: var(--accent); color: var(--text-on-accent);
  border: none; border-radius: var(--radius);
  padding: 9px 22px; font-size: .9rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: filter var(--dur-fast);
}
#disclaimer-accept:hover { filter: brightness(1.1); }
#disclaimer-accept:disabled { opacity: .4; cursor: not-allowed; }

/* ── App layout ──────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 280px 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  position: sticky; top: 0; z-index: 100;
}

.logo { display: flex; align-items: center; text-decoration: none; }
.logo span { color: var(--logo-accent); font-size: 1.1rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }

.topbar-tagline { color: var(--text-faint); font-size: .8rem; }

/* actions cluster handled by §33 .topbar-actions above */

/* ── Sidebar / navigation drawer ─────────────────────── */
#sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* General button */
.nav-general-btn {
  appearance: none; -webkit-appearance: none;
  display: flex; align-items: center; gap: 8px;
  width: calc(100% - 16px);
  margin: 4px 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  font-size: .85rem; font-weight: 600;
  font-family: inherit;
  text-align: left;
  color: var(--text-dim);
  cursor: pointer; user-select: none;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.nav-general-btn:hover { background: var(--surface2); color: var(--text); }
.nav-general-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.nav-general-btn svg { flex-shrink: 0; }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* Tree */
.nav-tree { flex: 1; }

/* Top-level category rows */
.tree-cat-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 10px;
  font-size: .78rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim);
  cursor: pointer; user-select: none;
  border-radius: var(--radius);
  margin: 0 4px;
  border: 1px solid transparent;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.tree-cat-row:hover { background: var(--surface2); color: var(--text); }
.tree-cat-row.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.tree-chevron {
  font-size: .6rem; width: 10px; flex-shrink: 0;
  transition: transform .18s var(--ease-out);
  color: var(--text-faint);
}
.tree-cat-row.open > .tree-chevron,
.tree-sub-row.open > .tree-chevron { transform: rotate(90deg); }
.tree-cat-row.active .tree-chevron { color: var(--accent); }

.tree-cat-icon { font-size: .9rem; flex-shrink: 0; }
.tree-cat-label, .tree-sub-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Subcategory children container */
.tree-children { display: none; }
.tree-cat-row.open + .tree-children,
.tree-sub-row.open + .tree-sub-children { display: block; }

/* Subcategory rows */
.tree-sub-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 22px;
  font-size: .8rem; font-weight: 500;
  color: var(--text-dim);
  cursor: pointer; user-select: none;
  border-radius: var(--radius);
  margin: 0 4px;
  border: 1px solid transparent;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.tree-sub-row:hover { background: var(--surface2); color: var(--text); }
.tree-sub-row.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.tree-sub-children { display: none; }
.tree-sub-row.open + .tree-sub-children { display: block; }

/* Document rows */
.tree-doc-row {
  display: flex; align-items: center;
  padding: 5px 8px 5px 38px;
  font-size: .78rem;
  color: var(--text-faint);
  cursor: pointer; user-select: none;
  border-radius: var(--radius);
  margin: 0 4px;
  border: 1px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.tree-doc-row:hover { background: var(--surface2); color: var(--text); }
.tree-doc-row.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Nav filter bar ───────────────────────────────────── */
.nav-filter {
  padding: 4px 10px 10px;
  display: flex; flex-direction: column; gap: 9px;
}

.nav-search-wrap { position: relative; display: flex; align-items: center; }
.nav-search-icon {
  position: absolute; left: 9px; font-size: .95rem;
  color: var(--text-faint); pointer-events: none;
}
#nav-search {
  width: 100%;
  appearance: none; -webkit-appearance: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit; font-size: .82rem;
  padding: 7px 26px 7px 28px;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
#nav-search::placeholder { color: var(--text-faint); }
#nav-search:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.nav-search-clear {
  position: absolute; right: 6px;
  appearance: none; -webkit-appearance: none;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: .78rem; line-height: 1;
  padding: 4px; border-radius: 50%;
}
.nav-search-clear:hover { color: var(--text); background: var(--surface2); }

.facet-group { display: flex; flex-direction: column; gap: 5px; }
.facet-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint);
}
.facet-row { display: flex; flex-wrap: wrap; gap: 4px; }
.facet-chip {
  appearance: none; -webkit-appearance: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-family: inherit; font-size: .72rem; font-weight: 600;
  padding: 3px 9px; cursor: pointer; user-select: none;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.facet-chip:hover { color: var(--text); border-color: var(--text-faint); }
.facet-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-filter-foot {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 16px;
}
#nav-result-count { font-size: .7rem; color: var(--text-faint); }
.nav-clear {
  appearance: none; -webkit-appearance: none;
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-family: inherit; font-size: .72rem; font-weight: 600;
  padding: 2px 4px;
}
.nav-clear:hover { text-decoration: underline; }

/* Per-function match count badge */
.tree-cat-count {
  flex-shrink: 0;
  font-size: .68rem; font-weight: 700;
  color: var(--text-faint);
  background: var(--surface2);
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 18px; text-align: center;
}
.tree-cat-row.active .tree-cat-count,
.tree-sub-row.active .tree-cat-count { color: var(--accent); background: transparent; }

/* Filtered empty state */
.nav-empty {
  padding: 24px 16px; text-align: center;
  font-size: .8rem; color: var(--text-faint); line-height: 1.6;
}
.nav-clear-inline {
  margin-top: 8px;
  appearance: none; -webkit-appearance: none;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  color: var(--text); font-family: inherit; font-size: .76rem;
  padding: 5px 12px;
}
.nav-clear-inline:hover { border-color: var(--accent); color: var(--accent); }

/* ── General page ────────────────────────────────────── */
#general-pane {
  display: none; flex-direction: column; flex: 1;
}
#general-pane.visible { display: flex; }

.general-header {
  padding: 28px 48px 0;
  flex-shrink: 0;
}
.general-header h1 {
  font-size: 1.4rem; font-weight: 700; color: var(--text);
  margin-bottom: 6px;
}
.general-header p {
  font-size: .87rem; color: var(--text-dim); line-height: 1.5;
  max-width: 560px; margin-bottom: 24px;
}
.general-header-divider {
  border: none; border-top: 1px solid var(--border); margin: 0 -48px 0;
}

.general-body {
  flex: 1; overflow-y: auto;
  padding: 28px 48px 48px;
  max-width: 720px;
}

.general-section {
  margin-bottom: 32px;
}
.general-section-title {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.general-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.general-field-grid.single { grid-template-columns: 1fr; }

.general-field { display: flex; flex-direction: column; gap: 5px; }
.general-field label {
  font-size: .8rem; font-weight: 500; color: var(--text-dim);
}
.general-field input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text); font-size: .87rem; width: 100%;
  transition: border-color var(--dur-fast);
}
.general-field input[type="text"]:focus {
  outline: none; border-color: var(--accent);
}
.general-field input::placeholder { color: var(--text-faint); }

.general-actions {
  display: flex; align-items: center; gap: 10px;
  padding-top: 8px;
}
.general-save-btn {
  background: var(--accent); color: var(--text-on-accent);
  border: none; border-radius: var(--radius);
  padding: 8px 20px; font-size: .87rem; font-weight: 700;
  cursor: pointer; transition: filter var(--dur-fast);
}
.general-save-btn:hover { filter: brightness(1.1); }
.general-saved-msg {
  font-size: .8rem; color: var(--ok); min-height: 1em;
}

/* ── Category / subcategory info page ───────────────── */
#category-pane {
  display: none; flex-direction: column; flex: 1;
}
#category-pane.visible { display: flex; }

.category-header {
  padding: 28px 48px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.category-breadcrumb {
  font-size: .72rem; color: var(--text-faint);
  margin-bottom: 6px;
  font-family: var(--font-mono);
}
.category-breadcrumb span { color: var(--text-dim); }
.category-header h2 {
  font-size: 1.3rem; font-weight: 700; color: var(--text);
  margin-bottom: 8px;
}
.category-header p {
  font-size: .87rem; color: var(--text-dim);
  line-height: 1.6; max-width: 640px;
}

.category-body {
  flex: 1; overflow-y: auto;
  padding: 24px 48px 48px;
}

.category-list-title {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.category-cards {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 680px;
}

.category-card {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.category-card:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.category-card-icon {
  font-size: 1.2rem; flex-shrink: 0; margin-top: 1px;
}
.category-card-body { flex: 1; min-width: 0; }
.category-card-title {
  font-size: .9rem; font-weight: 600; color: var(--text);
  margin-bottom: 3px;
}
.category-card:hover .category-card-title { color: var(--accent); }
.category-card-desc {
  font-size: .8rem; color: var(--text-dim); line-height: 1.5;
}
.category-card-meta {
  font-size: .72rem; color: var(--text-faint);
  font-family: var(--font-mono);
  margin-top: 5px;
}
.category-card-arrow {
  color: var(--text-faint); font-size: .9rem;
  align-self: center; flex-shrink: 0;
  transition: color var(--dur-fast), transform var(--dur-fast);
}
.category-card:hover .category-card-arrow {
  color: var(--accent); transform: translateX(3px);
}

/* ── Main content ────────────────────────────────────── */
#main {
  grid-area: main;
  overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--bg);
}

#welcome-pane {
  display: none; flex: 1; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; gap: 16px;
}
#welcome-pane.visible { display: flex; }
#welcome-pane .welcome-icon { font-size: 3rem; }
#welcome-pane h1 { font-size: 1.5rem; color: var(--text); }
#welcome-pane p { color: var(--text-dim); max-width: 400px; font-size: .9rem; line-height: 1.6; }

#doc-pane { display: none; flex-direction: column; flex: 1; }
#doc-pane.visible { display: flex; }

.doc-toolbar {
  display: flex; align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 10px; flex-shrink: 0;
}
.doc-toolbar h2 { font-size: 1rem; font-weight: 600; }
.doc-toolbar-spacer { flex: 1; }

.doc-toolbar-btn {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-dim);
  padding: 5px 10px; font-size: .8rem; cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.doc-toolbar-btn:hover { border-color: var(--accent); color: var(--accent); }

#doc-content {
  flex: 1; overflow-y: auto;
  padding: 32px 48px;
  max-width: 860px;
}

/* ── Vars banner ─────────────────────────────────────── */
.vars-banner {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: 10px 16px; font-size: .82rem; color: #e5c97a;
  margin: 12px 48px 0;
  display: none; align-items: center; gap: 8px; flex-shrink: 0;
}
html[data-theme="light"] .vars-banner { color: #92600a; }
.vars-banner.visible { display: flex; }
.vars-banner a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ── Markdown rendering ──────────────────────────────── */
.doc-render { color: var(--text); line-height: 1.75; }

.doc-render h1 {
  font-size: 1.6rem; font-weight: 700; color: var(--text);
  margin-bottom: 8px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.doc-render h2 {
  font-size: 1.15rem; font-weight: 600; color: var(--accent);
  margin-top: 32px; margin-bottom: 12px;
}
.doc-render h3 {
  font-size: 1rem; font-weight: 600; color: var(--text);
  margin-top: 24px; margin-bottom: 8px;
}
.doc-render h4 {
  font-size: .9rem; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em;
  margin-top: 20px; margin-bottom: 8px;
}
.doc-render p { margin-bottom: 14px; }
.doc-render ul, .doc-render ol { margin-bottom: 14px; padding-left: 22px; }
.doc-render li { margin-bottom: 4px; }
.doc-render li input[type="checkbox"] { accent-color: var(--accent); margin-right: 6px; }
.doc-render strong { color: var(--text); font-weight: 600; }
.doc-render em { color: var(--text-dim); }

.doc-render code {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
  font-family: var(--font-mono); font-size: .88em;
  color: #e2b96a;
}
html[data-theme="light"] .doc-render code { color: #9a5c00; }

.doc-render pre {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  overflow-x: auto; margin-bottom: 16px;
}
.doc-render pre code {
  background: none; border: none; padding: 0;
  color: var(--text); font-size: .87rem;
}

.doc-render table {
  width: 100%; border-collapse: collapse;
  margin-bottom: 16px; font-size: .88rem;
}
.doc-render th {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 8px 12px; text-align: left;
  color: var(--text-faint); font-weight: 600;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
}
.doc-render td { border: 1px solid var(--border); padding: 8px 12px; vertical-align: top; }
.doc-render tr:nth-child(even) td { background: color-mix(in srgb, var(--surface2) 40%, transparent); }

.doc-render blockquote {
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  background: var(--accent-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 16px;
  color: #e5c97a;
  font-size: .9rem;
}
html[data-theme="light"] .doc-render blockquote { color: #7a5000; }
.doc-render blockquote p:last-child { margin-bottom: 0; }

.doc-render hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.doc-render a { color: var(--accent); text-decoration: none; }
.doc-render a:hover { text-decoration: underline; }

/* Framework reference citations — small chip-row below section headings */
.doc-render cite.fw {
  display: block;
  font-style: normal;
  font-size: .7rem;
  font-family: var(--font-mono);
  color: var(--text-faint);
  margin: -8px 0 14px;
  letter-spacing: .02em;
}
.doc-render cite.fw span {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 4px;
  margin-bottom: 2px;
  color: var(--text-dim);
}

/* ── Placeholders panel (per-document) ───────────────── */
#ph-scrim {
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, .35); z-index: 99;
}
#ph-scrim[hidden] { display: none; }

#placeholders-panel {
  display: none; position: fixed;
  top: 52px; right: 0; bottom: 0; width: 380px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 100; flex-direction: column;
  box-shadow: -10px 0 30px rgba(0, 0, 0, .28);
}
#placeholders-panel.open { display: flex; }

.ph-header {
  padding: 16px 18px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 10px;
}
.ph-header > div:first-child { flex: 1; min-width: 0; }
.ph-header h3 { font-size: .95rem; font-weight: 700; line-height: 1.2; }
.ph-doc-name {
  font-size: .74rem; color: var(--text-faint); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ph-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.1rem; cursor: pointer; padding: 2px 6px; flex-shrink: 0;
}
.ph-close:hover { color: var(--text); }

.ph-intro {
  padding: 12px 18px; font-size: .77rem; color: var(--text-dim);
  line-height: 1.5; border-bottom: 1px solid var(--border);
}

.ph-body { flex: 1; overflow-y: auto; padding: 14px 18px; }

.ph-field { margin-bottom: 14px; }
.ph-field label {
  display: flex; align-items: center; gap: 7px;
  font-size: .8rem; color: var(--text); margin-bottom: 5px;
}
.ph-badge {
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; padding: 1px 5px; border-radius: 3px;
  background: var(--surface2); color: var(--text-faint);
}
.ph-field input[type="text"] {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px;
  color: var(--text); font-size: .87rem; width: 100%;
  transition: border-color var(--dur-fast);
}
.ph-field input[type="text"]:focus { outline: none; border-color: var(--accent); }
.ph-field input::placeholder { color: var(--text-faint); }

.ph-empty { font-size: .82rem; color: var(--text-dim); padding: 8px 0; line-height: 1.5; }

.ph-footer {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.ph-save-btn {
  background: var(--accent); color: var(--text-on-accent);
  border: none; border-radius: var(--radius);
  padding: 8px 20px; font-size: .87rem; font-weight: 700;
  cursor: pointer; transition: filter var(--dur-fast);
}
.ph-save-btn:hover { filter: brightness(1.1); }
.ph-saved-msg { font-size: .8rem; color: var(--ok); min-height: 1em; }

/* ── Section variables (subcategory page) ────────────── */
.section-vars { margin-top: 34px; max-width: 680px; }
.section-vars-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .09em; color: var(--text-faint); margin-bottom: 8px;
}
.section-vars-count {
  display: inline-block; margin-left: 6px;
  font-size: .72rem; font-weight: 700;
  color: var(--text-faint); background: var(--surface2);
  border-radius: 999px; padding: 0 8px;
}
.section-vars-intro {
  font-size: .8rem; color: var(--text-dim); line-height: 1.55;
  margin-bottom: 16px; max-width: 600px;
}
.section-vars-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-bottom: 18px;
}
.section-vars-empty {
  font-size: .82rem; color: var(--text-dim); line-height: 1.55;
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}

@media (max-width: 640px) {
  .general-field-grid, .section-vars-grid { grid-template-columns: 1fr; }
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }
