/* Pagina /statistiche: usa le variabili e i componenti di app.css (tema chiaro/scuro compreso). */

body.pagina-stats { display: block; height: auto; min-height: 100vh; overflow: auto; }
.stats-titolo { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; flex: 1 1 auto; }
.stats { max-width: 1280px; margin: 0 auto; padding: 18px 18px 60px; display: grid; gap: 18px; }
.stats-barra { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.stats-nota, .blocco-nota { margin: 0; color: var(--testo-2); font-size: 12.5px; }
.stats-stato { padding: 30px; text-align: center; color: var(--testo-2); }
.stats-stato.errore { color: var(--errore); }

.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi-card { background: var(--superficie); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 14px 16px; box-shadow: var(--ombra); }
.kpi-card .etichetta { font-size: 12px; color: var(--testo-2); font-weight: 600; }
.kpi-card .valore { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-card .nota { font-size: 11.5px; color: var(--muto); margin-top: 2px; }

.blocco { background: var(--superficie); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 16px; box-shadow: var(--ombra); min-width: 0; display: grid; gap: 10px; align-content: start; }
.blocco-testa { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.blocco-testa h2 { margin: 0; font-size: 16px; font-weight: 700; margin-right: auto; }
.doppio { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 18px; }

.stats-cerca { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--bordo); background: var(--superficie-2); min-width: 200px; outline: none; }
.stats-cerca:focus { border-color: var(--accento); box-shadow: 0 0 0 3px var(--accento-tenue); }

.tabella-scroll { overflow: auto; max-height: 560px; border: 1px solid var(--bordo); border-radius: var(--raggio-sm); }
.tabella-stats { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.tabella-stats th, .tabella-stats td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--bordo); }
.tabella-stats th:first-child, .tabella-stats td:first-child { text-align: left; }
.tabella-stats thead th { position: sticky; top: 0; background: var(--superficie-2); cursor: pointer; user-select: none; font-size: 12px; color: var(--testo-2); z-index: 1; }
.tabella-stats thead th:hover { color: var(--testo); }
.tabella-stats thead th.ordine::after { content: " ▼"; font-size: 9px; }
.tabella-stats thead th.ordine.cresc::after { content: " ▲"; }
.tabella-stats tbody tr:hover { background: var(--superficie-2); }
.tabella-stats td a { font-weight: 600; text-decoration: none; }
.tabella-stats td a:hover { text-decoration: underline; }
.tabella-stats td.vuoto { color: var(--muto); }
.sconto-pos { color: var(--ok); font-weight: 600; }
.sconto-neg { color: var(--errore); font-weight: 600; }
.cop-alta { background: var(--errore-tenue); }
.cop-media { background: var(--warn-tenue); }

.mappa-stats { height: 460px; border-radius: var(--raggio-sm); border: 1px solid var(--bordo); background: var(--superficie-2); }
.mappa-stats.mappa-scura .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.5); }
.legenda { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--testo-2); }
.legenda .scala { display: inline-block; width: 160px; height: 10px; border-radius: 6px; background: linear-gradient(90deg, hsl(42 88% 60%), hsl(170 76% 36%)); vertical-align: middle; }
.legenda .nd { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #94a3b8; vertical-align: middle; margin-right: 4px; }

.barre { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: 18px; }
.barra { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.barra .colonna { width: 100%; background: var(--accento-tenue); border: 1px solid var(--accento); border-radius: 5px 5px 0 0; min-height: 1px; display: flex; align-items: flex-end; }
.barra .colonna i { display: block; width: 100%; background: var(--accento); border-radius: 4px 4px 0 0; }
.barra .n { font-size: 11.5px; font-weight: 700; margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.barra .sett { font-size: 10.5px; color: var(--muto); margin-top: 4px; white-space: nowrap; }

@media (max-width: 720px) {
  .stats { padding: 12px 12px 40px; }
  .stats-titolo { display: none; }
  .topbar { gap: 10px; padding: 0 12px; }
  .mappa-stats { height: 340px; }
  .barre { gap: 3px; }
  .barra .sett { font-size: 9px; }
  .segmento { flex-wrap: wrap; border-radius: 16px; }
}

/* Pagina /glossario */
.glossario { max-width: 860px; }
.glossario-elenco { margin: 0; display: grid; gap: 10px; }
.glossario-voce { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 6px 16px; padding-bottom: 10px; border-bottom: 1px solid var(--bordo); }
.glossario-voce:last-child { border-bottom: 0; padding-bottom: 0; }
.glossario-voce dt { font-weight: 700; }
.glossario-voce dd { margin: 0; color: var(--testo-2); }
.glossario-voce:target { background: var(--accento-tenue); border-radius: var(--raggio-sm); padding: 8px; }
@media (max-width: 600px) { .glossario-voce { grid-template-columns: 1fr; } }
/* Fonte sotto tabelle e grafici */
.fonte { font-style: italic; color: var(--muto); }
