:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #ebf1f7;
  --text: #0f1b2a;
  --muted: #586879;
  --border: #d7e1ec;
  --accent: #005d9d;
  --accent-strong: #00467a;
  --accent-soft: #e0eef9;
  --e85: #0f766e;
  --ethanol-from: #6cb4e8;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgb(10 30 55 / 6%), 0 4px 16px rgb(10 30 55 / 6%);
  --radius: 16px;
  --tabbar-h: 60px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1.5 1.5 6 6l4.5-4.5' fill='none' stroke='%23005d9d' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: light;
}

/* Thème sombre : posé sur <html> par le script de l'en-tête, selon le réglage ou le système. */
:root[data-theme="dark"] {
  --bg: #09111b;
  --surface: #111c29;
  --surface-2: #182636;
  --text: #e6edf5;
  --muted: #93a4b7;
  --border: #243549;
  --accent: #5aaeeb;
  --accent-strong: #a5d3f5;
  --accent-soft: #10294a;
  --e85: #2dd4bf;
  --ethanol-from: #a5d3f5;
  --warn: #fbbf24;
  --warn-soft: #3a2e10;
  --danger: #f87171;
  --shadow: none;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1.5 1.5 6 6l4.5-4.5' fill='none' stroke='%235aaeeb' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

/* La page prend toujours tout l'écran : sinon, quand le contenu est court,
   iOS (appli installée) ne colle pas la barre d'onglets tout en bas. */
body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-header,
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 20px;
  padding-bottom: 8px;
}
/* Le logo prend la hauteur du titre et du sous-titre. */
.app-header img { width: 52px; height: 52px; border-radius: 13px; flex: none; }
.app-header h1 { margin: 0; font-size: 1.4rem; letter-spacing: -0.01em; }
.app-header p { margin: 0; color: var(--muted); font-size: 0.875rem; }

/* Sur mobile, le sous-titre passerait sur deux lignes à côté du logo :
   logo et titre partagent la première ligne, le sous-titre prend toute la largeur dessous. */
@media (max-width: 459px) {
  .app-header { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 6px; }
  .app-header div { display: contents; }
  .app-header img { width: 36px; height: 36px; border-radius: 9px; }
  /* 13 px : le sous-titre tient sur une ligne dès 375 px de large. */
  .app-header p { grid-column: 1 / -1; font-size: 0.8125rem; text-wrap: balance; }
}

main { padding-bottom: calc(var(--tabbar-h) + 24px); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 14px;
}

h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}
h2 small { color: var(--muted); font-weight: 500; }

.grid { display: grid; gap: 10px; }
.grid.prices { grid-template-columns: repeat(4, 1fr); }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
/* Une colonne par champ affiché : litres de chaque carburant, puis montant. */
.grid.fill-amounts { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.grid.fill-when { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-top: 12px; }
.grid.fill-when + .hint { display: block; margin-top: 8px; }
@media (max-width: 420px) {
  .grid.prices { grid-template-columns: 1fr 1fr; }
}

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.grid .field { margin-top: 0; }
.field > span, .limit-head > span { font-size: 0.8125rem; color: var(--muted); font-weight: 500; }

input[type="text"],
input[type="date"],
.field select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.field select { font-size: 1rem; }
/* Safari iOS centre la date et réduit la hauteur du champ natif. */
input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 2.875rem; font-size: 1rem; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="text"]:focus, input[type="date"]:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="text"]:disabled { opacity: 0.6; }
.field-e85 input { border-color: color-mix(in srgb, var(--e85) 45%, var(--border)); }

.suffix { position: relative; }
.suffix input { padding-right: 34px; }
.suffix em {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  color: var(--muted);
  pointer-events: none;
}

.hint { display: block; color: var(--muted); font-size: 0.8125rem; margin: 8px 0 0; }

