/* ============================================================================
   NEUROANALYTICA — "Research Suite" design system
   Warm archival/editorial light. A curated neuropathology specimen archive
   crossed with a scientific journal: letterpress restraint, catalog discipline,
   anatomical-archive oxblood. The data is the hero; every flourish earns its
   place by improving scannability. Pure CSS + HTMX; no build step.
   ============================================================================ */

/* ── 1. TOKENS ──────────────────────────────────────────────────────────── */
:root {
  /* color — warm paper substrate */
  --paper:        #f4f0e8;
  --paper-edge:   #ece6da;
  --surface:      #fbf9f4;
  --surface-2:    #f7f3ea;
  --sunken:       #ebe4d6;
  --selected:     #f3e7e4;
  --selected-rule:#c9a99f;
  /* color — ink */
  --ink:          #241f1b;
  --ink-2:        #5a5048;
  --ink-3:        #8a7e72;
  --ink-inverse:  #fbf9f4;
  /* color — hairlines */
  --rule:         #ddd4c4;
  --rule-strong:  #cabfa9;
  --rule-faint:   #e8e1d2;
  /* color — accent (anatomical oxblood) */
  --accent:       #7b2d2a;
  --accent-deep:  #611f1d;
  --accent-tint:  #f3e7e4;
  --accent-ink:   #6a2623;   /* accent used AS text on paper (AA) */
  /* color — secondary (catalog gold) */
  --gold:         #9a7b35;
  --gold-tint:    #f1ead4;
  /* color — semantics */
  --ok:           #4a6a3f;  --ok-tint:    #e7eede;
  --warn:         #9a6a1f;  --warn-tint:  #f3e8d2;
  --danger:       #8f3331;  --danger-tint:#f4e2e0;
  --provisional:  #8a5a12;

  /* elevation */
  --shadow-1: 0 1px 2px rgba(58,42,28,.06), 0 1px 1px rgba(58,42,28,.04);
  --shadow-2: 0 2px 6px rgba(58,42,28,.08), 0 4px 14px rgba(58,42,28,.05);

  /* radii */
  --r-xs: 3px;  --r-sm: 5px;  --r-md: 7px;  --r-lg: 10px;  --r-round: 999px;

  /* spacing (4px base) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* typography */
  --font-display: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --font-body:    "Newsreader", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-sans:    "Spline Sans", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-mono:    "Spline Sans Mono", "SFMono-Regular", "Cascadia Mono", ui-monospace, monospace;
  --t-xs:  0.733rem; --t-sm:  0.8rem;  --t-base:0.933rem; --t-md: 1.067rem;
  --t-lg:  1.333rem; --t-xl:  1.75rem; --t-2xl: 2.4rem;   --t-3xl: 3.2rem;
  --lh-tight: 1.15;  --lh-snug: 1.3;   --lh-body: 1.55;
  --w-reg: 400; --w-med: 500; --w-semi: 600; --w-bold: 700;

  /* motion */
  --ease-out: cubic-bezier(.2,.7,.3,1);
  --dur-fast: 120ms; --dur: 200ms; --dur-slow: 320ms; --dur-reveal: 480ms;

  /* layout */
  --shell-h: 56px;
  --measure: 68ch;
  --content-max: 1180px;
  --rail-w: 296px;

  font-size: 15px;
}

/* ── 2. RESET + BASE ────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  line-height: var(--lh-body);
  font-size: var(--t-base);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
  line-height: var(--lh-tight);
  font-weight: var(--w-semi);
}
.ui, button, input, select, .opt, .facet-group > summary, th, .chip { font-family: var(--font-sans); }
.mono, .tabular, code, .ocount, .gcount, .cat-no { font-family: var(--font-mono); }
.tabular, .n-slides, .n-cases, .ocount, .gcount, td.num, th.num {
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
a { color: var(--accent-ink); }

.eyebrow {
  font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-semi);
  text-transform: uppercase; letter-spacing: 0.13em; color: var(--gold);
}

/* focus + visually-hidden utilities */
:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }
.vh {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

main { max-width: var(--content-max); margin: 0 auto; padding: var(--s-5) var(--s-5) var(--s-8); }

/* ── 3. MASTHEAD + SURFACE NAV ──────────────────────────────────────────── */
.masthead {
  display: flex; align-items: center; gap: var(--s-4);
  height: var(--shell-h); padding: 0 var(--s-5);
  background: var(--surface); border-bottom: 1px solid var(--rule-strong);
  box-shadow: var(--shadow-1); position: sticky; top: 0; z-index: 30;
}
.wordmark { display: flex; align-items: baseline; gap: var(--s-2); text-decoration: none; color: var(--ink); }
.wm-name { font-family: var(--font-display); font-weight: var(--w-bold); font-size: var(--t-lg); letter-spacing: -0.02em; }
.wm-mark { color: var(--accent); font-size: 1.1em; transform: translateY(1px); }
.masthead-tag { border-left: 1px solid var(--rule); padding-left: var(--s-4); align-self: center; }

.surface-nav { display: flex; gap: var(--s-1); margin-left: var(--s-4); }
.surface-nav a, .surface-nav span.disabled {
  font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-med);
  color: var(--ink-2); text-decoration: none; padding: 6px 12px; border-radius: var(--r-sm);
  position: relative; transition: color var(--dur), background var(--dur);
}
.surface-nav a:hover { color: var(--ink); background: var(--sunken); }
.surface-nav a[aria-current="page"] { color: var(--accent-ink); }
.surface-nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.surface-nav span.disabled { color: var(--ink-3); opacity: .55; cursor: not-allowed; }

