:root {
  --bg: #241726;
  --surface: #3E2F44;
  --surface-elevated: #4A3A50;
  --mint: #14B8A6;
  --mint-light: #8CE8CC;
  --violet: #9A8CE0;
  --green: #A9E89B;
  --coral: #F08080;
  --orange: #FF8A3D;
  --blue: #64B5F6;
  --slate: #64748B;
  --text-primary: #F4EEF6;
  --text-secondary: #C9BBD1;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* ---- boutons / champs communs ---- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  color: var(--text-primary);
}

.btn-primary {
  background: var(--mint);
  color: var(--bg);
  font-weight: 600;
  padding: 12px 16px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  width: 100%;
}
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--text-secondary);
  color: var(--text-primary);
  padding: 12px 16px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
}

.icon-btn {
  background: transparent;
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.icon-svg { fill: currentColor; display: block; }
.icon-mint { color: var(--mint); }

input[type="text"] {
  width: 100%;
  background: var(--surface-elevated);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-primary);
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--mint); }
input[type="text"]::placeholder { color: var(--text-secondary); }

input[type="range"] { accent-color: var(--mint); width: 100%; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
}
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--surface-elevated);
  border-radius: 999px;
  transition: background .15s;
  cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-secondary);
  transition: transform .15s, background .15s;
}
.switch input:checked + .slider { background: var(--mint); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--bg); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-elevated);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  border: 1.5px solid transparent;
}
.chip.selected { border-color: var(--mint); color: var(--mint-light); }

/* ---- cartes flottantes ---- */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#search-panel {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  max-width: 460px;
  padding: 10px;
  z-index: 20;
  transition: opacity .2s, transform .2s;
}

.search-row { display: flex; align-items: center; gap: 6px; }
.search-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-wrap { position: relative; }
.field-wrap input { padding-left: 34px; padding-right: 32px; }
.field-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 14px; pointer-events: none;
}
.field-icon.start { color: var(--mint); }
.field-icon.end { color: var(--coral); }
.field-clear {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  background: none; width: 28px; height: 28px; color: var(--text-secondary);
  display: none; align-items: center; justify-content: center; border-radius: 50%;
  font-size: 13px;
}
.field-clear.visible { display: flex; }
.field-clear:hover { background: rgba(255,255,255,.08); }

.search-actions { display: flex; flex-direction: column; }

#suggestions {
  max-height: 180px;
  overflow-y: auto;
  margin-top: 4px;
}
.suggestion-item {
  padding: 9px 8px;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
}
.suggestion-item:hover { background: var(--surface-elevated); }

.hint-text {
  font-size: 11px;
  color: var(--text-secondary);
  padding: 6px 4px 2px;
}

/* Bascule de langue, coin bas-gauche de la carte de recherche : les deux libellés toujours
   visibles, le côté actif surligné en menthe. */
.lang-toggle {
  display: flex;
  flex: none;
  background: var(--surface-elevated);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.lang-option {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
}
.lang-option.active { background: var(--mint); color: var(--bg); }

/* ---- panneau bas ---- */
#bottom-panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 460px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity .2s, transform .2s;
}

/* Tap sur le fond de carte (une fois des résultats affichés) : masque temporairement les
   panneaux flottants pour dégager la vue, portage de panelsExpanded (MainScreen.kt). */
#search-panel.panel-hidden { opacity: 0; transform: translateY(-10px); pointer-events: none; }
#bottom-panel.panel-hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }

#idle-actions { display: flex; gap: 8px; padding: 10px; }
#idle-actions > * { flex: 1; }

#error-box {
  display: none;
  padding: 12px;
  color: var(--coral);
  font-size: 13px;
}

/* Animation de chargement : flotte seule au centre de la carte (calcul d'itinéraire uniquement),
   fond transparent, sans cadre - portage direct du Lottie flottant d'Android. */
