/* ============================================================================
 * carte-core.css — Mise en page du coeur de carte Strasbourg Mobilité
 * Mobile-first, plein écran, mode sombre (prefers-color-scheme), contrôles.
 * Ne stylise QUE la coquille + la carte. Recherche / panneau / intelligence
 * ont leurs propres feuilles.
 * ========================================================================== */

:root {
  --sm-green: #16a34a;
  --sm-green-dark: #128040;
  --sm-bg: #ffffff;
  --sm-surface: #ffffff;
  --sm-text: #111827;
  --sm-muted: #6b7280;
  --sm-border: #e5e7eb;
  --sm-shadow: 0 6px 24px rgba(0, 0, 0, .12);
  --sm-radius: 14px;
  --sm-ctrl: 44px; /* zone tactile minimale */
}

/* ------------------------------------------------------------------ Layout */

.sm-carte-main {
  width: 100%;
  margin: 0;
  color: var(--sm-text);
}

/* Titre + intro : réellement visibles (indexables, pas de cloaking) mais compacts */
.sm-seo-intro {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px 10px;
}
.sm-seo-intro h1 {
  font-size: clamp(1.25rem, 2.4vw, 1.9rem);
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 6px;
  /* Couleur fixe (pas la variable themée) : l'intro reste sur fond blanc même en
     mode sombre — sinon --sm-text passe en clair -> texte blanc sur blanc (1,1:1). */
  color: #1f2937;
}
.sm-seo-intro p {
  font-size: .9rem;
  line-height: 1.5;
  color: #4b5563; /* fixe : contraste AA sur fond blanc, même en mode sombre */
  margin: 0;
  /* Sur mobile on limite la hauteur pour laisser la place à la carte */
  max-height: 3.2em;
  overflow: hidden;
}
@media (min-width: 768px) {
  .sm-seo-intro p { max-height: none; }
}

/* Conteneur applicatif plein écran */
.sm-app {
  position: relative;
  width: 100%;
  height: 72vh;
  min-height: 420px;
  overflow: hidden;
  background: #e8eef1;
}
@media (min-width: 768px) {
  .sm-app { height: 78vh; max-height: 900px; }
}

/* Badge P+R : pastille chiffrée (places libres) colorée selon la disponibilité */
.sm-pr-icon { background: none; border: none; }
.sm-pr-badge {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 13px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}

/* La carte occupe tout le conteneur.
 * z-index:0 = crée un contexte d'empilement isolé : les panes internes de
 * Leaflet (tuiles z200, marqueurs z600, popups z700...) restent CONFINÉS sous
 * la carte et ne recouvrent plus les overlays frères (recherche, chips,
 * légende) qui ont un z-index > 0. Sans ça, la carte masque les contrôles. */
.sm-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #e8eef1;
}
.sm-map:focus { outline: none; }

/* -------------------------------------------------------- Chips de couches */

.sm-layers {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 30;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: calc(100% - 24px);
}
/* Quand la recherche est en haut, on décale les chips sous la barre sur mobile */
@media (max-width: 520px) {
  .sm-layers { top: 64px; }
}

.sm-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--sm-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .95);
  color: var(--sm-muted);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--sm-shadow);
  transition: background .2s, color .2s, border-color .2s, transform .1s;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.sm-chip:hover { transform: translateY(-1px); }
.sm-chip i { font-size: .8rem; }
.sm-chip.is-active {
  background: var(--sm-green);
  border-color: var(--sm-green);
  color: #fff;
}

/* --------------------------------------------------- Bouton « autour de moi » */

.sm-locate {
  position: absolute;
  right: 12px;
  bottom: 96px; /* au-dessus des contrôles de zoom */
  z-index: 30;
  width: var(--sm-ctrl);
  height: var(--sm-ctrl);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--sm-green);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--sm-shadow);
  transition: transform .15s, background .2s;
}
.sm-locate:hover { transform: scale(1.06); }
.sm-locate:active { transform: scale(.96); }
.sm-locate.is-loading i { animation: sm-spin 1s linear infinite; }
@keyframes sm-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- Légende réseau */

.sm-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 30;
  width: min(260px, calc(100% - 24px));
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--sm-border);
  border-radius: var(--sm-radius);
  box-shadow: var(--sm-shadow);
  overflow: hidden;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: .85rem;
}

.sm-legend-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--sm-ctrl);
  padding: 0 14px;
  border: none;
  background: transparent;
  color: var(--sm-text);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  text-align: left;
}
.sm-legend-head i:first-child { color: var(--sm-green); }
.sm-legend-head span { flex: 1; }
.sm-legend-caret {
  font-size: .7rem;
  color: var(--sm-muted);
  transition: transform .2s;
}
.sm-legend.is-collapsed .sm-legend-caret { transform: rotate(180deg); }

.sm-legend-body {
  padding: 4px 12px 12px;
}
.sm-legend.is-collapsed .sm-legend-body { display: none; }

