:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efede6; --ink: #1d2126; --ink-2: #555b63; --line: #dcd9cf;
  --accent: #1f5f8b; --accent-ink: #ffffff; --pos: #2f7d4f; --neg: #b6452c; --warn: #9a6a00;
  --s1: #1f5f8b; --s2: #c2702c; --s3: #4f8f5c; --s4: #8a5aa8; --s5: #b6452c;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --surface: #1d2126; --surface-2: #262b31; --ink: #e8e6e1; --ink-2: #a3a8ae; --line: #343a41;
    --accent: #6aa7d6; --accent-ink: #0d1b26; --pos: #6cc18f; --neg: #e8846b; --warn: #e0b04a;
    --s1: #6aa7d6; --s2: #e39a5c; --s3: #7cc08a; --s4: #b893d4; --s5: #e8846b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --surface: #1d2126; --surface-2: #262b31; --ink: #e8e6e1; --ink-2: #a3a8ae; --line: #343a41;
  --accent: #6aa7d6; --accent-ink: #0d1b26; --pos: #6cc18f; --neg: #e8846b; --warn: #e0b04a;
  --s1: #6aa7d6; --s2: #e39a5c; --s3: #7cc08a; --s4: #b893d4; --s5: #e8846b; --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; margin-top: 1.4em; }

