/* ==========================================================================
   GEA-Map Guinée — Page Carte (P10, refonte P30)
   --------------------------------------------------------------------------
   Layout sidebar + carte plein écran. La sidebar disparaît sous lg sur
   mobile (largeur d'écran réduite : on privilégie la carte).

   P30 — refonte UX : support du thème sombre (data-bs-theme="dark"),
   recherche de site, chips de filtres actifs, spinner de chargement,
   barre d'outils. Toutes les couleurs passent par des tokens pour rester
   cohérentes en clair/sombre.
   ========================================================================== */

:root {
  --map-surface: #ffffff;
  --map-surface-muted: #f8f9fa;
  --map-border: var(--bs-border-color, #dee2e6);
  --map-canvas-bg: #e6e9ec;
  --map-text: #212529;
  --map-text-muted: #6c757d;
  --map-shadow: rgba(0, 0, 0, .15);
}

[data-bs-theme="dark"] {
  --map-surface: #1f2937;
  --map-surface-muted: #111827;
  --map-border: #374151;
  --map-canvas-bg: #0b1220;
  --map-text: #e5e7eb;
  --map-text-muted: #9ca3af;
  --map-shadow: rgba(0, 0, 0, .55);
}

.map-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 4rem); /* place pour header + footer Bootstrap */
}

@media (min-width: 992px) {
  .map-page {
    flex-direction: row;
    min-height: calc(100vh - 8rem);
  }
}

.map-sidebar {
  background-color: var(--map-surface);
  color: var(--map-text);
  border-right: 1px solid var(--map-border);
  flex: 0 0 320px;
  max-width: 100%;
  overflow-y: auto;
}

[dir="rtl"] .map-sidebar {
  border-right: none;
  border-left: 1px solid var(--map-border);
}

.map-sidebar .border-bottom {
  border-color: var(--map-border) !important;
}

.map-container {
  flex: 1 1 auto;
  min-height: 60vh;
  background-color: var(--map-canvas-bg);
  position: relative;
}

@media (min-width: 992px) {
  .map-sidebar {
    height: calc(100vh - 8rem);
  }
  .map-container {
    height: calc(100vh - 8rem);
  }
}