.gauge-buttons { display: flex; gap: 8px; margin-top: 10px; }
.segmented { display: flex; gap: 8px; }
.gauge-buttons button,
.segmented button {
  flex: 1;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 0;
  cursor: pointer;
}
.gauge-buttons { margin-top: 2px; }
.gauge-buttons button { font-size: 1.0625rem; font-weight: 600; padding: 12px 0; border-radius: 12px; }
.gauge-buttons button:active { background: var(--accent-soft); }
.gauge-buttons button[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: var(--accent); }
.segmented button[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.segmented.stacked { flex-direction: column; margin-top: 6px; }
.segmented.stacked button { padding: 10px 14px; border-radius: 12px; text-align: left; }
#amount-wrap { margin-top: 6px; }

.limit-head { display: flex; justify-content: space-between; align-items: baseline; }
.limit-head output { font-weight: 700; font-size: 1.125rem; color: var(--accent); font-variant-numeric: tabular-nums; }
/* Piste en dégradé bleu clair → E85, révélé jusqu'au curseur (--frac posé par le script). */
input[type="range"] {
  --thumb: 28px;
  --range-fill: linear-gradient(90deg, transparent calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--frac, 0.5)), var(--border) 0),
    linear-gradient(90deg, var(--ethanol-from), var(--e85));
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: var(--thumb); margin: 6px 0 2px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: var(--range-fill); }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 999px; background: var(--range-fill); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: var(--thumb); height: var(--thumb); margin-top: calc((8px - var(--thumb)) / 2);
  border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
}
input[type="range"]::-moz-range-thumb { width: var(--thumb); height: var(--thumb); border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgb(0 0 0 / 30%); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 5px var(--accent); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 5px var(--accent); }
input[type="range"]:disabled { opacity: 0.4; }

.check { display: flex; align-items: center; gap: 8px; font-size: 0.9375rem; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* Résultat */
.result { border: 2px solid var(--accent); }
.result.empty { border: 1px dashed var(--border); color: var(--muted); text-align: center; }
.result.empty p { margin: 4px 0; }
.result-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 10px;
  transition: margin-bottom 0.3s ease;
}
.result-head h2 { font-size: 1.25rem; margin: 0; }
/* Repliée, la carte propose toutes les options dans une liste à la place du titre. */
.result-option { align-self: stretch; }
.result-option .field { margin-top: 2px; }
.result-option .field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.result-option select { font-size: 1.0625rem; font-weight: 700; }
.badge.is-other { color: var(--muted); background: var(--surface-2); }

/* Repli du choix quand on enregistre le plein : il ne garde que son titre. */
.result-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.3s ease, opacity 0.2s ease; }
.result-body > div { min-height: 0; overflow: hidden; }
.result.is-collapsed .result-head { margin-bottom: 0; }
.result.is-collapsed .result-body { grid-template-rows: 0fr; opacity: 0; visibility: hidden; transition: grid-template-rows 0.3s ease, opacity 0.2s ease, visibility 0s 0.3s; }
.fill-inline { animation: slide-in 0.3s ease; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-12px); } }
@media (prefers-reduced-motion: reduce) {
  .result-head, .result-body, .result.is-collapsed .result-body { transition: none; }
  .fill-inline { animation: none; }
}
.badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 10px;
}