.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.sub { margin: 0; color: var(--ink-2); font-size: .9rem; max-width: 60ch; }
.version { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.version button { border: 0; background: none; color: var(--ink); padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.version button small { display: block; font-weight: 400; color: var(--ink-2); font-size: .75rem; }
.version button.on { background: var(--accent); color: var(--accent-ink); }
.version button.on small { color: inherit; opacity: .85; }

.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; color: var(--ink-2); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab { display: none; } .tab.on { display: block; }

main { padding: 16px 20px 40px; }
.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.presets h2 { font-size: .95rem; }
.preset-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: 999px; padding: 5px 10px; font: inherit; font-size: .82rem; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

details.group { border-top: 1px solid var(--line); padding: 8px 0; }
details.group > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; color: var(--ink-2); font-weight: 400; }
details.group[open] > summary::after { content: "−"; }
details.group > summary .badge { font-size: .72rem; font-weight: 600; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 1px 7px; margin-left: 6px; }
.grp-help { color: var(--ink-2); font-size: .82rem; margin: 2px 0 6px; }
.sub-h { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin: 12px 0 2px; }

.ctl { padding: 6px 0; }
.ctl.disabled { opacity: .45; }
.ctl label { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; }
.ctl label output { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: .85rem; color: var(--ink); white-space: nowrap; }
.ctl label output.nz { color: var(--accent); font-weight: 600; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
.ctl select { width: 100%; font: inherit; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); margin-top: 4px; }
.ctl .help { font-size: .76rem; color: var(--ink-2); margin: 1px 0 0; }
.panel-foot { display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.btn { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn.ghost { background: none; color: var(--accent); }

.year-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 12px; }
.year-bar input { flex: 1 1 200px; accent-color: var(--accent); }
.status { color: var(--ink-2); font-size: .8rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.kpi .k { font-size: .78rem; color: var(--ink-2); }
.kpi .v { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.kpi .v.pos { color: var(--pos); } .kpi .v.neg { color: var(--neg); }
.kpi .d { font-size: .78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.note { color: var(--ink-2); font-size: .82rem; margin: 10px 0 14px; max-width: 90ch; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 6px; box-shadow: var(--shadow); }
.chart h3 { font-size: .9rem; margin: 0 0 2px; }
.chart .unit { font-size: .75rem; color: var(--ink-2); margin: 0 0 6px; }
.chart .cv { position: relative; height: 190px; }
.table-wrap { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.table-wrap summary { cursor: pointer; font-weight: 600; }
.scroll { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; min-width: 100%; }
th, td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
thead th { color: var(--ink-2); font-weight: 600; }

.prose { max-width: 820px; }
.prose p, .prose li { color: var(--ink); }
.prose code, .prose pre { font-family: var(--mono); font-size: .82rem; }
.prose pre { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; line-height: 1.45; }
.prose table { margin: 8px 0 14px; min-width: 0; }
.prose th, .prose td { text-align: left; }
.prose th:first-child, .prose td:first-child { position: static; }
#eq-out h2 { margin-top: 1.6em; }

.valid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 12px; margin-top: 12px; }
.vcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.vcard h3 { margin: 0 0 6px; font-size: .92rem; }
.vcard td.ref { color: var(--ink-2); }
.vcard td.bad { color: var(--neg); }
.legend-v { font-size: .8rem; color: var(--ink-2); }

.foot { color: var(--ink-2); font-size: .78rem; padding: 0 20px 24px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .top, main, .tabs, .foot { padding-left: 16px; padding-right: 16px; }
  .charts, .valid-grid { grid-template-columns: 1fr; }
}

/* ---------- onglet Présidentielle 2027 ---------- */
.gp-intro { max-width: 860px; }
.gp-intro p { color: var(--ink-2); margin: 0 0 12px; }
.cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 6px 0 14px; }
.cand { text-align: left; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: 8px; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.cand:hover { border-color: var(--c); }
.cand.on { box-shadow: 0 0 0 2px var(--c) inset; background: var(--surface-2); }
.cand .cn { font-weight: 650; font-size: .92rem; }
.cand .cp { font-size: .78rem; color: var(--ink-2); }
.cand .cs { font-size: .7rem; color: var(--ink-2); opacity: .85; }
.gp-year { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 4px 0 12px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.gp-year input { flex: 1 1 220px; accent-color: var(--accent); }
.gp-year .hint { color: var(--ink-2); font-size: .8rem; }
.prog-card { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.prog-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.prog-head h3 { margin: 0; font-size: 1.1rem; }
.prog-head span { color: var(--ink-2); font-size: .85rem; }
.prog-card p { margin: 6px 0; }
.prog-card details summary { cursor: pointer; font-weight: 600; font-size: .9rem; margin: 6px 0; }
.mes { margin: 4px 0 8px; padding-left: 20px; font-size: .88rem; }
.mes li { margin: 3px 0; }
.mes .src { font-size: .76rem; }
.mes .conf { font-size: .7rem; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; white-space: nowrap; }
.chif { font-size: .85rem; color: var(--ink-2); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.pill { font-size: .78rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }
.gp-h { margin: 22px 0 8px; font-size: 1rem; }
.kpi .d .pos, td.pos { color: var(--pos); font-weight: 600; }
.kpi .d .neg, td.neg { color: var(--neg); font-weight: 600; }
.gp-ir, .gp-comp { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.gp-comp th { white-space: nowrap; font-size: .78rem; }
.gp-comp .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.gp-comp td.sel, .gp-comp th.sel { background: var(--surface-2); font-weight: 650; }
.gp-comp td.best { color: var(--pos); }
.gp-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--ink-2); margin: 8px 0 0; }
.gp-legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; }
.gp-sources ul { font-size: .85rem; color: var(--ink-2); padding-left: 20px; }
#gp-charts .cv { height: 210px; }
.caveat { font-size: .85rem; color: var(--ink) !important; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 8px; padding: 8px 12px; }
:root { --bg-mieux: #dcefe2; --bg-moins: #f6dcd5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg-mieux: #1e3a29; --bg-moins: #47241c; } }
:root[data-theme="dark"] { --bg-mieux: #1e3a29; --bg-moins: #47241c; }
.gp-comp td.mieux { background: var(--bg-mieux); }
.gp-comp td.moins { background: var(--bg-moins); }
.gp-comp td.sel.mieux, .gp-comp td.sel.moins { box-shadow: inset 2px 0 0 var(--ink-2), inset -2px 0 0 var(--ink-2); }
.gp-legend i.lg { width: 14px; height: 10px; border-radius: 2px; border: 1px solid var(--line); }
.gp-legend i.mieux { background: var(--bg-mieux); } .gp-legend i.moins { background: var(--bg-moins); }
.gp-year .opt { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; white-space: nowrap; }
.gp-year .opt input[type=checkbox] { flex: none; margin: 0; accent-color: var(--accent); }
.gp-year select { font: inherit; padding: 2px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.back { margin: 0 0 4px; font-size: .85rem; }
.mode { font-size: .75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; vertical-align: middle; color: var(--ink-2); }
.retr { font-size: .88rem; }
