/* Carte Blocus — feuille principale. Mobile d'abord ; desktop à partir de 900 px.
   Couleurs et formes : variables de tokens.css uniquement. */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police);
  font-size: 15px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--texte); }
a:hover { color: var(--accent); }
p { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--texte); outline-offset: 2px; }

.secondaire { color: var(--texte-2); }

/* ---------- Mise en page ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "entete" "controles" "carte" "barre";
  overflow: hidden;
}

/* ---------- En-tête ---------- */

.entete {
  grid-area: entete;
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--bordure);
}

.logo { display: flex; align-items: center; min-height: var(--cible-tactile); }
.logo-carre { fill: var(--accent); }
.logo-texte {
  fill: var(--texte);
  font-family: var(--police);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.entete-actions { display: flex; gap: 2px; }

.icone {
  width: var(--cible-tactile);
  height: var(--cible-tactile);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--texte);
  border-radius: var(--rayon-s);
}

/* Thème : icône du choix en cours (data-theme posé par theme-init.js avant l'affichage). */
#bouton-affichage svg { display: none; }
:root[data-theme="jour"] #bouton-affichage .theme-jour,
:root[data-theme="nuit"] #bouton-affichage .theme-nuit,
:root:not([data-theme]) #bouton-affichage .theme-auto { display: block; }

/* ---------- Contrôles ---------- */

.controles {
  grid-area: controles;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 8px;
}

.segmente {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  border: 1px solid var(--texte);
  border-radius: var(--rayon-m);
  overflow: hidden;
}

.segmente button {
  min-height: var(--cible-tactile);
  border: 0;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

.segmente button[aria-pressed="true"] { background: var(--texte); color: var(--fond); }

/* Mobile : période choisie aux flèches de la ligne de date (passé ‹ aujourd'hui › À venir). */
.controles > .segmente { display: none; }

.ligne-date {
  display: flex;
  align-items: center;
  min-height: 28px;
}

.date-libelle { flex: 1; font-size: 14px; color: color-mix(in srgb, var(--texte-2), var(--texte)); }
.ligne-date:has(.fleche:not([hidden])) .date-libelle { text-align: center; }

.fleche {
  width: var(--cible-tactile);
  height: var(--cible-tactile);
  border: 0;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--texte);
}

.fleche:disabled { opacity: 0.3; cursor: default; }

/* 28 px : exception aux 44 px (cadrage §3.1), pour ne pas grandir la ligne de date. */
.info-date {
  width: 28px;
  height: 28px;
  border: 0;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--texte-2);
}

.info-date[aria-expanded="true"] { color: var(--texte); }

.mention-debut { font-size: 12px; color: var(--texte-2); }

.puces { display: flex; gap: 8px; flex-wrap: wrap; }

.puces button {
  min-height: var(--cible-tactile);
  padding: 0 14px;
  border: 1px solid var(--bordure);
  border-radius: 22px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

.puces button[aria-pressed="true"] { background: var(--texte); color: var(--fond); border-color: var(--texte); }

/* Mobile : catégories de l'accueil en segmenté pleine largeur, tiers égaux. */
.controles .puces {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 0;
  border: 1px solid var(--texte);
  border-radius: var(--rayon-m);
  overflow: hidden;
}
/* 35 px : exception aux 44 px (cadrage §3.1), pour laisser la hauteur à la carte. */
.controles .puces button { min-height: 35px; padding: 0; border: 0; border-radius: 0; }

/* ---------- Carte ---------- */

/* Mobile : onglets de vue, carte, bande légende + territoire, empilés. Desktop : tout sur la carte. */
.zone-carte {
  grid-area: carte;
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "vues" "plan" "bas";
  background: var(--carte-mer);
}

.carte { grid-area: plan; position: relative; min-height: 0; }

.carte-boutons {
  grid-area: plan;
  align-self: start;
  justify-self: end;
  position: relative;
  z-index: 1;
  margin: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Mobile : zoom au pincement. */
#zoom-plus, #zoom-moins { display: none; }

.bouton-carte {
  width: var(--cible-tactile);
  height: var(--cible-tactile);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-m);
  background: var(--surface);
  font-size: 22px;
}

/* Bascule de vue de la carte : Points, Zones, Densité. Mobile : onglets au-dessus de la carte. */
.segmente-carte {
  grid-area: vues;
  border: 0;
  border-bottom: 1px solid var(--bordure);
  border-radius: 0;
  background: var(--fond);
}
.segmente-carte button { border-bottom: 2px solid transparent; background: none; color: var(--texte-2); }
.segmente-carte button[aria-pressed="true"] { border-bottom-color: var(--texte); background: none; color: var(--texte); }

.bouton-pilule {
  min-height: var(--cible-tactile);
  padding: 0 12px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-m);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
}

/* Légende puis choix du territoire ; la liste s'ouvre vers le haut.
   Mobile : bande sous la carte, territoire à droite. Desktop : en bas à gauche sur la carte. */
.carte-bas-gauche {
  grid-area: bas;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--bordure);
  background: var(--fond);
}

.territoires { position: relative; flex-shrink: 0; }

