/* ═══════════════════════════════════════════════════════════════
   Saturazione Mezzi — foglio di stile
   Impostazione mobile-first: le regole base valgono per smartphone,
   i breakpoint aggiungono spazio su tablet e desktop.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg:            #f4f5f7;
  --bg-elev:       #ffffff;
  --bg-sunken:     #eceef1;
  --border:        #dcdfe4;
  --text:          #16191d;
  --text-mut:      #5f6672;
  --text-faint:    #8b929e;

  --accent:        #0d7d72;
  --accent-ink:    #ffffff;
  --accent-soft:   #d8efec;

  --c-fermo:       #b4243a;
  --c-bassa:       #d97706;
  --c-media:       #b8a005;
  --c-alta:        #14804a;
  --c-alta-soft:   #5a9e46;
  --c-oltre:       #3358cc;
  --c-nodata:      #98a0ac;

  --shadow-sm: 0 1px 2px rgba(16,20,26,.07), 0 1px 1px rgba(16,20,26,.04);
  --shadow-md: 0 4px 16px rgba(16,20,26,.10), 0 1px 3px rgba(16,20,26,.06);
  --shadow-lg: 0 -8px 32px rgba(16,20,26,.18);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --hdr-h: 104px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --ff: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ff-num: ui-monospace, "SF Mono", "Segoe UI Mono", "Roboto Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0f1419;
    --bg-elev:     #171d24;
    --bg-sunken:   #10161c;
    --border:      #2a323c;
    --text:        #e7ebf0;
    --text-mut:    #98a3b2;
    --text-faint:  #6d7787;

    --accent:      #2bb3a3;
    --accent-ink:  #07231f;
    --accent-soft: #17332f;

    --c-fermo:     #f2647c;
    --c-bassa:     #f0a23c;
    --c-media:     #d9c33f;
    --c-alta:      #45c98a;
    --c-alta-soft: #8cc95e;
    --c-oltre:     #7c9bf5;
    --c-nodata:    #6d7787;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 -8px 32px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }

/* Ogni regola `display` di questo foglio avrebbe la meglio sul `display:none`
   che il browser applica a [hidden]: qui l'attributo torna a comandare. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--ff);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

button, input, select { font: inherit; color: inherit; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ─────────────── Header ─────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.hdr-row { display: flex; align-items: center; gap: 10px; }
.hdr-title { min-width: 0; flex: 1; }
.hdr-title h1 { font-size: 17px; line-height: 1.2; }
.hdr-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--text-mut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hdr-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--text-mut);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--bg-sunken); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hdr-controls { margin-top: 8px; }

.sel-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  height: 38px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.sel-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  flex-shrink: 0;
}
.sel-wrap select {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 550;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 14px;
  cursor: pointer;
}
.sel-wrap::after {
  content: "";
  position: absolute;
  right: 10px;
  width: 7px; height: 7px;
  border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint);
  transform: translateY(-2px) rotate(45deg);
  pointer-events: none;
}
.month-wrap { max-width: 190px; }

.filter-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.filter-btn svg { width: 17px; height: 17px; }
.filter-btn:active { background: var(--border); }

.badge-count {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

/* ─────────────── Layout principale ─────────────── */

.main {
  padding: 12px 14px calc(var(--tab-h) + var(--safe-b) + 20px);
  max-width: 1180px;
  margin: 0 auto;
}

.view { display: block; }

.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 56px 20px;
  text-align: center;
  color: var(--text-mut);
}
.state-box.error { color: var(--c-fermo); }
.state-ico { width: 34px; height: 34px; }
.state-box p { margin: 0; max-width: 34ch; }

.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ─────────────── Card ─────────────── */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 14px; }
.card-hint { font-size: 11.5px; color: var(--text-faint); }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}
.link-btn[data-info] {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  color: var(--text-mut);
  padding: 0;
  line-height: 1;
}

/* ─────────────── KPI ─────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  display: block;
  margin-bottom: 5px;
}
.kpi-value {
  font-size: 25px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  display: block;
  overflow-wrap: anywhere;
}
.kpi-value .unit { font-size: 14px; font-weight: 600; color: var(--text-mut); margin-left: 2px; }
.kpi-sub { font-size: 11.5px; color: var(--text-mut); margin-top: 4px; display: block; }
.kpi.wide { grid-column: 1 / -1; }
.kpi.alert .kpi-value { color: var(--c-fermo); }
.kpi.good .kpi-value { color: var(--c-alta); }

/* ─────────────── Grafici ─────────────── */