.spacer { flex: 1; }
.who { font-size: var(--t-sm); color: var(--ink-2); }
.role {
  font-family: var(--font-sans); font-weight: var(--w-semi); font-size: 0.66rem;
  text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 7px;
  border-radius: var(--r-xs); border: 1px solid transparent;
}
.role-admin { background: var(--gold-tint); color: #6f5410; border-color: #d8c590; }
.role-brain_bank { background: var(--accent-tint); color: var(--accent-ink); border-color: #d9bdb7; }
.role-normal { background: var(--surface-2); color: var(--ink-2); border-color: var(--rule); }
.inline { display: inline; }
.linkbtn {
  background: none; border: none; color: var(--accent-ink); font-family: var(--font-sans);
  font-size: var(--t-sm); cursor: pointer; padding: 0; text-decoration: underline;
  text-underline-offset: 2px; text-decoration-thickness: 1px;
}
.linkbtn:hover { color: var(--accent-deep); }

/* legacy .topbar alias (kept harmless) */
.topbar { display: flex; align-items: center; gap: var(--s-4); }
.brand { font-family: var(--font-display); font-weight: var(--w-bold); }
.tag { color: var(--ink-3); font-size: var(--t-xs); font-family: var(--font-sans); }
.tag em { color: var(--provisional); font-style: normal; font-weight: var(--w-semi); }

/* ── 4. SURFACE HEADER ──────────────────────────────────────────────────── */
.surface-head { padding: var(--s-6) 0 var(--s-4); border-bottom: 1px solid var(--rule-strong); margin-bottom: var(--s-5); }
.surface-title { font-size: var(--t-2xl); margin: var(--s-1) 0; }
.surface-dek { color: var(--ink-2); font-size: var(--t-md); max-width: var(--measure); margin: 0; }

/* ── 5. BROWSE GRID (facet rail + results) ──────────────────────────────── */
.browse-grid { display: grid; grid-template-columns: var(--rail-w) 1fr; gap: var(--s-5); align-items: start; }
.facet-rail { display: flex; flex-direction: column; gap: var(--s-3); }
.results-col { min-width: 0; }
.rail-label { display: flex; align-items: center; justify-content: space-between; }

/* ── 6. COUNTS BAR + TALLY ──────────────────────────────────────────────── */
.counts-bar {
  position: sticky; top: var(--shell-h); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-5);
  padding: var(--s-4) var(--s-5); margin-bottom: var(--s-4);
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}
.counts-left { display: flex; align-items: center; gap: var(--s-4); }
#counts { display: flex; align-items: baseline; gap: var(--s-3); font-family: var(--font-display); color: var(--ink-3); }
.tally-fig { display: inline-flex; align-items: baseline; gap: 8px; }
.n-slides, .n-cases {
  font-size: var(--t-xl); font-weight: var(--w-semi);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em; display: inline-block;
}
/* grain emphasis: the active grain's figure is full ink, the other dimmed.
   Driven by .emph on the figure (set in _counts.html) so it updates on swap. */
.tally-fig .n-slides, .tally-fig .n-cases { color: var(--ink-3); transition: color var(--dur); }
.tally-fig.emph .n-slides, .tally-fig.emph .n-cases { color: var(--ink); }
.tally-unit { font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-med); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); }
.sep { color: var(--rule-strong); font-size: var(--t-lg); }
.counts-empty { font-family: var(--font-body); font-style: italic; font-size: var(--t-sm); color: var(--ink-3); margin-left: var(--s-3); }

/* grain pivot */
.grain-pivot { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface-2); }
.grain-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.grain-opt span {
  display: block; font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-med);
  color: var(--ink-2); padding: 5px 14px; border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.grain-opt input:checked + span { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-1); font-weight: var(--w-semi); }
.grain-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 7. SELECTED-CRITERIA CHIPS ─────────────────────────────────────────── */
.criteria-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-2) 0 var(--s-3); }
.crit-chip {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-sans);
  font-size: var(--t-sm); font-weight: var(--w-med); color: var(--accent-ink);
  background: var(--accent-tint); border: 1px solid var(--selected-rule);
  border-radius: var(--r-sm); padding: 3px 4px 3px 10px;
}
.crit-x {
  border: none; background: none; cursor: pointer; color: var(--accent); font-size: 15px;
  line-height: 1; width: 20px; height: 20px; border-radius: var(--r-xs);
  display: grid; place-items: center; text-decoration: none; transition: background var(--dur-fast);
}
.crit-x:hover { background: #e6d2cd; color: var(--accent-deep); }
.crit-clear { margin-left: var(--s-2); }

/* ── 8. FACET GROUPS + LEADER-DOT INDEX ROWS ────────────────────────────── */
.facet-search { margin-bottom: var(--s-1); }
.field {
  width: 100%; font-family: var(--font-sans); font-size: var(--t-base); color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-sm);
  padding: 8px 10px; transition: border-color var(--dur), box-shadow var(--dur);
}
.field::placeholder { color: var(--ink-3); }
.field:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.field-search {
  padding-left: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a7e72' stroke-width='1.6'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 10px center;
}

.facet-group { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); margin-bottom: var(--s-2); overflow: hidden; }
.facet-group > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); padding: 10px var(--s-4); font-family: var(--font-sans); font-weight: var(--w-semi);
  font-size: var(--t-sm); color: var(--ink); transition: background var(--dur-fast);
}
.facet-group > summary::-webkit-details-marker { display: none; }
.fg-name { display: flex; align-items: center; gap: var(--s-2); }
.fg-name::before {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3); transform: rotate(-45deg);
  transition: transform var(--dur) var(--ease-out);
}
.facet-group[open] .fg-name::before { transform: rotate(45deg); }
.facet-group > summary:hover { background: var(--sunken); }
.gcount { color: var(--ink-3); font-weight: var(--w-med); font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
.opts { border-top: 1px solid var(--rule-faint); padding: var(--s-1) 0; }

.opt {
  display: flex; align-items: center; gap: var(--s-2); padding: 5px var(--s-4) 5px var(--s-3);
  font-size: var(--t-sm); font-family: var(--font-sans); cursor: pointer; min-height: 32px;
  transition: background var(--dur-fast);
}
.opt:hover { background: var(--accent-tint); }
.oname { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leader { flex: 1 1 auto; align-self: flex-end; height: 1em; border-bottom: 1px dotted var(--rule-strong); margin: 0 6px 4px; min-width: 14px; }
.ocount { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: var(--t-xs); font-family: var(--font-mono); }
.opt:has(input:checked) { background: var(--selected); }
.opt:has(input:checked) .oname { color: var(--accent-ink); font-weight: var(--w-semi); }

/* custom checkbox */
.opt input, .review-toggle input[type=checkbox], .chip-check input {
  position: absolute; opacity: 0; width: 18px; height: 18px; margin: 0; cursor: pointer;
}
.opt-box {
  flex: 0 0 auto; width: 16px; height: 16px; border: 1.5px solid var(--rule-strong);
  border-radius: var(--r-xs); background: var(--surface); position: relative;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.opt input:checked + .opt-box { background: var(--accent); border-color: var(--accent); }
.opt input:checked + .opt-box::after {
  content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
  border: solid var(--ink-inverse); border-width: 0 2px 2px 0; transform: rotate(42deg);
}
.opt input:focus-visible + .opt-box { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 9. MORE FILTERS (advanced facets) ──────────────────────────────────── */
.more-filters { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; }
.more-filters > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--s-2);
  padding: 10px var(--s-4); font-family: var(--font-sans); font-weight: var(--w-semi);
  font-size: var(--t-sm); color: var(--ink-2);
}
.more-filters > summary::-webkit-details-marker { display: none; }
.more-filters > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3); transform: rotate(-45deg);
  transition: transform var(--dur) var(--ease-out);
}
.more-filters[open] > summary::before { transform: rotate(45deg); }
.mf-body { border-top: 1px solid var(--rule-faint); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-5); }
.mf-block { display: flex; flex-direction: column; gap: var(--s-2); }
.mf-cap { font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-semi); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-2); }

/* boolean chips */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-sans);
  font-size: var(--t-sm); font-weight: var(--w-med); color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-round);
  padding: 5px 12px; cursor: pointer; min-height: 30px;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-check:has(input:checked) { background: var(--accent-tint); border-color: var(--selected-rule); color: var(--accent-ink); }