.liste-territoires {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 2;
  min-width: 200px;
  margin: 0;
  padding: 4px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.15);
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-l);
}

.liste-territoires button {
  width: 100%;
  min-height: var(--cible-tactile);
  padding: 0 12px;
  border: 0;
  border-radius: var(--rayon-s);
  background: none;
  text-align: left;
  font-size: 14px;
}

.liste-territoires button:hover { background: var(--fond); }

/* Mobile : légende en ligne, sans cadre ; le dégradé de densité reste en colonne. */
.legende {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}

.legende p { display: flex; align-items: center; gap: 6px; }
.legende-bloc { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legende-bloc:has(.legende-degrade) { flex-direction: column; }
.legende-titre { flex-basis: 100%; font-weight: 600; }
.legende-case { flex-shrink: 0; width: 14px; height: 10px; border-radius: 2px; }
.legende-degrade { display: block; width: 150px; height: 8px; border-radius: 4px; }
.legende-bornes { width: 150px; justify-content: space-between; color: var(--texte-2); font-size: 11px; }
.legende-zone { flex-basis: 100%; }
.legende .secondaire { font-size: 11px; padding-top: 2px; }

.pastille {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.niv-0 { background: var(--niv-0); }
.niv-1 { background: var(--niv-1); }
.niv-2 { background: var(--niv-2); }
.niv-3 { background: var(--niv-3); }
.niv-4 { background: var(--niv-4); box-shadow: inset 0 0 0 2px var(--niv-4-contour); }
.pale { opacity: var(--opacite-non-confirme); }

/* Contrôles natifs MapLibre conservés : attribution seulement */
.maplibregl-ctrl.maplibregl-ctrl-attrib { font-size: 11px; background: var(--surface); color: var(--texte-2); }
.maplibregl-ctrl-attrib a { color: var(--texte-2); }
.maplibregl-ctrl-attrib-button { filter: var(--filtre-icone, none); }
:root[data-theme="nuit"] { --filtre-icone: invert(1); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="jour"]) { --filtre-icone: invert(1); } }

/* ---------- Barre basse ---------- */

.barre-basse {
  grid-area: barre;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 16px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--bordure);
  background: var(--surface);
}

/* Mobile : nombre et libellé sur une ligne, détail dessous, aligné à gauche. */
.resume { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; gap: 2px 8px; }
.resume-nombre { font-size: 32px; font-weight: 800; line-height: 1; }
.resume-texte { display: contents; font-size: 15px; line-height: 1.3; }
.resume-texte br { display: none; }
.resume-texte .secondaire { grid-column: 1 / -1; font-size: 13px; }

/* Mobile : bouton rond « + » sur la ligne du résumé ; libellé lu par les lecteurs d'écran. */
.bouton-principal {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 16px;
  font-weight: 700;
}

.bouton-principal-texte {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mention { grid-column: 1 / -1; font-size: 11px; color: var(--texte-2); text-align: center; }
.mention a { color: var(--texte-2); }

/* ---------- Fiche : panneau bas (mobile) ---------- */

.voile {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(0 0 0 / 0.35);
}

.fiche {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--rayon-feuille) var(--rayon-feuille) 0 0;
  box-shadow: 0 -4px 24px rgb(0 0 0 / 0.18);
}

.fiche-haut {
  position: relative;
  display: flex;
  justify-content: flex-end;
  padding: 6px 8px 0;
}

.poignee {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: var(--bordure);
}

.fiche-contenu {
  overflow-y: auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.fiche-type {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--texte-2);
}

.fiche-nom { margin: 4px 0 2px; font-size: 22px; font-weight: 800; line-height: 1.2; }
.fiche-lieu { font-size: 14px; color: var(--texte-2); }

.fiche-bloc { display: flex; flex-direction: column; gap: 8px; }
.fiche-bloc + .fiche-bloc { padding-top: 16px; border-top: 1px solid var(--bordure); }
.fiche-titre { font-size: 13px; color: var(--texte-2); }

