/* ============================================================
   Carte territoriale — composant atomique réutilisable
   v2.0 (19/05/2026)
   ============================================================
   v2.0 :
     - Punaises visibles (cercle bordeaux + dot blanc central)
     - Hitbox invisible séparée pour confort tactile
     - Variante highlight (Gommecourt/Clachaloze) : pas de
       punaise visible, seulement une hitbox élargie
     - Hover : élargissement + couleur plus saturée
   ============================================================ */

/* --- Container racine ------------------------ */
.carte-territoriale {
  position: relative;
  display: block;
  width: 100%;
  max-width: 901px;
  margin: 1.5rem auto;
  background: #f4f1ea;
  border: 1px solid #d8d2c4;
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}

/* --- Viewport : la hauteur est définie par l'image --- */
.carte-territoriale__viewport {
  position: relative;
  width: 100%;
  transform-origin: 0 0;
  transition: transform 200ms cubic-bezier(.2, .8, .3, 1);
  cursor: grab;
  will-change: transform;
  font-size: 0;
}
.carte-territoriale__viewport.is-dragging {
  cursor: grabbing;
  transition: none;
}

.carte-territoriale__fond {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.carte-territoriale__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --- Labels surchargés (Gommecourt / Clachaloze) --- */
.carte-territoriale__label-cache {
  fill: #ffffff;
  fill-opacity: 0.75;
}
.carte-territoriale__label-text {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 25px;
  fill: #501919;
  text-anchor: middle;
  dominant-baseline: middle;
  filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.4));
  pointer-events: none;
}
.carte-territoriale__label-text--ajoute {
  paint-order: stroke fill;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-opacity: 0.85;
  stroke-linejoin: round;
}

/* --- Labels style IGN pour communes invisibles (non-highlight) ---
   Discrets, calés sur le style des labels IGN authentiques. */
.carte-territoriale__label-ign-like {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: 400;
  fill: #3c2820;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke fill;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-opacity: 0.85;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ============================================================
   PUNAISES (marqueurs visibles)
   ============================================================ */

.carte-territoriale__marker {
  cursor: pointer;
  pointer-events: all;
}
.carte-territoriale__marker:focus { outline: none; }

/* Cercle extérieur bordeaux */
.carte-territoriale__marker-bg {
  fill: #501919;
  stroke: #ffffff;
  stroke-width: 2;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
  transition: fill 150ms ease, transform 150ms ease;
  transform-origin: center;
  transform-box: fill-box;
}

/* Point central blanc */
.carte-territoriale__marker-dot {
  fill: #ffffff;
  pointer-events: none;
  transition: transform 150ms ease;
  transform-origin: center;
  transform-box: fill-box;
}

/* Hitbox invisible (zone tactile élargie) */
.carte-territoriale__marker-hit {
  fill: transparent;
  pointer-events: all;
}

/* --- Hover et focus : effet "vivant" --- */
.carte-territoriale__marker:hover .carte-territoriale__marker-bg,
.carte-territoriale__marker:focus-visible .carte-territoriale__marker-bg {
  fill: #6b2222;
  transform: scale(1.25);
}
.carte-territoriale__marker:hover .carte-territoriale__marker-dot,
.carte-territoriale__marker:focus-visible .carte-territoriale__marker-dot {
  transform: scale(1.25);
}
.carte-territoriale__marker:focus-visible .carte-territoriale__marker-bg {
  stroke: #468ac8;
  stroke-width: 3;
}

/* --- Variante highlight (Gommecourt, Clachaloze) ---
   Pas de punaise visible : juste la hitbox élargie centrée
   sur le label, qui sert de zone tactile pour le clic. */
.carte-territoriale__marker--highlight {
  cursor: pointer;
}

/* --- Variante filtrée (V2 : grisé doux) --- */
.carte-territoriale__marker--filtered {
  pointer-events: none;
  opacity: 0.3;
}

/* ============================================================
   CONTRÔLES ZOOM
   ============================================================ */

.carte-territoriale__controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
  font-size: 1rem;
}
.carte-territoriale__btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #b8a87a;
  border-radius: 4px;
  color: #501919;
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: background 150ms ease, transform 100ms ease;
}
.carte-territoriale__btn:hover { background: #ffffff; }
.carte-territoriale__btn:active { transform: scale(0.95); }
.carte-territoriale__btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   ATTRIBUTION
   ============================================================ */

.carte-territoriale__attribution {
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 5;
  margin: 0;
  padding: 4px 10px;
  font-size: 0.7rem;
  color: #555;
  background: rgba(255, 255, 255, 0.88);
  border-top-left-radius: 4px;
  pointer-events: auto;
}
.carte-territoriale__attribution a {
  color: #501919;
  text-decoration: none;
}
.carte-territoriale__attribution a:hover { text-decoration: underline; }

/* ============================================================
   POPOVER
   ============================================================ */

.carte-territoriale__popover {
  position: absolute;
  top: -9999px;
  left: -9999px;
  z-index: 20;
  background: #ffffff;
  border: 1px solid #b8a87a;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  padding: 12px;
  max-width: 280px;
  font-size: 1rem;
}
.carte-territoriale__popover[hidden] { display: none; }

.carte-territoriale__popover__close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}
.carte-territoriale__popover__close:hover { color: #501919; }

.carte-territoriale__popover__image {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 3px;
  margin-bottom: 10px;
  background: #f4f1ea;
  display: block;
}
.carte-territoriale__popover__title {
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 1.1rem;
  color: #501919;
  margin: 0 0 4px;
  padding-right: 28px;
}
.carte-territoriale__popover__subtitle {
  font-size: 0.85rem;
  color: #666;
  margin: 0 0 10px;
  font-style: italic;
}
.carte-territoriale__popover__link,
.carte-territoriale__popover__link:link,
.carte-territoriale__popover__link:visited,
.carte-territoriale__popover__link:hover,
.carte-territoriale__popover__link:focus,
.carte-territoriale__popover__link:active {
  display: inline-block;
  padding: 6px 12px;
  background: #501919;
  color: #ffffff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
}
.carte-territoriale__popover__link:hover { background: #6b2222; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1023px) {
  .carte-territoriale__btn { width: 32px; height: 32px; font-size: 18px; }
}

@media (max-width: 767px) {
  .carte-territoriale { max-width: 100%; }
  .carte-territoriale__controls { top: 8px; right: 8px; }
  .carte-territoriale__popover {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    border-radius: 12px 12px 0 0;
    padding: 16px;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
  }
  .carte-territoriale__attribution {
    font-size: 0.65rem;
    padding: 3px 8px;
  }
}

/* ============================================================
   ACCESSIBILITÉ
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .carte-territoriale__viewport,
  .carte-territoriale__marker-bg,
  .carte-territoriale__marker-dot {
    transition: none;
  }
}