.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; counter-reset: step; }
.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
}
.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--surface);
  font-weight: 700;
  font-size: 0.875rem;
}
.steps li.is-e85::before { background: var(--e85); }
.steps strong { display: block; font-size: 1.0625rem; }
.steps small { color: var(--muted); font-size: 0.8125rem; }
.steps .amount { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.steps .amount small { display: block; font-weight: 500; }

.ethanol { margin: 14px 0 4px; }
.ethanol p { margin: 6px 0 0; font-size: 0.875rem; color: var(--muted); }
.ethanol-bar { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.ethanol-bar > div { height: 100%; background: linear-gradient(90deg, var(--ethanol-from), var(--e85)); border-radius: 999px; }
.ethanol-bar > i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: 0.55; }
.ethanol.over .ethanol-bar > div { background: var(--danger); }
.ethanol.over p { color: var(--danger); }

.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.figures div { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; }
.figures dt { font-size: 0.75rem; color: var(--muted); }
.figures dd { margin: 0; font-weight: 700; font-size: 1.0625rem; font-variant-numeric: tabular-nums; }
.figures .highlight { background: var(--accent-soft); }
.figures .highlight dd { color: var(--accent-strong); }

.warning, .tip { border-radius: 12px; padding: 10px 12px; font-size: 0.875rem; margin: 0 0 10px; }
.warning { background: var(--warn-soft); color: var(--warn); }
.tip { background: var(--surface-2); color: var(--muted); }

button.primary {
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: #005d9d;
  border: 0;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}
button.primary:active { background: #00467a; }

/* Autres propositions */
.options { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.option {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.option:active { background: var(--accent-soft); }
.option strong { display: block; font-size: 0.9375rem; }
.option small { display: block; color: var(--muted); font-size: 0.8125rem; }
.option-cost { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.option.is-over > span:first-child small { color: var(--danger); }
.option-cost small.gain-pos { color: var(--accent); }
.option-cost small.gain-neg { color: var(--danger); }

/* Réglages */
details > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { margin: 0; }
details > summary::after { content: "›"; font-size: 1.4rem; color: var(--muted); transform: rotate(90deg); transition: transform 0.15s; }
details[open] > summary::after { transform: rotate(-90deg); }
details[open] > summary { margin-bottom: 4px; }
details .grid { margin-top: 12px; }

/* Historique */
.history-head { display: flex; justify-content: space-between; align-items: baseline; }
.history-head h2 { margin: 0; }
button.link, a.link { font: inherit; font-size: 0.875rem; color: var(--muted); background: none; border: 0; cursor: pointer; text-decoration: underline; padding: 0; }
.total-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0; }
.total { margin: 0; font-size: 0.9375rem; }
.total strong { color: var(--accent); }
.history { list-style: none; margin: 0; padding: 0; font-size: 0.875rem; }
.history li { border-top: 1px solid var(--border); }
.history-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.history-item small { display: block; color: var(--muted); }
.history-item small.conso-line { color: var(--e85); }
.history-item > span:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Liste à bascule : le chevron pivote et le formulaire du plein se déplie sous sa ligne. */
.history-item > span:first-child { flex: 1; min-width: 0; }
.history-item::before {
  content: "";
  flex: none;
  align-self: center;
  width: 12px;
  height: 8px;
  margin-right: -4px;
  background: var(--muted);
  -webkit-mask: var(--chevron) center / contain no-repeat;
  mask: var(--chevron) center / contain no-repeat;
  transform: rotate(-90deg);
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.history-item[aria-expanded="true"]::before { transform: none; background: var(--accent); }
.history li.is-closing .history-item::before { transform: rotate(-90deg); background: var(--muted); }
.history li.is-editing { scroll-margin: 16px 0 calc(var(--tabbar-h) + 16px); }
.history li.is-editing .history-item > span:first-child > span { color: var(--accent); font-weight: 600; }
.history-edit { display: grid; grid-template-rows: 1fr; }
.history-edit > div { min-height: 0; padding-bottom: 14px; font-size: 1rem; }
.history-edit.is-opening { animation: collapse-open 0.3s ease; }
.history li.is-closing .history-edit { grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows 0.25s ease, opacity 0.2s ease; }
/* Rogné seulement pendant l'animation, pour garder le halo des champs. */
.history-edit.is-opening > div, .history li.is-closing .history-edit > div { overflow: hidden; }
@keyframes collapse-open { from { grid-template-rows: 0fr; opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .history-item::before { transition: none; }
  .history-edit.is-opening { animation: none; }
}

.conso .figures { margin: 10px 0 0; }
.conso .figures div { display: flex; flex-direction: column; justify-content: space-between; }
.conso .figures dd small { font-weight: 500; font-size: 0.75rem; color: var(--muted); }
.conso .hint { margin-bottom: 10px; }

/* Dépenses par mois : une colonne par mois, la barre part de la ligne de base. */
.monthly { margin: 4px 0 12px; }
.monthly-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; margin-bottom: 6px; }
.monthly h3 { margin: 0; font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.monthly .legend { margin: 0; display: flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--muted); }
.monthly .key { width: 10px; height: 10px; border-radius: 3px; }
.monthly .key-spent { background: var(--accent); }
.monthly .key-saved { background: var(--e85); margin-left: 8px; }
.months { display: flex; }
.month {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.month-plot {
  width: 100%;
  height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
/* La barre de la dépense porte, au-dessus, le segment de l'économie du mois. */
.month-stack { width: 24px; max-width: 70%; display: flex; flex-direction: column; border-radius: 4px 4px 0 0; overflow: hidden; }
.month-bar { background: color-mix(in srgb, var(--accent) 40%, var(--surface)); }
.month-saved { background: color-mix(in srgb, var(--e85) 40%, var(--surface)); box-shadow: inset 0 -1px 0 var(--surface); }
.month-value { font-size: 0.75rem; font-weight: 600; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.month-label { font-size: 0.75rem; margin-top: 4px; }
.month[aria-pressed="true"] .month-bar { background: var(--accent); }
.month[aria-pressed="true"] .month-saved { background: var(--e85); }
.month[aria-pressed="true"] .month-label { color: var(--text); font-weight: 600; }
#month-detail { margin-top: 6px; }

.disclaimer { color: var(--muted); font-size: 0.8125rem; margin: 18px 4px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
}

/* Stations proches */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; white-space: nowrap; }
button.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button.pill:disabled { opacity: 0.6; cursor: progress; }

.selected-station {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 0.875rem;
}
.selected-station strong { display: block; }
.selected-name { flex: 1; min-width: 0; }
.fav-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: -6px -4px -6px -8px;
  color: var(--accent-strong);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.fav-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.fav-toggle[aria-pressed="true"] svg { fill: currentColor; }

.favorites { margin: 12px 0 16px; }
.favorites h3 { margin: 0 0 6px; font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.favorites .stations { margin: 0; }
.selected-station small { color: var(--muted); }
.selected-station.stale small { color: var(--warn); }
.selected-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; white-space: nowrap; }

.station-search { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.station-search input,
.station-search select {
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

/* Sélecteurs aux couleurs du thème, plutôt que l'apparence native (grise sur iOS). */
.field select,
.station-search select {
  -webkit-appearance: none;
  appearance: none;
  font-weight: 600;
  color: var(--accent-strong);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 34px;
  cursor: pointer;
  outline: none;
}
.station-search select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select option { color: var(--text); background: var(--surface); }

/* Liste ouverte aux couleurs du thème là où le navigateur le permet (Chrome, Safari 27) ; ailleurs, menu natif. */
@supports (appearance: base-select) {
  .field select,
  .station-search select,
  .field select::picker(select),
  .station-search select::picker(select) { appearance: base-select; }
  select::picker-icon { display: none; }
  select::picker(select) {
    margin-block: 6px;
    padding: 6px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgb(10 30 55 / 18%);
  }
  select option { padding: 10px 12px; border-radius: 8px; font-weight: 500; }
  select option:hover,
  select option:focus-visible { background: var(--accent-soft); outline: none; }
  select option:checked { color: var(--accent-strong); font-weight: 600; }
  select option::checkmark { order: 1; margin-inline-start: auto; color: var(--accent); }
  /* Mélange mis : le meilleur choix non sélectionné porte une étoile à la place de la coche. */
  #fill-option option.best:not(:checked)::checkmark { content: '★'; visibility: visible; }
}
.station-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.sort { display: flex; gap: 6px; margin-top: 10px; }
.sort button {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.sort button[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: transparent; font-weight: 600; }

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

.stations { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
/* Itinéraire à côté de la station : un lien ne peut pas être dans le bouton. */
.stations li { display: flex; gap: 6px; }
.stations li .station { flex: 1; min-width: 0; }
.station-route {
  flex: none;
  width: 40px;
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  background: var(--surface-2);
  border-radius: 12px;
}
.station-route:active { background: var(--accent-soft); }
.station {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.station.is-selected { border-color: var(--accent); }
.station-main { min-width: 0; }
.station-main strong { display: block; font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.station-meta { display: block; color: var(--muted); font-size: 0.8125rem; }
.station-meta.stale { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 0.75rem; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.chip-e85 { color: var(--e85); border-color: color-mix(in srgb, var(--e85) 40%, var(--border)); }
.station-cost { text-align: right; font-variant-numeric: tabular-nums; }
.station-cost strong { display: block; font-size: 1.0625rem; }
.station-cost small { display: block; color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.station.is-cheapest .station-cost strong { color: var(--accent); }
.station.is-cheapest .station-cost strong::before { content: "★ "; font-size: 0.8em; }
button.more { display: block; margin: 10px auto 0; }

/* Version et nouveautés */
.app-footer { text-align: center; color: var(--muted); font-size: 0.8125rem; margin-top: 16px; }

.sheet {
  width: min(480px, calc(100vw - 32px));
  max-height: min(80vh, 640px);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.sheet::backdrop { background: rgb(0 0 0 / 40%); }
.changelog section { padding: 10px 0; border-top: 1px solid var(--border); }
.changelog h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0 0 4px; font-size: 0.9375rem; }
.changelog h3 small { color: var(--muted); font-weight: 400; font-size: 0.8125rem; }
.changelog section.is-current h3 span { color: var(--accent); }
.changelog ul { margin: 0; padding-left: 18px; font-size: 0.875rem; }
.changelog li + li { margin-top: 2px; }

.notice h2 { margin: 0 0 8px; }
.notice ul { margin: 0; padding-left: 18px; font-size: 0.875rem; }
.notice li + li { margin-top: 6px; }
.notice button.primary { margin-top: 14px; }

.toast.clickable { cursor: pointer; }

/* Installation sur l'écran d'accueil */
.install h2 { margin: 0 0 4px; }
.install .hint { margin: 0; }
.install .hint + .hint { margin-top: 6px; }
.install-steps { margin: 10px 0 0; padding-left: 20px; font-size: 0.875rem; }
.install-steps li + li { margin-top: 4px; }
.install-steps svg { vertical-align: -3px; color: var(--accent); }
.install-actions { display: flex; align-items: center; gap: 16px; margin-top: 12px; }

/* Partage des économies */
.share #share-preview { margin: -4px 0 12px; white-space: pre-line; }
.share-targets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.share-targets a, .share-targets button {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 8px;
  cursor: pointer;
}
.share-targets a:active, .share-targets button:active { background: var(--accent-soft); }

/* Enregistrement d'un plein */
#fill-form > #fill-summary { margin: -4px 0 0; }
#fill-option-field:not([hidden]) + .hint { margin-top: 8px; }
#fill-form .grid { margin-top: 12px; }
#fill-form .check { margin-top: 12px; }
.sheet button.primary { margin-top: 14px; }
.fill-actions { display: flex; gap: 8px; margin-top: 14px; }
.fill-actions button.primary { flex: 1; }
button.link.danger { display: block; margin: 12px auto 0; color: var(--danger); }

/* Tirer pour rafraîchir (appli installée) */
html.has-ptr,
html.has-ptr body { overscroll-behavior-y: none; }
.ptr {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgb(0 0 0 / 15%);
  opacity: 0;
  transform: translate(-50%, -56px);
  pointer-events: none;
}
.ptr.animating { transition: transform 0.2s ease, opacity 0.2s ease; }
.ptr.ready { color: var(--accent); }
.ptr.spinning svg { display: none; }
.ptr.spinning::after {
  content: "";
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ptr-spin 0.7s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* Parcours en étapes */
.stepper { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stepper button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  column-gap: 4px;
  row-gap: 6px;
  font: inherit;
  font-size: 0.75rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.stepper button::after { content: ""; grid-row: 1; grid-column: 1 / -1; height: 4px; border-radius: 999px; background: var(--border); }
.stepper b { grid-row: 2; grid-column: 2; font-variant-numeric: tabular-nums; }
.stepper span { grid-row: 2; grid-column: 3; }
.stepper button.is-done { color: var(--text); }
.stepper button.is-done::after { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.stepper button.is-current { color: var(--accent-strong); font-weight: 700; }
.stepper button.is-current::after { background: var(--accent); }
.stepper button:disabled { cursor: default; opacity: 0.7; }

.recap { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.recap-item {
  width: 100%;
  display: grid;
  grid-template-columns: 4.75rem 1fr auto;
  align-items: baseline;
  gap: 8px;
  text-align: left;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}
.recap-item small { color: var(--muted); font-size: 0.8125rem; }
.recap-item span { min-width: 0; font-variant-numeric: tabular-nums; }
.recap-item em { font-style: normal; font-size: 0.8125rem; color: var(--accent-strong); }

/* Boutons de l'étape : sous le contenu, ou collés au-dessus des onglets s'il déborde. */
.step-actions {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  gap: 8px;
  margin: 14px -16px 0;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.step-actions button.primary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.primary:disabled { opacity: 0.45; cursor: default; }
button.secondary {
  flex: none;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
}
button.secondary:active { background: var(--surface-2); }

#manual-prices { margin-top: 14px; }
#prices-check { margin: 12px 0 0; }
.selected-station { margin: 0 0 12px; }

.eth-line, .car-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 12px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}
.car-line { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 16px; }
.eth-line .link, .car-line .link { flex: none; }

.car-intro { margin: -4px 0 4px; }
button.car-done { margin-top: 16px; }
.empty-state h2 { margin-bottom: 4px; }

/* Onglets */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1;
  max-width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.tabbar button[aria-current="page"] { color: var(--accent-strong); font-weight: 700; }
.toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 15; }
