:root {
  --bg: #0c0f14;
  --surface: #151b26;
  --surface2: #1c2433;
  --border: #2a3545;
  --text: #eef2f7;
  --muted: #757e8b;
  --accent: #34d399;
  --accent2: #38bdf8;
  --danger: #f87171;
  --warn: #fbbf24;
  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 12px;
  --tab-h: 52px;
  /* Hauteur minimum de la carte (le bloc grandit encore avec flex: 1) */
  --map-min-h: min(62vh, 560px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  line-height: 1.45;
}

body {
  display: flex;
  flex-direction: column;
}

.app {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

header.hero {
  flex-shrink: 0;
  padding: 1rem 1rem 0.75rem;
  background: linear-gradient(165deg, var(--surface2) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

header.hero h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header.hero .lead {
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
  max-width: 36rem;
}

header.hero .source {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.9;
}

.tabs-nav {
  flex-shrink: 0;
  display: flex;
  gap: 0;
  padding: 0 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.tabs-nav button {
  flex: 1;
  min-height: var(--tab-h);
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 0;
}

.tabs-nav button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(52, 211, 153, 0.06);
}

.tabs-nav button:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: -2px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  flex: 0 0 auto;
}

.tab-panel.is-active {
  display: flex;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.15rem 0 0;
  max-width: 28rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.panel h2,
.route-panel h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

input,
select,
button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  min-height: 44px;
}

button {
  cursor: pointer;
  background: linear-gradient(180deg, #059669 0%, #047857 100%);
  border-color: #10b981;
  color: #fff;
  font-weight: 600;
}

button.secondary {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

button:active {
  opacity: 0.92;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

details.help {
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
}

details.help summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent2);
}

.priority-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.priority-group label.opt {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  min-height: 44px;
}

.priority-group input[type="radio"] {
  width: 1.1rem;
  height: 1.1rem;
  min-height: unset;
}

.map-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: var(--map-min-h);
  position: relative;
  /* occupe l’espace vertical restant entre le formulaire et la liste */
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #0a0c10;
}

.leaflet-container {
  font-family: var(--font);
}

/* Regroupement de marqueurs (Leaflet.markercluster) — thème sombre */
.marker-cluster-small {
  background-color: rgba(52, 211, 153, 0.92);
  border: 2px solid rgba(15, 23, 42, 0.9);
}
.marker-cluster-small div {
  background-color: rgba(21, 27, 38, 0.95);
  color: var(--text);
  font-weight: 700;
  font-size: 0.8rem;
}

.marker-cluster-medium {
  background-color: rgba(56, 189, 248, 0.92);
  border: 2px solid rgba(15, 23, 42, 0.9);
}
.marker-cluster-medium div {
  background-color: rgba(21, 27, 38, 0.95);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
}

.marker-cluster-large {
  background-color: rgba(248, 113, 113, 0.92);
  border: 2px solid rgba(15, 23, 42, 0.9);
}
.marker-cluster-large div {
  background-color: rgba(21, 27, 38, 0.95);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Popups : fond clair Leaflet — texte foncé explicite (pas var(--text), illisible sur blanc) */
.leaflet-popup-content-wrapper {
  max-height: min(52vh, 420px);
  overflow: hidden;
  background: #fff;
  color: #0f172a;
}

.leaflet-popup-content {
  max-height: min(48vh, 380px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  color: #0f172a;
}

.leaflet-popup-content::-webkit-scrollbar {
  width: 8px;
}

.leaflet-popup-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.list-section {
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(44vh, 480px);
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.list-section .list-head {
  padding: 0.65rem 1rem 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.list-section h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.legend-price-row {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  max-width: 100%;
}

.legend-gradient {
  display: inline-block;
  width: 72px;
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, hsl(125, 82%, 46%), hsl(0, 75%, 45%));
  border: 1px solid var(--border);
}

.legend-bound {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend-caption {
  width: 100%;
  flex-basis: 100%;
  font-size: 0.68rem;
  color: var(--muted);
}

.leaflet-popup-content .popup-station {
  font-size: 0.88rem;
  line-height: 1.45;
  color: #0f172a;
}

.leaflet-popup-content .popup-station-name {
  font-size: 1rem;
  font-weight: 700;
  color: #020617;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  word-break: normal;
}

.leaflet-popup-content .popup-fuel {
  color: #1d4ed8;
  font-weight: 500;
}

.leaflet-popup-content .popup-addr {
  font-weight: 600;
  color: #0f172a;
}

.leaflet-tooltip.station-tooltip {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  /* Largeur minimale : sans ça Leaflet peut calculer ~0 px → césure après chaque caractère */
  min-width: min(200px, calc(100vw - 2rem));
  max-width: min(280px, calc(100vw - 2rem));
  width: auto;
  padding: 0.4rem 0.6rem;
  /* Leaflet impose souvent nowrap : sans ça les longues adresses dépassent du fond */
  white-space: normal !important;
  overflow-wrap: break-word;
  word-break: normal;
}

.leaflet-tooltip.station-tooltip::before {
  border-top-color: var(--surface2) !important;
}

.leaflet-popup-content .popup-meta {
  font-size: 0.8rem;
  color: #475569;
}

.leaflet-popup-content .popup-station strong:not(.popup-station-name) {
  color: #020617;
}

.leaflet-popup-content .popup-horaires {
  display: block;
  margin-top: 0.35rem;
  line-height: 1.55;
}

#station-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 1rem 1rem;
  overflow-y: auto;
  max-height: 42vh;
  -webkit-overflow-scrolling: touch;
}

#station-list li,
#station-list-route li {
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.45rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-left-color: var(--border);
  background: var(--bg);
  cursor: pointer;
}

#station-list li:hover,
#station-list li:focus-visible,
#station-list-route li:hover,
#station-list-route li:focus-visible {
  border-color: var(--accent);
  outline: none;
}

#station-list .station-name,
#station-list-route .station-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: normal;
}

#station-list .price,
#station-list-route .price {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 0.35rem;
}

#station-list .station-extra,
#station-list-route .station-extra {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
  line-height: 1.35;
}

.station-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.station-badges .badge {
  font-size: 0.68rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}

#station-list .meta,
#station-list-route .meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

#station-list-route {
  list-style: none;
  margin: 0;
  padding: 0.5rem 1rem 1rem;
  overflow-y: auto;
  max-height: 42vh;
  -webkit-overflow-scrolling: touch;
}