.chip-check:has(input:checked)::before { content: "✓"; font-size: 0.8em; color: var(--accent); margin-right: -2px; }
.chip-check:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* numeric range */
.range-ctl { display: flex; flex-direction: column; gap: 6px; }
.range-fields { display: flex; align-items: center; gap: var(--s-2); }
.field-num { width: 72px; text-align: center; padding: 7px 8px; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.range-dash { color: var(--ink-3); font-family: var(--font-mono); }

/* review toggle */
.review-toggle { display: inline-flex; align-items: center; gap: var(--s-2); font-family: var(--font-sans); font-size: var(--t-sm); color: var(--ink); cursor: pointer; user-select: none; padding: 4px 0; min-height: 32px; }

/* ── 10. BUTTONS ────────────────────────────────────────────────────────── */
.btn, .export-btn {
  font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-semi);
  text-transform: uppercase; letter-spacing: 0.06em; line-height: 1; padding: 9px 16px;
  border-radius: var(--r-sm); border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  min-height: 36px; transition: background var(--dur), border-color var(--dur), color var(--dur), box-shadow var(--dur);
}
.btn-primary, .export-btn { background: var(--accent); color: var(--ink-inverse); box-shadow: var(--shadow-1); }
.btn-primary:hover, .export-btn:hover { background: var(--accent-deep); }
.btn-secondary { background: var(--surface); color: var(--accent-ink); border-color: var(--selected-rule); }
.btn-secondary:hover { background: var(--accent-tint); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--sunken); color: var(--ink); }
.btn:disabled, .export-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── 11. DATA TABLE (NPBB ledger) ───────────────────────────────────────── */
.table-frame { border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); overflow: auto; max-height: 70vh; box-shadow: var(--shadow-1); }
.table-frame:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-family: var(--font-sans); font-size: var(--t-sm); }
.data-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left;
  font-weight: var(--w-semi); color: var(--ink-2); font-size: var(--t-xs); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 10px 14px; border-bottom: 1.5px solid var(--rule-strong); white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody td { padding: 9px 14px; border-bottom: 1px solid var(--rule-faint); color: var(--ink); vertical-align: baseline; }
.data-table tbody tr { transition: background var(--dur-fast); }
.data-table tbody tr.drillable { cursor: pointer; }
.data-table tbody tr.drillable:hover { background: var(--accent-tint); }
.data-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
td.mono, .data-table .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.col-drill { width: 32px; text-align: center; }
.drill { color: var(--ink-3); font-size: 18px; transition: transform var(--dur-fast), color var(--dur-fast); display: inline-block; }
.data-table tbody tr.drillable:hover .drill { color: var(--accent); transform: translateX(2px); }
.drill-row td { background: var(--surface-2); padding: 0; }
.drill-inner { padding: var(--s-3) var(--s-4); }

.status { font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-semi); padding: 2px 8px; border-radius: var(--r-round); white-space: nowrap; }
.status-ok    { background: var(--ok-tint);    color: var(--ok); }
.status-warn  { background: var(--warn-tint);  color: var(--warn); }
.status-danger{ background: var(--danger-tint);color: var(--danger); }

/* stat tiles (NPBB landing) */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-3); margin: var(--s-4) 0 var(--s-6); }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s-4); }
.tile .tile-n { font-family: var(--font-display); font-size: var(--t-xl); font-weight: var(--w-semi); color: var(--ink); font-variant-numeric: tabular-nums; display: block; }
.tile .tile-l { font-family: var(--font-sans); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.action-card { display: inline-flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--rule-strong); border-left: 3px solid var(--accent); border-radius: var(--r-md); padding: var(--s-4) var(--s-5); text-decoration: none; color: var(--ink); transition: background var(--dur); }
.action-card:hover { background: var(--accent-tint); }
.action-card .ac-title { font-family: var(--font-display); font-size: var(--t-lg); }
.action-card .ac-dek { font-size: var(--t-sm); color: var(--ink-2); }
.action-card.disabled { border-left-color: var(--rule-strong); opacity: .55; pointer-events: none; }

.npbb-toolbar { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4); }
.npbb-toolbar select.field, .npbb-toolbar input.field { width: auto; min-width: 200px; }
.npbb-toolbar .spacer { flex: 1; }

/* pipeline run dashboard */
.run-start { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s-4); margin-top: var(--s-3); }
.run-form { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-2); }
.run-form select.field { width: auto; min-width: 260px; }
.pbar { height: 6px; background: var(--surface-2); border-radius: var(--r-round); overflow: hidden; border: 1px solid var(--rule-faint); min-width: 120px; }
.pbar-fill { height: 100%; background: var(--accent); transition: width var(--dur) var(--ease-out); }
.pbar-label { font-size: var(--t-xs); color: var(--ink-3); }

/* ── 12. SUBNAV ─────────────────────────────────────────────────────────── */
.subnav { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--rule); margin-bottom: var(--s-5); }
.subnav a, .subnav span.disabled {
  font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-med); color: var(--ink-2);
  text-decoration: none; padding: 10px 14px; position: relative; display: inline-flex; align-items: center; gap: 6px;
  transition: color var(--dur);
}
.subnav a:hover { color: var(--ink); }
.subnav a[aria-current="page"] { color: var(--accent-ink); font-weight: var(--w-semi); }
.subnav a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }
.subnav span.disabled { color: var(--ink-3); opacity: .5; cursor: not-allowed; }
.subnav-badge { font-family: var(--font-mono); font-size: var(--t-xs); background: var(--sunken); color: var(--ink-2); border-radius: var(--r-round); padding: 1px 7px; }

