:root {
  color-scheme: light;
  --surface-0: #f3f3f1;
  --surface-1: #fcfcfb;
  --border: #dedcd6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --grid: rgba(11, 11, 11, 0.08);
  --mark: #8a8984;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --critical: #b3261e;
  --critical-bg: #fbe9e7;
  --warning-bg: #fff4d6;
  --good: #0f7a3d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #34332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9c9b93;
    --grid: rgba(240, 239, 236, 0.09);
    --mark: #7d7c75;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --critical: #f2b8b5;
    --critical-bg: #3b1d1b;
    --warning-bg: #3a2f12;
    --good: #7fd4a0;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --border: #34332f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9c9b93;
  --grid: rgba(240, 239, 236, 0.09);
  --mark: #7d7c75;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --critical: #f2b8b5;
  --critical-bg: #3b1d1b;
  --warning-bg: #3a2f12;
  --good: #7fd4a0;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code { font: 0.9em ui-monospace, SFMono-Regular, Consolas, monospace; }
h1 { font-size: 1.5rem; margin: 0.4rem 0 0.6rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; color: var(--text-secondary); }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
  padding: 0.6rem 16px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text-primary); text-decoration: none; }
.top nav { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; flex: 1; }
.top nav a { color: var(--text-secondary); text-decoration: none; padding: 0.15rem 0; border-bottom: 2px solid transparent; }
.top nav a[aria-current="page"] { color: var(--text-primary); border-bottom-color: var(--accent); }
.logout { margin: 0; }