#loading-lottie-wrap {
  /* opacity/visibility, PAS display:none : le <dotlottie-wc> mesure son conteneur pour
     dimensionner son canvas interne au premier rendu ; cacher via display:none le laisserait à
     0x0 à ce moment-là et son canvas retomberait sur la taille par défaut du navigateur
     (300x150, non carrée) sans jamais se redimensionner ensuite — d'où l'animation étirée. */
  visibility: hidden;
  opacity: 0;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 180px;
  height: 180px;
  z-index: 25;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
#loading-lottie-wrap.visible { visibility: visible; opacity: 1; }
#loading-lottie-wrap dotlottie-wc {
  width: 180px;
  height: 180px;
  flex: none; /* jamais étiré par le flex du conteneur */
  display: block;
  aspect-ratio: 1 / 1;
}

/* Logo Keloo, flottant seul (plus dans la barre de recherche) - coin supérieur droit, au-dessus
   de la carte. Les contrôles de zoom sont en bottom-right (voir map.js), pas de conflit.
   Image déjà conçue avec son propre fond/design carré : pas de fond/ombre/padding ajoutés ici,
   sinon "boîte dans une boîte" - juste l'image, telle quelle. */
#brand-logo {
  /* Masqué par défaut (téléphone) : à 100px il chevauche les champs de la barre de recherche sur
     petit écran - voir la media query ci-dessous qui le réaffiche à partir de 768px. */
  display: none;
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 100px;
  height: 100px; /* image source carrée (1024x1024) : pas de déformation */
  border-radius: 20px; /* épouse la forme du logo, sans lui ajouter de cadre */
  z-index: 21;
  pointer-events: none;
}
@media (min-width: 768px) {
  #brand-logo { display: block; }
}

#warning-box {
  display: none;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--coral);
  align-items: center;
  gap: 8px;
}

#results-box { display: none; flex-direction: column; gap: 8px; }

#route-cards {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 4px;
}
.route-card {
  flex: 0 0 auto;
  min-width: 128px;
  background: var(--surface-elevated);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  border: 1.5px solid transparent;
}
.route-card.selected { background: var(--mint); color: var(--bg); }
.route-card .title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.route-card .line { font-size: 11.5px; opacity: .9; }

#result-detail { padding: 12px; }
#elevation-chart-wrap { height: 90px; margin-bottom: 8px; }
#route-actions { display: flex; flex-direction: column; gap: 8px; }
#route-actions .row { display: flex; gap: 8px; }
#route-actions .row > * { flex: 1; }

/* ---- collapsible handle (résultats) ---- */
.handle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  cursor: pointer;
  color: var(--text-secondary);
  user-select: none;
}
.handle-row:hover { color: var(--text-primary); }

/* ---- options ---- */
#options-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 40;
  align-items: flex-end;
  justify-content: center;
}
#options-panel {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 16px 18px 24px;
  transition: transform .25s ease;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--text-secondary);
  opacity: .45;
  margin: 2px auto 10px;
  cursor: grab;
  /* PAS touch-action:none sur tout le panneau (casserait le défilement tactile du contenu) —
     seulement ici et sur l'en-tête (.options-close), les seules zones de déclenchement du
     glissement, pour que notre logique JS reçoive bien les pointermove sans scroll concurrent. */
  touch-action: none;
}
.options-close { touch-action: none; }
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--mint-light);
  margin: 16px 0 8px;
}
.section-title:first-child { margin-top: 0; }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.options-close {
  display: flex; justify-content: flex-end; margin-bottom: 4px;
}

/* ---- Fenêtre d'accueil (intro) ---- */
#intro-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#intro-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px 22px 20px;
  max-width: 380px;
  width: 100%;
}
#intro-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}
#intro-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
#intro-close { width: 100%; }

/* ---- Transition plein écran (jouée une fois à la fermeture de l'intro) ---- */
#transition-overlay {
  /* Même précaution que #loading-lottie-wrap : jamais display:none tant qu'on n'a pas fini de
     s'en servir — le <dotlottie-wc> mesurerait un conteneur cascadé à 0x0 et son canvas interne
     retomberait sur la taille par défaut du navigateur (non carrée, étirée). On garde donc
     l'élément en display:flex en permanence et on joue seulement sur opacity/visibility/
     pointer-events pour l'afficher, le masquer, et fonder la sortie (~300ms). */
  position: fixed;
  inset: 0;
  background: transparent; /* la carte reste visible derrière pendant l'animation */
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .3s ease;
}
#transition-overlay.visible { opacity: 1; visibility: visible; pointer-events: auto; }
#transition-lottie {
  width: 280px;
  height: 280px;
  flex: none; /* jamais étiré par le flex du conteneur */
  display: block;
  aspect-ratio: 1 / 1;
}

