/* Carburanti · stile chiaro MediaFM. Colori e misure sono tutti in :root. */
:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --ink: #0E1A22;
  --muted: #5A6670;
  --line: #E6E4DD;
  --accent: #FF4103;        /* marchio: prezzi grandi, grafica, pulsanti (testo scuro) */
  --accent-ink: #C73300;    /* arancio per testo piccolo e link: contrasto AA */
  --accent-soft: #FFF0EA;
  --green: #14A44D;         /* stazione più economica: grafica */
  --green-ink: #0E7A38;     /* stazione più economica: testo */
  --green-soft: #E8F6EE;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(14, 26, 34, .06), 0 6px 20px rgba(14, 26, 34, .07);
  --focus: 0 0 0 3px var(--bg), 0 0 0 5px var(--ink);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --topbar-h: 76px;
  --footer-h: 34px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 2000;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.tagline { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34ch; }

.controls { display: flex; align-items: center; gap: 20px; }
.fuel-picker {
  display: flex; gap: 4px; margin: 0; padding: 4px; border: 0;
  background: #EFEEE8; border-radius: 999px;
}
.fuel-picker label { position: relative; }
.fuel-picker input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.fuel-picker span {
  display: block; padding: 8px 14px; border-radius: 999px;
  font-weight: 600; font-size: 14px; color: var(--muted);
  transition: background .25s var(--ease), color .25s var(--ease), box-shadow .25s var(--ease);
}
.fuel-picker input:hover + span { color: var(--ink); }
.fuel-picker input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(14, 26, 34, .14); }
.fuel-picker input:focus-visible + span { box-shadow: var(--focus); }

.radius { display: grid; gap: 2px; min-width: 170px; }
.radius label { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; }
.radius output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 24px; margin: 0; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform .2s var(--ease), background .2s var(--ease), box-shadow .2s var(--ease);
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--ink); box-shadow: var(--shadow); }
.btn-primary:hover { background: #FF5A24; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 7fr 3fr;
  height: calc(100vh - var(--topbar-h) - var(--footer-h));
  height: calc(100dvh - var(--topbar-h) - var(--footer-h));
  min-height: 420px;
}
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #E9E7E0; }
.panel {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  border-left: 1px solid var(--line);
  padding: 16px 16px 24px;
  scroll-padding-top: 12px;
}
.panel:focus { outline: none; }

.search-here {
  position: absolute; z-index: 500; top: 16px; left: 50%; transform: translateX(-50%);
  animation: drop-in .35s var(--ease);
}
.search-here:active { transform: translateX(-50%) scale(.97); }
@keyframes drop-in { from { opacity: 0; transform: translate(-50%, -8px); } }