.band-bar {
  display: flex;
  height: 32px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-sunken);
  margin-bottom: 12px;
}
.band-seg {
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  min-width: 0;
  overflow: hidden;
  transition: flex-grow .3s ease;
}
.band-legend {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 14px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  padding: 3px 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  width: 100%;
  min-width: 0;
  color: inherit;
}
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-name {
  flex: 1;
  min-width: 0;
  color: var(--text-mut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-val { font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-wrap svg { display: block; width: 100%; height: auto; min-width: 260px; }
/* Il tratto impostato globalmente sulle icone renderebbe illeggibili
   le etichette dei grafici. */
.chart-wrap svg text { stroke: none; }
.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-mut);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ─────────────── Liste sintetiche ─────────────── */

.mini-list { display: flex; flex-direction: column; }
.mini-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
  border-left: 0; border-right: 0; border-bottom: 0;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.mini-row:first-child { border-top: 0; }
.mini-row:active { background: var(--bg-sunken); }
.mini-main { flex: 1; min-width: 0; }
/* display:block è indispensabile: su uno span inline il troncamento con
   ellissi non ha effetto e le matricole lunghe sfondano la pagina. */
.mini-name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-meta {
  display: block;
  font-size: 11.5px;
  color: var(--text-mut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-val {
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.mini-val strong { display: block; font-size: 14.5px; }
.mini-val span { font-size: 11px; color: var(--text-mut); }

/* ─────────────── Toolbar liste ─────────────── */

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.list-count { font-size: 12.5px; color: var(--text-mut); flex: 1; min-width: 0; }
.sel-wrap.compact { flex: 0 1 auto; max-width: 210px; height: 34px; }
.sel-wrap.compact select { font-size: 13px; }

/* ─────────────── Card mezzo ─────────────── */

.cards { display: flex; flex-direction: column; gap: 10px; }

.vcard {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--c-nodata);
  border-radius: var(--r-md);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.vcard:active { transform: scale(.995); background: var(--bg-sunken); }
.vcard.b-fermo { border-left-color: var(--c-fermo); }
.vcard.b-bassa { border-left-color: var(--c-bassa); }
.vcard.b-media { border-left-color: var(--c-media); }
.vcard.b-alta  { border-left-color: var(--c-alta); }
.vcard.b-oltre { border-left-color: var(--c-oltre); }

.vcard-top { display: flex; align-items: flex-start; gap: 10px; }
.vcard-id { flex: 1; min-width: 0; }
.vcard-matr {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.vcard-model {
  font-size: 12px;
  color: var(--text-mut);
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vcard-pct {
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.vcard-pct b { font-size: 22px; font-weight: 750; line-height: 1; letter-spacing: -0.02em; }
.vcard-pct small { display: block; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }

/* Reso esplicito il display: le barre vivono dentro <span>, che di suo
   ignorerebbe altezza e larghezza. */
.gauge {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-sunken);
  margin: 10px 0 9px;
  overflow: hidden;
  position: relative;
}
.gauge-fill { display: block; height: 100%; border-radius: 3px; transition: width .3s ease; }

.vcard-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  font-size: 11.5px;
  color: var(--text-mut);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: var(--bg-sunken);
  border-radius: 999px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.warn { background: color-mix(in srgb, var(--c-bassa) 18%, transparent); color: var(--c-bassa); font-weight: 600; }
.chip.err  { background: color-mix(in srgb, var(--c-fermo) 16%, transparent); color: var(--c-fermo); font-weight: 600; }
.chip.acc  { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.vcard-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
}
.fig { min-width: 0; }
.fig-label { display: block; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; }
.fig-value { font-weight: 650; font-variant-numeric: tabular-nums; }

.load-more { margin: 14px auto 0; display: block; }

/* ─────────────── Report ─────────────── */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-bottom: 12px;
}
.seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  color: var(--text-mut);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.seg.active {
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.rep-intro {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-mut);
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  margin: 0 0 12px;
}
.rep-intro strong { color: var(--text); }

.rep-card { padding-bottom: 8px; }
/* Il contenitore non deve avere padding orizzontale: le colonne ancorate si
   fermano al bordo interno, e il contenuto scorrevole resterebbe visibile
   nella striscia di padding alla loro sinistra. */
.rep-card .read-table-wrap { margin: 0; padding: 0; }
.rep-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.rep-titolo { flex: 1; min-width: 0; }
.rep-titolo h3 { font-size: 13.5px; font-weight: 650; overflow-wrap: anywhere; }
.rep-conta {
  flex-shrink: 0;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--text-mut);
  background: var(--bg-sunken);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

table.rep-table th, table.rep-table td { padding: 7px 9px; }
/* Alcune matricole superano i 50 caratteri: senza un tetto spingerebbero le
   letture fuori dalla porzione visibile della tabella. Il valore completo
   resta nel tooltip e nella scheda del mezzo. */
table.rep-table td.matr {
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Mese, matricola, modello e proprietario sono testo: allineati a sinistra.
   Dalla quinta colonna iniziano le letture, allineate a destra. */
table.rep-table td.mod,
table.rep-table th:nth-child(-n+4) { text-align: left; }
table.rep-table td.mod {
  color: var(--text-mut);
  font-size: 11.5px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 600px) {
  table.rep-table td.mod { max-width: 230px; }
}
table.rep-table td.um { text-align: center; color: var(--text-faint); }
/* Sette colonne non entrano in uno schermo da telefono: mese e matricola
   restano ancorate a sinistra mentre si scorre verso le letture, altrimenti
   si leggerebbero numeri senza sapere a quale mezzo appartengono. */
table.rep-table td.mese, table.rep-table th:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 48px;
  min-width: 48px;
  text-align: left;
  white-space: nowrap;
  color: var(--text-mut);
  font-size: 11.5px;
  background: var(--bg-elev);
}
table.rep-table td.matr, table.rep-table th:nth-child(2) {
  position: sticky;
  left: 48px;
  z-index: 2;
  background: var(--bg-elev);
  box-shadow: 1px 0 0 var(--border);
}
table.rep-table thead th { z-index: 3; }
table.rep-table td.val { font-weight: 650; }
table.rep-table td.illeg { color: var(--c-bassa); font-size: 11px; }
/* Le tre colonne dello schema di rilevazione restano visivamente unite. */
table.rep-table th:nth-child(5), table.rep-table td:nth-child(5) { border-left: 1px solid var(--border); }
table.rep-table th:nth-child(5),
table.rep-table th:nth-child(6),
table.rep-table th:nth-child(7) { color: var(--accent); }
table.rep-table tbody tr { cursor: pointer; }
table.rep-table tbody tr:active { background: var(--bg-sunken); }

.stato-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
}
.stato-pill.censire { background: color-mix(in srgb, var(--c-fermo) 16%, transparent); color: var(--c-fermo); }
.stato-pill.aggiornare { background: color-mix(in srgb, var(--c-bassa) 18%, transparent); color: var(--c-bassa); }

.cant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cant-row:first-child { border-top: 0; }
.cant-row:active { background: var(--bg-sunken); }

/* ─────────────── Cantieri ─────────────── */

.site-card { cursor: default; border-left-width: 1px; }
.site-head { display: flex; align-items: flex-start; gap: 10px; }
.site-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.site-code { font-size: 11.5px; color: var(--text-faint); font-family: var(--ff-num); }
.site-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.site-cell { min-width: 0; }
.site-cell .fig-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-cell .fig-value { font-size: 14px; display: block; }

/* ─────────────── Anomalie ─────────────── */

.anom-group { margin-bottom: 12px; }
.anom-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  color: inherit;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}
.anom-head[aria-expanded="true"] { border-radius: var(--r-md) var(--r-md) 0 0; }
.anom-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.anom-title { flex: 1; min-width: 0; }
.anom-title strong { display: block; font-size: 13.5px; font-weight: 650; }
.anom-title span { font-size: 11.5px; color: var(--text-mut); }
.anom-n {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--bg-sunken);
  padding: 2px 9px;
  border-radius: 999px;
}
.anom-chev { width: 16px; height: 16px; color: var(--text-faint); transition: transform .2s; }
.anom-head[aria-expanded="true"] .anom-chev { transform: rotate(180deg); }
.anom-body {
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--r-md) var(--r-md);
  background: var(--bg-elev);
  padding: 0 14px 6px;
}

/* ─────────────── Tabella letture ─────────────── */

.read-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table.reads {
  border-collapse: collapse;
  width: 100%;
  min-width: 340px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
table.reads th, table.reads td {
  padding: 7px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.reads th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-faint);
  font-weight: 600;
}
table.reads th:first-child, table.reads td:first-child { text-align: left; }
table.reads tr.neg td { color: var(--c-fermo); }
table.reads td.na { color: var(--text-faint); }

/* ─────────────── Sheet (bottom sheet) ─────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8,12,16,.45);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 70;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lg);
  animation: slideUp .24s cubic-bezier(.2,.8,.3,1);
  padding-bottom: var(--safe-b);
}
.sheet.tall { max-height: 92vh; max-height: 92dvh; }
@keyframes slideUp { from { transform: translateY(100%); } }

.sheet-grip {
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 8px auto 2px;
  flex-shrink: 0;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-head h2 { font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.sheet-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.sheet-foot {
  padding: 10px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

.field { display: block; margin-bottom: 13px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mut);
  margin-bottom: 5px;
}
.field input[type="search"],
.field input[type="number"],
.field select {
  width: 100%;
  height: 44px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  font-size: 16px; /* evita lo zoom automatico su iOS */
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
}
.field.checkbox input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--accent); }
.field.checkbox span { margin: 0; font-size: 13.5px; font-weight: 500; color: var(--text); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.sheet-sub {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-faint);
  margin: 20px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Conteggi cumulati delle fasce di utilizzo */
.cum-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.cum-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cum-row:active { background: var(--bg-sunken); }
.cum-label { flex: 0 0 auto; font-size: 12.5px; color: var(--text-mut); white-space: nowrap; }
.cum-label b { color: var(--text); font-weight: 650; }
.cum-bar {
  flex: 1;
  min-width: 24px;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.cum-fill { display: block; height: 100%; border-radius: 3px; }
.cum-val {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 54px;
}
.cum-val small { display: block; font-size: 10.5px; font-weight: 500; color: var(--text-faint); }

.note {
  font-size: 12.5px;
  color: var(--text-mut);
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  margin: 0 0 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:active { opacity: .82; }
.btn-ico { width: 17px; height: 17px; }

/* ─────────────── Dettaglio ─────────────── */

.det-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--bg-sunken);
  margin-bottom: 14px;
}
/* Dimensione esplicita: la misura di default delle icone prevarrebbe sugli
   attributi width/height dell'elemento. */
.det-ring { flex-shrink: 0; width: 64px; height: 64px; }
.det-hero-txt { min-width: 0; }
.det-hero-txt strong { display: block; font-size: 15px; }
.det-hero-txt span { font-size: 12.5px; color: var(--text-mut); }

.det-section { margin-bottom: 16px; }
.det-section > h3 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.det-rows { display: flex; flex-direction: column; margin: 0; }
.det-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.det-row:last-child { border-bottom: 0; }
.det-row dt { flex: 0 0 42%; color: var(--text-mut); margin: 0; }
.det-row dd { flex: 1; margin: 0; font-weight: 550; text-align: right; overflow-wrap: anywhere; }

.alert-box {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  margin-bottom: 10px;
  line-height: 1.4;
}
.alert-box svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.alert-box.warn { background: color-mix(in srgb, var(--c-bassa) 14%, transparent); color: var(--c-bassa); }
.alert-box.err  { background: color-mix(in srgb, var(--c-fermo) 13%, transparent); color: var(--c-fermo); }
.alert-box.info { background: var(--accent-soft); color: var(--accent); }

/* ─────────────── Tabbar ─────────────── */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 550;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--accent); }
.tab-badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 6px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--c-bassa);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

