:root {
  --surface-0: #f4f3f0; --surface-1: #fcfcfb; --surface-2: #ffffff; --border: #e2e0da;
  --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #77756f;
  --accent: #2a78d6; --accent-soft: #e3eefc; --hors-zone: #e6e5e1; --sans-donnee: #d4d2cc;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Échelle typographique : six tailles, rien en dessous de 12 px. 1 notes, sources, étiquettes ; 2 texte dense des
     panneaux ; 3 texte des atlas ; 4 texte des pages, noms ; 5 titres de section ; 6 grands chiffres. Le titre des pages
     éditoriales part de la sixième et grandit sur grand écran (clamp). */
  --taille-1: 12px; --taille-2: 13px; --taille-3: 14px; --taille-4: 16px; --taille-5: 20px; --taille-6: 28px;
  color: var(--text-primary);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #222220; --border: #353532;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8d86;
    --accent: #3987e5; --accent-soft: #1c2a3d; --hors-zone: #262624; --sans-donnee: #3a3a37;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #222220; --border: #353532;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8d86;
  --accent: #3987e5; --accent-soft: #1c2a3d; --hors-zone: #262624; --sans-donnee: #3a3a37;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--surface-0); display: flex; flex-direction: column; font-size: var(--taille-3); }
button { font: inherit; color: inherit; }

/* Accessibilité : focus du clavier toujours visible (les règles propres à un composant priment), lien d'évitement
   (menu.js) affiché seulement quand il a le focus, animations réduites si l'appareil le demande. MapLibre, lui,
   saute déjà ses déplacements animés dans ce cas. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.maplibregl-canvas:focus-visible { outline-offset: -2px; }
main:focus { outline: none; }
.lien-evitement {
  position: absolute; z-index: 1100; top: 8px; left: 8px; padding: 8px 14px; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; transform: translateY(-200%);
}
.lien-evitement:focus { transform: none; outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important;
    animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* Démarrage des cartes : tant que le script n'a pas affiché son premier état (classe « pret » sur body), les
   commandes de l'atlas restent masquées, au lieu d'un état provisoire faux, et un indicateur occupe la carte.
   Seulement avec JavaScript actif : sans lui, le message <noscript> reste seul. */
@media (scripting: enabled) {
  body[data-zone]:not(.pret) :is(#panneau-gauche, #panneau-droit, .barre-niveaux, .barre-choix, .barre-temps,
    .carte-cadre > :not(#carte), #legende, .maplibregl-control-container, #btn-volet) { visibility: hidden; }
  body:not(.pret) :is(.carte-cadre, .carte-monde)::after {
    content: ""; position: absolute; z-index: 5; top: 50%; left: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px;
    border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
    animation: tourne 0.9s linear infinite;
  }
}
@keyframes tourne { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  body:not(.pret) :is(.carte-cadre, .carte-monde)::after { animation: pulse 1.6s ease-in-out infinite alternate !important;
    animation-duration: 1.6s !important; animation-iteration-count: infinite !important; border-top-color: var(--border); }
}
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }

.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 16px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.topbar { position: relative; }
.topbar h1 { font-size: var(--taille-4); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.liens-vues { display: flex; gap: 6px; }
/* Sélecteur de langue : dernier élément de l'en-tête, à droite */
.choix-langue {
  flex: none; margin-left: auto; padding: 4px 6px; font: inherit; font-size: var(--taille-2); color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.topbar:has(#btn-recherche) .choix-langue { margin-left: 0; }
/* En-tête des atlas : accueil et nom à gauche, volet au centre, recherche, fond, informations à droite */
.topbar:has(#btn-recherche) { gap: 10px; }
.topbar:has(#btn-recherche) .liens-vues { margin: 0 auto; }
.topbar:has(#btn-recherche) .fonds { margin-left: 0; }
/* Recherche dépliée par la loupe, sous l'en-tête */
#recherche-zone {
  position: absolute; z-index: 26; top: calc(100% + 6px); right: 16px; width: min(380px, calc(100% - 32px)); margin: 0;
}
#recherche-zone[hidden] { display: none; }
#recherche-zone input { box-shadow: 0 8px 24px rgb(0 0 0 / .14); }
.topbar .recherche { margin-left: auto; }
#ariane + .recherche { margin-left: 0; }
#ariane { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; color: var(--text-secondary); }
#ariane button { background: none; border: 0; padding: 2px 4px; cursor: pointer; color: var(--accent); border-radius: 4px; }
#ariane button:hover { background: var(--accent-soft); }
#ariane .courant { color: var(--text-primary); font-weight: 600; padding: 2px 4px; }
#ariane .sep { color: var(--text-muted); }

.recherche { position: relative; width: min(340px, 40vw); }
.recherche input {
  width: 100%; font: inherit; color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px 7px 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2377756f' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 10px center;
}
.recherche input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
#suggestions {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px;
  list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .14); max-height: 420px; overflow-y: auto;
}
#suggestions li { padding: 7px 9px; border-radius: 7px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
#suggestions li[aria-selected="true"], #suggestions li:hover { background: var(--accent-soft); }
#suggestions .nom { font-weight: 600; }
#suggestions .indices { font-size: var(--taille-1); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
#suggestions .type { font-size: var(--taille-1); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-left: 6px; font-weight: 500; }
#suggestions .vide { color: var(--text-muted); cursor: default; }
#suggestions .vide:hover { background: none; }

.fonds { position: relative; }
.menu-fonds {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 25; min-width: 230px; padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .14);
}
.menu-fonds fieldset { border: 0; margin: 0 0 8px; padding: 0; }
.menu-fonds legend { font-size: var(--taille-1); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; padding: 0; margin-bottom: 4px; }
.menu-fonds label { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.menu-fonds input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.menu-fonds .note { margin: 4px 0 0; font-size: var(--taille-1); }
.menu-fonds .opacite { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 6px 0 2px; font-size: var(--taille-2); cursor: default; }
.menu-fonds .opacite input { grid-column: 1 / -1; width: 100%; height: auto; }
.menu-fonds .opacite span { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.menu-fonds .opacite:has(input:disabled) { opacity: .5; }
.court { display: none; }

/* Bouton à icône (accueil, recherche, informations, disponibilités) */
.btn-icone {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px; background: none; color: var(--text-primary); cursor: pointer;
  text-decoration: none;
}
.btn-icone:hover, .btn-icone[aria-expanded="true"] { background: var(--accent-soft); }
.btn-icone svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-icone svg.plein { fill: currentColor; stroke: none; }
.btn-icone.petit { width: 28px; height: 28px; border: 0; color: var(--text-muted); }

.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
.btn-ghost:hover { background: var(--accent-soft); }
a.btn-ghost { color: inherit; text-decoration: none; white-space: nowrap; }

.layout { flex: 1; display: grid; grid-template-columns: 280px 1fr 320px; min-height: 0; }
.panneau { background: var(--surface-1); overflow-y: auto; padding: 14px 16px; }
#panneau-gauche { border-right: 1px solid var(--border); }
#panneau-droit { border-left: 1px solid var(--border); }
.section-titre {
  font-size: var(--taille-1); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  margin: 0 0 8px; font-weight: 600;
}
section + section { margin-top: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.liste-ind { list-style: none; margin: 0; padding: 0; }
.liste-ind .groupe-cartes { margin: 10px 0 2px; padding: 0 10px; font-size: var(--taille-1); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
/* Options de la carte choisie, sous elle */
#modes-elec li > section, #modes-elec li > .option-carte { margin: 4px 0 8px 12px; padding-left: 10px; border-left: 2px solid var(--accent-soft); }
#modes-elec li > section .section-titre { margin: 6px 0 4px; }
.option-carte { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; padding: 6px 8px; border-radius: 8px; font-size: var(--taille-2); color: var(--text-secondary); cursor: pointer; }
.option-carte:hover { background: var(--accent-soft); }
.option-carte[hidden] { display: none; }
.option-carte input { margin: 0; accent-color: var(--accent); }
.liste-ind .groupe { font-size: var(--taille-1); color: var(--text-secondary); font-weight: 600; margin: 12px 0 4px; }
.liste-ind button {
  width: 100%; text-align: left; border: 0; background: none; padding: 7px 8px; border-radius: 6px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
}
.liste-ind button:hover { background: var(--accent-soft); }
.liste-ind button[aria-current="true"] { background: var(--accent-soft); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.liste-ind .badge { font-size: var(--taille-1); color: var(--text-muted); white-space: nowrap; font-weight: 400; }

.carte-zone { position: relative; min-width: 0; display: flex; flex-direction: column; }
.barre-niveaux {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.barre-niveaux .section-titre { margin: 0; }
/* Échelons en boutons */
.echelons { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.echelons::-webkit-scrollbar { display: none; }
.echelons button {
  flex: none; border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 12px;
  cursor: pointer; white-space: nowrap; font-size: var(--taille-2);
}
.echelons button:hover { background: var(--accent-soft); }
.echelons button.actuel { border-color: var(--accent); color: var(--accent); }
.echelons button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.echelons button:disabled { color: var(--text-muted); background: var(--surface-1); cursor: not-allowed; border-style: dashed; }
.barre-choix { display: none; }
.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.affichage { display: flex; align-items: center; gap: 8px; }
.affichage .section-titre { margin: 0; }
.affichage select {
  font: inherit; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px; max-width: 260px;
}
.segmented button {
  border: 0; border-right: 1px solid var(--border); background: var(--surface-2); padding: 5px 12px; cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.segmented button:disabled { color: var(--text-muted); cursor: not-allowed; background: var(--surface-1); }

/* Barre du temps */
.barre-temps {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.barre-temps.unique .btn-lecture, .barre-temps.unique .annees, .barre-temps.unique .mode-temps [data-mode="evol"] { display: none; }
#bloc-croise select { max-width: 240px; }
.temps-unique { color: var(--text-muted); font-size: var(--taille-1); }
.temps-unique:empty { display: none; }
.btn-lecture {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent);
  background: var(--surface-2); cursor: pointer; font-size: var(--taille-1); flex: none;
}
.btn-lecture:hover { background: var(--accent-soft); }
/* Rangées qui défilent (échelons, années) : fondu au bord où il reste de quoi défiler (classes posées par fondus()) */
.defile-g { -webkit-mask-image: linear-gradient(to right, transparent, #000 28px); mask-image: linear-gradient(to right, transparent, #000 28px); }
.defile-d { -webkit-mask-image: linear-gradient(to left, transparent, #000 28px); mask-image: linear-gradient(to left, transparent, #000 28px); }
.defile-g.defile-d { -webkit-mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent); }
/* Les années en frise */
.annees { display: flex; align-items: center; position: relative; overflow-x: auto; scrollbar-width: none; }
.annees::-webkit-scrollbar { display: none; }
.annees::before { content: ""; position: absolute; left: 14px; right: 14px; top: 50%; height: 2px; background: var(--border); }
.annees button {
  position: relative; border: 0; background: none; padding: 4px 7px; cursor: pointer; color: var(--text-secondary);
  font-variant-numeric: tabular-nums; font-size: var(--taille-1); border-radius: 6px; flex: none;
}
.annees button::before {
  content: ""; display: block; width: 8px; height: 8px; margin: 0 auto 3px; border-radius: 50%;
  background: var(--surface-1); border: 2px solid var(--text-muted);
}
.annees button:hover { color: var(--text-primary); }
.annees button[aria-pressed="true"] { color: var(--text-primary); font-weight: 650; }
.annees button[aria-pressed="true"]::before { background: var(--accent); border-color: var(--accent); }
.mode-temps button { padding: 4px 10px; font-size: var(--taille-2); }
.depuis { font-size: var(--taille-2); color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.depuis[hidden] { display: none; }
.raison-evol { font-size: var(--taille-1); color: var(--text-muted); }
.raison-evol:empty { display: none; }
.depuis select { font: inherit; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; }

/* Courbe d'évolution de la fiche */
.bloc-courbe { margin: 4px 0 14px; }
.courbe { width: 100%; height: auto; display: block; overflow: visible; touch-action: pan-y; cursor: crosshair; }   /* geste vertical : défilement de la fiche */
.courbe .grille { stroke: var(--border); stroke-width: 1; }
.courbe .axe { fill: var(--text-muted); font-size: var(--taille-1); font-variant-numeric: tabular-nums; }
.courbe .axe.fort { fill: var(--text-primary); font-weight: 600; }
.courbe .curseur { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.courbe polyline { fill: none; stroke-width: 2; stroke-linejoin: round; }
.courbe circle { stroke: var(--surface-1); stroke-width: 1.5; }
.courbe .s-terr { stroke: var(--accent); }
.courbe circle.s-terr { fill: var(--accent); stroke: var(--surface-1); }
.courbe .s-parent { stroke: #eb6834; }
.courbe circle.s-parent { fill: #eb6834; stroke: var(--surface-1); }
.courbe .s-france { stroke: var(--text-muted); stroke-dasharray: 4 3; }
.courbe circle.s-france { fill: var(--text-muted); stroke: var(--surface-1); stroke-dasharray: none; }
.lecture-courbe {
  display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: baseline; margin: 4px 0 2px; min-height: 18px;
  font-size: var(--taille-1); color: var(--text-secondary); font-variant-numeric: tabular-nums;
}
.lecture-courbe > b { color: var(--text-primary); }
.lecture-courbe i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.lecture-courbe i.s-terr { background: var(--accent); }
.lecture-courbe i.s-parent { background: #eb6834; }
.lecture-courbe i.s-france { background: var(--text-muted); }
.legende-courbe { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--taille-1); color: var(--text-secondary); margin-top: 2px; }
.legende-courbe i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legende-courbe i.s-terr { background: var(--accent); }
.legende-courbe i.s-parent { background: #eb6834; }
.legende-courbe i.s-france { background: repeating-linear-gradient(90deg, var(--text-muted) 0 4px, transparent 4px 7px); }
.tous .an { margin-left: 6px; font-size: var(--taille-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }

#carte { flex: 1; background: var(--surface-1); }
/* Fil d'Ariane de l'atlas de la France : sur la carte, en haut à gauche, dès qu'on est entré dans une région */
.carte-cadre { flex: 1; position: relative; display: flex; min-height: 0; }
.ariane-carte {
  position: absolute; top: 8px; left: 8px; z-index: 4; max-width: calc(100% - 70px); display: flex; flex-wrap: wrap;
  align-items: center; gap: 2px; padding: 3px 6px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 2px 8px rgb(0 0 0 / .08); font-size: var(--taille-2); color: var(--text-secondary);
}
#ariane.ariane-carte:empty, #ariane.ariane-carte:has(> .courant:only-child) { display: none; }
.maplibregl-ctrl-attrib { font-size: var(--taille-1); }

.encart-lib {
  font-size: var(--taille-1); line-height: 1; color: var(--text-secondary); padding: 3px 4px; pointer-events: none;
  text-shadow: 0 0 2px var(--surface-1), 0 0 2px var(--surface-1);
}
.legende {
  position: absolute; right: 12px; bottom: 28px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; max-width: 260px; font-size: var(--taille-1); box-shadow: 0 2px 8px rgb(0 0 0 / .08);
}
.legende .titre { font-weight: 600; margin-bottom: 2px; }
.legende .unite { color: var(--text-secondary); margin-bottom: 6px; }
.legende .ligne { display: flex; align-items: center; gap: 8px; margin: 2px 0; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.legende .pastille { width: 16px; height: 12px; border-radius: 2px; flex: none; }
.legende .sep { border-top: 1px solid var(--border); margin: 6px 0; }
.legende .source { color: var(--text-muted); margin-top: 6px; font-size: var(--taille-1); }
/* Légende repliée : il ne reste que la bande de couleurs et ses bornes */
.legende .tete-legende { display: flex; align-items: flex-start; gap: 8px; }
.legende .tete-legende .titre { flex: 1; min-width: 0; }
.legende .replier {
  flex: none; width: 22px; height: 22px; margin: -3px -5px 0 0; border: 0; border-radius: 5px; background: none;
  color: var(--text-muted); cursor: pointer; font-size: var(--taille-1); line-height: 1;
}
.legende .replier:hover { background: var(--accent-soft); color: var(--text-primary); }
.legende.repliee { cursor: pointer; }
.legende.repliee .ligne, .legende.repliee .sep, .legende.repliee .source, .legende.repliee .unite { display: none; }
.legende.repliee .tete-legende .titre { margin-bottom: 0; }
.legende.repliee .bande { display: flex; height: 8px; margin-top: 5px; border-radius: 2px; overflow: hidden; }
.legende .bande span { flex: 1; }
.legende.repliee .bornes {
  display: flex; justify-content: space-between; gap: 8px; font-size: var(--taille-1); color: var(--text-secondary);
  margin-top: 2px; font-variant-numeric: tabular-nums;
}

.infobulle {
  position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px; font-size: var(--taille-1); box-shadow: 0 2px 8px rgb(0 0 0 / .12); z-index: 5; max-width: 240px;
}
.infobulle .nom { font-weight: 600; }
.infobulle .val { font-variant-numeric: tabular-nums; }
.infobulle .note { color: var(--text-muted); }
.chargement {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: var(--taille-1);
}

.onglets { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.onglets button { border: 0; background: none; padding: 6px 10px; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; }
.onglets button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }

.fiche-type { font-size: var(--taille-1); color: var(--text-muted); }
.fiche-nom { font-size: var(--taille-5); font-weight: 650; margin: 2px 0 10px; }
.lien-fiche { display: inline-block; font-size: var(--taille-1); margin: -6px 0 10px; color: var(--accent); }
.liens-fiches { font-size: var(--taille-2); color: var(--text-secondary); }
.liens-fiches a { color: var(--accent); }
.hero { font-size: var(--taille-6); font-weight: 650; font-variant-numeric: tabular-nums; }
.hero small { display: block; font-size: var(--taille-2); font-weight: 400; color: var(--text-secondary); margin-top: 2px; }
.rang { color: var(--text-secondary); margin: 2px 0 14px; }
.comparaison { margin: 10px 0 16px; }
.comparaison .ligne { display: grid; grid-template-columns: 96px 1fr 64px; gap: 8px; align-items: center; margin: 5px 0; font-size: var(--taille-1); }
.comparaison .lib { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comparaison .barre { height: 8px; background: var(--hors-zone); border-radius: 4px; overflow: hidden; }
.comparaison .barre span { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.comparaison .barre span.ref { background: var(--text-muted); }
.comparaison .num { text-align: right; font-variant-numeric: tabular-nums; }
.def { color: var(--text-secondary); font-size: var(--taille-1); line-height: 1.45; }
.avert { background: var(--accent-soft); border-radius: 6px; padding: 6px 8px; font-size: var(--taille-1); margin: 8px 0; }

.tous { width: 100%; border-collapse: collapse; font-size: var(--taille-1); margin-top: 6px; }
.tous td { padding: 5px 2px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tous td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tous td.ecart { text-align: right; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tous tr.th td { color: var(--text-secondary); font-weight: 600; padding-top: 10px; }
.tous button { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; color: var(--accent); }


dialog#matrice {
  border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; background: var(--surface-1); color: var(--text-primary);
  max-width: 820px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
.matrice-tete { display: flex; justify-content: space-between; align-items: center; }
.matrice-tete h2 { font-size: var(--taille-4); margin: 0; }
.note { color: var(--text-secondary); font-size: var(--taille-1); }
.mat { width: 100%; border-collapse: collapse; font-size: var(--taille-2); }
.mat th, .mat td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: center; }
.mat th:first-child, .mat td:first-child { text-align: left; }
.mat td.cell { cursor: pointer; font-variant-numeric: tabular-nums; }
.mat td.cell:hover { background: var(--accent-soft); }
.mat td.absent, .mat td.a_venir { color: var(--text-muted); cursor: default; }
.mat td.absent:hover, .mat td.a_venir:hover { background: none; }
.mat tr.th td { font-weight: 600; color: var(--text-secondary); background: var(--surface-0); }
.mat small { color: var(--text-muted); }
#matrice-table { overflow-x: auto; }
.matrice-onglets { display: flex; gap: 4px; margin: 10px 0 6px; border-bottom: 1px solid var(--border); }
.matrice-onglets button { border: 0; background: none; padding: 6px 10px; font: inherit; font-size: var(--taille-2); color: var(--text-secondary);
  border-bottom: 2px solid transparent; cursor: pointer; }
.matrice-onglets button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }
.matrice-page { max-height: 70vh; overflow-y: auto; }
.matrice-page .def { margin: 4px 0 8px; }
#matrice-sources p { color: var(--text-secondary); font-size: var(--taille-2); line-height: 1.5; }

/* Fiche : badges d'écart, position parmi les territoires, voisins, profil compact */
.badges-val { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.badge-val {
  font-size: var(--taille-1); padding: 2px 8px; border-radius: 999px; background: var(--surface-0); color: var(--text-secondary);
  font-variant-numeric: tabular-nums; border: 1px solid var(--border);
}
.badge-val.haut { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }
.badge-val.bas { color: #c2551f; border-color: color-mix(in srgb, #eb6834 40%, transparent); background: color-mix(in srgb, #eb6834 10%, transparent); }
.bloc-position { margin: 4px 0 12px; }
.position { width: 100%; height: auto; display: block; overflow: visible; }
.position .axe-pos { stroke: var(--border); stroke-width: 1; }
.position .pt { fill: var(--sans-donnee); }
.position .pt.ctx { fill: var(--text-muted); }
.position .histo { fill: var(--sans-donnee); }
.position .histo.ctx { fill: var(--text-muted); }
.position .histo.ctx.cercle { fill: none; stroke: var(--text-primary); stroke-width: .8; opacity: .55; }
.position .pt.ctx.teinte { stroke: var(--text-primary); stroke-width: .9; }
.legende-courbe i.l-ctx.cercle { background: none; border: 1.5px solid var(--text-primary); opacity: .7; }
.bloc-position .situation { margin: 4px 0 0; font-size: var(--taille-1); color: var(--text-secondary); }
.position .mediane { stroke: var(--text-secondary); stroke-width: 1.5; }
.position .ref-pos { stroke: var(--text-primary); stroke-width: 1.5; stroke-dasharray: 3 2; }
.position .moi { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.position .axe { fill: var(--text-muted); font-size: var(--taille-1); font-variant-numeric: tabular-nums; }
.position .val-pos { fill: var(--accent); font-size: var(--taille-1); font-weight: 650; font-variant-numeric: tabular-nums; }
.legende-courbe i.l-moi { background: var(--accent); width: 8px; height: 8px; border-radius: 50%; }
.legende-courbe i.l-ctx { background: var(--text-muted); width: 8px; height: 8px; border-radius: 50%; }
.legende-courbe i.l-med { background: var(--text-secondary); width: 2px; height: 10px; }
.legende-courbe i.l-ref { background: repeating-linear-gradient(0deg, var(--text-primary) 0 3px, transparent 3px 5px); width: 2px; height: 10px; }
.voisins { margin: 0 0 14px; }
.voisins tr.courant td { background: var(--accent-soft); }
.voisins td.num:first-child { color: var(--text-muted); width: 2.5em; }
.voisins button { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.courbe text.fin { font-size: var(--taille-1); font-weight: 600; font-variant-numeric: tabular-nums; }
.courbe text.fin.s-terr { fill: var(--accent); }
.courbe text.fin.s-parent { fill: #eb6834; }
.courbe text.fin.s-france { fill: var(--text-muted); }
.profil details { border-bottom: 1px solid var(--border); }
.profil summary {
  cursor: pointer; padding: 9px 2px; font-weight: 600; font-size: var(--taille-2); color: var(--text-secondary); display: flex;
  align-items: center; gap: 6px; list-style: none;
}
.profil summary::-webkit-details-marker { display: none; }
.profil summary::before { content: "▸"; color: var(--text-muted); font-size: var(--taille-1); width: 10px; }
.profil details[open] summary::before { content: "▾"; }
.profil summary .nb { margin-left: auto; font-weight: 400; font-size: var(--taille-1); color: var(--text-muted); }
.profil .tous { margin: 0 0 8px; }
.profil .tous tr.courant td { background: var(--accent-soft); }
.profil td.pos { width: 46px; padding-left: 6px; padding-right: 6px; }
.mini-pos { display: block; position: relative; height: 6px; border-radius: 3px; background: var(--hors-zone); margin-top: 6px; }
.mini-pos i { position: absolute; top: -2px; width: 4px; height: 10px; margin-left: -2px; border-radius: 2px; background: var(--accent); }
.profil td.ecart.haut { color: var(--accent); }
.profil td.ecart.bas { color: #c2551f; }
.badge-val b { font-weight: 650; }

/* Éléments propres au mobile, masqués sur grand écran */
.feuille-tete, .btn-indicateur, .poignee, .voile, .legende .bande, .legende .bornes { display: none; }

/* ---------- Mobile et tablette portrait : carte plein écran, panneaux en feuilles coulissantes ---------- */
@media (max-width: 900px) {
  html, body { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
  body { font-size: var(--taille-4); }
  .topbar {
    flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  }
  .topbar h1 { font-size: var(--taille-4); }
  .topbar:not(:has(#btn-recherche)) .btn-theme { margin-left: auto; }   /* accueil : recherche sur sa ligne */
  .fonds { margin-left: auto; }
  .liens-vues .btn-ghost { padding: 6px 10px; font-size: var(--taille-2); }
  .liens-vues { margin-left: auto; }
  .long { display: none; }
  .court { display: inline; }
  .menu-fonds label { padding: 9px 0; }
  .recherche { width: 100%; order: 3; }
  .recherche input { font-size: var(--taille-4); padding-top: 10px; padding-bottom: 10px; }   /* 16 px : pas de zoom auto sur iOS */
  #suggestions { max-height: 55dvh; }
  #suggestions li { padding: 10px; }
  #ariane { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; font-size: var(--taille-2); }

  .layout { display: block; position: relative; flex: 1; min-height: 0; }
  .carte-zone { position: absolute; inset: 0; }

  .barre-niveaux { flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  .topbar:has(#btn-recherche) { flex-wrap: nowrap; gap: 8px; }
  .topbar:has(#btn-recherche) h1 { flex: 0 1 auto; }
  #recherche-zone { left: 12px; right: 12px; width: auto; order: 0; }
  .echelons button { min-height: 34px; padding: 5px 12px; font-size: var(--taille-3); }
  .barre-choix { display: block; padding: 6px 10px; background: var(--surface-1); border-bottom: 1px solid var(--border); }
  .barre-choix .btn-indicateur { min-height: 40px; }
  .affichage { flex: 1; min-width: 55%; }
  .affichage .section-titre { display: none; }
  .affichage select { width: 100%; max-width: none; min-height: 38px; }
  .btn-indicateur {
    display: flex; align-items: baseline; gap: 6px; width: 100%; min-height: 40px; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); text-align: left; cursor: pointer;
  }
  .btn-indicateur .lib { font-size: var(--taille-1); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
  .btn-indicateur strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .segmented { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .segmented::-webkit-scrollbar, #ariane::-webkit-scrollbar { display: none; }
  .segmented button { flex: none; min-height: 38px; padding: 6px 12px; }
  /* Années (qui défilent), affichage ; choix du second indicateur (Croiser) ou de l'année de départ sur sa ligne */
  .barre-temps { flex-wrap: wrap; gap: 4px 8px; padding: 4px 10px; }
  .barre-temps .annees { flex: 1 1 0; min-width: 0; }
  .barre-temps .segmented { width: auto; flex: none; }
  .mode-temps button { min-height: 32px; padding: 4px 10px; }
  .btn-lecture { width: 34px; height: 34px; }
  .annees button { padding: 4px 8px; }
  .depuis { flex: 1 1 100%; }
  .depuis select { flex: 1 1 0; width: 0; min-width: 0; max-width: none !important; min-height: 32px; }

  /* Feuilles coulissantes */
  .voile { display: block; position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .35); }
  .voile[hidden] { display: none; }
  #panneau-gauche, #panneau-droit {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; border: 0;
    border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgb(0 0 0 / .18);
    padding: 0 16px max(16px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain;
    transition: transform .28s ease, max-height .28s ease;
  }
  #panneau-gauche { max-height: 80dvh; transform: translateY(105%); z-index: 32; }
  body[data-choix="ouvert"] #panneau-gauche { transform: none; }
  .feuille-tete {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1;
    background: var(--surface-1); padding: 14px 0 8px; margin-bottom: 4px;
  }
  .feuille-tete h2 { font-size: var(--taille-4); margin: 0; }
  .btn-rond { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
  .liste-ind button { min-height: 44px; padding: 10px 8px; }
  .chips button { min-height: 36px; padding: 6px 12px; }

  /* Fiche : aperçu en bas de l'écran, ou agrandie */
  #panneau-droit { max-height: var(--apercu, 168px); overflow: hidden; }
  body[data-fiche="ouvert"] #panneau-droit { max-height: 78dvh; overflow-y: auto; }
  /* Aucun territoire choisi : la fiche du pays en aperçu réduit (son nom et ce que montre la carte), la carte gagne la place */
  body:not(.avec-sel):not([data-fiche="ouvert"]) { --apercu: 88px; }
  .poignee {
    display: flex; justify-content: center; position: sticky; top: 0; z-index: 1; width: calc(100% + 32px);
    margin: 0 -16px; padding: 10px 0 8px; border: 0; background: var(--surface-1); cursor: grab; touch-action: none;
  }
  .poignee span { width: 40px; height: 5px; border-radius: 3px; background: var(--border); }
  .onglets { position: sticky; top: 23px; z-index: 1; background: var(--surface-1); margin-bottom: 10px; }
  .onglets button { min-height: 40px; }
  body:not([data-fiche="ouvert"]) .onglets { display: none; }
  .fiche-nom { font-size: var(--taille-4); margin-bottom: 4px; }
  .hero { font-size: var(--taille-6); }

  /* Légende en bas à droite, au-dessus de la fiche ; attribution de la carte à gauche */
  .legende {
    right: 10px; left: auto; bottom: calc(var(--apercu, 168px) + 10px); max-width: min(260px, calc(100% - 20px));
    padding: 8px 10px;
  }
  .legende-monde { bottom: 10px; }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--apercu, 168px) + 4px); right: auto; left: 0; }
  .monde .maplibregl-ctrl-bottom-right { bottom: 0; }
  .maplibregl-ctrl-top-right { top: 4px; }
  .infobulle { display: none !important; }      /* pas de survol au doigt : la fiche en aperçu suffit */

  dialog#matrice { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; padding: 14px 12px; }
  .mat { font-size: var(--taille-1); }
  .mat th, .mat td { padding: 6px 4px; }
}

/* Fiche électorale : barre de majorité, gaufre de participation, bascule, écarts */
.bloc-majorite { position: relative; margin: 6px 0 16px; padding-top: 2px; }
.barre-majorite { position: relative; display: flex; height: 18px; border-radius: 4px; overflow: hidden; background: var(--hors-zone); gap: 1px; }
.barre-majorite .trait-maj { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text-primary); }
.lib-maj { position: relative; display: inline-block; transform: translateX(-50%); font-size: var(--taille-1); color: var(--text-secondary); margin: 3px 0 4px; white-space: nowrap; }
.bloc-majorite .legende-courbe i { width: 10px; height: 10px; border-radius: 2px; }
.bloc-gaufre { margin: 4px 0 14px; }
.gaufre { display: grid; grid-template-columns: repeat(20, 1fr); grid-template-rows: repeat(5, auto); grid-auto-flow: column; gap: 2px; max-width: 300px; }   /* par colonnes : un bloc par parti */
.gaufre i { aspect-ratio: 1; border-radius: 2px; }
.bloc-gaufre .legende-courbe i { width: 10px; height: 10px; border-radius: 2px; }
.res .ecarts { grid-column: 1 / -1; font-size: var(--taille-1); color: var(--text-muted); font-variant-numeric: tabular-nums; margin-top: -1px; }
.res .ecarts .haut { color: var(--accent); }
.res .ecarts .bas { color: #c2551f; }
.legende .marge { display: flex; gap: 2px; margin: 4px 0 2px; }
.legende.repliee .marge { display: none; }
.legende .marge span { flex: 1; height: 8px; border-radius: 2px; }
/* Menu principal des atlas (territoires/js/menu.js) : tiroir à gauche, sur ordinateur comme sur mobile */
.tiroir {
  position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(320px, 85vw); display: flex; flex-direction: column;
  background: var(--surface-1); border-right: 1px solid var(--border); box-shadow: 6px 0 24px rgb(0 0 0 / .16);
  padding: max(10px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom)); transform: translateX(-102%);
  transition: transform .22s ease;
}
.tiroir[hidden] { display: none; }
.tiroir.ouvert { transform: none; }
.voile-menu { position: fixed; inset: 0; z-index: 49; background: rgb(0 0 0 / .3); }
.voile-menu[hidden] { display: none; }
.tiroir-tete { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 8px 16px; border-bottom: 1px solid var(--border); }
.tiroir-tete .marque { font-weight: 700; font-size: var(--taille-4); color: var(--text-primary); text-decoration: none; letter-spacing: .01em; }
.tiroir-corps { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px; }
.tiroir-corps section { margin: 10px 0 0; }
.tiroir-corps .section-titre { margin: 0 8px 4px; }
.tiroir-corps ul { list-style: none; margin: 0; padding: 0; }
.tiroir .entree {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 8px; border: 0; border-radius: 8px; background: none;
  color: var(--text-primary); font: inherit; text-align: left; text-decoration: none; cursor: pointer; list-style: none;
}
.tiroir .entree::-webkit-details-marker { display: none; }
.tiroir .entree:hover, .tiroir .entree:focus-visible { background: var(--accent-soft); }
.tiroir .entree:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tiroir .entree svg { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: none; stroke: var(--text-secondary); stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.tiroir .entree span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tiroir .entree small { font-size: var(--taille-1); color: var(--text-muted); }
.tiroir .entree-theme .entree { cursor: default; }
.tiroir .entree-theme .entree:hover { background: none; }
.tiroir .entree-theme .entree svg path { stroke: none; fill: var(--text-secondary); }
.entree-theme .segmented { margin: 0 8px 6px 40px; flex-wrap: nowrap; }
.entree-theme .segmented button { flex: 1; }
.autres-atlas[open] > summary { background: var(--accent-soft); }
.autres-atlas ul { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; padding: 4px 0 6px 40px !important; }
.autres-atlas a { display: block; padding: 5px 6px; border-radius: 6px; color: var(--text-secondary); text-decoration: none; font-size: var(--taille-2); }
.autres-atlas a:hover { background: var(--accent-soft); color: var(--text-primary); }
.autres-atlas a[aria-current="page"] { color: var(--text-primary); font-weight: 600; }
.autres-atlas .note { grid-column: 1 / -1; padding: 4px 6px; }
/* Message bref en bas de l'écran (lien copié, export impossible) */
.avis {
  position: fixed; z-index: 60; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  max-width: min(460px, calc(100% - 32px)); padding: 9px 14px; border-radius: 8px; background: var(--text-primary); color: var(--surface-1);
  font-size: var(--taille-2); box-shadow: 0 6px 20px rgb(0 0 0 / .2); pointer-events: none; transition: opacity .2s, transform .2s;
}
.avis.visible { opacity: 1; transform: translate(-50%, 0); }

/* Fond de carte : icône « calques » sur la carte, sous les boutons de zoom ; le menu s'ouvre à sa gauche */
.carte-cadre > .fonds { position: absolute; z-index: 5; top: 80px; right: 10px; }
.btn-carte {
  display: flex; align-items: center; justify-content: center; width: 29px; height: 29px; padding: 0; border: 0; border-radius: 4px;
  background: var(--surface-2); color: var(--text-primary); box-shadow: 0 0 0 2px rgb(0 0 0 / .1); cursor: pointer;
}
.btn-carte:hover, .btn-carte[aria-expanded="true"] { background: var(--accent-soft); }
.btn-carte svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.carte-cadre > .fonds .menu-fonds { top: 0; right: calc(100% + 8px); max-height: calc(100vh - 220px); overflow-y: auto; }
@media (max-width: 900px) {
  .carte-cadre > .fonds { top: 80px; }
  .carte-cadre > .fonds .btn-carte { width: 34px; height: 34px; }
}
/* Carte croisée (bivariee.js) : carré de 3 × 3 et noms des axes, dans un même dessin */
.legende .biv-carre { display: block; max-width: 100%; height: auto; margin: 8px 0 2px; }
.legende.repliee .biv-carre { display: none; }

/* Impression (toutes les pages) : couleurs claires quel que soit le thème, ni menus, ni boutons, ni recherche ; les
   pages éditoriales et les fiches s'impriment sur toute leur hauteur, les cartes avec leur légende. */
@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --surface-0: #fff; --surface-1: #fff; --surface-2: #fff; --border: #ccc;
    --text-primary: #000; --text-secondary: #333; --text-muted: #555; --accent: #1a5fb4; --accent-soft: #fff;
    color-scheme: light;
  }
  html, body { height: auto; overflow: visible; background: #fff; }
  .tiroir, .voile-menu, .recherche, #recherche-zone, #suggestions, .btn-icone, .btn-ghost, .bouton, .fonds,
  .menu-fonds, .infobulle, .maplibregl-ctrl, noscript { display: none !important; }
  .topbar { border-bottom: 1px solid #ccc; }
  a { color: inherit; text-decoration: none; }
  figure, tr, .tuile { break-inside: avoid; }
}
