:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #16202e;
  --muted: #5c6b84;
  --border: #dbe2ec;
  --brand: #0b7a55;            /* vert : marque + recommandation uniquement */
  --brand-strong: #086647;
  --brand-soft: #e3f4ec;
  --on-brand: #ffffff;
  --sel-a: #2563eb;            /* sélection A */
  --sel-a-soft: #e8eefc;
  --sel-b: #c46a06;            /* sélection B */
  --sel-b-soft: #fbeedd;
  --route-direct: #9ca3af;     /* itinéraire direct */
  --warn: #9a5b00;
  --warn-soft: #fdf1dd;
  --danger: #b3261e;
  --ring: #2563eb;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
  --shadow-lift: 0 4px 14px rgba(20, 30, 50, 0.12);
  --radius: 12px;
  --radius-lg: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141b;
    --surface: #181e27;
    --surface-2: #212936;
    --text: #e8ecf3;
    --muted: #98a5bb;
    --border: #2b3442;
    --brand: #34c98e;
    --brand-strong: #4ad7a0;
    --brand-soft: #143529;
    --on-brand: #06281c;
    --sel-a: #5b8cff;
    --sel-a-soft: #1a2740;
    --sel-b: #e79b3c;
    --sel-b-soft: #382712;
    --route-direct: #6b7280;
    --warn: #e8a94a;
    --warn-soft: #3a2d14;
    --danger: #ff6d64;
    --ring: #5b8cff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 4px 14px rgba(0, 0, 0, 0.5);
  }
  .leaflet-tile { filter: brightness(0.85) contrast(1.05); }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; color: inherit; }
input { font: inherit; color: inherit; }

