/* Theme tokens. Dark is the default (M018-A Slice 3); [data-theme="light"] restores the Slice 1–2 palette.
   The theme is chosen before first paint by the inline script in base.html (localStorage, no backend). */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151B24; --surface: #1E2733; --surface-hover: #263140; --border: #354253;
  --text: #E6EDF5; --text-muted: #94A3B8; --accent: #60A5FA; --focus: #93C5FD;
  --sev-critical: #FCA5A5; --sev-high: #FDBA74; --sev-watch: #FDE047; --sev-info: #7DD3FC;
  --warn-bg: #3A2F14; --warn-text: #FDE68A; --warn-border: #8A6A1F;
  --err-bg: #3B1D22; --err-border: #9F3A45; --ok-bg: #1B3150; --ok-border: #3B6CA8;
  --backdrop: rgba(5, 8, 12, .62); --shadow: rgba(0, 0, 0, .5);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #ffffff; --surface-hover: #eef1f5; --border: #d9dee4;
  --text: #1b1f24; --text-muted: #5a6470; --accent: #0b5cad; --focus: #0b5cad;
  --sev-critical: #9b1c1c; --sev-high: #a8430b; --sev-watch: #7a5a00; --sev-info: #2f5d8a;
  --warn-bg: #fff4e5; --warn-text: #6b4300; --warn-border: #f0c47a;
  --err-bg: #fdecec; --err-border: #f2b8b8; --ok-bg: #eef5ff; --ok-border: #9cc0e8;
  --backdrop: rgba(15, 20, 25, .35); --shadow: rgba(0, 0, 0, .12);
}
:root { --muted: var(--text-muted); --line: var(--border); }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .04em; }
.status { display: flex; flex-wrap: wrap; gap: 8px 12px; color: var(--muted); font-size: 13px; align-items: center; }
.badge-demo { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); border-radius: 4px; padding: 1px 6px; }
.who { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.who-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.switch, .scenario { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
select, button, textarea { font: inherit; color: var(--text); padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
button:hover:not(:disabled), select:hover { background: var(--surface-hover); }
button:disabled { opacity: .55; cursor: not-allowed; }
button { cursor: pointer; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; background: var(--surface); }
.chip-muted { color: var(--muted); }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }

.layout { display: flex; min-height: calc(100vh - 60px); }
.sidebar { width: 168px; flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 12px 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: 8px 16px; text-decoration: none; color: var(--text); }
.sidebar a[aria-current="page"] { background: var(--ok-bg); border-left: 3px solid var(--accent); font-weight: 600; }
.scenario { flex-direction: column; align-items: stretch; padding: 16px; border-top: 1px solid var(--line); margin-top: 16px; }
main { flex: 1; min-width: 0; padding: 16px 20px 80px; }
.page-id h1 { margin: 0 0 8px; font-size: 22px; }
.crumb { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 12px; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.meta { color: var(--muted); font-size: 13px; }
.state { padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); margin: 12px 0; }
.state-error { background: var(--err-bg); border-color: var(--err-border); }
.state-denied { background: var(--warn-bg); border-color: var(--warn-border); }
.links { padding-left: 18px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 7px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); }
td.num, th.num { text-align: right; }
.sev { font-weight: 600; }
.sev::before { content: "■ "; }
td.when { white-space: nowrap; }
td .t { display: block; color: var(--muted); }
.sev-critical { color: var(--sev-critical); } .sev-high { color: var(--sev-high); }
.sev-watch { color: var(--sev-watch); } .sev-info { color: var(--sev-info); }
.act { white-space: nowrap; }
.act-off { color: var(--muted); white-space: nowrap; }
.summary dl, .card dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0; }
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 16px; }
dt { color: var(--muted); } dd { margin: 0; }

.cards { display: none; list-style: none; padding: 0; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin-bottom: 10px; }
.card-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.bottomnav { display: none; }

/* Slice 2: filters, drawers, listing detail */
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin: 0 0 10px; font-size: 13px; }
.filters label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.filters select { color: var(--text); }
tbody tr:hover td { background: var(--surface-hover); }
tr.row-active td { background: var(--ok-bg); }
.hint { display: block; color: var(--muted); font-size: 13px; }
.plain { list-style: none; margin: 4px 0; padding: 0; }
.plain li { margin: 2px 0; }
.drawer-backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); overflow-y: auto; z-index: 21;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 24px var(--shadow);
  padding: 0 20px 24px; }
