/* Circoscopie — feuille de style */
:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #fcfdfb;
  --surface-2: #eef1ea;
  --ink: #1f2421;
  --ink-2: #565b55;
  --muted: #8a8f87;
  --hairline: #dde1d7;
  --accent: #0c5c3d;
  --accent-ink: #0a4a32;
  --accent-soft: #e3ede6;
  --mark-circo: #008300;
  --mark-dep: #6f756d;
  --mark-reg: #a9aea5;
  --mark-fr: #1f2421;
  --pyr-f: #eb6834;
  --pyr-m: #2a78d6;
  --pyr-fr: #52514e;
  --warn-bg: #fdf6e3;
  --focus: #2a78d6;
  --radius: 10px;
  --radius-s: 6px;
  --shadow: 0 1px 2px rgba(31, 36, 33, 0.06), 0 4px 14px rgba(31, 36, 33, 0.05);
  --shadow-hover: 0 2px 4px rgba(31, 36, 33, 0.07), 0 10px 26px rgba(31, 36, 33, 0.10);
  --ff-display: "Montserrat", "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
  --ff-text: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #131613;
    --surface: #1b1f1b;
    --surface-2: #232823;
    --ink: #edefe9;
    --ink-2: #b9bdb4;
    --muted: #878c84;
    --hairline: #2e332d;
    --accent: #58b388;
    --accent-ink: #79c9a2;
    --accent-soft: #1f2e26;
    --mark-circo: #0ca30c;
    --mark-dep: #9aa096;
    --mark-reg: #5c615a;
    --mark-fr: #edefe9;
    --pyr-f: #d95926;
    --pyr-m: #3987e5;
    --pyr-fr: #c3c2b7;
    --warn-bg: #2c2a1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ff-text);
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

/* ---------- boutons (système) ---------- */
.btn {
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 14px; line-height: 1;
  padding: 10px 16px; border-radius: var(--radius-s);
  border: 1.5px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); text-decoration: none; }
.btn-secondary { border-color: var(--hairline); color: var(--accent-ink); background: var(--surface); }
.btn-secondary:hover { border-color: var(--accent); text-decoration: none; }
.btn-ghost { color: var(--accent-ink); padding: 10px 8px; }
.btn-ghost:hover { background: var(--accent-soft); text-decoration: none; }
.btn:active { transform: scale(0.98); }

/* ---------- en-tête ---------- */
header.site {
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}
header.site .wrap {
  display: flex; align-items: baseline; gap: 14px;
  padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap;
}
.brand {
  font-family: var(--ff-display);
  font-weight: 800; font-size: 24px; letter-spacing: -0.02em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; color: var(--accent-ink); }
.tagline { color: var(--ink-2); font-size: 13.5px; }

/* ---------- accueil ---------- */
.home-grid {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.9fr);
  gap: 48px; align-items: start; padding: 56px 0 72px;
}
.home-intro h1 {
  font-family: var(--ff-display);
  font-size: clamp(32px, 4.2vw, 48px);
  line-height: 1.08; letter-spacing: -0.025em; font-weight: 800;
  margin: 0 0 16px;
}
.home-intro p.lede { font-size: 17px; color: var(--ink-2); margin: 0 0 28px; max-width: 46ch; }

.searchbox { position: relative; margin-bottom: 14px; }
.searchbox input {
  width: 100%; padding: 13px 16px 13px 44px;
  font: inherit; font-size: 16px;
  border: 1.5px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.searchbox input:focus { border-color: var(--accent); outline: none; }
.searchbox .ico {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search-results {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 420px; overflow: auto; padding: 6px;
}
.search-results[hidden] { display: none; }
.sr-item {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  text-align: left; padding: 9px 10px; border-radius: var(--radius-s);
}
.sr-item { transition: background 0.12s ease; }
.sr-item:hover, .sr-item.sel { background: var(--accent-soft); }
.sr-item .n { font-weight: 600; }
.sr-item .d { color: var(--ink-2); font-size: 13px; }
.sr-item .c { margin-left: auto; color: var(--accent-ink); font-size: 13px; white-space: nowrap; }
.sr-head { padding: 8px 10px 2px; font-size: 12.5px; color: var(--muted); }
.sr-empty { padding: 12px; color: var(--ink-2); }
.search-hint { font-size: 13px; color: var(--muted); }

/* carte de France */
.map-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.map-card h2 { font-family: var(--ff-display); font-size: 20px; margin: 0 0 4px; font-weight: 700; }
.map-card .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }
svg.fr-map { width: 100%; height: auto; display: block; }
.fr-map path.dept {
  fill: var(--surface-2); stroke: var(--bg); stroke-width: 1.2;
  cursor: pointer; transition: fill 0.12s;
}
.fr-map path.dept:hover, .fr-map path.dept:focus-visible { fill: var(--accent); }
.insets { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; align-items: flex-end; }
.inset { text-align: center; }
.inset svg { display: block; margin: 0 auto; }
.inset .lbl { font-size: 11px; color: var(--ink-2); margin-top: 2px; }
.inset path { fill: var(--surface-2); stroke: var(--bg); stroke-width: 1; cursor: pointer; }
.inset:hover path, .inset path:focus-visible { fill: var(--accent); }
.com-links { margin-top: 12px; font-size: 13px; color: var(--ink-2); line-height: 1.8; }
.com-links a { margin-right: 10px; white-space: nowrap; }

.map-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--ink); color: var(--bg);
  padding: 5px 10px; border-radius: 6px; font-size: 13px; font-weight: 600;
  transform: translate(-50%, calc(-100% - 10px));
}
.map-tip[hidden] { display: none; }

