:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #d8dbe0;
  --text: #1c1f24;
  --muted: #666e79;
  --accent: #2f6feb;
  --accent-hover: #2559c4;
  --danger: #c4362f;
  --danger-hover: #a52a24;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1c20;
    --panel: #24272c;
    --border: #3a3e45;
    --text: #e8eaed;
    --muted: #9aa2ad;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.sr-only-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.actions {
  display: flex;
  gap: 8px;
}

main {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.search-group {
  border: none;
  padding: 0;
  margin: 0 0 14px;
}

.search-group legend {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 6px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

/* Case à cocher dans une grille de champs : `label` empile normalement
   l'intitulé au-dessus du champ, ce qui étirerait la case sur toute la
   largeur de la cellule et la placerait loin de son texte. */
.case-a-cocher {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  align-self: end;
  padding-bottom: 7px;
}

.case-a-cocher input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: none;
  padding: 0;
  accent-color: var(--accent);
}

input, select, textarea, button {
  font: inherit;
  color: inherit;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

input, select, textarea {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
}

input:disabled, select:disabled, textarea:disabled, button:disabled {
  opacity: 0.6;
}

textarea {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 60px;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
}

.ui-icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

button:hover {
  border-color: var(--accent);
}

.icon-button {
  padding: 6px 10px;
  font-size: 17px;
  line-height: 1;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

button.danger:hover {
  background: var(--danger-hover);
}

button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 2px 4px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 8px;
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

thead th.sorted::after {
  content: " " attr(data-dir);
}

thead th.no-sort {
  cursor: default;
}

tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* Personne décédée : ligne entière en gris italique. La fiche reste ouvrable,
   mais la ligne se lit au premier coup d'œil comme n'étant plus un contact. */
tbody tr.decede {
  color: var(--muted);
  font-style: italic;
}

/* La photo suivrait sinon la ligne au même niveau de contraste que les autres,
   alors que c'est elle qui accroche l'œil dans le tableau. */
tbody tr.decede .thumb {
  opacity: 0.6;
}

.thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  display: block;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
}

.status {
  margin: 8px 0;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status.error {
  color: var(--danger);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.dynamic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.dynamic-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dynamic-row input, .dynamic-row select {
  flex: 1;
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.photo-preview {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--border);
  border: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--border);
  color: var(--muted);
}

.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
}

.tag-input input {
  flex: 1;
  min-width: 160px;
  border: none;
  background: transparent;
  padding: 4px;
}

.tag-input input:focus {
  outline: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.tag button {
  border: none;
  background: none;
  padding: 0 4px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.md-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.md-toolbar button {
  padding: 4px 10px;
  font-size: 12px;
}

.md-preview {
  min-height: 200px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
}

.md-preview :first-child {
  margin-top: 0;
}

.md-preview :last-child {
  margin-bottom: 0;
}

.md-preview h3,
.md-preview h4,
.md-preview h5 {
  margin: 10px 0 4px;
  font-size: 14px;
}

.md-preview ul,
.md-preview ol {
  margin: 4px 0;
  padding-left: 22px;
}

.md-preview p {
  margin: 4px 0;
}

.md-preview code {
  background: var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.fiche-layout {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.fiche-main {
  flex: 1;
  min-width: 0;
}

.photo-search-panel {
  flex: 0 0 300px;
  position: sticky;
  top: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.photo-search-form {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.photo-search-form input {
  flex: 1;
}

.photo-search-results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.geo-ok,
.geo-absent,
.geo-entete,
.repere-cell {
  text-align: center;
  width: 32px;
  cursor: default;
}

.geo-ok svg,
.geo-absent svg,
.geo-entete svg,
.repere-cell svg {
  vertical-align: middle;
}

/* Monochrome : seule l'intensité distingue les deux états. */
.geo-ok {
  color: var(--text);
}

.geo-absent {
  color: var(--muted);
  opacity: 0.55;
}

.adresse-layout {
  display: flex;
  align-items: stretch;
  gap: 16px;
}

.adresse-champs {
  flex: 1;
  min-width: 0;
}

.adresse-carte {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* `flex: 1` dans un conteneur `stretch` : la carte prend la hauteur des champs,
   jamais plus — le bloc Adresse garde donc sa taille d'origine. */
#mini-map {
  flex: 1;
  /* La carte dépasse la hauteur des champs d'adresse (une centaine de pixels) :
     en dessous, l'attribution Google mange l'essentiel de la surface utile. */
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.adresse-ligne {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}

.coords {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mode-switch {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

/* Icône en SVG : sans `display: block` elle s'assoit sur la ligne de base et
   l'espace du jambage rendrait ce bouton plus haut que ses voisins, dont
   l'icône est un simple caractère. */
.icon-button svg {
  display: block;
}

.mode-switch .icon-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#map,
#map-ign {
  width: 100%;
  height: 65vh;
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* --- Couche de température politique (vue Google) --- */

/* Le canevas est positionné par l'`OverlayView`, en pixels, dans le repère de la
   carte : `absolute` est donc imposé, et non un choix de mise en page. Il ne doit
   par ailleurs intercepter aucun clic — le dégradé est un fond, les repères et le
   fond de carte restent seuls cliquables. */
.couche-temperature {
  position: absolute;
  pointer-events: none;
}

/* Légende, posée au-dessus du compte de points. Elle partage cette bande avec le
   bandeau d'avancement du géocodage, qui la recouvrira le cas échéant (z-index
   supérieur) : celui-ci ne paraît qu'une fois par session, et ce qu'il a à dire
   passe alors devant une légende que l'on connaît déjà. */
.temperature-legende {
  display: none;
}

body.mode-carte .temperature-legende:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  position: absolute;
  left: 12px;
  bottom: 92px;
  z-index: 2;
  max-width: min(520px, 70vw);
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--panel); /* repli si color-mix n'est pas supporté */
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border);
}

.temperature-legende .legende-titre {
  font-weight: 600;
}

.temperature-legende .legende-camp {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* Pastille de couleur. Un contour discret la détache aussi bien du panneau clair
   que du panneau sombre, sans quoi le gris de « Blanc / Abstention » s'y fondrait
   presque entièrement. */
.temperature-legende .legende-camp i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.temperature-legende .legende-note {
  color: var(--muted);
}

/* --- Vue Géoportail (Leaflet) ---
   Les marqueurs y sont du DOM, pas des images : le repère est le SVG que
   `svgRepere` produit déjà pour le tableau, et la pastille d'agrégat se
   compose en CSS. --- */

/* Neutralise l'habillage par défaut de `divIcon` (carré blanc bordé). */
.repere-ign,
.cluster-ign {
  background: none;
  border: none;
}

.repere-ign svg {
  display: block;
  /* Détache le repère du fond photographique, où un tracé sombre se perd. */
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.cluster-ign span {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border-radius: 50%;
  background: rgba(47, 111, 235, 0.9);
  border: 2px solid #ffffff;
  color: #fff;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
}

/* Repère armé pour l'ajustement : il saute sur place, comme sur la carte
   Google, pour qu'on voie lequel répond à la souris. */
@keyframes repere-saute {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}

.repere-ajustable svg {
  animation: repere-saute 0.7s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .repere-ajustable svg {
    animation: none;
    /* Sans le rebond, il faut autre chose pour désigner le repère armé. */
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 50%;
  }
}

/* La bulle Leaflet est blanche et ne suit pas le thème : on lui impose le même
   texte sombre que celui de la bulle Google. */
.leaflet-popup-content a {
  color: #1a56c4;
}

/* Bascule « cadastre seul », posée sous les commandes de zoom. Habillée comme
   les boutons de l'application plutôt que comme un contrôle Leaflet : c'est une
   commande de Sinefiles, pas de la bibliothèque. */
.bascule-cadastre {
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 5px;
  background: #ffffff;
  color: #1c1f24;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.bascule-cadastre:hover {
  background: #f1f3f6;
}

.bascule-cadastre.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Le parcellaire est une couche transparente : seul, il lui faut un fond sous
   lui. Un blanc chaud plutôt que le gris de Leaflet — un plan cadastral se lit
   comme un document, et ses traits sont dessinés pour du papier. Volontairement
   clair dans les deux thèmes : sur fond sombre, les limites de parcelle et les
   numéros disparaîtraient. */
#map-ign.fond-cadastre,
#map-ign.fond-cadastre .leaflet-container {
  background: #fbfaf7;
}

/* --- Mode carte : la carte occupe toute la surface de l'application et le
   formulaire de recherche se pose par-dessus, translucide. --- */

/* Nom de naissance rappelé derrière le nom d'usage : présent pour être lu,
   effacé pour ne pas concurrencer le nom sous lequel la personne est connue. */
.nom-naissance {
  color: var(--muted);
  font-size: 0.92em;
}

body.mode-carte {
  /* La carte est en position fixe : la page n'a plus rien à faire défiler. */
  overflow: hidden;
}

body.mode-carte #vue-carte,
body.mode-carte #vue-geoportail {
  position: fixed;
  /* --topbar-h est mesurée en JS : la barre d'outils doit rester accessible. */
  top: var(--topbar-h, 64px);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

body.mode-carte #map,
body.mode-carte #map-ign {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: none;
  border-radius: 0;
}

body.mode-carte .map-status {
  position: absolute;
  left: 12px;
  /* Dégagé du bas : en dessous se trouvent le logo Google, l'attribution
     cartographique et la barre Plan/Satellite, que ce bandeau recouvrait. */
  bottom: 52px;
  margin: 0;
  /* `width: max-content` : sans elle, ce bloc occupe toute la largeur
     disponible même pour un texte court, et masque ce qu'il y a derrière. */
  width: max-content;
  max-width: min(520px, 60vw);
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--panel); /* repli si color-mix n'est pas supporté */
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border);
}

/* Avancement du géocodage : posé au-dessus du compte de points, qui reste
   visible pendant l'opération. */
body.mode-carte .geo-status:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 10px;
  /* `fixed` et non `absolute` : ce bandeau est désormais commun aux deux
     cartes, donc posé hors de leurs conteneurs. */
  position: fixed;
  bottom: 92px;
  z-index: 3;
}

.geo-status #geo-stop {
  padding: 2px 8px;
  font-size: 12px;
}

body.mode-carte #panneau-recherche {
  position: fixed;
  top: calc(var(--topbar-h, 64px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(1360px, calc(100vw - 24px));
  z-index: 2;
  /* Aucun habillage : seuls les champs se posent sur la carte. */
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  overflow: visible;
  /* La carte reste manipulable partout où il n'y a pas de champ : le panneau
     laisse passer les clics, seuls les contrôles les captent (ci-dessous). */
  pointer-events: none;
}

/* Le titre du panneau n'a plus lieu d'être en mode carte. */
body.mode-carte #panneau-recherche .section-title {
  display: none;
}

body.mode-carte #search-form,
body.mode-carte #panneau-recherche .form-actions {
  opacity: 0.2;
  transition: opacity 120ms ease;
}

/* Dès qu'un champ a le focus, le formulaire devient pleinement opaque. */
body.mode-carte #panneau-recherche:focus-within #search-form,
body.mode-carte #panneau-recherche:focus-within .form-actions {
  opacity: 1;
}

/* Seuls les contrôles eux-mêmes sont cliquables : les libellés et les espaces
   entre les champs laissent la carte accessible. */
body.mode-carte #panneau-recherche input,
body.mode-carte #panneau-recherche select,
body.mode-carte #panneau-recherche button {
  pointer-events: auto;
}

/* Les icônes de bascule restent visibles et actives : c'est le seul chemin de
   retour vers le tableau. */
body.mode-carte #panneau-recherche .mode-switch {
  pointer-events: auto;
}

