/* Pages statiques (pipeline/fiches.py, composants de pipeline/composants.py) : par-dessus commun/style.css, dont elles
   reprennent les jetons (surfaces, textes, accent), l'en-tête, le menu ☰ et les contrôles segmentés. Pages de lecture :
   elles défilent, la largeur du texte est bornée, tout se lit sans JavaScript (commun/pages.js : onglets, infobulles). */
:root {
  /* Rampes des cartes, celles de l'atlas (carto/js/couleurs.js) : bleu séquentiel, divergente rouge ↔ bleu */
  --seq0: #cde2fb; --seq1: #9ec5f4; --seq2: #6da7ec; --seq3: #3987e5; --seq4: #256abf; --seq5: #184f95; --seq6: #0d366b;
  --div0: #a8282a; --div1: #e34948; --div2: #f2a9a3; --div3: #f0efec; --div4: #86b6ef; --div5: #2a78d6; --div6: #184f95;
  --oui: #2a78d6; --non: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --seq0: #0d366b; --seq1: #184f95; --seq2: #256abf; --seq3: #3987e5; --seq4: #6da7ec; --seq5: #9ec5f4; --seq6: #cde2fb;
    --div0: #c23a3a; --div1: #e66767; --div2: #8f4a46; --div3: #383835; --div4: #2f5f9c; --div5: #3987e5; --div6: #86b6ef;
    --oui: #3987e5; --non: #d95926;
  }
}
:root[data-theme="dark"] {
  --seq0: #0d366b; --seq1: #184f95; --seq2: #256abf; --seq3: #3987e5; --seq4: #6da7ec; --seq5: #9ec5f4; --seq6: #cde2fb;
  --div0: #c23a3a; --div1: #e66767; --div2: #8f4a46; --div3: #383835; --div4: #2f5f9c; --div5: #3987e5; --div6: #86b6ef;
  --oui: #3987e5; --non: #d95926;
}

