:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #deddd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --bar: #2a78d6;
  --bar-missing: #b9b8b2;
  --cell-1: #b7d3f3;
  --cell-2: #6ea6e6;
  --cell-3: #2a78d6;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #34332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1d2d42;
    --bar: #3987e5;
    --bar-missing: #5b5a55;
    --cell-1: #23456f;
    --cell-2: #2f68ad;
    --cell-3: #4a95ee;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --accent-soft: #1d2d42;
  --bar: #3987e5; --bar-missing: #5b5a55; --cell-1: #23456f; --cell-2: #2f68ad; --cell-3: #4a95ee;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* Banner: title + tabs top left, filters on the right; breadcrumb and active-filter chips on
   full-width rows below (only when shown). The search box sits at the top of the results list.
   .controls is display:contents so the filters box is placed in the grid directly. */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; gap: 10px 28px; align-items: start;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "brand filters"
    "tabs  filters";
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { grid-area: brand; align-self: start; }
.brand h1 { font-size: 18px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.top .tabs a { padding: 5px 10px; font-size: 13px; }
.tabs { grid-area: tabs; justify-self: start; align-self: end; }
.controls { display: contents; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.filters { grid-area: filters; justify-self: end; align-self: center; }
.context, .active { grid-column: 1 / -1; }   /* own full-width rows, only when shown */
/* search box at the top of the results list; stays visible while the list scrolls */
.results-search { position: sticky; top: 0; z-index: 2; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.results-search input { width: 100%; font-size: 15px; padding: 10px 12px; }
/* phones: everything stacked */
@media (max-width: 820px) {
  .top { grid-template-columns: minmax(0, 1fr); grid-template-areas: "brand" "tabs" "filters"; gap: 10px; }
  .tabs, .filters { justify-self: stretch; }
  .tabs { overflow-x: auto; }
}
.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 0; padding: 6px 8px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.filters select { max-width: 260px; }
.field[hidden] { display: none !important; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 8px 14px; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); cursor: default; font-weight: 500; }
.filters.dirty { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.active { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.active:empty { display: none; }
.fchip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.fchip b { font-weight: 600; }
.fchip button { border: 0; background: none; cursor: pointer; color: var(--text-2); font-size: 14px; line-height: 1; padding: 2px 5px; border-radius: 999px; }
.fchip button:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--text); }
.active .pending { color: var(--accent); font-weight: 600; }

/* view tabs + programme breadcrumb */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.context { flex-basis: 100%; font-size: 15px; }
.context a { color: var(--accent); text-decoration: none; }
.context a:hover { text-decoration: underline; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn.back { display: inline-block; margin-bottom: 10px; font-weight: 500; }

/* programme multi-select */
.msel { position: relative; }
.msel-btn { min-width: 190px; max-width: 280px; text-align: left; padding: 8px 30px 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.msel-btn::after { content: "▾"; position: absolute; right: 10px; color: var(--muted); }
.msel-btn.has { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.msel-pop { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; width: min(440px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.msel-actions { position: sticky; top: 0; display: flex; gap: 6px; align-items: center; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 12px; }
.msel-actions span { flex: 1; }
#progList { list-style: none; margin: 0; padding: 4px; }
#progList label { display: grid; grid-template-columns: auto 64px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
#progList label:hover { background: var(--surface-2); }
#progList li.on label { background: var(--accent-soft); }
#progList li.on b { color: var(--accent); }
#progList .nm { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#progList .ct { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#progList input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

/* results: selected programmes highlighted */
#results .psel { color: var(--accent); font-weight: 700; background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }
#results .also { color: var(--muted); }

/* question detail extras */
.eyebrow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.scope { margin: 6px 0 2px; padding: 8px 12px; border-radius: var(--radius); background: var(--accent-soft); font-size: 13px; }
.chips-lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); align-self: center; margin-right: 2px; }
a.chip.plink { text-decoration: none; }
a.chip.plink:hover { background: var(--border); color: var(--text); }
a.chip.plink.on { background: var(--accent); color: #fff; }

/* export markers (results list + question page) */
#results li { position: relative; padding-right: 40px; }
.mark { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; }
.mark:hover { background: var(--surface); border-color: var(--border); color: var(--accent); }
.mark.on { color: var(--accent); }
.mark:focus-visible { outline: 2px solid var(--accent); }
.mark-inline { display: inline-flex; vertical-align: -3px; color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.qhead { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.xtoggle { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; flex-shrink: 0; }
.xtoggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* sources and documentation */
ul.docs { margin: 0; padding-left: 18px; }
ul.docs li { margin: 3px 0; overflow-wrap: anywhere; }
ul.docs a, .dsrc a { color: var(--accent); }
.dist .dsrc { color: var(--muted); font-size: 12px; margin: -4px 0 8px; overflow-wrap: anywhere; }
table.occ td.srcf { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; max-width: 220px; }

/* export tab */
.export { padding: 24px; }
.ex-wrap { max-width: 1100px; margin: 0 auto; }
.ex-head { display: flex; gap: 16px 24px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.ex-head > div:first-child { flex: 1 1 420px; }
.ex-head p { margin: 6px 0 0; }
.ex-head a { color: var(--accent); }
.ex-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ex-actions .btn { padding: 8px 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.ex-msg { margin-bottom: 14px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.ex-msg.ok { border-color: #2e9b5f; background: color-mix(in srgb, #2e9b5f 10%, var(--surface)); }
.ex-msg.warn { border-color: #c98500; background: color-mix(in srgb, #c98500 10%, var(--surface)); }
.ex-msg.err { border-color: #c0392b; background: color-mix(in srgb, #c0392b 9%, var(--surface)); }
.ex-msg.info { border-color: var(--accent); background: var(--accent-soft); }
.ex-msg ul { margin: 6px 0 0; padding-left: 18px; }
.ex-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.ex-doc input[type=text], .exi-body textarea, #exMeth { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font: inherit; color: inherit; }
#exMeth { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5; resize: vertical; }
.ex-meth { margin: 6px 0 12px; }
.ex-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
label.toggle.big { font-size: 13px; color: var(--text); margin: 6px 0; display: flex; }
.exlist { list-style: none; margin: 0; padding: 0; }
.exi { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
.exi.open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.exi-head { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; }
.exi-tg { flex: 1; display: flex; gap: 10px; align-items: center; text-align: left; background: none; border: 0; padding: 8px; cursor: pointer; border-radius: 8px; min-width: 0; }
.exi-tg:hover { background: var(--surface-2); }
.exi-num { flex-shrink: 0; width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--text-2); }
.exi.open .exi-num { background: var(--accent); color: #fff; }
.exi-txt { display: flex; flex-direction: column; min-width: 0; }
.exi-txt b { font-weight: 600; }
.exi-sum { font-size: 12px; }
.chev { color: var(--muted); transition: transform .15s; margin-left: auto; }
.exi.open .chev { transform: rotate(90deg); }
.exi-btns { display: flex; gap: 4px; flex-shrink: 0; }
.exi-body { padding: 4px 16px 16px 46px; border-top: 1px solid var(--border); }
.exb-sec { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.exb-sec:last-child { border-bottom: 0; }
.exb-lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); margin-bottom: 8px; }
.exb-progs, .exb-incl, .exb-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.exb-tools { margin-bottom: 8px; font-size: 13px; }
.pchk { display: inline-flex; gap: 5px; align-items: center; padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: 13px; }
.pchk.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.pchk input, .exb-sec input[type=checkbox], .ex-doc input[type=checkbox] { accent-color: var(--accent); }
table.cov.pick td.c1, table.cov.pick td.c2, table.cov.pick td.c3 { cursor: pointer; }
table.cov.pick td.pk { box-shadow: inset 0 0 0 2px var(--text); }
table.cov.pick td.pp { box-shadow: inset 0 0 0 2px var(--text); background-image: linear-gradient(135deg, transparent 50%, var(--surface) 50%); }
.legend i.lg-pick { background: var(--cell-2); box-shadow: inset 0 0 0 2px var(--text); }
.legend i.lg-part { background: var(--cell-2) linear-gradient(135deg, transparent 50%, var(--surface) 50%); box-shadow: inset 0 0 0 2px var(--text); }
.exb-chosen { margin-top: 10px; }
.exb-chosen .chip { display: inline-flex; align-items: center; gap: 4px; padding-right: 2px; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 5px; border-radius: 999px; }
.chip-x:hover { color: var(--text); background: var(--border); }
@media (max-width: 820px) {
  .ex-grid2 { grid-template-columns: 1fr; }
  .exi-body { padding-left: 16px; }
  .exi-head { flex-wrap: wrap; }
  .export { padding: 16px; }
}

/* programme cards */
.prog-index { padding: 24px; max-width: 1200px; margin: 0 auto; }
.pi-head { margin-bottom: 16px; }
.pi-head p { margin: 4px 0 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.pcard { display: flex; flex-direction: column; gap: 4px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: inherit; text-decoration: none; transition: border-color .12s, box-shadow .12s; }
.pcard:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.pc-code { font-size: 20px; font-weight: 700; color: var(--accent); }
.pc-name { color: var(--text-2); min-height: 2.9em; }
.pc-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.pc-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type=search], select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
input[type=search]:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.layout { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 0; min-height: calc(100vh - var(--head-h, 120px)); }
.results { border-right: 1px solid var(--border); background: var(--surface); overflow: auto; max-height: calc(100vh - var(--head-h, 120px)); position: sticky; top: var(--head-h, 120px); }
.results-head { padding: 10px 16px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); }
#results { list-style: none; margin: 0; padding: 0; }
#results li { padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
#results li:hover { background: var(--surface-2); }
#results li.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
#results .lbl { font-weight: 500; }
#results .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; }

.btn { padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.results-foot { text-align: center; padding: 12px 16px 20px; }
.results-foot p { margin: 0; font-size: 12px; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.detail { padding: 20px 24px 48px; min-width: 0; }
.empty { max-width: 620px; margin: 48px auto; color: var(--text-2); }
.empty h2 { color: var(--text); margin-bottom: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card h3 { font-size: 14px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card h3 .spacer { flex: 1; }
.qtitle { font-size: 20px; margin-bottom: 6px; }
.kpis { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 10px; }
.kpi b { display: block; font-size: 20px; }
.kpi span { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--text-2); }
details.variants summary { cursor: pointer; color: var(--text-2); margin-top: 10px; }
details.variants ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); }

/* coverage grid */
.cov-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--border); border-radius: var(--radius); }
table.cov { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
table.cov th { font-weight: 500; color: var(--text-2); white-space: nowrap; background: var(--surface); }
table.cov thead th { position: sticky; top: 0; z-index: 2; writing-mode: vertical-rl; transform: rotate(180deg); padding: 4px 0; height: 40px; }
table.cov tbody th { position: sticky; left: 0; z-index: 1; text-align: left; padding-right: 8px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
table.cov td { width: 14px; min-width: 14px; height: 14px; border-radius: 3px; background: var(--surface-2); }
table.cov td.c1 { background: var(--cell-1); cursor: pointer; }
table.cov td.c2 { background: var(--cell-2); cursor: pointer; }
table.cov td.c3 { background: var(--cell-3); cursor: pointer; }
table.cov td.sel { outline: 2px solid var(--text); outline-offset: -1px; }
.legend { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* occurrences table */
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.tools input { flex: 1 1 200px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.occ-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--border); border-radius: var(--radius); }
table.occ { width: 100%; border-collapse: collapse; font-size: 13px; }
table.occ th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; padding: 6px 10px; cursor: pointer; white-space: nowrap; user-select: none; }
table.occ td { padding: 6px 10px; border-top: 1px solid var(--border); vertical-align: top; }
table.occ tr.row { cursor: pointer; }
table.occ tr.row:hover td { background: var(--surface-2); }
table.occ tr.on td { background: var(--accent-soft); }
table.occ td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.occ code { font-size: 12px; }
table.occ .alt { color: var(--muted); font-size: 12px; }

/* distributions */
.dists { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.dist { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); position: relative; }
.dist h4 { margin: 0 24px 2px 0; font-size: 13px; }
.dist .dsub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.dist .x { position: absolute; top: 6px; right: 6px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px; }
.bars { display: grid; grid-template-columns: minmax(80px, 42%) 1fr auto; gap: 3px 8px; align-items: center; font-size: 12px; }
.bars .bl { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bl .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.bars .track { height: 14px; }
.bars .fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 1px; }
.bars .fill.miss { background: var(--bar-missing); }
.bars .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.bars .pct span { color: var(--muted); margin-left: 4px; }
.bars .row { display: contents; }
.bars .row:hover .bl, .bars .row:hover .pct { color: var(--text); }
.hist { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin: 4px 0; }
.hist div { flex: 1; background: var(--bar); border-radius: 3px 3px 0 0; min-height: 1px; }
.hist-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.note { color: var(--muted); font-size: 12px; margin-top: 6px; }
label.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--text-2); font-weight: 400; cursor: pointer; }

.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12px; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.tip b { display: block; }

.loading { color: var(--muted); padding: 24px; }
.err { color: #c0392b; }

@media (max-width: 820px) {
  .top { padding: 10px 16px; }
  .layout { grid-template-columns: 1fr; }
  .results { position: static; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .detail { padding: 16px; }
  .dists { grid-template-columns: 1fr; }
}
