/* ═══════════════════════════════════════════════════════════════════════════
   Roadjust — foglio di stile
   Struttura: token → base → layout → barra in alto → filtri → viste →
   componenti (liste, webcam, gruppi) → popup mappa → dialog → responsive
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --ink: #111820;
  --muted: #5b6673;
  --faint: #8a95a2;
  --line: #e1e5ea;
  --acc: #1f6fd6;          /* blu dei cartelli autostradali */
  --acc-ink: #ffffff;
  --acc-soft: rgba(31, 111, 214, 0.12);
  --warn: #e0a800;
  --bad: #d7263d;
  --good: #1f9d6b;
  --shadow: 0 10px 30px -12px rgba(16, 24, 32, 0.28);
  --shadow-sm: 0 2px 8px rgba(16, 24, 32, 0.10);
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --h-tab: 64px;
  font-family: Inter, "SF Pro Text", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1016;
  --surface: #141b23;
  --surface-2: #1c2530;
  --ink: #eef2f6;
  --muted: #a1adba;
  --faint: #6f7c8a;
  --line: #26303b;
  --acc: #5aa2ff;
  --acc-ink: #06121f;
  --acc-soft: rgba(90, 162, 255, 0.16);
  --shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* ─────────────────────────────── base ─────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--acc); }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.link { border: 0; background: none; padding: 0; color: var(--acc); cursor: pointer; }