.sm-legend-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.sm-legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border: 2px solid transparent;
  border-radius: 10px;
  font-weight: 800;
  font-size: .95rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .12s, box-shadow .2s, opacity .2s;
}
.sm-legend-badge:hover { transform: translateY(-1px); }
.sm-legend-badge:active { transform: scale(.94); }
.sm-legend.is-isolated .sm-legend-badge { opacity: .45; }
.sm-legend-badge.is-active {
  opacity: 1;
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--sm-green), 0 2px 6px rgba(0, 0, 0, .3);
}

.sm-legend-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--sm-border);
  border-radius: 999px;
  background: var(--sm-surface);
  color: var(--sm-text);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.sm-legend-reset:hover { border-color: var(--sm-green); color: var(--sm-green); }
.sm-legend-reset i { color: var(--sm-green); }

/* Sur mobile, la légende démarre repliée pour ne pas masquer la carte */
@media (max-width: 520px) {
  .sm-legend { width: min(220px, calc(100% - 24px)); bottom: 12px; }
}

/* --------------------------------------------------- Contenu SEO sous carte */

.sm-seo-more {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}
.sm-seo-more h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 18px 0 8px;
  color: var(--sm-text);
}
.sm-seo-more p {
  font-size: .95rem;
  line-height: 1.65;
  color: var(--sm-muted);
  margin: 0 0 6px;
}
.sm-seo-more a { color: var(--sm-green); text-decoration: underline; }

/* --------------------------------------------------------- Contrôles carte */

/* Harmonise les contrôles MapLibre/Leaflet avec la charte */
.maplibregl-ctrl-group,
.leaflet-bar {
  border-radius: 12px !important;
  box-shadow: var(--sm-shadow) !important;
  overflow: hidden;
}
.maplibregl-ctrl-bottom-right { margin-bottom: 8px; }
.leaflet-control-zoom a {
  width: 40px !important;
  height: 40px !important;
  line-height: 40px !important;
  font-size: 1.2rem !important;
}
.maplibregl-ctrl-attrib,
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, .8) !important;
}

/* ----------------------------------------------------------- Mode sombre */

@media (prefers-color-scheme: dark) {
  :root {
    --sm-bg: #0f172a;
    --sm-surface: #1e293b;
    --sm-text: #f1f5f9;
    --sm-muted: #94a3b8;
    --sm-border: #334155;
    --sm-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
  .sm-app { background: #0b1220; }
  .sm-map { background: #0b1220; }
  .sm-chip {
    background: rgba(30, 41, 59, .95);
    color: var(--sm-muted);
    border-color: var(--sm-border);
  }
  .sm-chip.is-active { background: var(--sm-green); color: #fff; border-color: var(--sm-green); }
  .sm-locate { background: #1e293b; color: #4ade80; }
  .sm-legend {
    background: rgba(30, 41, 59, .96);
    border-color: var(--sm-border);
  }
  .sm-legend-head { color: var(--sm-text); }
  .sm-legend-head i:first-child { color: #4ade80; }
  .sm-legend-reset {
    background: #0f172a;
    border-color: var(--sm-border);
    color: var(--sm-text);
  }
  .sm-legend-reset:hover { border-color: #4ade80; color: #4ade80; }
  .sm-legend-reset i { color: #4ade80; }
  .sm-legend-badge.is-active { box-shadow: 0 0 0 2px #4ade80, 0 2px 6px rgba(0, 0, 0, .5); }
  .maplibregl-ctrl-attrib,
  .leaflet-control-attribution {
    background: rgba(30, 41, 59, .85) !important;
    color: #cbd5e1 !important;
  }
  .maplibregl-ctrl-attrib a,
  .leaflet-control-attribution a { color: #4ade80 !important; }
}

/* ----------------------------------------------------- Accessibilité focus */

.sm-chip:focus-visible,
.sm-locate:focus-visible {
  outline: 3px solid var(--sm-green);
  outline-offset: 2px;
}

/* Réduction des animations si demandé */
@media (prefers-reduced-motion: reduce) {
  .sm-chip, .sm-locate { transition: none; }
  .sm-locate.is-loading i { animation: none; }
  .sm-legend-badge, .sm-legend-reset, .sm-legend-caret { transition: none; }
}

/* Accessibilité focus légende */
.sm-legend-head:focus-visible,
.sm-legend-badge:focus-visible,
.sm-legend-reset:focus-visible {
  outline: 3px solid var(--sm-green);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
 * Cibles tactiles (audit mobile) : agrandir les contrôles Leaflet et la
 * croix de fermeture des popups pour atteindre ~44px au doigt.
 * ------------------------------------------------------------------------- */
.leaflet-control-zoom a {
  width: 40px; height: 40px; line-height: 40px; font-size: 20px;
}
.leaflet-popup-close-button {
  width: 32px !important; height: 32px !important;
  font-size: 22px !important; line-height: 28px !important;
}
@media (max-width: 767px) {
  .leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
  .leaflet-popup-close-button { width: 40px !important; height: 40px !important; line-height: 36px !important; }
}