/* ---------- fil d'ariane + vues ---------- */
.crumbs { padding: 26px 0 0; font-size: 14px; color: var(--ink-2); }
.crumbs a { color: var(--ink-2); }
.crumbs a:hover { color: var(--accent-ink); }
.crumbs .sep { margin: 0 7px; color: var(--muted); }
.crumbs .cur { color: var(--ink); font-weight: 600; }

/* vue département */
.dep-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 44px; padding: 28px 0 64px; align-items: start; }
.dep-grid h1, .circo-head h1 {
  font-family: var(--ff-display); font-weight: 800; letter-spacing: -0.02em;
  font-size: clamp(28px, 3.4vw, 40px); margin: 8px 0 2px; line-height: 1.1;
}
.dep-reg { color: var(--ink-2); margin: 0 0 18px; }
svg.dep-map { width: 100%; height: auto; }
.dep-map path.circo {
  fill: var(--surface-2); stroke: var(--bg); stroke-width: 2; cursor: pointer;
  transition: fill 0.12s;
}
.dep-map path.circo:hover, .dep-map path.circo:focus-visible, .dep-map path.circo.hl { fill: var(--accent); }
.dep-map path.circo { stroke: var(--mark-reg); stroke-width: 2.5; }
.dep-map text.circo-num {
  fill: var(--ink-2); font-family: var(--ff-display); font-weight: 800;
  pointer-events: none; paint-order: stroke; stroke: var(--surface); stroke-width: 4px;
}
.circo-list { display: flex; flex-direction: column; gap: 10px; }
.circo-item {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 15px 18px; box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.circo-item:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.circo-item .num {
  font-family: var(--ff-display); font-weight: 800; font-size: 19px;
  color: var(--accent-ink); min-width: 34px;
}
.circo-item .nm { font-weight: 600; }
.circo-item .meta { color: var(--ink-2); font-size: 13px; }
.circo-item .go { margin-left: auto; color: var(--muted); }

/* ---------- vue circonscription ---------- */
.circo-head { padding: 4px 0 0; }
.circo-head .where { color: var(--ink-2); margin: 2px 0 0; }
.syn { margin: 20px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.syn-chip {
  background: var(--accent-soft); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; font-size: 14px; font-weight: 600; cursor: default;
}
.syn-note { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 28px 0 8px; }
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  transition: box-shadow 0.18s ease;
}
.tile:hover { box-shadow: var(--shadow-hover); }
.tile .lbl { font-size: 12.5px; color: var(--ink-2); line-height: 1.3; }
.tile .val { font-family: var(--ff-display); font-weight: 800; font-size: 28px; margin-top: 4px; letter-spacing: -0.01em; }
.tile .cmp { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* onglets */
.tabs {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); border-bottom: 1px solid var(--hairline);
  margin-top: 28px;
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 13px 16px 11px; font-size: 15px; font-weight: 600; color: var(--ink-2);
  border-bottom: 2.5px solid transparent; white-space: nowrap;
  transition: color 0.15s ease, border-color 0.2s ease;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }

.panel { padding: 32px 0 72px; }
.panel[hidden] { display: none; }

/* sections d'indicateurs */
.sect {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 24px 18px; margin-bottom: 20px;
  animation: rise 0.35s ease both;
}
.panel .sect:nth-child(2) { animation-delay: 0.05s; }
.panel .sect:nth-child(3) { animation-delay: 0.1s; }
.panel .sect:nth-child(4) { animation-delay: 0.15s; }
.panel .sect:nth-child(n+5) { animation-delay: 0.2s; }
.sect-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.sect-head h3 { font-family: var(--ff-display); font-size: 20px; font-weight: 700; margin: 0; }
.sect-head .note { font-size: 12.5px; color: var(--muted); }
.sect-head .tgl {
  margin-left: auto; font-size: 12.5px; color: var(--accent-ink);
  padding: 3px 10px; border: 1px solid var(--hairline); border-radius: 999px;
}
.sect-head .tgl { transition: border-color 0.15s ease, background 0.15s ease; }
.sect-head .tgl:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ligne indicateur : libellé | barre | valeur | rang */
.rows { display: grid; grid-template-columns: minmax(150px, 230px) 1fr 76px 70px; align-items: center; column-gap: 14px; }
.rows.rows-2 { grid-template-columns: minmax(150px, 260px) 1fr 76px; }
.row-l { font-size: 13.5px; color: var(--ink-2); padding: 7px 0; line-height: 1.3; }
.row-v { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; font-size: 14px; }
.row-r { font-size: 11.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-r.hi { color: var(--accent-ink); font-weight: 700; }
.bar { position: relative; height: 26px; }
.bar .track { position: absolute; inset: 9px 0; background: var(--surface-2); border-radius: 4px; }
.bar .fill {
  position: absolute; top: 9px; bottom: 9px; left: 0;
  background: var(--mark-circo); border-radius: 0 4px 4px 0; min-width: 2px;
  transform-origin: left center; animation: growx 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.bar .tick { position: absolute; top: 5px; bottom: 5px; width: 2px; border-radius: 1px; transform: translateX(-1px); }
.bar .tick.dep { background: var(--mark-dep); }
.bar .tick.reg { background: var(--mark-reg); }
.bar .tick.fr { background: var(--mark-fr); top: 2px; bottom: 2px; }
.bar:hover .track { background: var(--hairline); }

.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--ink-2); margin: 10px 0 2px; }
.legend .k { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 8px; border-radius: 3px; background: var(--mark-circo); }
.legend .tk { width: 2px; height: 12px; border-radius: 1px; display: inline-block; }

/* tableau alternatif */
table.vals { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 6px; }
table.vals th { text-align: right; font-weight: 600; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--hairline); }
table.vals th:first-child, table.vals td:first-child { text-align: left; }
table.vals td { padding: 6px 8px; border-bottom: 1px solid var(--hairline); text-align: right; font-variant-numeric: tabular-nums; }
table.vals tr:last-child td { border-bottom: none; }
table.vals td.c { font-weight: 700; }