button, .card, summary, a { transition: background-color 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

.icon { width: 1em; height: 1em; vertical-align: -0.125em; flex: none; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1100;
}
.topbar h1 {
  font-size: 1.05rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.topbar h1 .icon { color: var(--brand); font-size: 1.25em; }

.mode-switch {
  display: flex;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}
.mode-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-weight: 500;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button[aria-selected="true"] {
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}

main { max-width: 1200px; margin: 0 auto; padding: 0.8rem; }

/* ---------- Contrôles ---------- */
.controls { display: grid; gap: 0.6rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.chips button:hover { border-color: var(--brand); }
.chips button[aria-checked="true"], .chips button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}
.chips-small button { padding: 0.25rem 0.7rem; font-size: 0.85rem; }
.chips-small .fav-del { margin-left: 0.35rem; opacity: 0.7; display: inline-flex; }
.chips-small .fav-del:hover { opacity: 1; color: var(--danger); }

.dest-row { display: flex; gap: 0.4rem; }
.autocomplete { position: relative; flex: 1; }
.autocomplete input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.autocomplete input:focus { border-color: var(--ring); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.autocomplete ul {
  position: absolute;
  inset: 100% 0 auto 0;
  margin: 0.2rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  z-index: 1200;
  max-height: 40vh;
  overflow-y: auto;
}
.autocomplete li { padding: 0.45rem 0.6rem; border-radius: 8px; cursor: pointer; }
.autocomplete li:hover, .autocomplete li.focused { background: var(--surface-2); }
.autocomplete li small { color: var(--muted); display: block; }

.ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 0 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.ghost:hover { color: var(--text); border-color: var(--ring); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }

.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.8rem;
}
.settings summary { cursor: pointer; color: var(--muted); user-select: none; }
.settings summary:hover { color: var(--text); }
.settings-grid { display: flex; flex-wrap: wrap; gap: 0.8rem; padding-top: 0.6rem; }
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.settings-grid input[type="number"] {
  width: 7.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.settings-grid .check { flex-direction: row; align-items: center; align-self: end; gap: 0.4rem; }

.banner {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  margin: 0.6rem 0 0;
}

/* ---------- Recommandation ---------- */
.reco {
  margin-top: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--brand);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}
.reco-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
}
.reco-types { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.reco-types button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.reco-types button:hover { color: var(--text); border-color: var(--ring); }
.reco-types button[aria-pressed="true"] {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
}
.closed-now { color: var(--danger); }

.reco .reco-tag {
  color: var(--brand);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.reco h2 { margin: 0.15rem 0 0.1rem; font-size: 1.2rem; }
.reco .reco-city { color: var(--muted); font-size: 0.9rem; }
.reco .reco-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  margin: 0.6rem 0;
  align-items: baseline;
}
.reco .price { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; }
.reco .price small, .list .price small { font-size: 0.55em; font-weight: 400; color: var(--muted); }
.reco .total { font-size: 1.05rem; }
.verdict {
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.92rem;
  background: var(--brand-soft);
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
}
.verdict .icon { color: var(--brand); font-size: 1.1em; }
.verdict.stay { background: var(--warn-soft); }
.verdict.stay .icon { color: var(--warn); }
.reco-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }
.reco-actions a {
  background: var(--brand);
  color: var(--on-brand);
  text-decoration: none;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}
.reco-actions a:hover { background: var(--brand-strong); }
.freshness { color: var(--muted); font-size: 0.85rem; }

/* ---------- Comparaison d'itinéraires ---------- */
.compare {
  margin-top: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.8rem 0.9rem;
  box-shadow: var(--shadow);
}
.compare-head { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin-bottom: 0.5rem; }
.compare-head h2 { margin: 0; font-size: 1rem; }
.compare-slots { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.slot-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.22rem 0.6rem 0.22rem 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.slot-letter {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--route-direct);
  vertical-align: middle;
  flex: none;
}
.slot-letter.l-0 { background: var(--sel-a); }
.slot-letter.l-1 { background: var(--sel-b); }
.slot-chip.slot-0 { background: var(--sel-a-soft); color: var(--sel-a); }
.slot-chip.slot-0 .slot-letter { background: var(--sel-a); }
.slot-chip.slot-1 { background: var(--sel-b-soft); color: var(--sel-b); }
.slot-chip.slot-1 .slot-letter { background: var(--sel-b); }
.slot-chip.slot-empty {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  font-weight: 500;
}
.slot-chip.slot-empty .slot-letter { background: var(--surface-2); color: var(--muted); }
.slot-chip .slot-remove {
  display: inline-flex;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0.1rem;
  opacity: 0.75;
  border-radius: 50%;
}
.slot-chip .slot-remove:hover { opacity: 1; }
.slot-chip.slot-direct { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.slot-chip.slot-direct .slot-letter { background: var(--route-direct); }

.compare-scroll { overflow-x: auto; }
.compare table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.compare th, .compare td {
  text-align: left;
  padding: 0.42rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.compare thead th { padding-bottom: 0.55rem; }
.compare tbody tr:last-child th, .compare tbody tr:last-child td { border-bottom: 0; }
.compare tbody th { color: var(--muted); font-weight: 500; }
.compare td.best { color: var(--brand); font-weight: 700; }
.compare td.best .icon { font-size: 0.9em; margin-right: 0.2rem; }
.compare .hint { margin-top: 0.5rem; }

/* ---------- Liste + carte ---------- */
.columns { margin-top: 0.8rem; display: grid; gap: 0.8rem; }
#map {
  height: 42vh;
  min-height: 260px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  z-index: 0;
}

.list { display: grid; gap: 0.5rem; align-content: start; }
.card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  position: relative;
}
.card:hover { border-color: var(--ring); box-shadow: var(--shadow); }
.card .name { font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; }
.card .meta { color: var(--muted); font-size: 0.85rem; }
.card .price { text-align: right; font-weight: 700; font-size: 1.1rem; }
.card .total { text-align: right; color: var(--muted); font-size: 0.85rem; }
.card .gain { color: var(--brand); font-weight: 600; }
.card .gain.neg { color: var(--danger); }

.card-foot {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.3rem;
}
.badges { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.badge {
  font-size: 0.72rem;
  border-radius: 6px;
  padding: 0.12rem 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.badge.on-route { background: var(--surface-2); color: var(--text); border-color: transparent; }
.badge.stale { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.closed {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border-color: transparent;
  font-weight: 600;
}
.badge.reco-badge { background: var(--brand-soft); color: var(--brand); border-color: transparent; font-weight: 600; }

/* Affordance de sélection pour la comparaison (mode trajet) */
.select-ctl {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  white-space: nowrap;
}
.card:hover .select-ctl { color: var(--text); border-color: var(--ring); }
.card.sel-0, .card.sel-1 { border-style: solid; border-width: 1px; }
.card.sel-0 { border-color: var(--sel-a); background: var(--sel-a-soft); }
.card.sel-1 { border-color: var(--sel-b); background: var(--sel-b-soft); }

/* Épingles A/B sur la carte */
.sel-pin { background: none; border: none; }
.sel-pin-inner {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}
.sel-pin-inner.slot-bg-0 { background: var(--sel-a); }
.sel-pin-inner.slot-bg-1 { background: var(--sel-b); }

footer {
  max-width: 1200px;
  margin: 1.2rem auto 0;
  padding: 0.8rem 1rem 1.6rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
footer p { margin: 0.25rem 0; }

@media (min-width: 900px) {
  .columns { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .columns #map {
    order: 2;
    position: sticky;
    top: 4.2rem;
    height: calc(100vh - 5.5rem);
  }
  .list { order: 1; }
}