/* ---- popup carte (station / POI) ---- */
.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
  border-radius: 12px !important;
  padding: 12px 14px !important;
  box-shadow: var(--shadow);
}
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--text-secondary) !important; font-size: 18px !important; padding: 4px 8px !important; }
.popup-title { font-weight: 600; font-size: 14.5px; margin-bottom: 4px; }
.popup-line { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }
.popup-live { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--green); }
.dot.low { background: var(--coral); }


/* ---- toasts ---- */
#toast {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-elevated);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  max-width: 90vw;
  text-align: center;
}
#toast.visible { opacity: 1; }

/* ---- responsive desktop : panneaux plus larges, côte à côte possible ---- */
@media (min-width: 900px) {
  #search-panel { max-width: 380px; }
  #bottom-panel { max-width: 380px; }
}

/* ---- contenu indexable (SEO) : jamais affiché par-dessus la carte, mais toujours présent dans
   le DOM (pas display:none, invisible aux moteurs de recherche) - technique standard
   "visually-hidden" : réduit à 1x1px et rogné, hors du flux visuel, lisible par les crawlers. */
#seo-about {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-elevated); border-radius: 8px; }

/* ---- bandeau "Ajouter à l'écran d'accueil" (iOS Safari uniquement, voir install-prompt.js) ---- */
#ios-install-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 70;
  background: var(--surface-elevated);
  color: var(--text-primary);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 10px 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  max-width: 460px;
  margin: 0 auto;
  animation: ios-hint-in .25s ease-out;
}
#ios-install-hint span { flex: 1; line-height: 1.4; }
#ios-install-hint button {
  background: transparent;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 14px;
}
#ios-install-hint button:hover { background: rgba(255,255,255,.08); color: var(--text-primary); }
@keyframes ios-hint-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- écran de navigation (portage de NavigationScreen.kt) ---- */
#nav-permission-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  padding: 20px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

#nav-top-banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  max-width: 460px;
  margin: 0 auto;
  z-index: 20;
  padding: 14px 16px;
}
.nav-top-row { display: flex; align-items: center; gap: 12px; }
.nav-maneuver-icon { font-size: 32px; line-height: 1; flex-shrink: 0; }
.nav-top-text { flex: 1; min-width: 0; }
.nav-distance-big { font-size: 22px; font-weight: 700; }
.nav-instruction {
  font-size: 13.5px;
  color: var(--text-secondary);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.nav-rerouting-bar {
  margin-top: 10px;
  height: 3px;
  border-radius: 3px;
  background: var(--surface-elevated);
  overflow: hidden;
}
.nav-rerouting-fill {
  height: 100%;
  width: 40%;
  background: var(--mint);
  animation: nav-rerouting-slide 1s ease-in-out infinite;
}
@keyframes nav-rerouting-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.fab {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--mint);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

#nav-bottom-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 460px;
  margin: 0 auto;
  z-index: 20;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#nav-bottom-pill {
  display: none;
  justify-content: center;
  padding: 0 16px 12px;
  font-size: 14px;
}
#nav-bottom-expanded {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 14px;
  gap: 10px;
}
.nav-bottom-stats { display: flex; flex-direction: column; gap: 2px; }
.nav-stat-primary { font-size: 15px; font-weight: 700; }
.nav-stat-secondary { font-size: 12.5px; color: var(--text-secondary); }
.nav-bottom-actions { display: flex; align-items: center; gap: 8px; }
.nav-stop-btn { background: var(--coral) !important; color: var(--bg) !important; width: auto; padding: 10px 16px; min-height: 40px; }

@media (min-width: 900px) {
  #nav-top-banner, #nav-bottom-banner { max-width: 380px; }
}