/* ── 13. LOGIN TITLE PAGE ───────────────────────────────────────────────── */
.login.title-page {
  max-width: 380px; margin: var(--s-8) auto; padding: var(--s-7) var(--s-6);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); text-align: center;
}
.tp-title { font-size: clamp(1.9rem, 6vw, 2.5rem); font-weight: var(--w-bold); margin: var(--s-2) 0 4px; letter-spacing: -0.03em; overflow-wrap: break-word; }
.tp-sub { color: var(--ink-2); font-style: italic; font-size: var(--t-md); margin: 0; }
.tp-rule { border: none; border-top: 1px solid var(--rule); margin: var(--s-5) 0; }
.tp-form { text-align: left; display: flex; flex-direction: column; gap: var(--s-4); }
.tp-form label { display: flex; flex-direction: column; gap: 6px; font-family: var(--font-sans); font-size: var(--t-sm); color: var(--ink-2); }
.tp-submit { width: 100%; margin-top: var(--s-2); }
.tp-mark { display: block; color: var(--accent); font-size: 2rem; line-height: 1; margin-bottom: var(--s-3); }
.tp-eyebrow { margin: 0 0 var(--s-2); }
.tp-note { margin-top: var(--s-5); font-size: var(--t-xs); color: var(--ink-3); line-height: 1.6; }
.login .hint { margin-top: var(--s-5); font-size: var(--t-xs); color: var(--ink-3); }
.login .error { color: var(--danger); background: var(--danger-tint); border: 1px solid #e0b9b7; border-radius: var(--r-sm); padding: 8px 12px; font-size: var(--t-sm); margin-bottom: var(--s-4); }
code { font-family: var(--font-mono); background: var(--surface-2); color: var(--accent-ink); padding: 1px 5px; border-radius: var(--r-xs); font-size: 0.85em; border: 1px solid var(--rule-faint); }

/* ── 14. EMPTY STATE + PROVENANCE + COLOPHON ────────────────────────────── */
.empty-state { text-align: center; padding: var(--s-8) var(--s-5); color: var(--ink-2); }
.empty-mark { font-family: var(--font-display); font-size: 2.5rem; color: var(--rule-strong); display: block; margin-bottom: var(--s-3); }
.empty-title { font-family: var(--font-display); font-size: var(--t-lg); color: var(--ink); margin: 0 0 4px; }
.empty-dek { font-size: var(--t-base); max-width: 36ch; margin: 0 auto var(--s-4); }

.prov { font-family: var(--font-mono); font-size: 0.7rem; font-weight: var(--w-semi); color: var(--provisional); background: var(--gold-tint); border: 1px solid #ddca97; border-radius: var(--r-xs); padding: 0 4px; cursor: help; letter-spacing: 0.02em; vertical-align: 1px; }
.provisional-banner { display: flex; align-items: center; gap: var(--s-2); font-family: var(--font-sans); font-size: var(--t-sm); color: #6f5410; background: var(--gold-tint); border: 1px solid #ddca97; border-left: 3px solid var(--gold); border-radius: var(--r-sm); padding: 8px 14px; margin-bottom: var(--s-4); }
.provisional-banner strong { font-weight: var(--w-semi); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--t-xs); }
.prov-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex: 0 0 auto; }

/* ── contextual help “?” (click/focus or hover -> blurb) ─────────────────── */
.help { position: relative; display: inline-flex; vertical-align: middle; margin-left: 5px; }
.help-btn {
  width: 16px; height: 16px; padding: 0; border-radius: 50%; border: 1px solid var(--rule-strong);
  background: var(--surface); color: var(--ink-3); font-family: var(--font-sans); font-size: 11px;
  font-weight: 700; line-height: 1; cursor: help; display: grid; place-items: center;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.help-btn:hover, .help:focus-within .help-btn { background: var(--gold-tint); color: #6f5410; border-color: #ddca97; }
.help-pop {
  position: absolute; top: 100%; left: 50%; z-index: 60;
  width: max-content; max-width: min(300px, 78vw);
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong);
  border-left: 3px solid var(--gold); border-radius: var(--r-sm); box-shadow: var(--shadow-2);
  padding: 10px 13px; font-family: var(--font-body); font-size: var(--t-sm); line-height: 1.5;
  text-transform: none; letter-spacing: normal; font-weight: var(--w-reg); white-space: normal;
  opacity: 0; visibility: hidden; transform: translate(-50%, 2px);
  transition: opacity var(--dur), transform var(--dur), visibility var(--dur);
}
.help:hover .help-pop, .help:focus-within .help-pop {
  opacity: 1; visibility: visible; transform: translate(-50%, 7px);
}
/* keep the popover on-screen near the right edge */
.help.help-right .help-pop { left: auto; right: 0; transform: translate(0, 2px); }
.help.help-right:hover .help-pop, .help.help-right:focus-within .help-pop { transform: translate(0, 7px); }

.colophon { margin-top: var(--s-8); padding: var(--s-5) var(--s-5) var(--s-7); background: var(--paper-edge); border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); font-size: var(--t-xs); color: var(--ink-3); }
.col-meta { font-family: var(--font-mono); }
.col-rule { flex: 1; min-width: 24px; border-top: 1px dotted var(--rule-strong); }
.col-note { font-style: italic; font-family: var(--font-body); }
.col-link { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }

.masthead-link { font-family: var(--font-sans); font-size: var(--t-sm); font-weight: var(--w-med); color: var(--ink-2); text-decoration: none; padding: 5px 9px; border-radius: var(--r-sm); transition: color var(--dur-fast), background var(--dur-fast); }
.masthead-link:hover { color: var(--accent-ink); background: var(--sunken); }

/* ── user guide ─────────────────────────────────────────────────────────── */
.guide { max-width: 760px; }
.guide-toc { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); padding: var(--s-2) 0 var(--s-5); border-bottom: 1px solid var(--rule); margin-bottom: var(--s-5); }
.guide-toc a { font-family: var(--font-sans); font-size: var(--t-sm); color: var(--accent-ink); text-decoration: none; }
.guide-toc a:hover { text-decoration: underline; }
.guide-sec { margin-bottom: var(--s-6); scroll-margin-top: calc(var(--shell-h) + var(--s-4)); }
.guide-sec h2 { font-size: var(--t-lg); margin-bottom: var(--s-3); padding-bottom: var(--s-2); border-bottom: 1px solid var(--rule-faint); }
.guide-sec p { font-size: var(--t-base); line-height: var(--lh-body); margin-bottom: var(--s-3); max-width: var(--measure); }
.guide-sec ul, .guide-sec ol { margin: 0 0 var(--s-3) var(--s-5); }
.guide-sec li { font-size: var(--t-base); line-height: var(--lh-body); margin-bottom: 6px; max-width: var(--measure); }
.guide-note { color: var(--ink-2); font-style: italic; }
.guide-gloss dt { font-family: var(--font-display); font-weight: var(--w-semi); color: var(--ink); margin-top: var(--s-3); }
.guide-gloss dd { margin: 2px 0 0; color: var(--ink-2); font-size: var(--t-sm); line-height: var(--lh-body); max-width: var(--measure); }

/* toasts */
.toast-stack { position: fixed; top: calc(var(--shell-h) + var(--s-3)); right: var(--s-5); z-index: 60; display: flex; flex-direction: column; gap: var(--s-2); max-width: 340px; }
.toast { display: flex; align-items: flex-start; gap: 8px; font-family: var(--font-sans); font-size: var(--t-sm); padding: 10px 14px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--rule-strong); border-left: 3px solid var(--ink-3); box-shadow: var(--shadow-2); animation: toast-in var(--dur) var(--ease-out) both; }
.toast-ok { border-left-color: var(--ok); }
.field:user-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-tint); }

/* ── 15. MOTION ─────────────────────────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
main > * { animation: rise var(--dur-reveal) var(--ease-out) both; }
main > :nth-child(1) { animation-delay: 0ms; }
main > :nth-child(2) { animation-delay: 60ms; }
main > :nth-child(3) { animation-delay: 120ms; }
main > :nth-child(4) { animation-delay: 180ms; }
main > :nth-child(n+5) { animation-delay: 220ms; }

#counts .n-slides, #counts .n-cases { transition: color var(--dur); }
#counts.htmx-swapping { opacity: .45; transition: opacity var(--dur-fast) var(--ease-out); }
#counts.htmx-settling .n-slides, #counts.htmx-settling .n-cases { animation: count-tick var(--dur-slow) var(--ease-out); }
@keyframes count-tick { 0% { transform: translateY(-3px); color: var(--accent); } 60% { color: var(--accent); } 100% { transform: none; } }

.facet-group[open] .opts { animation: disclose var(--dur) var(--ease-out); }
@keyframes disclose { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.htmx-added.opt, .htmx-added .opt { animation: rise var(--dur) var(--ease-out) both; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ── micro-interactions / loading polish ────────────────────────────────── */
/* tactile press on buttons + interactive rows */
.btn:active, .export-btn:active { transform: translateY(1px); }
.btn { transition: background var(--dur), border-color var(--dur), color var(--dur), box-shadow var(--dur), transform var(--dur-fast); }
.grain-opt input:active + span, .chip:active { transform: translateY(1px); }