.statut { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.statut-niveau { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.statut-niveau .pastille { width: 16px; height: 16px; }
.statut-quand { font-size: 13px; color: var(--texte-2); }
.avis-partages { font-size: 13px; color: var(--texte-2); }

.voix-ligne {
  display: grid;
  grid-template-columns: 9em 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.voix-barre { height: 8px; border-radius: 4px; background: var(--fond); overflow: hidden; }
.voix-barre span { display: block; height: 100%; border-radius: 4px; }

.puce-neutre {
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: 16px;
  background: var(--fond);
  border: 1px solid var(--bordure);
  font-size: 13px;
}

.puce-neutre.non-confirme { border-style: dashed; color: var(--texte-2); }

/* Indiquer un incident : bouton-lien qui ouvre trois boutons (même forme que le vote). */
.incident-choix { display: flex; flex-direction: column; gap: 8px; }
.incident-panneau { display: flex; flex-direction: column; gap: 8px; }
.incident-aide { font-size: 13px; }

.annonce { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.bouton-lien {
  align-self: flex-start;
  min-height: var(--cible-tactile);
  padding: 0;
  border: 0;
  background: none;
  font-size: 14px;
  text-decoration: underline;
}

.historique { display: flex; gap: 6px; }
.historique-jour { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--texte-2); }
.historique-case { width: 28px; height: 20px; border-radius: 4px; }
.historique-case.vide { box-shadow: inset 0 0 0 1px var(--bordure); }

.fiche-pied { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--texte-2); }
.fiche-pied a { color: var(--texte-2); }

/* Vote : cinq boutons, niveau affiché encadré (cadrage §3.3). */
.vote-entete { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.vote-titre { font-size: 15px; font-weight: 700; }
.vote-date {
  min-height: var(--cible-tactile);
  max-width: 55%;
  padding: 0 8px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-s);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 14px;
}
.vote-boutons { display: flex; flex-direction: column; gap: 6px; }
.vote-bouton {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-m);
  background: var(--surface);
  font-size: 15px;
  text-align: left;
}
.vote-bouton.affiche { padding: 0 11px; border: 2px solid var(--texte); }
.vote-bouton:disabled { opacity: 0.6; cursor: default; }
.vote-bouton .pastille { width: 14px; height: 14px; }
.vote-etiquette { margin-left: auto; font-size: 12px; color: var(--texte-2); }
.vote-etiquette + .vote-etiquette { margin-left: 8px; }
.vote-message { font-size: 13px; color: var(--texte-2); }
.vote-message:empty { display: none; }

/* ---------- Recherche d'un établissement (même panneau que la fiche) ---------- */

.recherche { height: 85dvh; }
.recherche .fiche-contenu { gap: 10px; }
.recherche-titre { margin: 0; font-size: 18px; font-weight: 700; }
.recherche-saisie {
  min-height: var(--cible-tactile);
  padding: 0 12px;
  border: 1px solid var(--texte);
  border-radius: var(--rayon-m);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 16px; /* 16 px : pas de zoom automatique sur iOS */
}
.recherche-etat { font-size: 13px; }
.recherche-etat:empty { display: none; }
.recherche-resultats { margin: 0; padding: 0; list-style: none; }
.resultat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  min-height: var(--cible-tactile);
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--bordure);
  background: none;
  text-align: left;
}
.resultat-nom { font-size: 15px; font-weight: 600; }
.resultat .secondaire { font-size: 13px; }
.resultat:hover .resultat-nom { color: var(--accent); }

/* Widget Turnstile : visible seulement si Cloudflare demande une interaction. */
.turnstile { display: flex; justify-content: center; }
.turnstile:not(:empty) { padding: 0 16px 12px; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .app {
    grid-template-columns: 380px 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "entete carte"
      "controles carte"
      "barre carte";
  }

  .entete, .controles, .barre-basse { border-right: 1px solid var(--bordure); }

  .controles > .segmente { display: grid; }
  .controles .puces { display: flex; gap: 8px; border: 0; border-radius: 0; overflow: visible; }
  .controles .puces button { min-height: var(--cible-tactile); padding: 0 14px; border: 1px solid var(--bordure); border-radius: 22px; }
  .controles .puces button[aria-pressed="true"] { border-color: var(--texte); }
  .bouton-pilule { padding: 0 14px; border-radius: 22px; }

  .resume { display: flex; gap: 8px; }
  .resume-texte { display: block; }
  .resume-texte br { display: revert; }

  .bouton-principal { width: auto; height: auto; min-height: 52px; display: block; border-radius: var(--rayon-l); }
  .bouton-principal svg { display: none; }
  .bouton-principal-texte { position: static; width: auto; height: auto; overflow: visible; clip-path: none; white-space: normal; }

  .zone-carte { display: block; }
  .carte { position: absolute; inset: 0; }
  .carte-boutons { position: absolute; right: 10px; top: 10px; margin: 0; }
  #zoom-plus, #zoom-moins { display: flex; }

  .segmente-carte { position: absolute; left: 10px; top: 10px; border: 1px solid var(--bordure); border-radius: 22px; background: none; }
  .segmente-carte button { padding: 0 12px; border-bottom: 0; background: var(--surface); color: var(--texte); font-size: 13px; }
  .segmente-carte button[aria-pressed="true"] { background: var(--texte); color: var(--fond); }

  .carte-bas-gauche {
    position: absolute;
    left: 10px;
    bottom: 28px;
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
    border: 0;
    background: none;
  }
  .liste-territoires { left: 0; right: auto; }

  .legende {
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon-m);
  }
  .legende-bloc { flex-direction: column; flex-wrap: nowrap; gap: 5px; }
  .legende-titre, .legende-zone { flex-basis: auto; max-width: 13em; }
  .legende-bornes { width: auto; }
  .barre-basse { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding-top: 20px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); border-top: 0; background: var(--fond); }
  .mention { margin-top: auto; }

  .voile { display: none !important; }

  .fiche {
    position: absolute;
    left: auto;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--bordure);
    box-shadow: -4px 0 24px rgb(0 0 0 / 0.12);
  }

  .recherche { height: auto; }
  .poignee { display: none; }
  .zone-carte:has(.fiche:not([hidden])) .carte-boutons { right: 410px; }
}