.route-panel {
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.vehicle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

@media (max-width: 520px) {
  .vehicle-grid {
    grid-template-columns: 1fr;
  }
}

.status {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.35rem 1rem 0.5rem;
  min-height: 1.5rem;
}

.status.error {
  color: var(--danger);
}

.status.warn {
  color: var(--warn);
}

@media (min-width: 900px) {
  :root {
    --map-min-h: min(62vh, 600px);
  }

  .main-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
  }

  .main-split .panel,
  .main-split .route-panel {
    grid-column: 1 / -1;
  }

  .main-split .map-wrap {
    min-height: var(--map-min-h);
  }

  .main-split .list-section {
    max-height: min(38vh, 440px);
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 2000;
  padding: 0.5rem 1rem;
  background: var(--accent2);
  color: var(--bg);
  font-weight: 600;
  border-radius: var(--radius);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.faq-section {
  flex-shrink: 0;
  padding: 1.25rem 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  max-width: 52rem;
  margin: 0 auto;
  width: 100%;
}

.faq-section h2 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.faq-list {
  margin: 0;
  display: grid;
  gap: 0.85rem;
}

.faq-list dt {
  font-weight: 600;
  margin: 0;
  font-size: 0.95rem;
}

.faq-list dd {
  margin: 0.25rem 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.site-footer {
  flex-shrink: 0;
  padding: 1rem 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  justify-content: center;
}

.site-footer a {
  color: var(--accent2);
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  text-decoration: underline;
}

.site-footer-sep {
  color: var(--muted);
  user-select: none;
}

.privacy-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0));
  background: var(--surface2);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}

.privacy-banner-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

@media (min-width: 640px) {
  .privacy-banner-inner {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }

  .privacy-banner-desc {
    flex: 1;
  }
}

.privacy-banner-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.privacy-banner-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.privacy-banner-desc a {
  color: var(--accent2);
}

.privacy-banner-btn {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.privacy-banner-btn:hover,
.privacy-banner-btn:focus-visible {
  background: rgba(52, 211, 153, 0.12);
}

.legal-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 42rem;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.legal-header {
  padding: 1.25rem 0 0.5rem;
}

.legal-back {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.legal-back a {
  color: var(--accent2);
  text-decoration: none;
}

.legal-back a:hover {
  text-decoration: underline;
}

.legal-header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.legal-meta {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.legal-page {
  flex: 1;
}

.legal-page section {
  margin-top: 1.25rem;
}

.legal-page h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.legal-page p,
.legal-page ul {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.legal-page ul {
  padding-left: 1.25rem;
}

.legal-page li {
  margin-bottom: 0.35rem;
}

.legal-page a {
  color: var(--accent2);
}

.legal-footer-inner {
  margin-top: auto;
  padding-top: 2rem;
}