.drawer:focus, .drawer:focus-visible { outline: none; }  /* focus is moved here on open; controls inside keep rings */
.drawer-head { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 0 10px; margin-bottom: 8px; }
.drawer-head h2 { margin: 0; font-size: 19px; }
.drawer-head p { margin: 2px 0 0; }
.drawer-close { white-space: nowrap; text-decoration: none; border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; }
.fields { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 14px; margin: 8px 0; }
.fields dd { overflow-wrap: anywhere; }
.evidence { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; font-size: 13px; }
.sections { list-style: none; counter-reset: sec; padding: 0; margin: 0; }
.sections > li { counter-increment: sec; border-bottom: 1px solid var(--line); padding: 8px 0; }
.sections h3 { margin: 0 0 4px; font-size: 15px; }
.sections h3::before { content: counter(sec) ". "; color: var(--muted); }
.drawer-actions { padding-top: 12px; }
table.diff { font-size: 13px; }
table.diff th[scope="row"] { color: var(--muted); font-weight: 600; }
.diff-cards { list-style: none; padding: 0; margin: 0; }
.diff-cards li { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 6px; }
.compact-only { display: none; }
.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 12px; align-items: start; }
.two-col > div { display: flex; flex-direction: column; gap: 12px; }
.summary h2 { font-size: 16px; margin: 8px 0 0; }
.listing-head dl { grid-template-columns: max-content 1fr max-content 1fr; }
.listing-head .t, td .t0 { display: block; }
.tech summary { cursor: pointer; color: var(--muted); }
details summary { cursor: pointer; }
.timeline { list-style: none; padding: 0; margin: 8px 0; border-left: 2px solid var(--line); }
.timeline li { padding: 6px 0 10px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .t { display: block; }
h2 { font-size: 18px; margin: 16px 0 8px; }
code { font-size: 12px; overflow-wrap: anywhere; }

/* Slice 4: Home dashboard, listings search */
input[type="search"] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; padding: 4px 8px; min-width: 12rem; }
input[type="search"]::placeholder { color: var(--text-muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px; color: var(--text); text-decoration: none; }
a.kpi:hover { background: var(--surface-hover); }
.kpi-label { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.2; }
.kpi-value.kpi-time { font-size: 20px; }
.kpi-note { color: var(--text-muted); font-size: 13px; }
.home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 4px 16px 12px; }
.panel h2 { font-size: 16px; }
.panel .state { margin: 4px 0; }
.rank, .activity, .quick { margin: 0; padding-left: 20px; }
.rank li, .activity li { margin: 0 0 8px; }
.activity { list-style: none; padding: 0; }
.quick li { margin: 4px 0; }
.table-scroll { overflow-x: auto; }
.table-scroll:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
table.listings { min-width: 1500px; }
table.listings td { min-width: 6rem; }

/* MEDIUM: listing summaries stack before the sidebar layout runs out of width */
@media (max-width: 1024px) {
  .listing-head dl { grid-template-columns: max-content 1fr; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}

/* COMPACT: cards instead of tables, bottom navigation (CMS V1 §5, §32) */
@media (max-width: 720px) {
  .layout { display: block; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 0; }
  .sidebar ul { display: none; }
  .scenario { flex-direction: row; margin: 0; border: 0; padding: 8px 16px; }
  main { padding: 12px 16px 88px; }
  .table-wrap { display: none; }
  .cards { display: block; }
  .table-wrap.compact-scroll { display: block; }   /* tables without a card form stay, scrolling sideways */
  .who { align-items: flex-start; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--line); justify-content: space-around; padding: 6px 0; }
  .bottomnav a { padding: 8px 6px; text-decoration: none; color: var(--muted); font-size: 13px; }
  .bottomnav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .drawer { width: 100%; border-left: 0; padding: 0 16px 24px; }
  .wide-only { display: none; }
  .compact-only { display: block; }
  .two-col { display: block; }
  .two-col > div { margin-top: 12px; }
  .listing-head dl { grid-template-columns: max-content 1fr; }
  .segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 6px; gap: 0; }
  .segmented a { text-align: center; padding: 8px 6px; font-size: 13px; border-bottom-width: 0; }
  .stack-compact dl { grid-template-columns: 1fr; gap: 0; }
  .stack-compact dd { margin-bottom: 6px; }
  .segmented a[aria-current="page"] { background: var(--ok-bg); }
  .fields { grid-template-columns: 1fr; gap: 0 0; }
  .fields dd { margin-bottom: 6px; }
  .filters { gap: 6px 8px; }
}