/* subtle fade while a USER-initiated fragment swaps (facets, npbb table) — no
   spinner. Scoped so the 1.5s jobs-list poll + #counts (own fade) don't flicker. */
#facet-stain.htmx-swapping, #npbb-surface.htmx-swapping { opacity: 0.5; transition: opacity var(--dur-fast) var(--ease-out); }
#facet-stain.htmx-request, #npbb-surface.htmx-request, .facet-search input.htmx-request { cursor: progress; }

/* the checkbox checkmark pops in when selected */
@keyframes check-pop { from { transform: rotate(42deg) scale(0.2); opacity: 0; } to { transform: rotate(42deg) scale(1); opacity: 1; } }
.opt input:checked + .opt-box::after { animation: check-pop var(--dur-fast) var(--ease-out); }

/* export "preparing" busy state (toggled by a tiny inline handler) */
.btn.is-busy { opacity: 0.65; pointer-events: none; }

/* facet option selection feels a touch springier */
.opt, .chip, .crit-chip { transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast); }

/* ── 16. RESPONSIVE ─────────────────────────────────────────────────────── */
@media (pointer: coarse) { .opt { min-height: 40px; } .btn, .export-btn { min-height: 44px; } .chip { min-height: 36px; } }
@media (max-width: 880px) {
  .browse-grid { grid-template-columns: 1fr; }
  .facet-rail { order: 2; }
  .counts-bar { position: static; flex-direction: column; align-items: stretch; gap: var(--s-3); }
  .counts-bar .export-btn, .counts-bar .btn { width: 100%; }
  /* masthead reflows: wordmark + user/sign-out on row 1, nav on a scrollable row 2 */
  .masthead { flex-wrap: wrap; height: auto; min-height: var(--shell-h); padding: var(--s-2) var(--s-3); gap: var(--s-2) var(--s-3); }
  .masthead-tag { display: none; }
  .who { display: none; }                 /* keep the role pill + sign-out; drop the username */
  .surface-nav { order: 3; width: 100%; margin: 0; overflow-x: auto; scrollbar-width: none; }
  .surface-nav::-webkit-scrollbar { height: 0; }
  .table-frame { max-height: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 380px) { :root { --s-5: 18px; } .surface-title { font-size: var(--t-xl); } }

/* ── 17. REDUCED MOTION ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  main > * { opacity: 1 !important; transform: none !important; }
  #counts.htmx-settling .n-slides, #counts.htmx-settling .n-cases { color: var(--accent); }
}

/* ── 18. REPORTS SURFACE ────────────────────────────────────────────────── */
/* The export summary sheets as live tables. Reuses .data-table / .table-frame /
   .action-card / .criteria-bar — only the report-specific chrome is new. */
.counts-actions { display: flex; align-items: center; gap: var(--s-2); }

.report-cohort {
  background: var(--surface-2); border: 1px solid var(--rule);
  border-radius: var(--r-lg); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-5);
}
.report-cohort .rc-counts { display: flex; align-items: baseline; gap: var(--s-2); flex-wrap: wrap; }
.rc-n { font-family: var(--font-display); font-size: var(--t-lg); font-weight: var(--w-semi);
  font-variant-numeric: tabular-nums; color: var(--ink); }
.rc-l { font-size: var(--t-sm); color: var(--ink-3); }
.rc-sep { color: var(--ink-3); padding: 0 var(--s-1); }
.report-cohort .criteria-bar { margin-top: var(--s-2); padding-bottom: 0; }
.report-cohort .rc-all { margin: var(--s-1) 0 0; font-size: var(--t-sm); color: var(--ink-2); }
.rc-edit { margin-left: var(--s-2); }

.report-cards { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-5); }
.report-cards .action-card { flex: 1 1 220px; max-width: 340px; }

.th-sort { color: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.th-sort:hover { color: var(--ink); text-decoration: underline; }
.sort-ind { color: var(--accent); font-weight: var(--w-bold); }
.table-note { font-size: var(--t-sm); color: var(--ink-3); margin: var(--s-2) 0 0; }
.empty-cell { text-align: center; color: var(--ink-3); padding: var(--s-6); }

/* pivot matrix: sticky stain column + emphasized totals */
.matrix .matrix-rowhead {
  position: sticky; left: 0; background: var(--surface);
  font-weight: var(--w-med); white-space: nowrap; box-shadow: 1px 0 0 var(--rule-faint);
}
.matrix thead .matrix-rowhead { background: var(--surface-2); z-index: 3; }
.matrix td.zero { color: var(--ink-3); }
.matrix .total-col, .matrix .total-row { font-weight: var(--w-semi); background: var(--surface-2); }
.matrix tfoot .total-row { border-top: 1.5px solid var(--rule-strong); }

@media (max-width: 540px) {
  .counts-actions { flex-direction: column; width: 100%; }
  .report-cards .action-card { max-width: none; }
}

/* ── 19. ANALYSIS SURFACE ────────────────────────────────────────────────── */
/* job status pills (reuse .status base) */
.status-queued    { background: var(--sunken);      color: var(--ink-2); }
.status-running   { background: var(--gold-tint);   color: var(--gold); }
.status-done      { background: var(--ok-tint);     color: var(--ok); }
.status-failed    { background: var(--danger-tint); color: var(--danger); }
.status-cancelled { background: var(--sunken);      color: var(--ink-3); }

.compute-badge {
  font-family: var(--font-mono); font-size: var(--t-xs); font-weight: var(--w-semi);
  letter-spacing: 0.04em; background: var(--accent-tint); color: var(--accent-ink);
  border-radius: var(--r-xs); padding: 1px 6px; vertical-align: middle;
}
.report-cards .action-card.ac-headline { border-left-width: 4px; background: var(--accent-tint); }

.run-form { max-width: 640px; }
.params-pick, .source-pick { border: 1px solid var(--rule); border-radius: var(--r-lg); padding: var(--s-4); margin: var(--s-4) 0; display: grid; gap: var(--s-3); }
.params-pick legend { font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-semi); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); padding: 0 var(--s-2); }
.param-field { display: flex; flex-direction: column; gap: 4px; }
.param-field .pf-label { font-size: var(--t-sm); font-weight: var(--w-med); }
.param-check { font-weight: var(--w-reg); font-size: var(--t-sm); }
.source-pick legend { font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-semi); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); padding: 0 var(--s-2); }
.source-opt { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3); border: 1px solid var(--rule-faint); border-radius: var(--r-md); cursor: pointer; transition: background var(--dur-fast); }
.source-opt:hover { background: var(--surface-2); }
.source-opt input[type=radio] { margin-top: 3px; }
.so-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.so-title { font-weight: var(--w-semi); }
.so-dek { font-size: var(--t-sm); color: var(--ink-2); }

.analysis-figs { display: flex; flex-wrap: wrap; gap: var(--s-4); margin: var(--s-4) 0; }
.analysis-fig { max-width: 100%; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-1); }
.warn-text { color: var(--warn); font-weight: var(--w-med); }