main { max-width: 1240px; margin: 0 auto; padding: 1rem 16px 2rem; }
footer { max-width: 1240px; margin: 0 auto; padding: 0 16px 2rem; color: var(--text-muted); font-size: 0.8rem; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin: 0 0 1rem; min-width: 0; }
.narrow { max-width: 720px; }
.grid2, .grid3 { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid2 > .card, .grid3 > .card { margin: 0; }
@media (min-width: 900px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 600px) and (max-width: 899px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
}

.lead { color: var(--text-secondary); margin: 0 0 1rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.big { font-size: 3rem; font-weight: 700; margin: 0.2rem 0; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-size: 1.1rem; color: var(--text-muted); font-weight: 400; }

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; }
td.r, th.r { text-align: right; }
table.compact th, table.compact td { padding: 0.2rem 0.4rem; font-size: 0.85rem; }
table.kv { width: auto; }
table.kv th { color: var(--text-secondary); font-weight: 500; padding-right: 1rem; }
.scroll { overflow-x: auto; }
.scroll.tall { max-height: 32rem; overflow-y: auto; }
tr.loss td { background: var(--critical-bg); }
tr.miss td { background: var(--warning-bg); }
.tag-loss { color: var(--critical); }
meter { width: 5rem; height: 0.7rem; vertical-align: middle; }

.flash { background: var(--warning-bg); border: 1px solid var(--border); padding: 0.6rem 0.8rem; border-radius: 6px; }
.note { background: var(--surface-1); border-left: 4px solid var(--mark); padding: 0.4rem 0.9rem; margin: 0 0 1rem; }
.note p { margin: 0.3rem 0; }
.error { color: var(--critical); }
.warn { color: var(--critical); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: end; margin: 0 0 1rem; }
.stack { display: grid; gap: 0.8rem; }
label { display: grid; gap: 0.2rem; font-size: 0.9rem; color: var(--text-secondary); }
label.inline { display: flex; gap: 0.4rem; align-items: baseline; color: var(--text-primary); }
fieldset { border: 1px solid var(--border); border-radius: 6px; display: grid; gap: 0.3rem; }
input, select, textarea, button {
  font: inherit; color: var(--text-primary); background: var(--surface-0);
  border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.55rem; max-width: 100%;
}
input[type="checkbox"], input[type="radio"] { padding: 0; }
textarea { width: 100%; }
button { background: var(--accent); color: #fff; border-color: transparent; cursor: pointer; justify-self: start; }
button.link { background: none; color: var(--accent); padding: 0; border: 0; }
button:disabled { opacity: 0.6; cursor: progress; }

.login { max-width: 360px; margin: 10vh auto 0; }
.login form { display: grid; gap: 0.8rem; }
.login input { width: 100%; }

.status { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 99px; border: 1px solid var(--border); vertical-align: middle; font-weight: 600; }
.status-approved { color: var(--good); }
.status-rejected { color: var(--critical); }
.status-conditional, .status-unchecked { color: var(--text-secondary); }
.role { font-size: 0.8rem; color: var(--text-secondary); }
.role-coalition { font-weight: 700; color: var(--text-primary); }

ul.events, ul.news { list-style: none; padding: 0; margin: 0; }
ul.events li { padding: 0.3rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
ul.news li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
ul.news p { margin: 0.25rem 0; }
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 4px; padding: 0 0.35rem; color: var(--text-secondary); }

details summary { cursor: pointer; color: var(--accent); }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* charts */
figure.chart { margin: 0; min-height: 300px; }
figure.chart .u-legend { font-size: 0.85rem; color: var(--text-secondary); text-align: left; }
figure.chart .u-legend .u-marker { border-radius: 2px; }
figure.chart .mark-caption { min-height: 1.3em; font-size: 0.85rem; color: var(--text-secondary); margin: 0.2rem 0 0; }
figure.chart details { margin-top: 0.4rem; font-size: 0.85rem; }
figure.chart details table { margin-top: 0.4rem; }

/* lexicon highlights: one hue per tag, always with a title naming tag and term */
mark.hl { color: inherit; border-radius: 3px; padding: 0 0.12em; border-bottom: 2px solid var(--hl, var(--mark));
  background: color-mix(in srgb, var(--hl, var(--mark)) 22%, transparent); }
.hl-crisis { --hl: var(--series-2); }
.hl-resignation { --hl: var(--series-1); }
.hl-no_confidence { --hl: var(--series-4); }
.hl-key_vote { --hl: var(--series-3); }
.hl-support_refused { --hl: var(--critical); }
.hl-support_gained { --hl: var(--good); }
.hl-negotiating { --hl: var(--text-muted); }
.hl-demands_unmet { --hl: var(--series-4); }
.hl-private_life { --hl: var(--critical); }
.tag[class*="hl-"] { border-color: var(--hl, var(--border)); }
.legend mark { font-size: 0.8rem; }

/* rules page */
.terms td.w { width: 45%; }
svg.barsvg { display: block; width: 100%; height: 0.6rem; overflow: visible; }
svg.barsvg rect { fill: var(--hl, var(--accent)); }
svg.barsvg.neg rect { fill: var(--text-muted); }
svg.barsvg.score { height: 0.8rem; background: var(--grid); border-radius: 2px; }
svg.barsvg .thr { stroke: var(--text-primary); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
p.tried { font-size: 1.05rem; margin: 0.8rem 0; }
.alone { color: var(--good); font-weight: 600; }
.try textarea, .try input { width: 100%; }
.score-row { display: grid; grid-template-columns: 9rem 1fr 4rem; gap: 0.6rem; align-items: center; }
.assigned { font-weight: 700; }

/* plenary schedule */
table.plenary td.time { white-space: nowrap; width: 7.5rem; font-variant-numeric: tabular-nums; }
table.plenary td.kind { width: 15rem; color: var(--text-secondary); }
table.plenary tr.vote td { background: color-mix(in srgb, var(--series-3) 14%, transparent); }
table.plenary tr.vote td.kind { color: var(--text-primary); font-weight: 600; }
table.plenary tr.done td { opacity: 0.6; }
table.plenary tr.now td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.nowtag { color: var(--accent); }

/* party stances */
.stance { font-size: 0.78rem; font-weight: 600; border-radius: 99px; padding: 0 0.5rem; border: 1px solid var(--border); white-space: nowrap; }
.stance.stance_for { color: var(--good); border-color: var(--good); }
.stance.stance_against { color: var(--critical); border-color: var(--critical); }
.stance.stance_open { color: var(--text-secondary); }
.rule-text { font: 0.82rem ui-monospace, SFMono-Regular, Consolas, monospace; }

/* rules: processing flow */
ol.flow { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
@media (min-width: 800px) { ol.flow { grid-template-columns: repeat(4, 1fr); } }
.flow-step { position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; background: var(--surface-0); font-size: 0.85rem; display: grid; gap: 0.2rem; }
.flow-step span { color: var(--text-secondary); }
.flow-step.stop { border-color: var(--critical); }
@media (min-width: 800px) {
  .flow-step:not(:last-child)::after { content: "→"; position: absolute; right: -0.55rem; top: 50%; transform: translate(50%, -50%); color: var(--text-muted); }
}

/* rules: trees (top-down, connector lines from borders) */
.rule-grid { display: grid; gap: 1rem; }
@media (min-width: 1000px) { .rule-grid { grid-template-columns: 1fr 1fr; } }
.rule-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem; min-width: 0; }
.rule-card h3 { margin: 0 0 0.2rem; color: var(--text-primary); font-size: 0.95rem; }
.rule-no { display: inline-block; min-width: 1.5rem; text-align: center; border-radius: 99px; background: var(--surface-0); border: 1px solid var(--border); font-size: 0.75rem; margin-right: 0.3rem; }
.rule-body { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; margin: 0.4rem 0; }
.rule-body > .scroll { flex: 1 1 auto; min-width: 0; }
.then { display: flex; align-items: center; gap: 0.4rem; }
.then-arrow { color: var(--text-muted); font-size: 1.2rem; }

ul.tree, ul.tree ul { list-style: none; margin: 0; padding: 0; }
ul.tree { display: flex; justify-content: center; padding: 0.2rem 0; }
ul.tree ul { display: flex; justify-content: center; padding-top: 14px; position: relative; }
ul.tree li { position: relative; text-align: center; padding: 14px 4px 0; }
ul.tree > li { padding-top: 0; }
ul.tree li::before, ul.tree li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 14px; border-top: 2px solid var(--border); }
ul.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--border); }
ul.tree li:only-child::before, ul.tree li:only-child::after, ul.tree > li::before, ul.tree > li::after { display: none; }
ul.tree li:only-child { padding-top: 0; }
ul.tree li:first-child::before, ul.tree li:last-child::after { border: 0 none; }
ul.tree li:last-child::before { border-right: 2px solid var(--border); border-radius: 0 6px 0 0; }
ul.tree li:first-child::after { border-radius: 6px 0 0 0; }
ul.tree ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 14px; border-left: 2px solid var(--border); }
ul.tree li:only-child > ul::before { height: 14px; }