/* Slice 3: theme toggle, flash messages, quarantine queue, review form */
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.theme-toggle .when-light { display: none; }
:root[data-theme="light"] .theme-toggle .when-light { display: inline; }
:root[data-theme="light"] .theme-toggle .when-dark { display: none; }
.flash { padding: 10px 14px; border: 1px solid var(--ok-border); background: var(--ok-bg); border-radius: 6px; margin: 8px 0 12px; }
.flash-error { border-color: var(--err-border); background: var(--err-bg); }
.review fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 8px 0; }
.review legend { font-weight: 600; padding: 0 4px; }
.review textarea { width: 100%; margin: 4px 0 8px; }
.decisions { display: flex; flex-wrap: wrap; gap: 8px; }
.decisions button { padding: 6px 12px; }
.history-list { list-style: none; padding: 0; margin: 4px 0; font-size: 13px; }
.history-list li { border-left: 3px solid var(--line); padding: 2px 0 6px 10px; }
.reset { padding: 0 16px 12px; }

/* M018B-03 Real Data */
.badge-real { background: var(--ok-bg); color: var(--text); border-color: var(--ok-border); }
.pager { flex-wrap: wrap; border-bottom: 0; }
.data-source { margin-top: 0; }
.elig-summary { margin: 4px 0 8px; }

/* HM-01 MT-04 Collection Runs: keep chips and run ids whole (inside the horizontal scroll region) */
.runs-table .chip, .runs-table code { white-space: nowrap; }

/* HM-01 MT-06 Market Analytics: server-rendered horizontal bars (no chart library) */
.bars { list-style: none; padding: 0; margin: 8px 0 16px; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 12px; background: var(--surface-hover); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-value { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kpi-range { font-size: 1.1rem; }
@media (max-width: 600px) {
  .bars li { grid-template-columns: minmax(0, 1fr) auto; }
  .bars .bar-track { grid-column: 1 / -1; grid-row: 2; }
}

/* HM-03 production footer */
.site-footer { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 12px; }

/* COL-09-R2 private platform: login / setup / account forms */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; box-sizing: border-box; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 24px; box-shadow: 0 8px 28px var(--shadow); box-sizing: border-box; }
.auth-brand { font-weight: 700; letter-spacing: .08em; font-size: 15px; margin: 0 0 4px; }
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-card .meta, .form .meta { color: var(--muted); font-size: 13px; }
.form label { display: block; font-weight: 600; margin: 14px 0 6px; }
.form input[type="text"], .form input[type="password"], .form select {
  font: inherit; width: 100%; box-sizing: border-box; padding: 9px 10px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; }
.form input:focus-visible, .form select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.form .actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-primary { background: var(--accent); color: var(--bg); border: 1px solid var(--accent); border-radius: 6px;
  padding: 9px 16px; font: inherit; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.form-narrow { max-width: 440px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; padding: 8px 12px; border: 1px dashed var(--line);
  border-radius: 6px; display: inline-block; user-select: all; overflow-wrap: anywhere; }
.inline-form { display: inline; margin: 0; }
.account-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.account-bar button { font-size: 13px; }
/* ACQ-11-R2 Source Coverage */
.form-row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin: 8px 0 16px; }
.form-row input[type="number"] { width: 6em; }
tr.muted td { color: var(--muted, inherit); }
table[data-targets], table[data-runs], table[data-listings] { min-width: 760px; } /* scroll sideways, never crush */
/* ACQ-11-R3: two collection lanes side by side (stacked on narrow screens) */
.lanes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin: 8px 0 16px; }
.lane { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.lane h4 { margin: 0 0 4px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
