[hidden] { display: none !important; }
:root {
  color-scheme: dark;
  --bg: #0f1012;
  --surface-1: #191919;
  --surface-2: #212224;
  --border: #2c2d30;
  --grid: #2a2a2a;
  --text-primary: #efefef;
  --text-secondary: #9c9c9c;
  --accent: #338ced;
  --series-bas: #338ced;
  --series-central: #e76624;
  --series-haut: #00a888;
  --warning: #d28e05;
  --critical: #eb6263;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login p { color: var(--text-secondary); margin: 0 0 20px; }
.login label { display: block; color: var(--text-secondary); font-size: 12px; margin-bottom: 6px; }
.login input { width: 100%; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button { width: 100%; margin-top: 14px; }
.error { color: var(--critical); font-size: 13px; margin-top: 10px; }

/* Shell */
header.top { position: sticky; top: 0; z-index: 5; background: rgba(15,16,18,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 650; font-size: 15px; margin-right: auto; }
.brand small { display: block; font-weight: 400; color: var(--text-secondary); font-size: 12px; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; display: grid; gap: 16px; }

.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; color: var(--text-secondary); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 550; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-primary); font-weight: 450; }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h2 { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.card .sub { color: var(--text-secondary); font-size: 12px; margin: 0 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.banner { border: 1px solid var(--warning); background: rgba(210,142,5,.08); border-radius: var(--radius); padding: 12px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner strong { color: var(--text-primary); }
.banner span { color: var(--text-secondary); flex: 1 1 260px; }

/* Region cards */
.region .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.hero { font-size: 30px; font-weight: 650; letter-spacing: -.01em; }
.hero-unit { color: var(--text-secondary); font-size: 13px; margin-left: 4px; font-weight: 400; }
.delta { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.kpi dt { color: var(--text-secondary); font-size: 12px; }
.kpi dd { margin: 0; font-weight: 600; }

.chart-box { position: relative; height: 280px; }
.chart-box.short { height: 230px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }

/* Import */
.import-form { display: grid; gap: 12px; grid-template-columns: 2fr 1fr auto; align-items: end; }
@media (max-width: 700px) { .import-form { grid-template-columns: 1fr; } }
.field label { display: block; color: var(--text-secondary); font-size: 12px; margin-bottom: 4px; }
.field input[type=text], .field input[type=file] { width: 100%; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text-secondary); font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 12px; color: var(--text-secondary); }
.muted { color: var(--text-secondary); }
.empty { text-align: center; padding: 40px 16px; }
.empty h2 { font-size: 18px; }
footer { color: var(--text-secondary); font-size: 12px; text-align: center; padding: 0 16px 30px; }
[data-mt] { margin-top: 12px; }

/* Section heading between blocks */
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin: 12px 0 -4px; }

/* Benchmarks */
tr.total td { font-weight: 600; border-top: 1px solid var(--border); }
.ibar { display: inline-block; width: 90px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; vertical-align: middle; }
.ibar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Map */
.map-card { padding-bottom: 12px; }
.map-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
.pills button { border: 1px solid var(--border); background: transparent; color: var(--text-secondary); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; transition: all .15s; }
.pills button:hover { color: var(--text-primary); border-color: #3d3e42; }
.pills button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.map-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; }
@media (max-width: 900px) { .map-body { grid-template-columns: 1fr; } }
.map-wrap { position: relative; border-radius: 10px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1b2230 0%, #141519 70%); border: 1px solid var(--border); }
#map-svg { display: block; width: 100%; height: auto; aspect-ratio: 960 / 620; }
.map-outline { fill: none; stroke: rgba(51,140,237,.18); stroke-linejoin: round; }
.commune { stroke: #0f1012; stroke-linejoin: round; cursor: pointer; transition: fill .35s ease, opacity .25s; outline: none; }
.commune.out { cursor: default; }
.commune.hover, .commune:focus-visible { stroke: #fff; stroke-width: 1.4px; filter: url(#glow); }
.commune.pinned { stroke: #fff; stroke-width: 1.8px; }
.map-lake { fill: #0b1a2c; stroke: #1d3550; stroke-width: .5; pointer-events: none; }
.map-districts { fill: none; stroke: rgba(239,239,239,.35); stroke-dasharray: 3 2; pointer-events: none; }
.map-labels text { fill: var(--text-primary); paint-order: stroke; stroke: rgba(15,16,18,.85); text-anchor: middle; dominant-baseline: middle; font-weight: 600; pointer-events: none; }
.map-tip { position: absolute; left: 0; top: 0; z-index: 3; min-width: 220px; max-width: 280px; background: rgba(30,31,34,.96); border: 1px solid #3a3b3e;
  border-radius: 10px; padding: 10px 12px; pointer-events: none; box-shadow: 0 8px 30px rgba(0,0,0,.45); font-size: 12px; }
.tip-head { display: flex; flex-direction: column; margin-bottom: 6px; }
.tip-head strong { font-size: 14px; }
.map-tip table td, .map-detail table td { padding: 3px 0; border: 0; white-space: nowrap; }
.map-tip table td.r, .map-detail table td.r { padding-left: 12px; }
.map-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.legend-scale { display: flex; gap: 2px; }
.legend-step { flex: 1; height: 10px; border-radius: 2px; }
.legend-scale .legend-step:first-child { border-radius: 4px 2px 2px 4px; }
.legend-scale .legend-step:last-child { border-radius: 2px 4px 4px 2px; }
.legend-ends { display: flex; justify-content: space-between; color: var(--text-secondary); font-size: 12px; margin-top: 4px; }
.map-detail { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 12px; }
.map-detail p { margin: 0; }
.rank h3 { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin: 0 0 6px; }
.rank ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rank li { display: grid; grid-template-columns: 1fr 70px auto; gap: 8px; align-items: center; font-size: 12px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.rank li:hover { background: var(--surface-2); }
.rk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.rk-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.rk-val { color: var(--text-secondary); text-align: right; }

/* Capture */
.cap-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cap-actions select, #cap-table select, .add-form select, .add-form input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
.bm-link { display: inline-block; padding: 9px 14px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--accent); color: var(--text-primary); text-decoration: none; font-weight: 600; cursor: grab; }
.steps { margin: 8px 0 0; padding-left: 18px; color: var(--text-secondary); font-size: 13px; }
.steps li { margin: 4px 0; }
.add-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; align-items: end; margin-top: 8px; }
.add-form .field input, .add-form .field select { width: 100%; }

.cap-thumb, .row-thumb { width: 64px; height: 44px; object-fit: cover; border-radius: 4px; vertical-align: middle; background: var(--surface-2); }
.row-thumb { width: 72px; height: 48px; display: block; }
.addr { color: var(--text-secondary); font-size: 12px; }
.was { color: var(--text-secondary); text-decoration: line-through; font-size: 12px; margin-right: 4px; }
.tag.cut { background: rgba(0, 168, 136, .15); color: #4fd1b5; }

.communes-title { font-size: 14px; font-weight: 600; margin: 20px 0 2px; }
.communes-wrap { max-height: 520px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.communes-table { width: 100%; font-size: 12px; }
.communes-table thead th { position: sticky; top: 0; background: var(--surface-1); z-index: 1; white-space: nowrap; }
.communes-table th.sortable { cursor: pointer; user-select: none; }
.communes-table th.sortable:hover { color: var(--text-primary); }
.communes-table tbody tr { cursor: pointer; }
.communes-table tbody tr:hover, .communes-table tbody tr.pinned { background: var(--surface-2); }
.communes-table td { white-space: nowrap; }

.commune-pick { display: flex; align-items: center; gap: 8px; margin: 8px 0 10px; font-size: 13px; color: var(--text-secondary); }
.commune-pick select { min-width: 240px; max-width: 100%; padding: 7px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); }

/* Explorer: Valais > region > commune */
.explore { margin-bottom: 16px; }
.ex-trail { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.ex-trail a { color: var(--accent); text-decoration: none; cursor: pointer; }
.ex-trail span.sep { margin: 0 6px; }
.ex-nav { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.ex-nav .commune-pick { margin: 0; }
.ex-title { font-size: 22px !important; margin: 14px 0 2px !important; }
.ex-segs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 8px; }
@media (max-width: 760px) { .ex-segs, .ex-grid { grid-template-columns: 1fr !important; } }
.ex-seg { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.ex-seg h3 { margin: 0 0 6px; font-size: 13px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.ex-seg .big { font-size: 28px; font-weight: 650; }
.ex-seg .big small { font-size: 13px; font-weight: 450; color: var(--text-secondary); margin-left: 6px; }
.ex-seg .range { color: var(--text-secondary); font-size: 12px; margin-bottom: 10px; }
.ex-seg dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0; }
.ex-seg dt { font-size: 11px; color: var(--text-secondary); }
.ex-seg dd { margin: 2px 0 0; font-weight: 600; }
.ex-seg .n { font-size: 11px; color: var(--text-secondary); margin-top: 10px; }
.ex-bench { margin: 12px 0 0; font-size: 13px; }
.ex-bench .bm { display: inline-block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0 8px 8px 0; }
.ex-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.ex-panel h3 { font-size: 14px; margin: 0 0 8px; }
.ex-chart { height: 260px; }
.ex-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ex-table th, .ex-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.ex-table th { color: var(--text-secondary); font-weight: 500; font-size: 12px; }
.ex-table .r { text-align: right; font-variant-numeric: tabular-nums; }
.ex-table tr.go { cursor: pointer; }
.ex-table tr.go:hover td { background: var(--surface-2); }
.ex-table tr.go td:first-child { color: var(--accent); }
.ex-table .thin { color: var(--text-secondary); }
.ex-sources { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.ex-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
@media (max-width: 760px) { .ex-detail-grid { grid-template-columns: 1fr; } }
.ex-ctx { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ex-ctx div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.ex-ctx dt { font-size: 11px; color: var(--text-secondary); }
.ex-ctx dd { margin: 2px 0 0; font-weight: 600; }
.ex-wide { grid-column: 1 / -1; }