html, body.page { height: auto; }
body.page { display: block; font-size: var(--taille-4); line-height: 1.5; background: var(--surface-0); color: var(--text-primary); }
body.page a { color: var(--accent); }
.page .topbar { position: sticky; top: 0; z-index: 30; gap: 12px; }
.page .topbar .marque { font-weight: 700; font-size: var(--taille-4); color: var(--text-primary); text-decoration: none; white-space: nowrap; }
.page .topbar .marque span { color: var(--text-muted); font-weight: 500; }
.page .topbar .actions { margin-left: auto; display: flex; gap: 8px; }
.bouton {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: var(--taille-3);
  text-decoration: none; white-space: nowrap; border: 1px solid transparent;
}
.page a.bouton { color: #fff; background: var(--accent); }
.page a.bouton.second { color: var(--text-primary); background: var(--surface-2); border-color: var(--border); }
.page a.bouton:hover { filter: brightness(1.06); }
.bouton svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.contenu { max-width: 1120px; margin: 0 auto; padding: 16px 16px 56px; }
.ariane { font-size: var(--taille-2); color: var(--text-muted); margin: 4px 0 14px; }
.ariane a { text-decoration: none; }
.ariane a:hover { text-decoration: underline; }
.ariane .sep { margin: 0 6px; }

/* ---------- En-tête de la page : nom, chapeau, chiffres, carte de situation ---------- */
.heros { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: start; }
.heros h1 { font-size: clamp(var(--taille-6), 5vw, 44px); line-height: 1.1; margin: 0 0 6px; letter-spacing: -.01em; }
.heros h1 .code { color: var(--text-muted); font-weight: 500; }
.surtitre { font-size: var(--taille-1); text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 600; margin: 0 0 4px; }
.chapeau { font-size: var(--taille-4); color: var(--text-secondary); max-width: 68ch; margin: 8px 0 16px; }
.chapeau b { color: var(--text-primary); font-weight: 600; }
.actions-heros { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 4px; }
.situation { margin: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.situation svg { display: block; width: 100%; height: auto; }
.situation figcaption { font-size: var(--taille-1); color: var(--text-muted); text-align: center; margin-top: 4px; }
.sit-fond { fill: var(--hors-zone); stroke: var(--surface-1); stroke-width: .6; }
.sit-proche { fill: color-mix(in srgb, var(--accent) 28%, var(--hors-zone)); stroke: var(--surface-1); stroke-width: .6; }
.sit-cible { fill: var(--accent); stroke: var(--surface-1); stroke-width: .6; }

.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 10px; margin: 20px 0 0; padding: 0; list-style: none; }
.tuile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tuile .lib { font-size: var(--taille-1); color: var(--text-secondary); }
.tuile .val { display: block; font-size: var(--taille-6); font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; letter-spacing: -.01em; }
.tuile .sous { font-size: var(--taille-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tuile .bandeau { margin-top: 6px; }

/* ---------- Sections ---------- */
.bloc { margin-top: 40px; }
.bloc > h2 { font-size: var(--taille-5); margin: 0 0 4px; letter-spacing: -.005em; }
.bloc > .intro { color: var(--text-secondary); margin: 0 0 14px; max-width: 72ch; }
.bloc h3 { font-size: var(--taille-2); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; margin: 22px 0 8px; }
.carte-blanche { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.deux { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.deux > * { min-width: 0; }
.note { color: var(--text-muted); font-size: var(--taille-2); }

/* Faits marquants : cartes en grille */
.faits { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; list-style: none; padding: 0; margin: 0; }
.fait { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.fait .lib { font-size: var(--taille-2); color: var(--text-secondary); }
.fait .val { font-size: var(--taille-5); font-weight: 700; font-variant-numeric: tabular-nums; }
.fait .rang { display: inline-block; font-size: var(--taille-1); font-weight: 600; padding: 1px 7px; border-radius: 999px; margin: 0 0 0 6px;
  background: var(--accent-soft); color: var(--accent); vertical-align: 3px; }
.fait .rang.bas { background: color-mix(in srgb, var(--non) 16%, transparent); color: color-mix(in srgb, var(--non) 80%, var(--text-primary)); }
.fait .sous { font-size: var(--taille-1); color: var(--text-muted); }

/* Bandeau de position : étendue, quartiles, médiane, référence du pays, territoire */
.bandeau { display: block; width: 100%; max-width: 220px; height: 20px; overflow: visible; }
.bandeau .ligne { stroke: var(--border); stroke-width: 2; stroke-linecap: round; }
.bandeau .iq { fill: var(--sans-donnee); }
.bandeau .med { stroke: var(--text-muted); stroke-width: 1.5; }
.bandeau .ref { fill: var(--text-secondary); }
.bandeau .moi { fill: var(--accent); stroke: var(--surface-2); stroke-width: 2; }

/* ---------- Cartes SVG (communes, intercommunalités) ---------- */
.carte-svg { margin: 0; position: relative; }
.carte-svg .onglets-carte { margin: 0 0 10px; }
.carte-svg .onglets-carte[hidden] { display: none; }
.carte-svg .corps { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 16px; align-items: start; }
.carte-svg svg.zones { display: block; width: 100%; height: auto; max-height: 620px; }
.carte-svg .zones .cx { fill: var(--sans-donnee); }
.carte-svg .zones path { stroke: var(--surface-2); stroke-width: .35; stroke-linejoin: round; }
.carte-svg .zones path[data-href] { cursor: pointer; }
.carte-svg .zones path:hover { stroke: var(--text-primary); stroke-width: 1.2; }
.carte-svg .zones .contours { fill: none; stroke: var(--text-primary); stroke-width: 1; pointer-events: none; opacity: .55; }
.carte-svg .titre-onglet { font-weight: 600; margin: 0 0 8px; }
.legende-svg { font-size: var(--taille-2); }
.legende-svg ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.legende-svg li { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.legende-svg .case { flex: none; width: 14px; height: 14px; border-radius: 3px; }
.legende-svg .nb { margin-left: auto; color: var(--text-muted); font-size: var(--taille-1); }
.legende-svg .degrade { display: flex; gap: 2px; }
.legende-svg .degrade span { flex: 1; height: 12px; }
.legende-svg .degrade span:first-child { border-radius: 3px 0 0 3px; }
.legende-svg .degrade span:last-child { border-radius: 0 3px 3px 0; }
.legende-svg .bornes { display: flex; justify-content: space-between; font-size: var(--taille-1); color: var(--text-muted); margin-top: 3px; }
.legende-svg p { margin: 8px 0 0; color: var(--text-muted); font-size: var(--taille-1); }
.bulle-svg {
  position: absolute; z-index: 5; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: var(--taille-2); box-shadow: 0 6px 18px rgb(0 0 0 / .14); max-width: 240px;
}
.bulle-svg b { display: block; }
.bulle-svg[hidden] { display: none; }

/* ---------- Résultats électoraux ---------- */
.resultats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.resultats li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; align-items: baseline; }
.resultats .nom { display: flex; align-items: center; gap: 7px; min-width: 0; font-weight: 500; }
.resultats .nom small { color: var(--text-muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resultats .pct { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.resultats .piste { grid-column: 1 / -1; position: relative; height: 10px; background: var(--surface-0); border-radius: 5px; }
.resultats .barre { position: absolute; inset: 0 auto 0 0; border-radius: 5px; }
.resultats .repere { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text-primary); opacity: .7; border-radius: 1px; }
.resultats .ecart { grid-column: 1 / -1; font-size: var(--taille-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pastille { flex: none; width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legende-repere { font-size: var(--taille-1); color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin: 10px 0 0; }
.legende-repere i { display: inline-block; width: 2px; height: 14px; background: var(--text-primary); opacity: .7; }

.scrutins { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; list-style: none; padding: 0; margin: 0; }
.scrutin { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; }
.page a.scrutin { color: var(--text-primary); }
.page a.scrutin:hover { border-color: var(--accent); }
.scrutin .type { font-size: var(--taille-1); color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.scrutin .tete { display: flex; align-items: center; gap: 7px; font-weight: 600; margin-top: 4px; }
.scrutin .score { font-size: var(--taille-5); font-weight: 700; font-variant-numeric: tabular-nums; }
.scrutin .sous { font-size: var(--taille-1); color: var(--text-muted); }

/* Second tour de la présidentielle depuis 1965 */
.duels { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.duels li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 2px 10px; align-items: center; }
.duels .an { font-weight: 700; font-variant-numeric: tabular-nums; grid-row: span 2; }
.duels .noms { display: flex; justify-content: space-between; font-size: var(--taille-2); gap: 8px; }
.duels .noms span:last-child { text-align: right; }
.duels .noms b { font-variant-numeric: tabular-nums; }
.duels .piste { position: relative; display: flex; height: 12px; border-radius: 6px; overflow: hidden; }
.duels .piste span { display: block; height: 100%; }
.duels .repere { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--surface-2); }
.duels .milieu { position: absolute; top: -2px; bottom: -2px; left: 50%; width: 0; border-left: 1px dashed var(--text-primary); opacity: .45; }

/* Députés */
.deputes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.deputes li { display: flex; gap: 10px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.deputes .circ { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: var(--taille-2);
  background: var(--surface-0); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.deputes .qui { min-width: 0; display: flex; flex-direction: column; }
.deputes .qui small { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.groupe { display: inline-flex; align-items: center; gap: 5px; }
.hemicycle { display: flex; height: 16px; border-radius: 8px; overflow: hidden; margin: 6px 0 8px; gap: 2px; }
.hemicycle span { display: block; height: 100%; }
.groupes { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 0; font-size: var(--taille-2); }

/* ---------- Tableaux ---------- */
.defile { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.page table { width: 100%; border-collapse: collapse; font-size: var(--taille-3); background: var(--surface-2); }
.tableau { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.page th, .page td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.page tr:last-child > * { border-bottom: 0; }
.page thead th { font-size: var(--taille-1); color: var(--text-muted); font-weight: 600; white-space: nowrap; background: var(--surface-1); }
.page tbody th { font-weight: 500; }
.page tbody th small { display: block; color: var(--text-muted); font-weight: 400; font-size: var(--taille-1); }
.page td.num, .page th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.page td.evo { color: var(--text-secondary); font-size: var(--taille-2); }
.page td.pos { width: 180px; }
.page tbody tr:hover { background: var(--surface-1); }
details.theme { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
details.theme > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; list-style: none; }
details.theme > summary::-webkit-details-marker { display: none; }
details.theme > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); transition: transform .15s; }
details.theme[open] > summary::after { transform: rotate(-135deg); }
details.theme > summary small { color: var(--text-muted); font-weight: 400; }
details.theme table { border-top: 1px solid var(--border); }

.puces { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.puces a { display: inline-block; padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  text-decoration: none; font-size: var(--taille-3); }
.page .puces a { color: var(--text-primary); }
.puces a:hover { border-color: var(--accent); background: var(--accent-soft); }
.puces small { color: var(--text-muted); margin-left: 4px; }

.pied { border-top: 1px solid var(--border); background: var(--surface-1); color: var(--text-muted); font-size: var(--taille-2); }
.pied .contenu { padding-top: 20px; padding-bottom: 28px; display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 820px) {
  .heros { grid-template-columns: minmax(0, 1fr); }
  .situation { max-width: 280px; }
  .deux { grid-template-columns: minmax(0, 1fr); }
  .carte-svg .corps { grid-template-columns: minmax(0, 1fr); }
  .page .topbar .actions .bouton span { display: none; }
}
@media (max-width: 560px) {
  body.page { font-size: var(--taille-3); }
  .contenu { padding: 12px 16px 40px; }
  .chapeau { font-size: var(--taille-4); }
  .tuiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tuile .val { font-size: var(--taille-5); }
  .tuile { padding: 10px 12px; }
  .page td.pos { display: none; }
  .page th.pos { display: none; }
  .carte-svg .onglets-carte { flex-wrap: nowrap; overflow-x: auto; }
  .page td.evo, .page th.evo { display: none; }
  .situation { display: none; }
}
