/* ZonageCP — écran de l'outil (carte + panneau) */

html, body { height: 100%; }
body { overflow: hidden; }

.mono { font-family: var(--mono); }

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ---------- Volet carte ---------- */

#volet-carte {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
#carte { position: absolute; inset: 0; }
#carte.dessin { cursor: crosshair; }
/* Pendant le dessin, aucun marqueur/vecteur ne doit capter les clics :
   les éléments .leaflet-interactive redéfinissent pointer-events, il faut
   donc les neutraliser individuellement (pas seulement le pane parent). */
#carte.dessin .leaflet-interactive { pointer-events: none !important; cursor: crosshair; }

#legende {
  position: absolute;
  left: 18px;
  bottom: 24px;
  z-index: 600;
  background: var(--panneau);
  border: 1px solid var(--bord);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--ombre-carte);
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 178px;
}
.legende-titre {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--texte-3);
  font-weight: 700;
}
.legende-ligne {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 500;
}
.legende-ligne.sourdine { color: var(--texte-2); }
.legende-dept {
  font-size: 12.5px;
  color: var(--texte-2);
  padding-top: 8px;
  border-top: 1px solid var(--ligne);
}
.legende-dept .trait { width: 13px; height: 3px; background: var(--orange-dept); flex: none; }

.pastille { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.pastille.petite { width: 9px; height: 9px; }
.pastille.carre-ambre { border-radius: 3px; background: var(--orange-dept); }

.invite-titre { font-size: 16px; font-weight: 800; letter-spacing: -0.02em; }
.invite-texte { font-size: 13px; line-height: 1.6; color: var(--texte-2); }

/* ---------- Panneau ---------- */

#panneau {
  flex: 0 0 392px;
  width: 392px;
  min-width: 0;
  background: var(--panneau);
  border-left: 1px solid var(--bord);
  display: flex;
  flex-direction: column;
}

#panneau-entete {
  padding: 20px 20px 18px;
  background: var(--panneau-entete);
  border-bottom: 1px solid var(--bord);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.entete-marque {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.entete-marque a { text-decoration: none; }
.entete-marque a:hover { text-decoration: none; }
#compteur { font-size: 11px; color: var(--texte-2); }

.champ-groupe { display: flex; flex-direction: column; gap: 8px; }
.etiquette { font-size: 11.5px; color: var(--texte-2); font-weight: 600; }

.rangée { display: flex; gap: 8px; align-items: center; }
.rangée.espace { justify-content: space-between; }

#champ-dept {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 13px;
  border: 1px solid var(--bord);
  border-radius: 11px;
  background: var(--panneau);
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--encre);
  text-transform: uppercase;
}
#champ-dept:focus { outline: 2px solid var(--ardoise); outline-offset: -1px; }
#btn-charger { height: 40px; padding: 0 20px; font-size: 13.5px; flex: none; }

#erreur { font-size: 12px; color: var(--rouge); font-weight: 600; min-height: 0; }
#erreur:empty { display: none; }

/* Sélecteur de mode */
.segmente {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panneau);
  border: 1px solid var(--bord);
  border-radius: 999px;
}
.segment {
  flex: 1;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--texte-2);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.segment.actif { background: var(--ardoise); color: #ffffff; font-weight: 700; }

/* Champ rayon (mode Cercle) */
#champ-rayon {
  width: 90px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--bord);
  border-radius: 9px;
  background: var(--panneau);
  font-size: 12.5px;
  color: var(--encre);
  text-align: right;
}
#champ-rayon:focus { outline: 2px solid var(--ardoise); outline-offset: -1px; }
#champ-rayon:disabled { opacity: 0.45; }

/* Outils de tracé */
.outils-trace { gap: 6px; }
.outil {
  height: 38px;
  border: 1px solid var(--bord);
  border-radius: 11px;
  background: var(--panneau);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--encre);
  cursor: pointer;
  padding: 0 14px;
}
.outil:disabled { opacity: 0.45; cursor: default; }
.outil.principal { flex: 1 1 auto; font-weight: 700; }
.outil.principal.actif {
  background: var(--bleu);
  border-color: var(--bleu);
  color: #ffffff;
}
.outil.carre { flex: none; width: 38px; padding: 0; font-size: 15px; }

/* Case à cocher */
.case {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--texte-2);
  cursor: pointer;
  user-select: none;
}
.case input { position: absolute; opacity: 0; pointer-events: none; }
.case .coche {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--ardoise);
  color: #ffffff;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.case input:not(:checked) + .coche { background: var(--panneau); border: 1px solid var(--bord); color: transparent; }
.case input:disabled + .coche { opacity: 0.45; }