/* Le titre masqué laisserait les icônes glisser à gauche (`space-between` avec
   un seul élément) : on les rappelle explicitement à droite. */
body.mode-carte #panneau-recherche .panel-header {
  justify-content: flex-end;
  margin-bottom: 8px;
}

body.mode-carte #panneau-resultats,
body.mode-carte #db-path {
  display: none;
}

/* Filet de sécurité : cf. le MutationObserver de fiche.js, qui retire cette
   classe posée par le widget Google et qui bloquerait le défilement. */
body.gsc-overflow-hidden {
  overflow: auto;
}

/* Rendu du widget Google : présent dans le DOM (son curseur de pagination doit
   rester cliquable) mais invisible. `display: none` ne conviendrait pas. */
.cse-offscreen {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Le widget affiche ses résultats dans un overlay modal `position: fixed`, qui
   échapperait au déport hors écran et recouvrirait la fiche. */
.gsc-results-wrapper-overlay,
.gsc-modal-background-image {
  display: none !important;
}

.photo-result {
  margin: 0;
  min-width: 0;
}

.photo-result img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
}

.photo-result img:hover {
  border-color: var(--accent);
}

.photo-result figcaption {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.crop-overlay[hidden] {
  display: none;
}

.crop-dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  max-width: 90vw;
  max-height: 90vh;
}

