/* Statistiche per comune (/statistiche/<comune>, pagine.py + js/statistiche.js): otto grafici con la loro lettura */
:is(#st-pagina, #zona-stat), .st-scelta { --c-ac: #4FC3F7; --c-dc: #9B8CFF; --c-hpc: #FF6FA8; --hm0: #17305C; --hm1: #1D5C99; --hm2: #2B8FD4; --hm3: #5CC6F7; --hm4: #CDEFFF; }
:root[data-theme="light"] :is(#st-pagina, #zona-stat) { --c-ac: #1E6FD9; --c-dc: #6D55D9; --c-hpc: #D13F7A; --hm0: #CFE0F4; --hm1: #9CC6F0; --hm2: #5AA4EA; --hm3: #1E6FD9; --hm4: #0B3A85; }
.st-scelta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px; margin: 12px 0 16px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--border); }
.st-scelta label { flex: 1 1 180px; display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 13px; min-width: 0; }
.st-scelta label.st-scelta-com { flex-basis: 240px; }
.st-scelta select:disabled { opacity: .5; }
.st-tes-nome a { color: inherit; }
.st-scelta select { width: 100%; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
.st-scelta select:focus { outline: 2px solid var(--sun); outline-offset: 2px; }
.st-scelta option, .st-scelta optgroup { background: #0d2552; color: #EAF4FF; }
:root[data-theme="light"] .st-scelta option, :root[data-theme="light"] .st-scelta optgroup { background: #fff; color: #0A1F44; }
.st-kpi { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 14px 0; }
.st-kpi div { padding: 12px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.st-kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.st-kpi span { font-size: 12px; color: var(--muted); }
.st-griglia { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.st-card { padding: 14px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); min-width: 0; position: relative; }
.st-card.larga { grid-column: 1 / -1; }
.st-card h2 { font-size: 16px; margin: 0 0 2px; }
.st-card .nota { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.st-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.st-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--sun) 22%, transparent);
  color: var(--text); margin-left: 6px; vertical-align: 2px; }
.st-leg { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.st-leg i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
:is(#st-pagina, #zona-stat) .txt { fill: var(--muted); font-size: 10px; font-family: inherit; }
:is(#st-pagina, #zona-stat) .txt-b { fill: var(--text); font-size: 11px; font-family: inherit; font-weight: 700; }
.st-griglia-ln { stroke: var(--border); stroke-width: 1; fill: none; }
.st-asse { stroke: var(--muted); stroke-opacity: .35; }
.st-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 2px 0 6px; }
.st-seg button { font: inherit; font-size: 12px; padding: 5px 12px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.st-seg button[aria-pressed="true"] { background: var(--sun); color: #0A1F44; font-weight: 700; }
.st-seg button:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
#st-tip { position: fixed; pointer-events: none; z-index: 50; padding: 8px 10px; border-radius: 10px; font-size: 12px; line-height: 1.35; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); backdrop-filter: blur(16px); box-shadow: 0 6px 24px rgba(0,0,0,.3); display: none; max-width: 240px; }
.st-hl { stroke: var(--sun); stroke-width: 2; }
.st-tes { display: grid; gap: 9px; margin-top: 6px; }
.st-tes-riga { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.st-tes-nome { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-tes-barra { position: relative; height: 14px; border-radius: 7px; background: color-mix(in srgb, var(--muted) 14%, transparent); }
.st-tes-barra i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 7px; background: var(--c-ac); }
.st-tes-pct { text-align: right; font-variant-numeric: tabular-nums; }
.st-lettura { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--sky) 9%, transparent); border-left: 3px solid var(--sky);
  font-size: 13.5px; line-height: 1.5; }
.st-lettura b.tit { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.st-lettura p { margin: 4px 0 0; }
.st-come { margin-top: 10px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.st-come summary { cursor: pointer; font-weight: 700; color: var(--text); }
.st-come summary:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; border-radius: 4px; }
.st-come p { margin: 6px 0 0; }
.st-come b { color: var(--text); }
/* Comuni senza colonnine: barre con/senza, cerchi della mappa, nomi dei comuni */
.sz-barra { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 48px; gap: 10px; align-items: center; font-size: 13px; margin: 7px 0; }
.sz-barra span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sz-tr { position: relative; height: 16px; border-radius: 8px; overflow: hidden; background: color-mix(in srgb, var(--c-ac) 55%, transparent); }
.sz-tr i { position: absolute; right: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--bad) 78%, transparent); }
.sz-p { text-align: right; font-variant-numeric: tabular-nums; }
:is(#st-pagina, #zona-stat) .sz-con { fill: var(--c-ac); fill-opacity: .85; stroke: var(--surface); stroke-width: 1; }
:is(#st-pagina, #zona-stat) .sz-senza { fill: color-mix(in srgb, var(--bad) 18%, transparent); stroke: var(--bad); stroke-width: 1.6; }
:is(#st-pagina, #zona-stat) .sz-con.st-hl, :is(#st-pagina, #zona-stat) .sz-senza.st-hl { stroke: var(--sun); stroke-width: 3; }
.sz-chip { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.sz-chip a { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--border)); color: var(--text); text-decoration: none; }
.sz-chip a:hover { border-color: var(--bad); }
/* Statistiche del viaggio (1.15): righe delle soste, etichette di stato (colore + pallino), barra degli operatori */
.vg-sosta { display: grid; grid-template-columns: 34px 1fr 150px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.vg-sosta:first-of-type { border-top: 0; }
.vg-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--sun); color: #0A1F44; font-weight: 800; }
.vg-nome { font-weight: 700; font-size: 14px; }
.vg-meta { font-size: 12px; color: var(--muted); }
.vg-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-top: 4px;
  background: color-mix(in srgb, var(--st) 18%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--st) 50%, transparent); }
.vg-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--st); }
.vg-quota { display: flex; gap: 2px; height: 22px; border-radius: 8px; overflow: hidden; margin: 6px 0; }
.vg-quota span { display: block; height: 100%; min-width: 3px; }
@media (max-width: 760px) { .vg-sosta { grid-template-columns: 30px 1fr; } .vg-sosta svg { grid-column: 1 / -1; } }
/* Il viaggio a colpo d'occhio (1.17): esito, numeri, strada (orizzontale; verticale con .stretto), confronto tra velocità */
.vc .ok { --st: var(--ok); } .vc .warn { --st: var(--warn); } .vc .bad { --st: var(--bad); }
.vc-esito { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 16px; font-size: 16px; font-weight: 800; margin-top: 8px;
  background: color-mix(in srgb, var(--st) 14%, transparent); border: 1.5px solid color-mix(in srgb, var(--st) 55%, transparent); }
.vc-esito .ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--st); color: #fff; font-size: 20px; flex: none; }
.vc-esito small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.vc-num { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0 4px; }
.vc-num div { padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.vc-num b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.vc-num span { font-size: 12px; color: var(--muted); }
.vc.stretto .vc-num { grid-template-columns: repeat(2, 1fr); }
.vc-batt { font-size: 13px; font-weight: 800; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--st); white-space: nowrap; }
.vc-punto { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; background: var(--surface); border: 3px solid var(--text); flex: none; position: relative; z-index: 1; }
.vc-punto.sosta { background: var(--sun); border-color: var(--sun); }
.vc-vel { display: inline-block; padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--sky) 22%, transparent); color: var(--text); font-weight: 800; }
.vc-asfalto, .vc-linea { background: var(--ok); opacity: .85; position: relative; overflow: hidden; }
.vc-asfalto i, .vc-linea i { position: absolute; background: var(--bad); }
.vc-strada-o { position: relative; height: 190px; margin: 10px 46px 0; }
.vc-asfalto { position: absolute; left: 0; right: 0; top: 62px; height: 14px; border-radius: 7px; }
.vc-asfalto i { top: 0; bottom: 0; }
.vc-tappa { position: absolute; top: 0; transform: translateX(-50%); display: grid; justify-items: center; text-align: center; width: 110px; gap: 6px; }
.vc-tappa .vc-ora { font-size: 13px; font-weight: 800; height: 18px; }
.vc-tappa .vc-nome { font-size: 11px; color: var(--muted); line-height: 1.2; }
.vc-tratto { position: absolute; top: 132px; transform: translateX(-50%); text-align: center; font-size: 11.5px; color: var(--muted); line-height: 1.5; width: 130px; }
.vc-tratto b { color: var(--text); }
.vc-strada-v { list-style: none; padding: 0; margin: 10px 0 0; }
.vc-strada-v li { display: grid; grid-template-columns: 48px 34px 1fr; column-gap: 10px; align-items: center; }
.vc-strada-v .vc-ora { text-align: right; font-weight: 800; font-size: 14px; }
.vc-strada-v .vc-nome { font-weight: 800; font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.vc-linea { justify-self: center; width: 12px; height: 100%; min-height: 74px; margin: -3px 0; }
.vc-linea i { left: 0; right: 0; }
.vc-info { font-size: 13px; color: var(--muted); padding: 8px 0; line-height: 1.5; }
.vc-info b { color: var(--text); }
.vc-info.vc-ric { padding: 2px 0 6px; }
.vc-sez { font-size: 16px; margin: 22px 0 2px; }
/* Andata e ritorno (1.34.1): titolo di ogni strada, con il pallino del giudizio e i suoi numeri */
.vc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.vc-meta span { font-size: 13px; font-weight: 500; color: var(--muted); }
.vc-pall { width: 12px; height: 12px; border-radius: 50%; background: var(--st); flex: none; }
.vc-tab { width: 100%; min-width: 0 !important; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.vc-tab th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 8px; }
.vc-tab td { padding: 9px 8px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.vc-tab tr.scelta td { background: color-mix(in srgb, var(--sky) 12%, transparent); }
.vc-tag { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 999px; margin-left: 6px; white-space: nowrap; }
.vc-tag.top { background: var(--ok); color: #fff; } .vc-tag.tua { background: var(--sky); color: #0A1F44; }
.vc-barra { display: block; height: 6px; border-radius: 3px; background: var(--sky); margin-top: 4px; opacity: .7; }
.vc.stretto .vc-largo { display: none; }
.vc.stretto .vc-tab { font-size: 13px; } .vc.stretto .vc-tab td, .vc.stretto .vc-tab th { padding: 8px 5px; }
.vc.stretto .vc-tag { display: block; width: max-content; margin: 3px 0 0; } .vc.stretto .vc-tab td:first-child { white-space: nowrap; }
/* Mappe con i confini veri (data/confini): comuni attorno, territorio scelto, bordo; comuni colorati; regioni */
:is(#st-pagina, #zona-stat) .mp-comune { fill: color-mix(in srgb, var(--muted) 8%, transparent); stroke: var(--muted); stroke-opacity: .35; stroke-width: .7; }
:is(#st-pagina, #zona-stat) .mp-fuoco { fill: color-mix(in srgb, var(--sky) 10%, var(--surface)); }
:is(#st-pagina, #zona-stat) .mp-bordo { fill: none; stroke: var(--sun); stroke-width: 2; stroke-linejoin: round; }
:is(#st-pagina, #zona-stat) .mc-con { stroke: var(--surface); stroke-width: .8; }
:is(#st-pagina, #zona-stat) .mp-bordo-prov { fill: none; stroke: var(--text); stroke-opacity: .55; stroke-width: 1.4; stroke-linejoin: round; }
/* gradini di colore delle mappe (in app.css valgono solo dentro l'app: le pagine /statistiche/ non lo caricano) */
:is(#st-pagina, #zona-stat) .hm-0 { fill: var(--hm0); background: var(--hm0); } :is(#st-pagina, #zona-stat) .hm-1 { fill: var(--hm1); background: var(--hm1); }
:is(#st-pagina, #zona-stat) .hm-2 { fill: var(--hm2); background: var(--hm2); } :is(#st-pagina, #zona-stat) .hm-3 { fill: var(--hm3); background: var(--hm3); }
:is(#st-pagina, #zona-stat) .hm-4 { fill: var(--hm4); background: var(--hm4); }
:is(#st-pagina, #zona-stat) .mc-senza { fill: color-mix(in srgb, var(--bad) 30%, transparent); stroke: var(--bad); stroke-width: .9; }
:is(#st-pagina, #zona-stat) .mc-qui { stroke: var(--sun); stroke-width: 3; }
:is(#st-pagina, #zona-stat) .mc-con:hover, :is(#st-pagina, #zona-stat) .mc-senza:hover { stroke: var(--text); stroke-width: 1.6; }
:is(#st-pagina, #zona-stat) .mp-regione { fill: color-mix(in srgb, var(--muted) 7%, transparent); stroke: var(--muted); stroke-opacity: .5; stroke-width: .8; }
:is(#st-pagina, #zona-stat) .mp-regione:hover { fill: color-mix(in srgb, var(--sun) 14%, transparent); }
/* Zoom delle mappe: pulsanti + − ⟲, i bordi restano sottili ingrandendo */
/* le mappe ingrandite non escono dal riquadro (gli altri grafici hanno overflow: visible per le scritte ai bordi) */
.st-mappa { position: relative; overflow: hidden; border-radius: 14px; }
.st-card .st-mappa svg.st-zoom { overflow: hidden; }
.st-mappa svg.st-zoom { cursor: grab; user-select: none; -webkit-user-select: none; }
.st-mappa svg.st-zoom:active { cursor: grabbing; }
.st-mappa svg.st-zoom * { vector-effect: non-scaling-stroke; }
.st-zoom-btn { position: absolute; top: 10px; right: 10px; display: grid; gap: 4px; }
.st-zoom-btn button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 18px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.st-zoom-btn button:hover { border-color: var(--sun); }
.st-zoom-btn button:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
.st-zoom-aiuto { position: absolute; left: 12px; top: 10px; font-size: 11px; color: var(--muted); background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: 2px 8px; border-radius: 999px; pointer-events: none; transition: opacity .3s; }
.st-mappa.is-zoom .st-zoom-aiuto { opacity: 0; }
.st-invito { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 18px; border-radius: 14px; border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--sun) 6%, transparent); font-size: 14px; }
.st-invito svg { width: 26px; height: 26px; fill: none; stroke: var(--sun); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.st-vuoto { padding: 18px; text-align: center; color: var(--muted); font-size: 14px; }
/* Attesa mentre si apre la pagina di un'altra città */
.st-attesa { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, #020c24 55%, transparent); backdrop-filter: blur(4px); }
.st-attesa[hidden] { display: none; }
.st-attesa-box { width: min(380px, 100%); display: grid; gap: 8px; justify-items: center; text-align: center; padding: 22px 20px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border); backdrop-filter: blur(16px); box-shadow: 0 10px 40px rgba(0,0,0,.35); color: var(--text); }
.st-attesa-sub { font-size: 13px; color: var(--muted); }
/* Icona di attesa: anello di carica che si completa dall'azzurro al giallo, fulmine che pulsa (come il display di una colonnina) */
.st-carica { width: 64px; height: 64px; overflow: visible; }
.st-carica-fondo { fill: none; stroke: color-mix(in srgb, var(--muted) 22%, transparent); stroke-width: 5; }
.st-carica-anello { fill: none; stroke: url(#st-grad-carica); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 163; stroke-dashoffset: 163;
  transform: rotate(-90deg); transform-origin: 32px 32px; animation: st-anello 2.2s ease-in-out infinite; }
@keyframes st-anello { 0% { stroke-dashoffset: 163; } 70%, 85% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -163; } }
.st-carica-fulmine { fill: var(--sun); transform-origin: 32px 32px; animation: st-pulsa 2.2s infinite; }
:root[data-theme="light"] .st-carica-fulmine { fill: #E5A000; }   /* il giallo chiaro si perde sul fondo chiaro */
@keyframes st-pulsa { 0%, 60% { opacity: .55; transform: scale(.92); } 75% { opacity: 1; transform: scale(1.12); } 100% { opacity: .55; transform: scale(.92); } }
.st-barra { width: 100%; height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--muted) 18%, transparent); overflow: hidden; margin-top: 4px; }
.st-barra i { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--sky), var(--sun)); }
@media (prefers-reduced-motion: reduce) { .st-carica-anello, .st-carica-fulmine { animation: none; opacity: 1; stroke-dashoffset: 40; } }
@media (max-width: 760px) {
  .st-kpi { grid-template-columns: repeat(3, 1fr); }
  .st-kpi b { font-size: 19px; }
  .st-griglia { grid-template-columns: 1fr; }
  /* sul telefono i grafici si rimpiccioliscono: scritte più grandi in unità del disegno */
  :is(#st-pagina, #zona-stat) .txt { font-size: 15px; }
  :is(#st-pagina, #zona-stat) .txt-b { font-size: 16px; }
}