/* ── 20. ADMIN CONFIG SURFACE ────────────────────────────────────────────── */
.cfg-flash { background: var(--ok-tint); color: var(--ok); border-radius: var(--r-md); padding: var(--s-2) var(--s-4); margin-bottom: var(--s-4); font-size: var(--t-sm); }
.cfg-tabs { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-5) 0 var(--s-3); }
.cfg-tabs a { font-size: var(--t-sm); color: var(--accent-ink); text-decoration: none; padding: 2px 10px; border: 1px solid var(--rule); border-radius: var(--r-round); }
.cfg-tabs a:hover { background: var(--accent-tint); }

.cfg-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: var(--s-5); margin-bottom: var(--s-5); box-shadow: var(--shadow-1); scroll-margin-top: var(--s-7); }
.cfg-card.cfg-hot { border-left: 3px solid var(--accent); }
.cfg-group-title { font-family: var(--font-display); font-size: var(--t-lg); margin: 0 0 var(--s-4); }

.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s-4) var(--s-5); margin-bottom: var(--s-4); }
.cfg-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cfg-field-wide { grid-column: 1 / -1; }
.cfg-label { font-size: var(--t-sm); font-weight: var(--w-med); color: var(--ink); display: flex; align-items: center; gap: 6px; }
.cfg-stage { font-family: var(--font-mono); font-size: var(--t-xs); background: var(--sunken); color: var(--ink-2); border-radius: var(--r-xs); padding: 0 5px; }
.cfg-hot-dot { color: var(--accent); font-size: 9px; }
.cfg-help { font-size: var(--t-xs); color: var(--ink-3); line-height: var(--lh-snug); }
.cfg-note { font-size: var(--t-xs); color: var(--ink-3); font-style: italic; }
.cfg-ro { background: var(--sunken); color: var(--ink-3); }
.cfg-textarea { font-family: var(--font-mono); font-size: var(--t-xs); resize: vertical; min-height: 64px; }

/* toggle */
.cfg-toggle { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.cfg-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.cfg-knob { position: absolute; inset: 0; background: var(--sunken); border: 1px solid var(--rule-strong); border-radius: 999px; transition: background var(--dur-fast); }
.cfg-knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: var(--surface); border-radius: 50%; box-shadow: var(--shadow-1); transition: transform var(--dur-fast); }
.cfg-toggle input:checked + .cfg-knob { background: var(--accent); border-color: var(--accent); }
.cfg-toggle input:checked + .cfg-knob::after { transform: translateX(18px); }
.cfg-toggle input:focus-visible + .cfg-knob { outline: 2px solid var(--accent); outline-offset: 2px; }

.cfg-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; margin-top: var(--s-4); }
.inline-form { display: inline-flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.btn-danger { background: var(--danger-tint); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--ink-inverse); }

/* ── 21. DATA SURFACE (raw table browser) ────────────────────────────────── */
.data-card-meta { display: block; margin-top: var(--s-2); font-size: var(--t-xs); color: var(--ink-3); }
.data-meta { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; font-size: var(--t-sm); color: var(--ink-2); margin: var(--s-3) 0; }
.data-meta-bottom { margin-top: var(--s-3); }
.subnav-scroll { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

/* raw table: keep columns readable + horizontally scrollable; truncate cells */
.tbl-raw .data-table td, .tbl-raw .data-table th { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.tbl-raw .data-table .rownum { position: sticky; left: 0; background: var(--surface-2); color: var(--ink-3); text-align: right; z-index: 2; }
.tbl-raw .data-table thead .rownum { z-index: 3; }
.cell-null { color: var(--ink-3); }

.pager { display: inline-flex; align-items: center; gap: var(--s-3); }
.pager-mid { font-size: var(--t-xs); color: var(--ink-3); }
.btn-off { opacity: .4; pointer-events: none; }

/* cohort preview pane (Cohort Builder) */
.preview-pane { margin-top: var(--s-4); }
.preview-pane:empty { margin: 0; }
.preview-head { display: flex; align-items: baseline; gap: var(--s-3); margin-bottom: var(--s-2); }

/* admin collection multi-select (dropdown-with-checkboxes) */
.coll-picker { max-width: 420px; }
.coll-summary { display: block; cursor: pointer; list-style: none; user-select: none; }
.coll-summary::-webkit-details-marker { display: none; }
.coll-summary::after { content: "▾"; float: right; color: var(--ink-3); }
.coll-picker[open] .coll-summary::after { content: "▴"; }
.coll-menu { margin-top: var(--s-2); border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); max-height: 320px; overflow-y: auto; padding: var(--s-2); box-shadow: var(--shadow-1); }
.coll-menu-actions { display: flex; gap: var(--s-3); padding: 0 var(--s-2) var(--s-2); border-bottom: 1px solid var(--rule-faint); margin-bottom: var(--s-1); }
.coll-opt { display: flex; align-items: center; gap: var(--s-2); padding: 5px var(--s-2); font-size: var(--t-sm); border-radius: var(--r-sm); cursor: pointer; }
.coll-opt:hover { background: var(--surface-2); }

/* Master Slide Registry hero + scope chips */
.registry-hero { display: block; max-width: none; margin-bottom: var(--s-4); border-left-width: 4px; background: var(--accent-tint); }
.scope-chips { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.scope-chip { display: inline-flex; align-items: baseline; gap: 6px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-round); padding: 4px 12px; font-size: var(--t-sm); transition: background var(--dur-fast), border-color var(--dur-fast); }
.scope-chip:hover { background: var(--accent-tint); border-color: var(--accent); }
.scope-chip[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--ink-inverse); }
.scope-chip[aria-current] .mono { color: var(--ink-inverse); }
.scope-chip .mono { color: var(--ink-3); font-size: var(--t-xs); }
.subnav-sep { color: var(--ink-3); padding: 0 var(--s-1); }

/* definitions / guides JSON editors */
.def-form { max-width: 920px; }
.def-editor { width: 100%; font-family: var(--font-mono); font-size: var(--t-xs); line-height: 1.5;
  tab-size: 2; white-space: pre; overflow-wrap: normal; resize: vertical; }
.def-actions { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-3); flex-wrap: wrap; }
.def-view { max-width: 920px; max-height: 70vh; overflow: auto; background: var(--sunken);
  border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s-4);
  font-family: var(--font-mono); font-size: var(--t-xs); line-height: 1.5; white-space: pre; }

/* ── Collection guides: one flat comparable table + structured (no-JSON) editor ── */
.btn-sm { padding: 3px 10px; font-size: var(--t-xs); }

.guides-table th.g-coll, .guides-table td.g-coll,
.guides-table th[scope="row"].g-coll {
  position: sticky; left: 0; z-index: 2; background: var(--surface-2);
  text-align: left; font-family: var(--font-sans); font-weight: var(--w-semi);
  color: var(--ink); max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.guides-table thead th.g-coll { z-index: 3; }
.guides-table tbody tr.g-row:hover th.g-coll { background: var(--accent-tint); }
.guides-table .g-yes { color: var(--ok); font-weight: var(--w-semi); }
.guides-table .g-no { color: var(--ink-3); }
.guides-table .g-count { font-family: var(--font-mono); font-size: var(--t-xs); color: var(--ink-3); }
.g-chip { display: inline-flex; min-width: 22px; justify-content: center; font-family: var(--font-mono);
  font-size: var(--t-xs); background: var(--accent-tint); color: var(--accent-ink);
  border: 1px solid var(--selected-rule); border-radius: var(--r-round); padding: 0 7px; }

/* the structured detail / editor panel */
.guide-editor-wrap:empty { display: none; }
.guide-editor-wrap { margin-top: var(--s-5); }
.guide-detail { background: var(--surface); border: 1px solid var(--rule-strong);
  border-left: 3px solid var(--accent); border-radius: var(--r-md); padding: var(--s-5);
  box-shadow: var(--shadow-1); scroll-margin-top: var(--s-5); }
.gd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.gd-title { font-family: var(--font-display); font-size: var(--t-xl); color: var(--ink); }
.gd-close { white-space: nowrap; }
.gd-sec { border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s-4);
  margin: 0 0 var(--s-4); }