#nb-sommets { font-size: 11px; color: var(--texte-2); }
#aide-trace { font-size: 11.5px; color: var(--ardoise); font-weight: 600; }
#aide-trace:empty { display: none; }

/* Coordonnées repliables */
#coords summary {
  font-size: 12px;
  color: var(--ardoise);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
#coords summary::-webkit-details-marker { display: none; }
#coords summary::after { content: ' ▾'; font-size: 10px; }
#coords[open] summary::after { content: ' ▴'; }
#coords textarea {
  width: 100%;
  margin: 10px 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--bord);
  border-radius: 11px;
  font-size: 11.5px;
  color: var(--encre);
  resize: vertical;
  background: var(--panneau);
}
#coords textarea:focus { outline: 2px solid var(--ardoise); outline-offset: -1px; }
.btn.mini { height: 30px; padding: 0 13px; font-size: 11.5px; }

/* ---------- Résultats ---------- */

#resultats {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* État vide : l'invite vit dans la sidebar pour laisser la carte cliquable */
#etat-vide {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 40px 18px;
}

#blocs-zones { display: flex; flex-direction: column; gap: 14px; }

.bloc {
  flex: none;
  border: 1px solid var(--bord);
  border-radius: 14px;
  overflow: hidden;
}
.bloc-entete {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 13px;
  background: #f4f9fd;
}
.bloc-titre { flex: 1 1 auto; font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }

.nom-zone {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--encre);
  padding: 3px 6px;
  margin: -3px 0;
}
.nom-zone:hover { border-color: var(--bord); background: #ffffff; }
.nom-zone:focus { outline: none; border-color: var(--ardoise); background: #ffffff; }

.compteur-cp {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ardoise);
  background: var(--panneau-entete);
  padding: 4px 8px;
  border-radius: 999px;
  flex: none;
}
.compteur-cp.ambre { color: var(--ambre-fg); background: var(--ambre-chip); }

.bloc-chips {
  padding: 12px 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--bord);
  background: var(--chip-bg);
  color: var(--chip-fg);
  cursor: default;
}
.chip:hover { border-color: var(--ardoise); background: #ffffff; }
.chip-conflit {
  border-color: var(--ambre-bord);
  background: var(--ambre-bg);
  color: var(--ambre-fg);
}
.chip-conflit:hover { border-color: var(--ambre-fg); background: #ffffff; }
.vide-zone { font-size: 12px; color: var(--texte-3); }

/* Bloc conflits */
.bloc-ambre { border-color: var(--ambre-bord); background: #fffdf8; }
.bloc-ambre .bloc-entete { background: var(--ambre-bg); }
.bloc-ambre .bloc-titre { color: var(--ambre-fg); }

.conflit {
  padding: 13px;
  border-top: 1px solid var(--ambre-ligne);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.conflit:hover { background: #fdf8ec; }
.conflit-tete { display: flex; align-items: center; gap: 10px; }
.conflit-cp { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.conflit-decompte { font-family: var(--mono); font-size: 11px; color: var(--texte-2); }
.conflit-communes { font-size: 11.5px; line-height: 1.5; color: var(--texte-2); }
.conflit-segments { display: flex; gap: 5px; }
.seg {
  flex: 1;
  height: 30px;
  border: 1px solid var(--bord);
  border-radius: 999px;
  background: #ffffff;
  color: var(--chip-fg);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg.seg-both { flex: none; padding: 0 12px; }
.seg.actif { color: #ffffff; }

/* Bloc communes forcées */
.forcee {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-top: 1px solid var(--ligne);
  min-width: 0;
}
.forcee:hover { background: var(--fond-doux); }
.forcee-nom {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zone-forcee { flex: none; font-size: 11px; color: var(--texte-2); }
.btn-auto {
  flex: none;
  border: 1px solid var(--bord);
  background: #ffffff;
  border-radius: 999px;
  height: 25px;
  padding: 0 10px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--texte-2);
  cursor: pointer;
}
.btn-auto:hover { border-color: var(--ardoise); color: var(--ardoise); }

/* ---------- Pied ---------- */

#panneau-pied {
  flex: none;
  padding: 15px 20px;
  border-top: 1px solid var(--bord);
  background: var(--fond-doux);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
#panneau-pied .rangée { gap: 7px; }
.btn.pied {
  flex: 1;
  height: 36px;
  font-size: 12.5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn.pied-large { height: 42px; font-size: 13.5px; }

/* ---------- Écrans étroits ---------- */

@media (max-width: 900px) {
  body { overflow: auto; }
  #app { flex-direction: column; height: auto; }
  #volet-carte { height: 55vh; min-height: 340px; flex: none; }
  #panneau {
    flex: none;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--bord);
  }
  #resultats { overflow-y: visible; }
}
