/*
 * Page Carte : la carte remplit un cadre arrondi à droite du rail, avec la
 * barre d'outils et les panneaux qui flottent par-dessus.
 * Couleurs de catégorie : jetons --category-* de base.css.
 */

.map-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.map-frame {
  position: relative;
  height: 100%;
  padding: 12px 12px 12px 0;
}

.map-canvas {
  position: absolute;
  inset: 12px 12px 12px 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-card);
}

/* --- Barre d'outils flottante --- */
@media (max-height: 600px) and (orientation: landscape) {
  .map-page { display: flex; flex-direction: column; }
  .map-frame { flex: 1; height: auto; min-height: 0; }
}

.map-toolbar {
  position: absolute;
  top: 24px;
  right: 24px;
  left: 64px; /* laisse la place aux boutons de zoom de Leaflet */
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  pointer-events: none; /* la carte reste cliquable entre les boutons */
}

.map-toolbar > * {
  pointer-events: auto;
}

.map-toolbar-actions,
.map-category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: var(--color-surface-glass);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(14px);
}

.map-category-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--color-text-soft);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.map-category-filter:hover {
  background: var(--color-surface-hover);
}

.map-category-filter[aria-checked="true"] {
  background: var(--color-accent-fill);
  border-color: var(--color-accent-border);
  color: var(--color-text);
}

.map-category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.map-category-count {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

/* Couleur de chaque catégorie : pastille du filtre et épingle sur la carte. */
.map-category-atm_site { --category-color: var(--category-atm-site); }
.map-category-tpe_client { --category-color: var(--category-tpe-client); }
.map-category-parts_depot { --category-color: var(--category-parts-depot); }
.map-category-difficult_access { --category-color: var(--category-difficult-access); }
.map-category-other { --category-color: var(--category-other); }

.map-category-dot[class*="map-category-"] {
  background: var(--category-color);
}

/* --- Aide et état, en bas au centre --- */
.map-hint,
.map-status {
  position: absolute;
  bottom: 40px;
  left: 50%;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.map-hint {
  padding: 8px 16px;
  background: var(--color-surface-glass);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(14px);
  color: var(--color-text-soft);
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
}

.map-status {
  bottom: 88px;
  max-width: calc(100% - 48px);
  white-space: normal;
}

/* --- Panneaux latéraux (formulaire, points proches) --- */
.map-side-panel {
  position: absolute;
  top: 84px;
  right: 24px;
  z-index: 1001;
  width: min(380px, calc(100% - 48px));
  max-height: calc(100% - 108px);
  overflow-y: auto;
  background: var(--color-surface);
  box-shadow: var(--shadow-pop);
  animation: map-panel-slide-in 180ms ease-out;
}

@keyframes map-panel-slide-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
}

.map-form-coordinates {
  margin: 0 0 12px;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.map-form-actions {
  display: flex;
  gap: 8px;
}

.nearby-point-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nearby-point-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.nearby-point-button:hover {
  border-color: var(--color-accent-border);
}

.nearby-point-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.nearby-point-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby-point-category {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

/* --- Épingles : goutte colorée par catégorie, icône blanche (L.divIcon) --- */
.map-pin {
  background: none;
  border: 0;
}

.map-pin-body {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--category-color);
  border: 2px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 6px 14px -4px rgb(0 0 0 / 45%);
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}

.map-pin:hover .map-pin-body {
  transform: rotate(-45deg) scale(1.12);
}

.map-pin-body .icon {
  width: 16px;
  height: 16px;
  color: #ffffff;
  transform: rotate(45deg);
}

/* Position de l'utilisateur : point bleu avec halo qui pulse. */
.current-position-marker {
  fill: #0ea5e9;
  stroke: #ffffff;
  stroke-width: 3;
  fill-opacity: 1;
}

/* --- Bulle d'un point (contenu créé avec textContent) --- */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-pop);
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.leaflet-popup-content {
  margin: 14px 16px;
  font-family: var(--font-family);
  font-size: 0.9rem;
}

.leaflet-container a.leaflet-popup-close-button {
  top: 6px;
  right: 6px;
  color: var(--color-text-muted);
}

.map-point-popup-category {
  margin-bottom: 6px;
}

.map-point-popup-title {
  display: block;
  margin-top: 8px;
  font-size: 1.02rem;
  font-weight: 800;
}

.map-point-popup-description {
  margin: 6px 0;
  color: var(--color-text-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.map-point-popup-author {
  margin-top: 8px;
  color: var(--color-text-muted);
  font-size: 0.78rem;
}

.map-point-popup-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

[data-route-panel] .map-form-actions {
  flex-wrap: wrap;
  margin-bottom: 12px;
}

[data-route-panel] .muted {
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

/* --- Contrôles Leaflet aux couleurs du thème --- */
.leaflet-container {
  background: var(--color-surface-muted);
  font-family: var(--font-family);
}

.leaflet-top.leaflet-left {
  top: 12px;
  left: 12px;
}

.leaflet-bar {
  overflow: hidden;
  border: 1px solid var(--color-border) !important;
  border-radius: 14px !important;
  box-shadow: var(--shadow-card) !important;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  width: 36px;
  height: 36px;
  background: var(--color-surface);
  border-bottom-color: var(--color-border);
  color: var(--color-text);
  line-height: 36px;
}

.leaflet-bar a:hover {
  background: var(--color-surface-muted);
}

.leaflet-control-attribution {
  border-top-left-radius: 8px;
}

/* Thème sombre : fond de carte assombri (les tuiles OpenStreetMap n'existent qu'en clair). */
:root[data-theme="dark"] .leaflet-container .maplibregl-canvas {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.6);
}

:root[data-theme="dark"] .leaflet-control-attribution {
  background: rgb(12 20 16 / 80%);
  color: var(--color-text-muted);
}

:root[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--color-accent-strong);
}

/* --- Mobile : la carte occupe tout, la barre défile horizontalement --- */
@media (max-width: 720px) {
  .map-page {
    display: flex;
    flex-direction: column;
  }

  .map-frame {
    flex: 1;
    min-height: 0;
    padding: 0;
  }

  .map-canvas {
    inset: 0;
    border: 0;
    border-radius: 0;
  }

  .map-toolbar {
    top: 10px;
    right: 10px;
    left: 56px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .map-toolbar-actions .button span:last-child {
    display: none;
  }

  .map-toolbar-actions,
  .map-category-filters {
    flex: none;
    flex-wrap: nowrap;
  }

  .map-hint {
    bottom: 24px;
  }

  .map-side-panel {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: 70%;
  }

  .leaflet-top.leaflet-left {
    top: 0;
    left: 0;
  }
}