.node { display: inline-block; border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.5rem; font-size: 0.78rem; line-height: 1.3; background: var(--surface-1); color: var(--text-primary); white-space: nowrap; }
.node small { display: block; color: var(--text-muted); font-size: 0.7rem; }
.node.op { font-weight: 700; border-radius: 99px; padding: 0.15rem 0.6rem; }
.node.op-AND { border-color: var(--series-1); color: var(--series-1); }
.node.op-OR { border-color: var(--series-2); color: var(--series-2); }
.node.op-NOT { border-color: var(--critical); color: var(--critical); }
.node.leaf-party { border-style: dashed; }
.node.leaf-tag { background: var(--surface-0); }
.node.anchor { border-width: 2px; border-color: var(--text-primary); }
.node small.anchor-tag { color: var(--text-primary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.62rem; }
.then-node { border-color: var(--good); text-align: left; white-space: normal; max-width: 15rem; }

/* server-side SVG charts */
.kpis .big { font-size: 2.2rem; }
figure.svgchart { margin: 0; }
figure.svgchart svg { width: 100%; height: auto; display: block; overflow: visible; }
figure.svgchart.parties { max-width: 520px; }
.svgchart .grid { stroke: var(--grid); stroke-width: 1; }
.svgchart .tick, .svgchart .xlabel, .svgchart .val { fill: var(--text-secondary); font: 11px system-ui, sans-serif; }
.svgchart .total { fill: var(--text-primary); font: 600 11px system-ui, sans-serif; }
.svgchart .hit { fill: transparent; }
.svgchart g.bar:hover .hit { fill: var(--grid); }
.svgchart .mid, svg.pbar .mid { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.svgchart .track, svg.pbar .track { fill: var(--grid); }
.pb-for { fill: var(--series-1); background: var(--series-1); }
.pb-toss { fill: var(--mark); background: var(--mark); }
.pb-against { fill: var(--series-2); background: var(--series-2); }
.pb-hit { fill: var(--series-3); background: var(--series-3); }
.pb-miss { fill: var(--series-2); background: var(--series-2); }
.dot circle { stroke: var(--surface-1); stroke-width: 2; }
.dot circle.hit { fill: transparent; stroke: none; }
.dot-ok circle:not(.hit) { fill: var(--series-1); }
.dot-loss circle:not(.hit) { fill: var(--critical); stroke: var(--critical); stroke-width: 3; }
.dot-unknown circle:not(.hit) { fill: var(--mark); }
.dot-ok.swatch { background: var(--series-1); }
.dot-loss.swatch { background: var(--critical); }
.dot-unknown.swatch { background: var(--mark); }
.legend .key { display: inline-flex; align-items: center; gap: 0.35rem; margin-right: 0.8rem; }
.swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; }
.axis-note { text-align: center; margin: 0; }
td.pcell { white-space: nowrap; min-width: 9rem; }
svg.pbar { width: 5.5rem; height: 0.7rem; vertical-align: middle; }
.pval { font-size: 0.8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* evaluated trees (Explain) */
.node.held { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--surface-1)); }
.node.failed { border-color: var(--critical); border-style: dashed; color: var(--text-secondary); background: var(--surface-1); }
.node.op.held { color: var(--good); }
.node.op.failed { color: var(--critical); }
.res-mark { font-weight: 700; }
.node.held .res-mark { color: var(--good); }
.node.failed .res-mark { color: var(--critical); }
.node small.found { color: var(--text-primary); font-style: italic; }
.rule-card.trace.fired { border-color: var(--good); }
.trace.evaluated .node:not(.held):not(.failed):not(.then-node), .node.unchecked { opacity: 0.55; border-style: dotted; }