/* ─────────────── Toast ─────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  transform: translateX(-50%);
  z-index: 90;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: #16191d;
  color: #fff;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
  text-align: center;
}
@media (prefers-color-scheme: dark) { .toast { background: #2e3742; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-mut);
  font-size: 14px;
}

/* ═══════════ Tablet ═══════════ */
@media (min-width: 600px) {
  body { font-size: 15.5px; }
  /* I testi dell'SVG scalano con il viewBox: senza un tetto alla larghezza,
     su schermi ampi il grafico diventa un cartellone. */
  .chart-wrap { max-width: 620px; margin: 0 auto; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .band-legend { grid-template-columns: repeat(3, 1fr); }
  .cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .main { padding-left: 20px; padding-right: 20px; }
  .sheet {
    left: 50%;
    right: auto;
    bottom: 50%;
    width: min(560px, 92vw);
    transform: translate(-50%, 50%);
    border-radius: var(--r-lg);
    max-height: 84vh;
    animation: popIn .2s ease;
  }
  @keyframes popIn { from { opacity: 0; transform: translate(-50%, calc(50% + 12px)); } }
  .site-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ═══════════ Desktop ═══════════ */
@media (min-width: 960px) {
  .app-header { padding-left: 24px; padding-right: 24px; }
  .hdr-title h1 { font-size: 19px; }
  .kpi-grid { grid-template-columns: repeat(6, 1fr); }
  .kpi.wide { grid-column: span 2; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .main {
    padding: 18px 24px calc(var(--tab-h) + 32px);
  }
  .tabbar {
    grid-template-columns: repeat(5, minmax(0, 140px));
    justify-content: center;
  }
  .tab { flex-direction: row; gap: 8px; font-size: 13px; }
  .tab-badge { position: static; margin-left: 0; }
  .band-legend { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 1240px) {
  .cards { grid-template-columns: repeat(4, 1fr); }
}

/* Riduzione animazioni */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