/* ─────────────────────────────── layout ────────────────────────────── */
.layout { flex: 1; min-height: 0; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.views { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow: auto; display: none; padding: 8px 16px 32px; -webkit-overflow-scrolling: touch; }
.view.is-active { display: block; }
#view-mappa { padding: 0; overflow: hidden; }
#map { position: absolute; inset: 0; max-width: none; margin: 0; }
.view > * { max-width: 760px; margin-left: auto; margin-right: auto; }

/* barra laterale (desktop) */
.sidebar { display: none; }

/* marchio: un tratto di strada stilizzato */
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.brand-name { font-weight: 750; font-size: 18px; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--acc) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M9.5 4 6 20M14.5 4 18 20'/%3E%3Cpath d='M12 6v2.5M12 11v2.5M12 16v2.5' stroke-width='1.8'/%3E%3C/svg%3E") center/18px no-repeat; }

/* ───────────────────────────── barra in alto ───────────────────────── */
.appbar { display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 8px) 12px 6px 16px; background: var(--bg); }
.stato { flex: 1; margin: 0; font-size: 12.5px; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: var(--surface-2); width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:active { transform: scale(.96); }
.spin .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────── filtri ────────────────────────────── */
.filters { display: flex; gap: 6px; padding: 0 12px 8px; background: var(--bg); position: relative; z-index: 6; }
body:not([data-view="mappa"]):not([data-view="eventi"]) .filters { display: none; }
body[data-view="eventi"] #chip-cams { display: none; }
.dd { position: relative; }
.dd-btn, .toggle-chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm); }
.dd-btn[aria-expanded="true"] { border-color: var(--acc); }
.dd-label { font-weight: 650; }
.dd-val { color: var(--muted); }
.dd-val:empty { display: none; }
.chev { width: 16px; height: 16px; transition: transform .15s; }
.dd-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.toggle-chip { padding: 0 12px 0 10px; font-weight: 600; }
.toggle-chip input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-chip:has(input:checked) { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.toggle-chip .ic { width: 18px; height: 18px; }
.dd-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 240px; max-height: min(62dvh, 460px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow); padding: 6px; }
.dd-quick { display: flex; gap: 4px; padding: 2px 4px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dd-quick button { border: 0; background: none; color: var(--acc); font-size: 13px; padding: 4px 6px; cursor: pointer; border-radius: 6px; }
.dd-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.dd-item:hover { background: var(--surface-2); }
.dd-item input { width: 17px; height: 17px; margin: 0; accent-color: var(--acc); flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dd-name { flex: 1; }
.dd-item .n { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.dd-item.err .n { color: var(--bad); }

/* tendina Luogo */
.dd-luogo .dd-btn { padding-left: 10px; }
.dd-luogo .dd-btn > .ic:first-child { width: 17px; height: 17px; color: var(--acc); }
.dd-luogo #luogo-nome { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.dd-luogo.attivo .dd-btn { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.dd-luogo .dd-menu { width: 320px; }
.dd-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 8px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; font-size: 14px; }
.dd-row:hover { background: var(--surface-2); }
.dd-row .ic { width: 18px; height: 18px; color: var(--acc); }
.dd-row-muted .ic { color: var(--muted); }
.search-sm { height: 38px; margin: 4px 4px 2px; flex: none; }
.dd-results { list-style: none; margin: 4px 0; padding: 0; }
.dd-results:empty { display: none; }
.dd-results button { display: block; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 8px; text-align: left; cursor: pointer; }
.dd-results button:hover, .dd-results button:focus { background: var(--surface-2); outline: none; }
.dd-results small { display: block; color: var(--muted); font-size: 12px; }
.dd-results .nota { padding: 8px 10px; color: var(--muted); font-size: 13px; }
.dd-raggio { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; border-top: 1px solid var(--line); margin-top: 4px; font-size: 13px; color: var(--muted); }
.dd-raggio .seg-btn { padding: 5px 8px; font-size: 12.5px; }

/* ─────────────────────────────── viste ─────────────────────────────── */
.view-head { padding: 6px 0 10px; }
.view-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.view-sub { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.list-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.search { flex: 1 1 220px; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.search input { flex: 1; min-width: 0; border: 0; background: none; font: inherit; color: inherit; outline: none; font-size: 16px; }
.search .ic { color: var(--muted); width: 18px; height: 18px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn { border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg-btn.is-on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.ghost-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; }
.ghost-btn .ic { width: 18px; height: 18px; }
.more-btn { display: block; margin: 12px auto 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }

/* elenco eventi */
.event-list { list-style: none; margin: 0 auto; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ev { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 12px; align-items: start; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer; text-align: left; width: 100%; }
.ev:hover { border-color: var(--acc); }
.ev .dot { margin-top: 6px; }
.ev-title { font-weight: 650; }
.ev-road { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 5px; background: var(--acc); color: #fff; font-size: 12.5px; font-weight: 700; line-height: 20px; vertical-align: 1px; }
.ev-text { grid-column: 2 / 4; color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev-meta { color: var(--faint); font-size: 12px; white-space: nowrap; text-align: right; }

/* webcam */
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cam { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.cam a { color: inherit; text-decoration: none; }
.cam img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.cam-body { padding: 8px 12px 10px; }
.cam-title { font-weight: 600; font-size: 14px; }
.cam-sub { color: var(--muted); font-size: 12.5px; }

/* gruppi di impostazioni (Altro) */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 6px; margin-bottom: 14px; }
.group-title { margin: 8px 10px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 10px; border: 0; background: none; border-radius: 10px; text-align: left; cursor: pointer; flex-wrap: wrap; }
.row:hover { background: var(--surface-2); }
.row > span { flex: 1; }
.row .next { color: var(--faint); }
.row-val { color: var(--muted); font-weight: 500; font-size: 13.5px; }
.switch { width: 42px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
[aria-checked="true"] .switch { background: var(--good); }
[aria-checked="true"] .switch::after { transform: translateX(16px); }
.fonte { display: flex; align-items: center; gap: 10px; padding: 10px; font-size: 14px; }
.fonte span { flex: 1; }
.fonte b { font-weight: 500; color: var(--muted); font-size: 13px; }
.fonte .ok { background: var(--good); } .fonte .ko { background: var(--bad); } .fonte .wait { background: var(--faint); }
.page-foot { color: var(--faint); font-size: 12.5px; text-align: center; padding: 8px 0 24px; }

/* ─────────────────────────────── tab bar ───────────────────────────── */
.tabbar { flex: none; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 6px; font-size: 11px; color: var(--faint); cursor: pointer; position: relative; }
.tab .ic { width: 23px; height: 23px; }
.tab.is-active { color: var(--acc); }
.badge { position: absolute; top: 3px; left: calc(50% + 6px); min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 10.5px; line-height: 18px; font-weight: 700; }

/* ───────────────────────────── mappa e popup ───────────────────────── */
.segnaposto { width: 18px; height: 18px; border-radius: 50%; background: #1f6fd6; border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.35); }
.segnaposto.gps { background: #1a8cff; box-shadow: 0 0 0 6px rgba(26,140,255,.25), 0 1px 6px rgba(0,0,0,.35); }
.map-hint { position: absolute; z-index: 3; left: 50%; bottom: 28px; transform: translateX(-50%); margin: 0; padding: 6px 12px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-sm); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.maplibregl-ctrl-group { background: var(--surface) !important; box-shadow: var(--shadow-sm) !important; }
html[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
html[data-theme="dark"] .maplibregl-ctrl-attrib { background: rgba(20,27,35,.8) !important; color: var(--muted); }
html[data-theme="dark"] .maplibregl-ctrl-attrib a { color: var(--muted); }
html[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-popup-content { background: var(--surface); color: var(--ink); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 20px; padding: 2px 8px; }
.pop h4 { margin: 0 0 2px; font-size: 15px; padding-right: 18px; }
.pop p { margin: 6px 0 0; font-size: 13px; }
.pop .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.pop .tag { display: inline-block; padding: 1px 8px; border-radius: 999px; color: #fff; font-size: 11.5px; font-weight: 650; margin-bottom: 6px; }
.pop img { display: block; width: 100%; border-radius: 8px; margin-top: 8px; background: var(--surface-2); min-height: 60px; }

/* ─────────────────────────────── dialog ────────────────────────────── */
.doc-dialog { border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); width: min(640px, calc(100vw - 24px)); max-height: min(86dvh, 820px); box-shadow: var(--shadow); }
.doc-dialog::backdrop { background: rgba(8, 12, 18, .5); }
.doc-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.doc-head h2 { flex: 1; margin: 0; font-size: 18px; }
.doc-body { padding: 6px 20px 22px; font-size: 14.5px; }
.doc-body h3 { font-size: 15px; margin: 18px 0 4px; }
.doc-body p, .doc-body li { color: var(--ink); }
.doc-body ul { padding-left: 20px; }
.doc-body small { color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--h-tab) + env(safe-area-inset-bottom) + 14px);
  background: #111820; color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 13.5px; z-index: 50; max-width: 92vw; box-shadow: var(--shadow); }

/* ─────────────────────────────── responsive ────────────────────────── */
@media (max-width: 600px) {
  .filters { overflow-x: auto; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .dd-menu, .dd-luogo .dd-menu { position: fixed; left: 12px; right: 12px; width: auto; min-width: 0; top: var(--menu-top, 120px); transform: none !important; }
}
@media (max-width: 420px) {
  .dd-btn, .toggle-chip { padding: 0 6px 0 10px; font-size: 13px; }
  .toggle-chip span { display: none; }
}
@media (min-width: 900px) {
  .tabbar { display: none; }
  .brand-top { display: none; }
  .toast { bottom: 24px; }
  .sidebar { display: flex; flex-direction: column; width: 232px; flex: none; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--surface); }
  .sidebar .brand { padding: 4px 10px 18px; }
  .nav { display: flex; flex-direction: column; gap: 2px; }
  .nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 550; color: var(--muted); text-align: left; }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.is-active { background: var(--acc-soft); color: var(--acc); }
  .side-foot { margin-top: auto; padding: 10px; font-size: 12.5px; color: var(--faint); }
  .side-foot p { margin: 4px 0; }
  .appbar { padding-top: 12px; }
  .view { padding: 16px 28px 40px; }
}
