/*
 * map.css — Onglet Carte et personnalisation Leaflet
 *
 * CORRECTIONS D'AFFICHAGE LEAFLET — causes fréquentes de carte grise/vide :
 *
 * 1. HAUTEUR EXPLICITE : Leaflet exige que son conteneur ait une hauteur
 *    définie. "height: 100%" ne fonctionne pas si le parent n'a pas de
 *    hauteur fixe. On utilise position:absolute + inset:0.
 *
 * 2. Z-INDEX DES TUILES : Les tuiles Leaflet ont z-index interne. Si un
 *    parent a un z-index ou un transform, les tuiles peuvent disparaître.
 *    On neutralise les transforms sur #tab-map.
 *
 * 3. OVERFLOW : overflow:hidden sur un parent bloque le rendu des tuiles
 *    qui sortent légèrement du conteneur. On utilise overflow:visible sur
 *    #map-container et on laisse Leaflet gérer le clipping.
 *
 * 4. invalidateSize() : Appelé depuis map.js après chaque changement de
 *    visibilité (switch d'onglet). Indispensable sinon la carte se rend
 *    dans les dimensions de l'onglet caché (0×0).
 */

/* L'onglet carte ne scrolle pas — la carte prend tout l'espace */
#tab-map {
  overflow: hidden;
  /* Pas de transform ici : ça casserait le z-index des tuiles Leaflet */
}

/*
 * Conteneur Leaflet
 * position:absolute + inset:0 = hauteur et largeur calculées par le parent,
 * sans avoir besoin d'une valeur height explicite en px.
 * C'est la méthode la plus fiable pour Leaflet dans un layout flex/grid.
 */
#map-container {
  position: absolute;
  inset: 0;
  /* background sombre pendant le chargement des tuiles */
  background: #1e1e32;
  /*
   * PAS de overflow:hidden ici — Leaflet gère son propre clipping.
   * overflow:hidden forcerait un stacking context qui décale les tuiles.
   */
}

/* Message d'erreur carte */
.map-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-8);
}
.map-error__sub { font-size: var(--text-sm); opacity: .6; }

/* Indicateur de précision GPS */
.map-gps-indicator {
  position: absolute;
  bottom: calc(var(--space-5) + 48px + var(--space-3));
  right: var(--space-5);
  z-index: 10;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

/* ─────────────────────────────────────────────
   OVERRIDES LEAFLET — thème sombre
   Ces règles personnalisent l'apparence de Leaflet
   pour s'intégrer au thème de l'app.
   ───────────────────────────────────────────── */

/* Contrôles zoom */
#map-container .leaflet-control-zoom {
  border: 1px solid var(--color-border-strong) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  overflow: hidden;
}
#map-container .leaflet-control-zoom-in,
#map-container .leaflet-control-zoom-out {
  background: var(--color-bg-secondary) !important;
  color: var(--color-text-primary) !important;
  border: none !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
  font-weight: 400 !important;
  transition: background var(--transition-fast);
}
#map-container .leaflet-control-zoom-in:hover,
#map-container .leaflet-control-zoom-out:hover {
  background: var(--color-bg-elevated) !important;
}
#map-container .leaflet-control-zoom-in {
  border-bottom: 1px solid var(--color-border) !important;
}

/* Attribution */
#map-container .leaflet-control-attribution {
  background: rgba(15, 15, 26, 0.75) !important;
  color: var(--color-text-muted) !important;
  font-family: var(--font-primary) !important;
  font-size: 10px !important;
  border-radius: 4px 0 0 0 !important;
}
#map-container .leaflet-control-attribution a {
  color: var(--color-accent) !important;
}

/* Popups */
#map-container .leaflet-popup-content-wrapper {
  background: var(--color-bg-secondary) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}
#map-container .leaflet-popup-content {
  margin: 0 !important;
  font-family: var(--font-primary) !important;
}
#map-container .leaflet-popup-tip {
  background: var(--color-bg-secondary) !important;
}
#map-container .leaflet-popup-close-button {
  color: var(--color-text-secondary) !important;
  top: 8px !important;
  right: 8px !important;
  width: 24px !important;
  height: 24px !important;
  font-size: 18px !important;
}

/* Cercle de précision GPS (pulsant) */
#map-container .leaflet-accuracy-circle {
  animation: accuracy-pulse 2s ease-in-out infinite;
}
@keyframes accuracy-pulse {
  0%,100% { opacity: .25; }
  50%      { opacity: .5; }
}

/* ─────────────────────────────────────────────
   MARQUEURS POI PERSONNALISÉS
   Créés via L.divIcon dans map.js
   ───────────────────────────────────────────── */
.poi-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-bg-secondary);
  border: 2px solid var(--color-accent);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.poi-marker__number {
  transform: rotate(45deg);
  font-family: var(--font-primary);
  font-size: 11px;
  font-weight: 800;
  color: var(--color-accent);
  line-height: 1;
}
/* Marqueur actif (POI en cours de lecture) */
.poi-marker--active {
  background: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-dim), 0 4px 12px rgba(0,0,0,0.5);
  animation: marker-active-pulse 1.5s ease-in-out infinite;
}
.poi-marker--active .poi-marker__number {
  color: var(--color-bg-primary);
}
@keyframes marker-active-pulse {
  0%,100% { box-shadow: 0 0 0 4px var(--color-accent-dim), 0 4px 12px rgba(0,0,0,.5); }
  50%      { box-shadow: 0 0 0 8px var(--color-accent-muted), 0 4px 12px rgba(0,0,0,.5); }
}

/* Marqueur proche (dans le rayon de déclenchement) */
.poi-marker--nearby {
  border-color: var(--color-success);
  box-shadow: 0 0 0 3px rgba(93, 184, 122, 0.3), 0 4px 12px rgba(0,0,0,.5);
}
.poi-marker--nearby .poi-marker__number {
  color: var(--color-success);
}

/* Popup POI */
.poi-popup {
  min-width: 180px;
  padding: var(--space-3) var(--space-4);
}
.poi-popup__title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-1);
  padding-right: var(--space-5); /* espace pour le bouton fermer */
}
.poi-popup__duration {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}
.poi-popup__btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-accent);
  color: var(--color-bg-primary);
  border-radius: var(--radius-full);
  font-family: var(--font-primary);
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: opacity var(--transition-fast);
}
.poi-popup__btn:active { opacity: .85; }

/* ─── Marker position utilisateur ─── */
.user-marker {
  width: 16px;
  height: 16px;
  background: #4a90e2;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3), 0 2px 6px rgba(0,0,0,.4);
  animation: user-pulse 2s ease-in-out infinite;
}
@keyframes user-pulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(74,144,226,.3), 0 2px 6px rgba(0,0,0,.4); }
  50%      { box-shadow: 0 0 0 8px rgba(74,144,226,.1), 0 2px 6px rgba(0,0,0,.4); }
}