.map-loading {
  position: absolute; z-index: 500; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px;
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Stato ---------- */
.status:empty { display: none; }
.status {
  display: grid; gap: 10px; justify-items: start;
  margin-bottom: 14px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px;
}
.status[data-kind="error"] { background: #FFF4F1; border-color: #F5C6B8; }
.status[data-kind="info"] { background: #F3F6F8; border-color: #DCE3E8; }
.status .btn { min-height: 36px; font-size: 13px; }

/* ---------- Riquadro risparmio ---------- */
.savings {
  position: relative; overflow: hidden;
  background: var(--ink); color: #fff;
  border-radius: var(--radius); padding: 18px 18px 16px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.savings::after { /* arco decorativo del marchio */
  content: ""; position: absolute; right: -60px; top: -60px; width: 160px; height: 160px;
  border-radius: 50%; border: 18px solid var(--accent); opacity: .9;
}
.savings-kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #FFB79E; }
.savings-amount { margin-top: 4px; font-size: 38px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; position: relative; z-index: 1; }
.savings-amount small { font-size: 15px; font-weight: 600; letter-spacing: 0; color: #C9D2D8; }
.savings-text { margin-top: 6px; font-size: 14px; color: #DCE3E8; max-width: 30ch; }
.price-scale { margin: 14px 0 12px; }
.price-scale-bar {
  position: relative; height: 8px; border-radius: 99px;
  background: linear-gradient(90deg, var(--green) 0%, #F2C94C 50%, var(--accent) 100%);
}
.price-scale-bar i {
  position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%;
  transform: translate(-50%, -50%); border: 3px solid var(--ink); background: #fff;
}
.price-scale-bar .dot-min { left: 0; transform: translate(0, -50%); }
.price-scale-bar .dot-avg { left: 50%; transition: left .6s var(--ease); }
.savings-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.savings-stats div { min-width: 0; }
.savings-stats dt { font-size: 12px; color: #C9D2D8; }
.savings-stats dd { margin: 0; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.savings-year { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, .14); font-size: 13px; color: #DCE3E8; }
.savings-year strong { color: #fff; }

/* ---------- Lista ---------- */
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 4px 2px 10px; }
.list-head h2 { font-size: 16px; font-weight: 700; }
.list-hint { font-size: 12px; color: var(--muted); }
.stations { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.stations[aria-busy="true"] { opacity: .55; transition: opacity .2s; }

.station {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), transform .2s var(--ease);
}
.station:hover { box-shadow: var(--shadow); }
.station.is-active { border-color: var(--ink); box-shadow: var(--shadow); }
.station.is-cheapest { border-color: var(--green); background: linear-gradient(180deg, var(--green-soft), var(--surface) 70%); }
.station.is-cheapest.is-active { box-shadow: 0 0 0 2px var(--green), var(--shadow); }

.station-main {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start;
  width: 100%; padding: 12px 14px 8px; text-align: left;
  background: none; border: 0; border-radius: var(--radius) var(--radius) 0 0; cursor: pointer;
}
.station-name { font-weight: 700; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.station-brand { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.station-addr { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.station-addr.is-loading { color: #8A949B; font-style: italic; }
.station-price { grid-row: 1 / span 2; grid-column: 2; text-align: right; }
.price {
  display: block; font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums; color: var(--accent);
}
.is-cheapest .price { color: var(--green-ink); }
.price-unit { font-size: 12px; font-weight: 600; color: var(--muted); }
.station-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: #EFEEE8; color: var(--ink);
}
.badge-self { background: var(--accent-soft); color: var(--accent-ink); }
.badge-best { background: var(--green); color: #fff; background: var(--green-ink); }
.badge-old { background: #FFF6DB; color: #7A5A00; }
.station-links {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: 0 14px 12px; font-size: 13px; font-weight: 600;
}

/* ---------- Disponibilità segnalata dagli utenti ---------- */
.avail:empty { display: none; }
.avail { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.avail-detail { display: flex; margin: -2px 0 10px; }
.avail-note { font-size: 12px; color: var(--muted); }
.badge-ok { background: var(--green-soft); color: var(--green-ink); }
.badge-ko { background: #FDECEC; color: #A3141E; }
.station.is-out .price { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.station.is-out .station-name { color: var(--muted); }

.report { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.report-q { font-size: 12px; font-weight: 600; color: var(--muted); }
.report-btn {
  min-height: 32px; padding: 0 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: 12px; font-weight: 700;
  transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.report-btn:hover { border-color: var(--ink); }
.report-btn.is-yes[aria-pressed="true"] { background: var(--green-ink); border-color: var(--green-ink); color: #fff; }
.report-btn.is-no[aria-pressed="true"] { background: #B3261E; border-color: #B3261E; color: #fff; }
.report[aria-busy="true"] .report-btn { opacity: .6; cursor: progress; }
.report-msg:empty { display: none; }
.report-msg { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.leaflet-popup-content .report { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); width: 100%; }

.empty-list { color: var(--muted); font-size: 14px; padding: 8px 2px; }
.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, #EFEEE8 0%, #F7F6F2 50%, #EFEEE8 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Mappa: marker e popup ---------- */
.pin { display: block; border-radius: 50%; background: var(--ink); border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); transition: transform .2s var(--ease); }
.pin.is-active { background: var(--accent); transform: scale(1.35); }
.pin.is-out { background: #fff; border-color: #B3261E; box-shadow: inset 0 0 0 3px #B3261E, 0 1px 4px rgba(0, 0, 0, .35); }
.pin.is-out.is-active { background: #B3261E; }
.pin-best {
  display: grid; place-items: center; width: 40px; height: 40px;
  background: var(--green); color: #fff; border: 3px solid #fff; border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg); box-shadow: 0 3px 10px rgba(14, 122, 56, .45);
}
.pin-best svg { width: 20px; height: 20px; transform: rotate(45deg); }
.pin-user { width: 18px; height: 18px; border-radius: 50%; background: #2F6BFF; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(47, 107, 255, .2); }

.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 14px 16px; min-width: 210px; font-size: 14px; line-height: 1.45; }
.popup-best { font-size: 12px; font-weight: 800; color: var(--green-ink); text-transform: uppercase; letter-spacing: .06em; }
.popup-name { font-weight: 800; font-size: 16px; }
.popup-addr { color: var(--muted); font-size: 13px; }
.popup-price { margin: 6px 0; font-size: 26px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.popup-price.is-best { color: var(--green-ink); }
.popup-price small { font-size: 13px; color: var(--muted); font-weight: 600; }
.popup-meta { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.leaflet-popup-content .btn { min-height: 36px; font-size: 13px; color: var(--ink); }
.leaflet-container a.leaflet-popup-close-button { width: 28px; height: 28px; font-size: 20px; }

/* ---------- Footer ---------- */
.footer {
  height: var(--footer-h); display: flex; align-items: center; justify-content: center;
  padding: 0 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); text-align: center;
}
.footer a { color: var(--muted); }

/* ---------- Tablet stretto ---------- */
@media (max-width: 1180px) {
  .tagline { display: none; }
  .controls { gap: 12px; }
  .radius { min-width: 130px; }
  .fuel-picker span { padding: 8px 11px; }
}

/* ---------- Mobile: mappa sopra, lista sotto, controlli in basso ---------- */
@media (max-width: 859px) {
  :root { --controls-h: 132px; }
  body { padding-bottom: calc(var(--controls-h) + env(safe-area-inset-bottom)); }
  .topbar { height: auto; padding: 12px 16px; }
  .tagline { display: block; max-width: none; white-space: normal; }
  .brand h1 { font-size: 20px; }

  .controls {
    position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(250, 250, 247, .96); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(14, 26, 34, .08);
  }
  .fuel-picker { grid-column: 1 / -1; justify-content: space-between; }
  .fuel-picker label { flex: 1; }
  .fuel-picker span { text-align: center; padding: 10px 4px; }
  .radius { min-width: 0; }
  #locate { min-height: 44px; padding: 0 14px; }
  #locate span { display: none; }
  #locate::after { content: "Posizione"; }

  .layout { display: block; height: auto; }
  .map-wrap { height: 55vh; height: 55svh; }
  .panel { border-left: 0; overflow: visible; padding: 16px; }
  .list-hint { display: none; }
  .footer { height: auto; padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
