:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1c1d20;
  --muted: #6b6e76;
  --line: #e4e2dc;
  --accent: #b8452f;
  --ok: #1f8a4c;
  --late: #c0392b;
  --walk: #8a8d94;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #212226;
    --text: #ececec;
    --muted: #9a9ca3;
    --line: #34353b;
    --accent: #e0775f;
    --ok: #4cc47f;
    --late: #ff6b5b;
    --walk: #8a8d94;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 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);
}
main { max-width: 620px; margin: 0 auto; padding: 0 14px 24px; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { padding: 18px 2px 12px; }
.top h1 { margin: 0; font-size: 1.45rem; letter-spacing: -.01em; }
.top h1 span { color: var(--accent); font-weight: 600; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

/* Form */
#search { padding: 6px 6px 10px; position: relative; }
.field { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 12px; }
.field + .field { border-top: 1px solid var(--line); }
.field input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  padding: 11px 0; font-size: 1.02rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-from { border: 2.5px solid var(--text); }
.dot-to { background: var(--accent); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); padding: 8px;
  border-radius: 10px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg); color: var(--text); }
.icon-btn.busy { animation: pulse 1s infinite; }

.when { display: flex; gap: 8px; padding: 8px 6px 0; flex-wrap: wrap; }
.when select, .when input {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 9px 10px; min-width: 0;
}
.when input { flex: 1 1 180px; }
.go {
  margin-left: auto; border: 0; border-radius: 10px; padding: 9px 20px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}

.suggest {
  list-style: none; margin: 4px 0 0; padding: 4px 0; position: absolute; left: 0; right: 0;
  top: var(--suggest-top, 100%); z-index: 10; max-height: 60vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.suggest li { padding: 9px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--bg); }
.suggest .s-ico { width: 22px; text-align: center; flex: none; color: var(--muted); font-size: .95rem; }
.suggest .s-main { flex: 1; min-width: 0; }
.suggest .s-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .s-area { color: var(--muted); font-size: .85rem; }
.suggest .s-head { padding: 6px 14px 2px; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; cursor: default; }
.suggest .s-head:hover { background: none; }

.status { color: var(--muted); padding: 16px 4px; text-align: center; }
.status.error { color: var(--late); }

/* Risultati */
#results { display: grid; gap: 10px; margin-top: 14px; }
.itin { padding: 13px 14px; cursor: pointer; text-align: left; width: 100%; display: block; }
.itin:hover { border-color: var(--muted); }
.itin-row { display: flex; align-items: baseline; gap: 10px; }
.itin-times { font-size: 1.12rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.itin-dur { margin-left: auto; font-weight: 650; white-space: nowrap; }
.itin-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 9px 0 7px; }
.itin-meta { color: var(--muted); font-size: .88rem; display: flex; gap: 12px; flex-wrap: wrap; }
.chev { color: var(--muted); font-size: .8rem; }
.walk { color: var(--walk); font-size: .85rem; display: inline-flex; align-items: center; gap: 2px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 2px 7px;
  font-weight: 700; font-size: .86rem; line-height: 1.35; white-space: nowrap;
}
.badge svg { width: 14px; height: 14px; flex: none; }
.badge.metro { border-radius: 50%; width: 24px; height: 24px; padding: 0; justify-content: center; font-size: .82rem; }
.badge.metro.wide { width: auto; border-radius: 12px; padding: 0 7px; }

.live { color: var(--ok); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
.late { color: var(--late); font-weight: 600; }
.cancel { color: var(--late); font-weight: 700; }
.leave { font-weight: 600; }
@keyframes pulse { 50% { opacity: .35; } }

.more { text-align: center; margin: 14px 0; }
.more button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 18px; cursor: pointer;
}

/* Dettaglio */
.detail-top { display: flex; align-items: center; gap: 8px; }
.detail-top h2 { margin: 0; font-size: 1.15rem; }
.detail-top .sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.back { border: 0; background: transparent; padding: 6px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.back:hover { background: var(--card); }
.map { height: 30vh; min-height: 200px; max-height: 340px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--card); }

.legs { list-style: none; margin: 14px 0 0; padding: 0; }
.leg { display: grid; grid-template-columns: 52px 18px 1fr; column-gap: 8px; }
.leg-time { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding-top: 1px; font-size: .95rem; }
.leg-time .sched { display: block; color: var(--muted); text-decoration: line-through; font-weight: 400; font-size: .8rem; }
.leg-rail { position: relative; display: flex; justify-content: center; }
.leg-rail::before { content: ""; position: absolute; top: 18px; bottom: -4px; width: 4px; border-radius: 2px; background: var(--rail, var(--walk)); }
.leg.walking .leg-rail::before { background: none; border-left: 3px dotted var(--walk); width: 0; }
.leg.end .leg-rail::before { display: none; }
.leg-rail .node { position: relative; z-index: 1; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--rail, var(--text)); margin-top: 3px; }
.leg-body { padding-bottom: 18px; min-width: 0; }
.leg-place { font-weight: 600; }
.leg-place .track { font-weight: 500; color: var(--muted); font-size: .88rem; margin-left: 6px; }
.leg-info { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .92rem; }
.leg-info .dir { color: var(--text); }
.leg-sub { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.leg-actions { margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; font-size: .88rem; }
.link { border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; font-weight: 600; }
.stops-list { margin: 6px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: .88rem; }
.stops-list li { padding: 2px 0; display: flex; gap: 8px; }
.stops-list .t { font-variant-numeric: tabular-nums; min-width: 40px; }
.alert { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--late) 10%, transparent); font-size: .87rem; }
.alert summary { font-weight: 600; cursor: pointer; }
.alert[open] summary { margin-bottom: 4px; }

.departures { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dep { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.dep .dir { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep .when { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; padding: 0; display: block; }
.dep .when .min { font-weight: 700; }
.dep .when small { display: block; color: var(--muted); }

.foot { margin-top: 28px; color: var(--muted); font-size: .78rem; text-align: center; line-height: 1.6; }

.maplibregl-ctrl-attrib { font-size: 10px; }