.crop-canvas-wrap {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

.crop-canvas-wrap canvas {
  max-width: 100%;
  cursor: crosshair;
  border: 1px solid var(--border);
  touch-action: none;
}

/* --- Actions Photo & Modale Caméra --- */

.photo-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.photo-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.camera-dialog {
  width: min(560px, 92vw);
}

.camera-video-wrap {
  display: flex;
  justify-content: center;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
  max-height: 60vh;
}

#camera-video {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

.camera-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* --- Membres du foyer (autres électeurs à la même adresse) --- */

.foyer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.foyer-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  transition: border-color 120ms ease;
}

.foyer-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.foyer-card.decede {
  color: var(--muted);
  font-style: italic;
}

.foyer-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.foyer-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.foyer-meta {
  font-size: 12px;
  color: var(--muted);
}

.foyer-repere {
  flex: none;
  display: flex;
  align-items: center;
}

/* --- Tableau de bord Statistiques --- */

.stats-dashboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.stats-kpi {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.stats-kpi-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.stats-kpi-label {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}

.stats-kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.stats-grids {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.stats-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.stats-bar-row {
  margin-bottom: 10px;
}

.stats-bar-row:last-child {
  margin-bottom: 0;
}

.stats-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}

.stats-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.stats-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* --- Repli des filtres, Bouton Toggle & Ergonomie Mobile --- */

.btn-text-mobile,
.mode-label,
.mobile-only-btn,
.age-mobile {
  display: none;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-filtres-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.toggle-filtres-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.filtres-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.filtres-badge[hidden] {
  display: none;
}

.mobile-filter-btn {
  font-size: 13px;
  padding: 6px 10px;
}

.contact-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  text-decoration: none;
  padding: 5px 9px;
}

.contact-action-link[hidden] {
  display: none;
}

.mobile-resume-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mobile-resume-title {
  font-weight: 600;
  font-size: 14px;
}

.mobile-resume-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

body.fiche-readonly-repliee #panel-identite,
body.fiche-readonly-repliee #panel-electoral {
  display: none;
}