.gd-sec legend { font-family: var(--font-sans); font-weight: var(--w-semi); font-size: var(--t-sm);
  color: var(--accent-ink); padding: 0 var(--s-2); text-transform: uppercase; letter-spacing: .06em; }
.gd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-3) var(--s-4); }
.gd-field { display: flex; flex-direction: column; gap: 4px; }
.gd-label { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.gd-val { font-size: var(--t-sm); color: var(--ink); word-break: break-word; }
.gd-listarea { resize: vertical; line-height: 1.5; }
.gd-flags { display: flex; flex-wrap: wrap; gap: var(--s-3) var(--s-5); }
.gd-check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-sm); color: var(--ink); }
.gd-maps { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--s-4); }
.gd-map { border: 1px solid var(--rule-faint); border-radius: var(--r-md); padding: var(--s-3); background: var(--surface-2); }
.gd-map-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); }
.gd-map-table { width: 100%; border-collapse: collapse; }
.gd-map-table td { padding: 2px 4px; vertical-align: middle; }
.gd-map-table .field { padding: 5px 8px; font-size: var(--t-xs); }
.gd-arrow { color: var(--ink-3); width: 1.4em; text-align: center; }
.gd-mk { width: 38%; } .gd-mv { width: 52%; } .gd-mx { width: 1.6em; }
.gd-del { color: var(--ink-3); font-size: var(--t-sm); padding: 0 4px; }
.gd-del:hover { color: var(--danger); }
.gd-readonly { background: var(--sunken); }
.gd-ro { margin-bottom: var(--s-3); }
.gd-ro-note { margin: 0 0 var(--s-3); }
.gd-ro-pre { margin: 4px 0 0; max-height: 240px; overflow: auto; background: var(--surface);
  border: 1px solid var(--rule-faint); border-radius: var(--r-xs); padding: var(--s-2) var(--s-3);
  font-family: var(--font-mono); font-size: var(--t-xs); line-height: 1.5; white-space: pre; color: var(--ink-2); }
.gd-audit { margin-top: var(--s-3); }
.gd-audit summary { cursor: pointer; font-size: var(--t-sm); color: var(--accent-ink); }
.gd-audit-table { margin-top: var(--s-2); font-size: var(--t-xs); }

/* ── Blocking protocols (Brain Bank): per-protocol block→region tables ── */
.proto-frame { max-height: 60vh; }
.proto-blocks .field { padding: 5px 8px; font-size: var(--t-xs); }
.proto-blocks .pb-code { width: 90px; }
.proto-blocks td, .proto-blocks th { padding: 5px 10px; }
.proto-reference { margin-top: var(--s-6); }
.proto-ref { border: 1px solid var(--rule); border-radius: var(--r-md); margin-bottom: var(--s-2); background: var(--surface); }
.proto-ref > summary { cursor: pointer; padding: var(--s-3) var(--s-4); font-family: var(--font-sans);
  font-weight: var(--w-semi); color: var(--accent-ink); text-transform: capitalize; }
.proto-ref[open] > summary { border-bottom: 1px solid var(--rule-faint); }
.proto-ref-body { padding: var(--s-3) var(--s-4); overflow-x: auto; }
.kv-table { border-collapse: collapse; font-size: var(--t-sm); margin: 2px 0; }
.kv-table > tbody > tr > th.kv-k { text-align: left; vertical-align: top; color: var(--ink-3); font-weight: var(--w-med);
  padding: 3px 12px 3px 0; white-space: nowrap; }
.kv-table > tbody > tr > td { vertical-align: top; padding: 3px 0; color: var(--ink); }
.kv-list { margin: 2px 0; padding-left: var(--s-4); }
.kv-list li { margin: 1px 0; }

/* ── NPBB operations hub (the faithful GUI forms) ── */
.op-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: var(--s-4); align-items: start; }
.op-card { background: var(--surface); border: 1px solid var(--rule-strong); border-left: 3px solid var(--accent);
  border-radius: var(--r-md); padding: var(--s-5); box-shadow: var(--shadow-1); }
.op-title { font-family: var(--font-display); font-size: var(--t-lg); color: var(--ink); display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.op-dek { font-size: var(--t-sm); color: var(--ink-2); margin: 2px 0 var(--s-4); }
.op-checks { display: grid; grid-template-columns: 1fr; gap: 4px; max-height: 220px; overflow: auto; }
.op-colrow { display: flex; align-items: center; gap: var(--s-3); }
.op-warn { font-size: var(--t-xs); color: var(--danger); margin: var(--s-2) 0 0; }
.op-gate { margin-top: var(--s-2); }
.op-result:empty { display: none; }
.op-result { margin-bottom: var(--s-4); }
.op-parked { background: var(--accent-tint); border: 1px solid var(--selected-rule); border-radius: var(--r-md); padding: var(--s-4) var(--s-5); }
.op-parked-title { font-family: var(--font-display); font-size: var(--t-lg); color: var(--accent-ink); margin: 0 0 var(--s-2); }
.op-parked-params { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s-4); margin: var(--s-3) 0; font-size: var(--t-sm); }
.op-parked-params dt { color: var(--ink-3); } .op-parked-params dd { margin: 0; color: var(--ink); }
.col-modal { border: 1px solid var(--rule-strong); border-radius: var(--r-md); padding: var(--s-5); max-width: 560px; width: 92vw; box-shadow: var(--shadow-2, var(--shadow-1)); }
.col-modal::backdrop { background: rgba(38,30,24,.45); }
.col-modal-title { font-family: var(--font-display); font-size: var(--t-lg); margin: 0 0 var(--s-2); }
.col-groups { max-height: 50vh; overflow: auto; margin: var(--s-3) 0; }
.col-group { border-top: 1px solid var(--rule-faint); padding: var(--s-2) 0; }
.col-group-head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: 4px; }
.col-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 2px var(--s-3); }

/* ── Data Browser sections (Outputs · Inputs · Configuration) ── */
.data-sec-head { margin: var(--s-6) 0 var(--s-3); padding-bottom: 4px; border-bottom: 1px solid var(--rule); }
.data-sec-head:first-of-type { margin-top: var(--s-4); }

