.viz-root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --grid: #e4e3df;
  --border: #dddcd7;
  /* rayons : rampe ordinale bleue (proche = foncé) ; témoin : slot 2 orange */
  --r500: #184f95;
  --r1000: #2a78d6;
  --r1500: #86b6ef;
  --temoin: #eb6834;
  /* divergent bleu <-> rouge, milieu gris */
  --div-neg2: #c23a3a; --div-neg1: #ec9a96; --div-mid: #d6d5d0; --div-pos1: #86b6ef; --div-pos2: #1c5cab;
  --nodata: #ffffff;
}
@media (prefers-color-scheme: dark) {
  .viz-root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --grid: #2e2e2b;
    --border: #383835;
    --r500: #cde2fb;
    --r1000: #5598e7;
    --r1500: #256abf;
    --temoin: #d95926;
    --div-neg2: #e66767; --div-neg1: #9c4a48; --div-mid: #55554f; --div-pos1: #256abf; --div-pos2: #86b6ef;
    --nodata: #1a1a19;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--surface-0); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.viz-root { color: var(--text-primary); background: var(--surface-0); min-height: 100vh; padding: 16px 20px 32px; max-width: 1400px; margin: 0 auto; }
header h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.tagline { margin: 2px 0 12px; color: var(--text-secondary); }
h2 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.filters { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.filters .label { color: var(--text-secondary); font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; background: transparent; color: var(--text-secondary); padding: 6px 14px; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); }

main { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(340px, 1fr); gap: 16px; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
.map-wrap { position: relative; align-self: start; }
#map { height: 640px; border-radius: 10px; border: 1px solid var(--border); }
@media (max-width: 900px) { #map { height: 420px; } }
.map-legend { position: absolute; left: 10px; bottom: 10px; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.map-legend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid var(--text-muted); flex: none; }

.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.methodo { margin-top: 16px; }
.methodo ul { margin: 0; padding-left: 18px; color: var(--text-secondary); }
footer { margin-top: 12px; }

#classement { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
#classement li { display: grid; grid-template-columns: 1fr 80px 52px; gap: 8px; align-items: center; padding: 5px 4px; border-radius: 6px; cursor: pointer; font-size: 14px; }
#classement li:hover, #classement li.sel { background: var(--surface-0); }
#classement .bar { height: 8px; position: relative; }
#classement .bar span { position: absolute; top: 0; height: 8px; border-radius: 4px; }
#classement .bar::before { content: ""; position: absolute; left: 50%; top: -3px; height: 14px; border-left: 1px solid var(--text-muted); }
#classement .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

.fiche-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.fiche-head h2 { font-size: 20px; margin: 0; }
.badges { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.badge { font-size: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; color: var(--text-secondary); }
.close { background: none; border: 0; font-size: 20px; color: var(--text-muted); cursor: pointer; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.kpi .k { font-size: 12px; color: var(--text-muted); }
.kpi .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--text-secondary); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-secondary); margin: 4px 0; }
.chart-legend .sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-muted); font-size: 11px; }
.chart .lbl { fill: var(--text-secondary); font-size: 11px; }
.chart .grid line { stroke: var(--grid); }
.toggle { background: none; border: 0; padding: 0; color: var(--text-secondary); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 8px; }
th, td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; }
.note { font-size: 13px; color: var(--text-secondary); margin: 8px 0 0; }

.tooltip { position: fixed; pointer-events: none; z-index: 10; background: #1a1a19; color: #f0efec; border-radius: 6px; padding: 6px 8px; font-size: 12px; line-height: 1.4; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.tooltip .row { display: flex; align-items: center; gap: 6px; }
.tooltip .sw { width: 10px; height: 2px; display: inline-block; }
