/* Sottocasa: un solo foglio per telefono e computer. Sotto i 960 px una colonna con Elenco/Mappa;
   da 960 px domande e schede a sinistra, mappa sempre visibile a destra. */

:root {
  --bg: #f4f5f7; --card: #fff; --text: #1f2933; --muted: #6b7785; --line: #dde2e8; --brand: #17324f;
  --accent: #1f5fa8; --accent-soft: #e8f0fa; --warn: #b7791f; --warn-soft: #fdf6e7; --err: #c0392b; --err-soft: #fdecea;
  --head: 52px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; overflow-x: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.normal { font-weight: 400; }

/* ---------- Intestazione e navigazione ---------- */

.top { position: sticky; top: 0; z-index: 900; background: var(--brand); color: #fff; display: flex; align-items: center; gap: 10px;
       min-height: var(--head); padding: max(8px, env(safe-area-inset-top)) 16px 8px; }
.brand { color: #fff; text-decoration: none; font-size: 19px; font-weight: 700; margin-right: auto; }
.menu-button { border: 0; background: none; color: #fff; font-size: 24px; line-height: 1; padding: 4px 6px; margin-left: -6px; }
.top-nav { display: none; }
.top-nav a { color: #d5dfeb; text-decoration: none; font-size: 15px; font-weight: 600; padding: 7px 12px; border-radius: 999px; white-space: nowrap; }
.top-nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.top-nav a[aria-current="page"] { background: #fff; color: var(--brand); }

.drawer { position: fixed; inset: 0; z-index: 1100; display: flex; }
.drawer-panel { width: min(82vw, 320px); background: var(--card); display: flex; flex-direction: column; overflow-y: auto;
                padding-top: env(safe-area-inset-top); box-shadow: 2px 0 12px rgba(0,0,0,.25); animation: slide-in .2s ease-out; }
.drawer-shade { flex: 1; background: rgba(0,0,0,.4); animation: fade-in .2s ease-out; }
@keyframes slide-in { from { transform: translateX(-100%); } }
@keyframes fade-in { from { opacity: 0; } }
.drawer-head { background: var(--brand); color: #fff; font-weight: 700; font-size: 19px; padding: 14px 16px; }
.drawer-nav a { display: block; color: inherit; text-decoration: none; border-bottom: 1px solid #e9edf1; padding: 13px 16px; }
.drawer-nav a b { display: block; font-size: 16px; }
.drawer-nav a span { display: block; font-size: 13px; color: var(--muted); }
.drawer-nav a[aria-current="page"] { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.drawer-foot { margin-top: auto; padding: 14px 16px; font-size: 14px; }

/* ---------- L'app: colonna delle domande e dei risultati, mappa ---------- */

.app { max-width: 600px; margin: 0 auto; padding: 14px 16px 8px; }
.mode-title { margin: 0 2px 4px; font-size: 21px; line-height: 1.25; }
.mode-help { font-size: 14px; color: var(--muted); margin: 0 2px 12px; }

.ask { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.q { display: block; font-weight: 650; margin: 0 0 8px; }
.block + .block { margin-top: 16px; }
.place { width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 50px; text-align: left;
         border: 1px solid #c5ccd5; border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 17px; }
.place:hover { border-color: var(--accent); }
.place .placeholder { color: var(--muted); }
.choices { display: flex; gap: 8px; }
.choices button { flex: 1; min-height: 46px; border: 1px solid #b9cde6; border-radius: 10px; background: #fff; font-weight: 600; }
.choices button:hover { border-color: var(--accent); }
.choices button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.time { font: inherit; font-size: 17px; min-height: 46px; border: 1px solid #c5ccd5; border-radius: 10px; padding: 8px 12px;
        background: #fff; color: var(--text); }
.when { display: flex; gap: 8px; align-items: center; }
.when .choices { flex: 1; }
.chips { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.chip { display: flex; align-items: center; gap: 8px; border: 1px solid #c5ccd5; border-radius: 10px; padding: 6px 6px 6px 12px; background: #fff; }
.chip .name { flex: 1; min-width: 0; }
.chip button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 6px 10px; color: var(--muted); }
.add { justify-content: center; color: var(--accent); font-weight: 600; border-style: dashed; }

details.home { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
details.home summary { list-style: none; cursor: pointer; font-weight: 650; padding: 8px 0; display: flex; align-items: center; gap: 8px; }
details.home summary::-webkit-details-marker { display: none; }
details.home summary::after { content: '▾'; margin-left: auto; color: var(--muted); }
details.home[open] summary::after { content: '▴'; }
details.home summary .hint { font-weight: 400; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; margin-top: 10px; }
.row label { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }
.row input { display: block; width: 100%; margin-top: 3px; font: inherit; font-size: 17px; color: var(--text); min-height: 46px;
             border: 1px solid #c5ccd5; border-radius: 10px; padding: 8px 10px; background: #fff; }

/* Messaggi. */
.warn, .err, .info { border-radius: 10px; padding: 8px 12px; margin: 10px 0 0; font-size: 14px; }
.warn { background: var(--warn-soft); }
.info { background: var(--accent-soft); }
.err { background: var(--err-soft); color: #7d241b; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 22px 0; font-size: 15px; }
.spinner { width: 20px; height: 20px; flex: none; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
           animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Barra dei risultati. */
#resultsHead { margin: 18px 0 6px; font-weight: 650; }
#bar { position: sticky; top: var(--head); z-index: 800; background: var(--bg); padding: 6px 0 8px; display: flex; gap: 8px; }
.seg { display: flex; flex: 1; background: #e3e8ee; border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px 4px; font-size: 14px; font-weight: 600; color: #3d4a57; }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

/* Schede dei risultati. */
.card { width: 100%; text-align: left; display: block; background: var(--card); border: 1px solid transparent; border-radius: 14px;
        padding: 12px 14px; margin: 8px 0; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card:hover { border-color: #b9cde6; }
.card:active, .card.on { background: var(--accent-soft); }
.card-top { display: flex; align-items: center; gap: 8px; }
.card-top .name { font-weight: 650; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.card-top .km { color: var(--muted); font-size: 13px; white-space: nowrap; }
.big { font-size: 26px; font-weight: 750; letter-spacing: -.3px; margin-top: 2px; }
.big small { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.line { font-size: 14px; color: #3d4a57; }
.price { font-size: 15px; font-weight: 600; margin-top: 4px; }
.price .muted { font-weight: 400; font-size: 13px; }
.tag { display: inline-block; font-size: 12px; border-radius: 999px; padding: 1px 8px; background: var(--warn-soft); color: #7a5312; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.badge { display: inline-block; min-width: 14px; padding: 0 4px; margin: 0 1px; border-radius: 4px; vertical-align: 1px;
         color: #fff; font-weight: 700; font-size: 11px; line-height: 16px; text-align: center; white-space: nowrap; }
.badge.more { background: #fff; color: #3d4a57; border: 1px solid #9aa6b2; }
.split { display: block; width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid #fff;
  background: linear-gradient(90deg, var(--l) 50%, var(--r) 50%); box-shadow: 0 0 0 1px rgba(0,0,0,.45); }
.split.est { border: 2px dashed #7a4fb3; }

/* Mappa: sul telefono al posto dell'elenco, con "Mappa". */
.map-pane { max-width: 600px; margin: 0 auto; padding: 0 16px; }
#map { height: calc(100vh - 140px); height: calc(100dvh - 140px); min-height: 320px; border-radius: 14px; overflow: hidden; background: #e8ecef; }
.legend { background: rgba(255,255,255,.94); border-radius: 8px; padding: 6px 8px; font-size: 11px; line-height: 1.5; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.legend .ramp { display: inline-block; width: 46px; height: 8px; border-radius: 4px; margin: 0 4px;
                background: linear-gradient(to right, hsl(120,80%,40%), hsl(60,80%,40%), hsl(0,80%,40%)); }
.map-wait { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); padding: 16px; text-align: center; }

/* ---------- Selettore della stazione e dettaglio ---------- */

.overlay { position: fixed; inset: 0; z-index: 1000; display: flex; }
.overlay-box { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.overlay-top { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
.overlay-top button { border: 0; background: none; color: #fff; font-weight: 600; padding: 6px 4px; }
.overlay-top input { flex: 1; font: inherit; font-size: 17px; border: 0; border-radius: 10px; padding: 9px 12px; min-width: 0; }
.overlay-body { flex: 1; overflow-y: auto; }
.stop-item { width: 100%; text-align: left; border: 0; border-bottom: 1px solid #e9edf1; background: #fff; padding: 13px 16px;
             display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 16px; }
.stop-item:hover { background: var(--accent-soft); }
.stop-item.current { font-weight: 650; }
.stop-empty { padding: 16px; color: var(--muted); }

#sheetBody { padding: 14px 16px 32px; max-width: 600px; margin: 0 auto; width: 100%; }
#sheetBody h2 { margin: 0 0 2px; font-size: 22px; }
.panel { background: var(--card); border-radius: 14px; padding: 12px 14px; margin: 12px 0; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.panel h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.leg { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; margin: 8px 0; }
.leg .muted { font-size: 13px; }
.button { display: block; text-align: center; text-decoration: none; background: var(--accent); color: #fff; border-radius: 12px;
          padding: 12px; margin: 8px 0 0; font-weight: 650; }
.button.light { background: var(--accent-soft); color: var(--accent); }

/* ---------- Testi delle pagine ---------- */

.about, .page { max-width: 760px; margin: 0 auto; padding: 8px 16px 8px; font-size: 15.5px; line-height: 1.6; }
.about { margin-top: 24px; border-top: 1px solid var(--line); }
.about h2, .page h2 { font-size: 19px; margin: 1.4em 0 .4em; }
.page h1 { font-size: 26px; margin: .6em 0 .3em; }
.about ul, .page ul { padding-left: 1.2em; }
.about li, .page li { margin: .3em 0; }
.table-wrap { overflow-x: auto; }
.page table { border-collapse: collapse; width: 100%; font-size: .95em; background: var(--card); }
.page th, .page td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.page th { background: #eceff3; }
@media (max-width: 600px) { .page:not(.stats) th:nth-child(3), .page:not(.stats) td:nth-child(3) { display: none; } }
.stats .tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.stats .tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stats .tile b { display: block; font-size: 24px; }
.stats .periods { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.stats .periods a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; }
.stats .periods a[aria-current] { background: #17324f; color: #fff; border-color: #17324f; }
.stats .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 0 24px; }
.stats .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats .bar { display: block; height: 6px; margin-top: 3px; background: #f39200; border-radius: 3px; min-width: 2px; }
.stats .detail { color: var(--muted, #667); font-size: .9em; }

.foot { margin: 24px 16px 28px; font-size: 12px; color: #666; text-align: center; }
.foot a { color: inherit; }
.foot-modes a { margin: 0 6px; }

/* ---------- Computer: due colonne, mappa sempre visibile ---------- */

@media (min-width: 960px) {
  .menu-button { display: none; }
  .top { padding: 8px 24px; }
  .top-nav { display: flex; gap: 4px; }

  .app { max-width: 1500px; display: grid; grid-template-columns: minmax(380px, 460px) 1fr; gap: 24px; align-items: start; padding: 20px 24px 8px; }
  .map-pane { max-width: none; width: 100%; margin: 0; padding: 0; position: sticky; top: calc(var(--head) + 20px); }
  #map { height: calc(100vh - var(--head) - 40px); min-height: 480px; }
  #view { display: none; }
  #bar { top: var(--head); }
  .mode-title { font-size: 24px; }

  /* Selettore: finestra al centro. Dettaglio: pannello a destra, sopra la mappa. */
  .overlay { background: rgba(15, 25, 40, .45); animation: fade-in .15s ease-out; }
  #picker { align-items: flex-start; justify-content: center; padding-top: 8vh; }
  #picker .overlay-box { flex: none; width: 560px; max-height: 80vh; border-radius: 14px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
  .sheet { justify-content: flex-end; }
  .sheet .overlay-box { flex: none; width: 480px; box-shadow: -4px 0 24px rgba(0,0,0,.25); animation: slide-left .2s ease-out; }
  @keyframes slide-left { from { transform: translateX(100%); } }
  .about { margin-top: 40px; }
}