/* pyramide */
.pyr-grid { display: grid; grid-template-columns: 1fr; gap: 4px; }
svg.pyr { width: 100%; height: auto; display: block; }
svg.pyr rect[data-b] { transition: opacity 0.12s ease; }
svg.pyr rect[data-b]:hover { opacity: 0.82; }
.pyr-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* compléments locaux */
.dpe-row { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 12px; margin: 5px 0; }
.dpe-lbl { font-size: 12.5px; color: var(--ink-2); }
.dpe-bar { display: flex; gap: 2px; height: 22px; border-radius: 5px; overflow: hidden; }
.dpe-bar div {
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 700; min-width: 2px;
}
.dpe-bar div[style*="f0c330"] { color: #1f2421; }

/* communes */
.communes-tools { margin: 4px 0 10px; }
.communes-tools input {
  width: 100%; max-width: 340px; padding: 8px 12px; font: inherit;
  border: 1px solid var(--hairline); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink);
}
table.communes { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.communes th {
  text-align: left; font-weight: 600; color: var(--ink-2);
  border-bottom: 1.5px solid var(--hairline); padding: 7px 8px;
  cursor: pointer; user-select: none;
}
table.communes th.num, table.communes td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.communes td { padding: 6px 8px; border-bottom: 1px solid var(--hairline); }
table.communes a { font-weight: 600; }
.badge-part {
  font-size: 11px; color: var(--ink-2); background: var(--surface-2);
  padding: 1px 8px; border-radius: 999px; white-space: nowrap;
}
.more-btn { margin: 10px 0 0; font-size: 13.5px; color: var(--accent-ink); font-weight: 600; }

/* élections : état vide */
.empty {
  border: 1.5px dashed var(--hairline); border-radius: var(--radius);
  padding: 32px 26px; text-align: center; color: var(--ink-2);
  background: var(--surface);
}
.empty h3 { font-family: var(--ff-display); color: var(--ink); margin: 0 0 6px; }
.empty p { max-width: 52ch; margin: 0 auto; }

/* avertissement approximation */
.approx { font-size: 12.5px; color: var(--ink-2); background: var(--warn-bg); border-radius: var(--radius-s); padding: 7px 12px; margin-top: 10px; display: inline-block; }

/* tooltip global */
.tip {
  position: fixed; z-index: 70; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 8px; box-shadow: var(--shadow);
  padding: 9px 12px; font-size: 12.5px; max-width: 280px;
}
.tip[hidden] { display: none; }
.tip .t { font-weight: 700; margin-bottom: 5px; }
.tip .r { display: flex; justify-content: space-between; gap: 18px; }
.tip .r b { font-variant-numeric: tabular-nums; font-weight: 700; }
.tip .rk { margin-top: 5px; color: var(--accent-ink); font-weight: 600; }

/* pied de page */
footer.site { border-top: 1px solid var(--hairline); background: var(--surface); margin-top: 30px; }
footer.site .wrap { padding: 22px 20px 30px; font-size: 12.5px; color: var(--ink-2); }
footer.site h4 { font-size: 13px; margin: 0 0 6px; color: var(--ink); }
footer.site ul { margin: 0 0 12px; padding-left: 18px; }
footer.site li { margin-bottom: 2px; }

.loading { padding: 60px 0; text-align: center; color: var(--muted); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes growx { from { transform: scaleX(0); } }

@media (max-width: 860px) {
  .home-grid, .dep-grid { grid-template-columns: 1fr; gap: 22px; }
  .rows { grid-template-columns: minmax(110px, 150px) 1fr 66px; }
  .row-r { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