/* ----- Recherche de site (P30) ------------------------------------------- */
.map-search {
  position: relative;
}
.map-search-results {
  position: absolute;
  z-index: 1100;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  background: var(--map-surface);
  border: 1px solid var(--map-border);
  border-radius: .375rem;
  box-shadow: 0 4px 16px var(--map-shadow);
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: .25rem 0;
  list-style: none;
}
.map-search-results:empty,
.map-search-results[hidden] { display: none; }
.map-search-result {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: none;
  padding: .4rem .75rem;
  color: var(--map-text);
  font-size: .85rem;
  cursor: pointer;
}
.map-search-result:hover,
.map-search-result.active {
  background: var(--unicef-blue-soft, #d8f1fa);
  color: var(--unicef-dark, #00355A);
}
[data-bs-theme="dark"] .map-search-result:hover,
[data-bs-theme="dark"] .map-search-result.active {
  background: rgba(96, 165, 250, .2);
  color: #fff;
}
.map-search-result .code {
  font-size: .72rem;
  color: var(--map-text-muted);
}

/* ----- Chips de filtres actifs (P30) ------------------------------------- */
.map-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .5rem;
}
.map-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .15rem .5rem;
  border-radius: 1rem;
  background: var(--unicef-blue-soft, #d8f1fa);
  color: var(--unicef-dark, #00355A);
  font-size: .72rem;
  font-weight: 600;
  border: 1px solid transparent;
}
[data-bs-theme="dark"] .map-chip {
  background: rgba(96, 165, 250, .18);
  color: #cfe3ff;
}
.map-chip button {
  border: 0;
  background: none;
  padding: 0;
  line-height: 1;
  color: inherit;
  cursor: pointer;
  opacity: .7;
}
.map-chip button:hover { opacity: 1; }

/* ----- Marqueur DivIcon custom (couleur du type d'intervention) ---------- */
.gea-marker {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gea-marker .gea-marker-inner {
  transform: rotate(45deg);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
}

/* Marqueur multi-types : liseré épaissi pour signaler la présence de
   plusieurs types sur le même site (P30). */
.gea-marker.is-multi {
  border-width: 3px;
}

[data-bs-theme="dark"] .gea-marker {
  border-color: #111827;
}

/* Cluster : conserve les classes Leaflet par défaut, on rajoute juste un
   accent UNICEF sur le contour. */
.marker-cluster {
  border: 2px solid var(--unicef-blue);
}

/* ----- Popup ----- */
.leaflet-popup-content {
  margin: 12px;
  min-width: 220px;
}

/* Thème sombre des popups / contrôles Leaflet (P30). */
[data-bs-theme="dark"] .leaflet-popup-content-wrapper,
[data-bs-theme="dark"] .leaflet-popup-tip {
  background: var(--map-surface);
  color: var(--map-text);
}
[data-bs-theme="dark"] .leaflet-popup-content a.btn-primary { color: #fff; }
[data-bs-theme="dark"] .leaflet-bar a,
[data-bs-theme="dark"] .leaflet-control-layers-toggle {
  background-color: var(--map-surface);
  color: var(--map-text);
  border-color: var(--map-border);
}
[data-bs-theme="dark"] .leaflet-bar a:hover {
  background-color: var(--map-surface-muted);
}
[data-bs-theme="dark"] .leaflet-control-layers,
[data-bs-theme="dark"] .leaflet-control-attribution {
  background: var(--map-surface);
  color: var(--map-text-muted);
}
[data-bs-theme="dark"] .leaflet-control-attribution a { color: var(--bs-link-color, #60a5fa); }
/* Atténue la luminosité des tuiles OSM en mode sombre pour le confort. */
[data-bs-theme="dark"] .leaflet-tile-pane { filter: brightness(.78) contrast(1.05); }

.gea-popup { min-width: 240px; }
.gea-popup-title {
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.25;
  color: var(--map-text);
}
.gea-popup-meta {
  font-size: .75rem;
  color: var(--map-text-muted);
  margin-bottom: .35rem;
}
.gea-popup-tag {
  display: inline-block;
  background: var(--unicef-blue-soft, #d8f1fa);
  color: var(--unicef-dark, #00355A);
  border-radius: .25rem;
  padding: 0 .35rem;
  font-weight: 600;
}
[data-bs-theme="dark"] .gea-popup-tag {
  background: rgba(96, 165, 250, .2);
  color: #cfe3ff;
}
.gea-popup-row {
  font-size: .8rem;
  margin: .15rem 0;
  color: var(--map-text);
}
.gea-popup-row .bi { color: var(--unicef-blue); margin-inline-end: .15rem; }
.gea-popup-actions {
  display: flex;
  gap: .4rem;
  margin-top: .6rem;
}
.gea-popup-actions .btn { flex: 1 1 auto; white-space: nowrap; }

.gea-popup-photo {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: .25rem;
  margin-bottom: .5rem;
}

.gea-popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin: .5rem 0;
}

.gea-popup-badge {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: .25rem;
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ----- Filtres type : ligne combinée légende + toggle (P30) -------------- */
.type-filter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.type-filter {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  border: 1px solid transparent;
  background: none;
  border-radius: .375rem;
  padding: .3rem .4rem;
  cursor: pointer;
  color: var(--map-text);
  font-size: .82rem;
  text-align: start;
  transition: background-color .12s ease, opacity .12s ease;
}
.type-filter:hover { background: var(--map-surface-muted); }
.type-filter .legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .2);
  flex: 0 0 auto;
}
.type-filter .type-label { flex: 1 1 auto; }
.type-filter .type-count {
  font-size: .72rem;
  color: var(--map-text-muted);
  font-variant-numeric: tabular-nums;
}
.type-filter[aria-pressed="false"] {
  opacity: .45;
}
.type-filter[aria-pressed="false"] .legend-swatch {
  background: transparent !important;
  border-style: dashed;
}

/* ----- Spinner de chargement (P30) --------------------------------------- */
.map-loading {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: none;
  align-items: center;
  gap: .5rem;
  background: var(--map-surface);
  color: var(--map-text);
  padding: .4rem .85rem;
  border-radius: 2rem;
  box-shadow: 0 2px 10px var(--map-shadow);
  font-size: .82rem;
}
.map-loading.is-active { display: inline-flex; }
.map-loading .spinner-border { width: 1rem; height: 1rem; border-width: .15em; }

/* ----- Empty state overlay ----- */
.map-empty-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--map-surface);
  color: var(--map-text);
  padding: 1.5rem 2rem;
  border-radius: .5rem;
  box-shadow: 0 2px 12px var(--map-shadow);
  text-align: center;
  max-width: 340px;
  z-index: 1000;
  pointer-events: none;
}