#panneau-recherche.filtres-replies #search-form,
#panneau-recherche.filtres-replies .form-actions {
  display: none !important;
}

#panneau-recherche.filtres-replies .panel-header {
  margin-bottom: 0;
}

/* --- Bouton & Modale QR Code APK (Application Web uniquement) --- */

.apk-top-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-color: var(--accent);
}

.apk-top-btn[hidden] {
  display: none !important;
}

.apk-mini-qr {
  display: inline-flex;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  flex: none;
}

.apk-mini-qr svg {
  width: 100%;
  height: 100%;
  display: block;
}

.apk-qr-dialog {
  width: min(400px, 92vw);
  text-align: center;
}

.apk-qr-large {
  display: flex;
  justify-content: center;
  margin: 14px auto;
}

.apk-qr-large svg {
  width: 210px;
  height: 210px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.apk-qr-url {
  word-break: break-all;
  margin: 8px 0 12px;
}

.apk-qr-actions {
  justify-content: center;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.button-link.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button-link.primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

/* --- Bouton Cible GPS flottant & Repère GPS Mobile --- */

.gps-fab {
  position: absolute;
  right: 14px;
  bottom: 64px;
  z-index: 950;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.gps-fab:hover {
  background: var(--accent);
  color: #fff;
}

.repere-gps-mobile {
  background: none;
  border: none;
}

.gps-marker-pulse {
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gps-marker-dot {
  position: relative;
  z-index: 2;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00b0ff;
  border: 3px solid #ffffff;
  box-shadow: 0 1px 6px rgba(0, 102, 255, 0.75);
}

.gps-marker-halo {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 176, 255, 0.38);
  animation: gps-pulse-anim 1.8s ease-out infinite;
}

@keyframes gps-pulse-anim {
  0% {
    transform: scale(0.5);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* --- Adaptation Mobile / Android (Responsive <= 768px) --- */

@media (max-width: 768px) {
  .btn-text-desktop,
  .brand-sub {
    display: none;
  }

  .btn-text-mobile,
  .mode-label,
  .mobile-only-btn,
  .age-mobile {
    display: inline;
  }

  .age-mobile {
    color: var(--muted);
    font-size: 12px;
  }

  /* Masquer le bouton d'import CSV local et le bouton webcam PC sur mobile */
  #btn-import,
  .apk-btn-text,
  .webcam-btn {
    display: none;
  }

  /* Barre supérieure compacte et fixe en haut, avec bandeau supérieur de sécurité */
  header.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
    max-width: 100vw;
  }

  header.topbar h1 {
    font-size: 15px;
    white-space: nowrap;
  }

  .brand {
    gap: 6px;
    min-width: 0;
  }

  .brand-logo {
    height: 26px;
  }

  .actions {
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: auto;
  }

  .actions button {
    padding: 5px 8px;
    font-size: 12px;
    min-height: 34px;
  }

  /* Espace en bas pour la barre de navigation mobile fixe */
  main {
    padding: 8px 8px 74px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .panel {
    padding: 10px;
    margin-bottom: 10px;
    max-width: 100%;
    overflow: hidden;
  }

  input, select, button, .button-link {
    min-height: 38px;
  }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    gap: 8px;
  }

  /* Si le panneau de filtres est replié sur mobile, son cadre disparaît mais
     garde `overflow: visible` pour ne jamais masquer la barre `.mode-switch` */
  #panneau-recherche {
    overflow: visible;
  }

  #panneau-recherche.filtres-replies {
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    overflow: visible;
  }

  #panneau-recherche .section-title {
    display: none;
  }

  /* Barre d'onglets fixe en bas de l'écran (accessible au pouce, toujours visible, y compris sur les cartes) */
  .mode-switch {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    pointer-events: auto;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 6px 8px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 4px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
  }

  .mode-switch .icon-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 6px;
    min-height: 44px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
  }

  .mode-switch .icon-button[hidden] {
    display: none !important;
  }

  .mode-switch .mode-label {
    font-size: 11px;
    font-weight: 500;
  }

  /* En mode Carte sur mobile : la carte s'arrête au-dessus de la barre d'onglets basse */
  body.mode-carte #vue-carte,
  body.mode-carte #vue-geoportail {
    bottom: 56px;
  }

  /* Tiroir de filtres flottant par-dessus la carte uniquement quand il est déplié.
     IMPORTANT : `transform: none` pour que `.mode-switch` (`position: fixed`) reste
     ancrée au bas de la fenêtre d'affichage et non piégée par un parent transformé ! */
  body.mode-carte #panneau-recherche {
    left: 8px;
    right: 8px;
    width: auto;
    transform: none;
    top: calc(var(--topbar-h, 54px) + 8px);
    z-index: 1500;
  }

  body.mode-carte #search-form,
  body.mode-carte #panneau-recherche .form-actions {
    opacity: 1;
    background: var(--panel);
  }

  body.mode-carte #panneau-recherche:not(.filtres-replies) {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    max-height: calc(100vh - var(--topbar-h, 54px) - 76px);
    overflow-y: auto;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
  }

  body.mode-carte .map-status {
    bottom: 12px;
    left: 8px;
    max-width: calc(100vw - 72px);
    font-size: 12px;
  }

  body.mode-carte .temperature-legende:not([hidden]) {
    bottom: 48px;
    left: 8px;
    max-width: calc(100vw - 16px);
  }

  /* Transformation du tableau de résultats en cartes de contact mobiles */
  #results-table,
  #results-table tbody {
    display: block;
    width: 100%;
  }

  #results-table thead {
    display: none;
  }

  #results-table tbody tr {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    grid-template-areas:
      "photo nom repere"
      "photo prenoms geo"
      "photo adresse adresse";
    align-items: center;
    gap: 2px 8px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    max-width: 100%;
  }

  #results-table tbody td {
    border: none;
    padding: 0;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  #results-table .td-photo {
    grid-area: photo;
    align-self: start;
    padding-top: 2px;
  }

  #results-table .td-Photo .thumb,
  #results-table .td-photo .thumb {
    width: 38px;
    height: 38px;
  }

  #results-table .td-nom {
    grid-area: nom;
    font-weight: 600;
    font-size: 14px;
  }

  #results-table .td-prenoms {
    grid-area: prenoms;
    font-size: 13px;
    color: var(--text);
  }

  #results-table .td-age {
    display: none;
  }

  #results-table .td-adresse {
    grid-area: adresse;
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
  }

  #results-table .td-repere {
    grid-area: repere;
    justify-self: end;
    width: auto;
  }

  #results-table .td-geo {
    grid-area: geo;
    justify-self: end;
    width: auto;
  }

  /* Page Fiche sur mobile */
  .fiche-layout {
    flex-direction: column;
  }

  .photo-search-panel {
    flex: none;
    width: 100%;
    position: static;
    max-height: none;
  }

  .photo-row {
    flex-direction: row;
    align-items: center;
  }

  .photo-preview {
    width: 72px;
    height: 72px;
  }

  .adresse-layout {
    flex-direction: column;
  }

  .adresse-carte {
    flex: none;
    width: 100%;
  }

  .dynamic-row {
    flex-wrap: wrap;
  }
}