/* ── Landing / home (the hub) ── */
.landing-hero { padding: var(--s-6) 0 var(--s-4); border-bottom: 1px solid var(--rule); margin-bottom: var(--s-2); }
.landing-title { font-family: var(--font-display); font-size: clamp(2rem, 5vw, 3.2rem); font-weight: var(--w-semi); color: var(--ink); line-height: 1.05; margin: 2px 0 var(--s-3); }
.landing-dek { font-family: var(--font-body, var(--font-sans)); font-size: var(--t-lg); color: var(--ink-2); max-width: 64ch; line-height: 1.5; }
.landing-stats { margin: var(--s-5) 0 0; max-width: 520px; }
.landing-ext { border-left-color: var(--gold); }
.landing-ext:hover { background: var(--gold-tint); }
.landing-ext-mark { color: var(--gold); font-weight: var(--w-semi); }

/* ── Virtual-scroll data grid (static/grid.js) ── */
.grid { margin-top: var(--s-2); }
.grid-toolbar { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); flex-wrap: wrap; }
.grid-search { min-width: 240px; flex: 0 1 320px; }
.grid-count { font-size: var(--t-xs); color: var(--ink-3); }
.grid-colmenu { position: absolute; z-index: 30; margin-top: -8px; background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-2, var(--shadow-1)); padding: var(--s-3); max-height: 60vh; overflow: auto; min-width: 240px; }
.grid-colmenu-ctl { display: flex; gap: var(--s-3); padding-bottom: var(--s-2); margin-bottom: var(--s-2); border-bottom: 1px solid var(--rule-faint); }
.grid-colopt { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: var(--t-sm); color: var(--ink); cursor: pointer; }

.grid-scroll { overflow: auto; max-height: 74vh; border: 1px solid var(--rule); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-1); }
.grid-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.grid-table { width: max-content; min-width: 100%; position: relative; font-family: var(--font-sans); font-size: var(--t-sm); }
.grid-head { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: var(--gcols); background: var(--surface-2); }
.grid-h { box-sizing: border-box; display: flex; align-items: center; gap: 4px; padding: 7px 12px; height: 36px;
  border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule-faint); cursor: pointer; user-select: none;
  font-family: var(--font-sans); font-weight: var(--w-semi); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-h:hover { color: var(--accent-ink); background: var(--accent-tint); }
.grid-hname { overflow: hidden; text-overflow: ellipsis; }
.grid-caret { color: var(--accent); font-size: var(--t-xs); }
.grid-body { position: relative; }
.grid-vp { position: absolute; top: 0; left: 0; right: 0; will-change: transform; }
.grid-row { display: grid; grid-template-columns: var(--gcols); height: 30px; }
.grid-row:hover .grid-cell { background: var(--accent-tint); }
.grid-cell { box-sizing: border-box; display: flex; align-items: center; padding: 4px 12px; height: 30px;
  border-bottom: 1px solid var(--rule-faint); border-right: 1px solid var(--rule-faint); color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.grid-sticky { position: sticky; left: 0; z-index: 2; }
.grid-cell.grid-sticky { background: var(--surface); font-family: var(--font-mono); }
.grid-row:hover .grid-cell.grid-sticky { background: var(--accent-tint); }
.grid-h.grid-sticky { z-index: 6; background: var(--surface-2); }
.grid-row-load { opacity: .4; }
.grid-link { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.grid-row.grid-clickable { cursor: pointer; }

/* ── Vocabulary CRUD (stain / region editor) ── */
.vocab-admin { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); flex-wrap: wrap; }
.vocab-ed { margin-top: var(--s-5); }
.vocab-err { background: var(--danger-tint); color: var(--danger); border: 1px solid #e0b9b7;
  border-radius: var(--r-md); padding: var(--s-2) var(--s-4); margin-bottom: var(--s-4); font-size: var(--t-sm); }

/* ── Reports visualizations (themed inline SVG; static = webapp/charts.py) ── */
.report-charts { margin: var(--s-4) 0 var(--s-5); }
.report-charts-row { display: flex; gap: var(--s-4); flex-wrap: wrap; }
.report-charts-row .chart-fig { flex: 1 1 300px; }
.chart-fig { margin: 0 0 var(--s-4); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-md); padding: var(--s-4) var(--s-5); box-shadow: var(--shadow-1); overflow-x: auto; max-width: 100%; }
.chart-svg { display: block; max-width: 100%; height: auto; font-family: var(--font-sans); }
.chart-lbl { fill: var(--ink-2); font-size: 12px; }
.chart-lbl-lg { fill: var(--ink); font-size: 15px; font-weight: 600; font-family: var(--font-display); }
.chart-val { fill: var(--ink-3); font-size: 11px; font-family: var(--font-mono); }
.chart-bar { fill: var(--accent); transition: fill var(--dur-fast, .12s); }
.chart-row:hover .chart-bar { fill: var(--accent-deep); }
.chart-donut-bg { stroke: var(--sunken); }
.chart-donut-fg { stroke: var(--accent); }
.chart-donut-pct { fill: var(--ink); font-size: 22px; font-weight: 600; font-family: var(--font-display); }
.chart-donut-sub { fill: var(--ink-3); font-size: 11px; font-family: var(--font-mono); }
.chart-collbl { fill: var(--ink-2); font-size: 10px; }
.chart-heat-cell { fill: var(--accent); }
.chart-heat-empty { fill: var(--surface-2); }
.chart-cellval { fill: var(--ink-2); font-size: 10px; font-family: var(--font-mono); }
.chart-cellval.on { fill: var(--ink-inverse); }
.heat-toggle { display: flex; align-items: center; gap: var(--s-2); margin: var(--s-4) 0 0; flex-wrap: wrap; }
.heat-toggle a { font-size: var(--t-sm); color: var(--ink-2); text-decoration: none; padding: 3px 10px;
  border: 1px solid var(--rule); border-radius: var(--r-round); }
.heat-toggle a:hover { border-color: var(--accent); color: var(--accent-ink); }
.heat-toggle a[aria-current] { background: var(--accent); color: var(--ink-inverse); border-color: var(--accent); }

/* ── Cohort Builder: collection multi-select ── */
.coll-checks { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow: auto;
  padding: var(--s-1) 0; }
.coll-check { display: flex; align-items: center; gap: 6px; }
.coll-check .chip-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coll-check .gcount { color: var(--ink-3); font-size: var(--t-xs); }

/* ── Cohort Builder: stain tiers + region lens picker ── */
.region-lens { display: flex; flex-wrap: wrap; gap: 3px; padding: var(--s-2) var(--s-3) 0; border: 0; margin: 0; }
.region-lens .lens-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.region-lens .lens-opt span {
  display: block; font-family: var(--font-sans); font-size: var(--t-xs); font-weight: var(--w-med);
  color: var(--ink-2); padding: 3px 9px; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid var(--rule); transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.region-lens .lens-opt input:checked + span { background: var(--accent); color: var(--ink-inverse); border-color: var(--accent); }
.region-lens .lens-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.facet-note { font-size: var(--t-xs); color: var(--ink-3); padding: var(--s-2) var(--s-3) 0; margin: 0; }
/* keep long option lists (region, target, collection) scannable */
.facet-group .opts { max-height: 17rem; overflow-y: auto; }
#facet-region.htmx-swapping { opacity: 0.5; transition: opacity var(--dur-fast) var(--ease-out); }
#facet-region.htmx-request, #regionq.htmx-request { cursor: progress; }
