/* =====================================================================
   meteo.css  -  Stazione Meteo Pi 4, redesign 2026
   - Fasce con colore proprio (Notte/Mattina/Pomeriggio/Sera)
   - Icona-fascia affiancata al titolo (separata dall'icona-meteo)
   - Umidita' e pioggia distinte
   - Carosello orizzontale per le previsioni su mobile
   - Card storico (grafico) e card stato hardware
   ===================================================================== */
:root {
  --bg-1: #0b1f38;
  --bg-2: #0f2744;
  --bg-3: #163558;
  --bg-4: #214166;
  --border: #2d4b73;
  --border-2: #245182;
  --text: #e5e7eb;
  --text-dim: #9cb4cf;
  --text-faint: #6b87a8;
  --accent: #93c5fd;
  --temp: #fca5a5;
  --umid: #7dd3fc;
  --press: #a7f3d0;
  --lux: #fde68a;
  --rain: #60a5fa;
  --ok: #22c55e;
  --warn: #eab308;
  --orange: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  /* colori fascia */
  --f-notte: #6366f1;
  --f-mattina: #f59e0b;
  --f-pomeriggio: #38bdf8;
  --f-sera: #fb7185;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(ellipse at top, #164273 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, #06121f 100%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header / nav -------------------------------------------------- */
.topbar {
  background: linear-gradient(180deg, #16385f, #0c2440);
  border-bottom: 1px solid #1f4a7a;
  box-shadow: var(--shadow);
  padding: 14px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title status" "nav nav";
  gap: 10px;
  align-items: center;
}
.topbar h1 { grid-area: title; font-size: 22px; font-weight: 600; color: #bfdbfe; }
.topbar .upd { grid-area: status; font-size: 13px; color: var(--text-faint); text-align: right; }
.nav { grid-area: nav; display: flex; flex-wrap: wrap; gap: 8px; }
.nav a {
  background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 6px 14px;
  font-size: 14px; color: #cfe3ff; transition: background .15s;
}
.nav a:hover { background: #1d4774; text-decoration: none; }
.nav a.on { background: #2563a8; border-color: #3b82f6; color: #fff; }

/* badge "dati non aggiornati" */
.stale-banner {
  display: none;
  background: linear-gradient(90deg, #7f1d1d, #b91c1c);
  color: #fff; text-align: center; padding: 8px 14px; font-size: 14px;
}
.stale-banner.show { display: block; }

/* ---- Layout -------------------------------------------------------- */
.wrap { padding: 18px; max-width: 1400px; margin: 0 auto; }
.card {
  background: linear-gradient(180deg, var(--bg-4), #19314f);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card .hd {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  font-size: 14px; letter-spacing: .05em; text-transform: uppercase;
  color: #cfe3ff; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.card .bd { padding: 16px; }

/* nuove intestazioni fascia (per previsioni): emoji + testo affiancati */
.fb-head {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  margin: 0 -6px 8px -6px;
}
.fb-head .fic { font-size: 30px; line-height: 1; }
.fb-head b { font-size: 16px; font-weight: 600; }
.fb-head.f-notte { background: rgba(99,102,241,.18); border-bottom-color: var(--f-notte); }
.fb-head.f-mattina { background: rgba(245,158,11,.18); border-bottom-color: var(--f-mattina); }
.fb-head.f-pomeriggio { background: rgba(56,189,248,.18); border-bottom-color: var(--f-pomeriggio); }
.fb-head.f-sera { background: rgba(251,113,133,.18); border-bottom-color: var(--f-sera); }
.fb-head.f-notte b { color: #c7d2fe; }
.fb-head.f-mattina b { color: #fcd34d; }
.fb-head.f-pomeriggio b { color: #bae6fd; }
.fb-head.f-sera b { color: #fecdd3; }

/* riga corpo previsione: icona meteo + descrizione affiancati */
.fb-row {
  display: flex; align-items: center; gap: 12px;
  justify-content: flex-start;
  padding: 4px 8px;
  margin: 6px 0 4px 0;
}
.fb-row img { width: 56px; height: 56px; margin: 0; flex-shrink: 0; }
.fb-row .ds {
  font-size: 14px; color: #e2e8f0; line-height: 1.25;
  text-align: left; flex: 1; min-width: 0; font-weight: 600;
}
.fb .tt {
  font-size: 16px; font-weight: 600; margin: 8px 0;
  text-align: center; line-height: 1.3;
}
.fb .tt .mn { color: #44ddaa; font-weight: 700; }
.fb .tt .mx { color: #ffdd44; font-weight: 700; }
.fb .tt .sp { color: #6b7280; margin: 0 4px; font-weight: 400; }
.fb .meta {
  display: flex; justify-content: center; gap: 14px;
  margin-top: 8px; font-size: 14px;
}
.fb .meta .hu { color: var(--umid); }
.fb .meta .ra { color: var(--rain); }
.fb .nd { font-size: 13px; color: #94a3b8; padding: 20px 8px; text-align: center; line-height: 1.4; }

/* icona meteo "locale" nelle fasce locali (basata sulla luminosità) */
.fb-row .fic-meteo { font-size: 48px; line-height: 1; flex-shrink: 0; }

/* altezza uniforme tra colonne dei giorni: garantita dal grid del .col */

/* ---- Tessere valori ------------------------------------------------ */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { background: #16304f; border: 1px solid #284b71; border-radius: var(--radius-sm); padding: 14px 16px; }
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #8aa0bd; }
.tile .v { font-size: 28px; font-weight: 600; margin-top: 4px; line-height: 1.1; }
.tile .u { font-size: 14px; color: var(--text-dim); font-weight: 400; margin-left: 2px; }
.v.temp { color: var(--temp); } .v.umid { color: var(--umid); }
.v.press { color: var(--press); } .v.lux { color: var(--lux); }

/* Tessere "previsione locale / condizione luce / tendenza": icone grandi e
   testo proporzionato al resto delle tile */
.tile.big-info { padding: 16px 18px; }
.tile.big-info .k {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: #b5cce4;
}
.tile.big-info .big-icon { font-size: 32px; line-height: 1; }
.tile.big-info .v {
  font-size: 17px; font-weight: 600; line-height: 1.35;
  margin-top: 8px;
}
#v_prev   { color: #93c5fd; }
#v_luce   { color: #6ee7b7; }
#v_ptrend { color: #fbbf24; }

.gauge { background: #0e2540; border-radius: var(--radius-sm); height: 12px; overflow: hidden; margin-top: 10px; border: 1px solid #25456b; }
.gauge i { display: block; height: 100%; background: linear-gradient(90deg, #3b82f6, #22d3ee); transition: width .5s ease; }
.gauge i.warm { background: linear-gradient(90deg, #22c55e, #eab308, #ef4444); }

/* ---- Fasce locali / previsioni (griglia desktop, carosello mobile) - */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: stretch; }

/* colonna giorno (previsioni) / colonna fascia (fasce locali) */
.col {
  background: #1c3a5e;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  /* PREVISIONI 5gg (5 righe = intestazione giorno + 4 fasce):
     allinea fasce alla stessa altezza tra colonne diverse */
  grid-template-rows: auto repeat(4, 1fr);
}

/* per le FASCE LOCALI ogni .col contiene una sola fascia: non ha senso
   forzare 5 righe. La regola successiva la sovrascrive quando .col contiene
   solo un .fb (il caso fasce locali). */
.col:has(> .fb:only-child) { grid-template-rows: 1fr; }

/* intestazione colonna giorno (previsioni): "28/05 — giovedì" */
.day-head {
  text-align: center;
  padding: 12px 8px;
  background: linear-gradient(180deg, #1e4a78, #163a60);
  border-bottom: 2px solid var(--accent);
}
.day-head b {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .02em;
  text-transform: capitalize;
}

.fb { text-align: center; padding: 10px 8px; display: flex; flex-direction: column; min-height: 0; }
.fb .meta { margin-top: auto; }   /* meta sempre in fondo per allineamento */
/* Data evidenziata nel titolo "Rilevazioni in tempo reale" */
.date-hl {
  color: #fde68a;
  font-weight: 700;
}

/* Badge stato fascia: tre varianti (.attiva/.prossima/.passata).
   Il default .badge senza modificatore resta verde per retrocompatibilita'. */
.badge {
  display: inline-block; font-size: 9px;
  color: #34d399; background: rgba(52,211,153,.12);
  text-transform: uppercase; letter-spacing: .05em;
  border-radius: 4px; padding: 2px 6px; margin-left: 6px;
}
.badge.attiva   { color: #34d399; background: rgba(52,211,153,.12); }
.badge.prossima { color: #93c5fd; background: rgba(96,165,250,.15);
                  border: 1px solid rgba(96,165,250,.25); }
.badge.passata  { color: #94a3b8; background: rgba(148,163,184,.10); font-weight: 500; }

/* Etichetta sottile nelle card PROSSIMA: "previsione prossime ore" */
.fb .tt.prev-only {
  font-style: italic; font-size: 12px;
  color: var(--text-faint); font-weight: 400;
  margin: 6px 0 4px;
}

/* Card "prossima": meta riga centrata se ha solo ☔ */
.fb .meta.only-rain {
  justify-content: center;
}

/* Variante card per le fasce prossime: leggermente attenuata,
   bordo tratteggiato per dire "previsione, non misura" */
.fb.st-prossima {
  background: rgba(15, 39, 68, .35);
  border-left: 2px dashed rgba(96,165,250,.35);
}
.fb.st-passata {
  opacity: .82;
}

/* ===== Carosello mobile per Previsioni 5gg =========================
   Su mobile (≤768px) le 5 card giorno diventano un carosello:
   - una card alla volta (~92% larghezza), scroll-snap centrato
   - frecce ai lati per click navigation
   - indicatori a puntini in basso
   - hint testuale rimosso (sostituito da puntini)
   Su desktop/tablet: vista 5 colonne affiancate (immutata).            */
@media (max-width: 768px) {
  .cols.carousel {
    position: relative;   /* serve perche' col.offsetLeft (in JS) sia
                             relativo al container del carosello       */
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
    gap: 10px; padding-bottom: 8px; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cols.carousel::-webkit-scrollbar { display: none; }
  .cols.carousel .col {
    flex: 0 0 92%; scroll-snap-align: center;
    min-width: 0;
  }
  .carousel-hint { display: none !important; }

  /* COMPATTAZIONE CARD-GIORNO NEL CAROSELLO PREVISIONI 5gg
     Font/padding/icone ridotti perche' la card intera (header giorno +
     4 fasce) entri in un solo viewport mobile, senza scroll verticale. */
  .cols.carousel .col .day-head {
    padding: 5px 6px;
  }
  .cols.carousel .col .day-head b {
    font-size: 13px;
  }
  .cols.carousel .col .fb {
    padding: 5px 6px;
  }
  .cols.carousel .col .fb-head {
    padding: 3px 4px;
    margin: 0 -6px 4px -6px;
    gap: 6px;
  }
  .cols.carousel .col .fb-head .fic {
    font-size: 20px;
  }
  .cols.carousel .col .fb-head b {
    font-size: 13px;
  }
  .cols.carousel .col .fb-row {
    gap: 8px; padding: 2px 4px; margin: 3px 0 2px 0;
  }
  .cols.carousel .col .fb-row img {
    width: 36px; height: 36px;
  }
  .cols.carousel .col .fb-row .ds {
    font-size: 12px; line-height: 1.2;
  }
  .cols.carousel .col .fb .tt {
    font-size: 13px; margin: 3px 0;
  }
  .cols.carousel .col .fb .meta {
    font-size: 12px; gap: 12px; margin-top: 4px;
  }
  /* Riduco anche il padding interno della card-contenitore (.bd)
     solo quando contiene un carosello, per recuperare spazio verticale */
  .card .bd:has(.carousel-wrap) {
    padding: 10px;
  }

  /* Wrap che contiene cols + dots + nav buttons */
  .carousel-wrap { position: relative; }

  /* Indicatori a puntini */
  .carousel-dots {
    display: flex; justify-content: center; gap: 8px;
    margin-top: 6px; padding: 4px 0;
  }
  .carousel-dots .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--border-2); cursor: pointer;
    transition: background .2s, transform .2s;
    box-shadow: none;
  }
  .carousel-dots .dot.active {
    background: #60a5fa; transform: scale(1.3);
  }

  /* Frecce di navigation (overlay laterale) */
  .carousel-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(15, 39, 68, .85);
    border: 1px solid var(--border-2);
    color: #cfe3ff; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; line-height: 1; padding: 0;
    z-index: 5; transition: opacity .2s, background .2s;
    font-family: inherit;
  }
  .carousel-nav:hover { background: rgba(96,165,250,.5); }
  .carousel-nav:disabled { opacity: .35; cursor: default; }
  .carousel-nav.prev { left: -6px; }
  .carousel-nav.next { right: -6px; }
}
/* Su desktop/tablet i puntini e le frecce non esistono */
@media (min-width: 769px) {
  .carousel-dots, .carousel-nav { display: none !important; }
}
.carousel-hint { display: none; }

/* ---- Grafico storico ----------------------------------------------- */
.range-btns { display: flex; gap: 6px; }
.range-btns button {
  background: var(--bg-3); border: 1px solid var(--border-2); color: #cfe3ff;
  border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.range-btns button.on { background: #2563a8; border-color: #3b82f6; color: #fff; }
.chart-box { position: relative; height: 280px; }
.chart-empty { text-align: center; color: var(--text-faint); padding: 40px 0; font-size: 13px; }

/* ---- Impostazioni / hardware --------------------------------------- */
.row { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,.05); }
.row:last-child { border-bottom: 0; }
.row.flex { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.flex > .grow { flex: 1; min-width: 200px; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: middle; margin-right: 8px; box-shadow: 0 0 8px 2px rgba(255,255,255,.2); }
.btn { border: 0; border-radius: var(--radius-sm); padding: 8px 18px; font-size: 14px; font-weight: 500; color: #fff; cursor: pointer; transition: opacity .15s, transform .1s; font-family: inherit; }
.btn:active { transform: scale(.97); } .btn:hover { opacity: .9; }
.btn.g { background: var(--ok); } .btn.r { background: var(--danger); } .btn.b { background: var(--info); } .btn.y { background: var(--warn); color: #111; }
.inp { background: var(--bg-2); color: var(--text); border: 1px solid #374f6b; border-radius: var(--radius-sm); padding: 7px 12px; font-size: 14px; width: 110px; font-family: inherit; }
.inp:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 2px rgba(59,130,246,.2); }
.lbl { font-size: 12px; color: #8aa0bd; display: block; margin-bottom: 6px; }
.stat-on { color: #34d399; font-weight: 600; } .stat-off { color: #f87171; font-weight: 600; } .stat-dsp { color: #f59e0b; font-weight: 600; }

/* card stato hardware - raggruppata per dispositivo */
.hw { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.hw-item { background: #16304f; border: 1px solid #284b71; border-radius: var(--radius-sm); padding: 16px; }
.hw-item .dev-title {
  font-size: 16px; font-weight: 600; color: #cfe3ff;
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.hw-item .dev-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; font-size: 15px;
}
.hw-item .dev-label { color: #8aa0bd; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.hw-item .note { font-size: 11px; color: var(--text-faint); margin-top: 8px; line-height: 1.4; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 10px; margin-left: 6px; }
.pill.ok { background: rgba(34,197,94,.18); color: #4ade80; }
.pill.warn { background: rgba(234,179,8,.18); color: #facc15; }
.pill.orange { background: rgba(245,158,11,.18); color: #fbbf24; }
.pill.danger { background: rgba(239,68,68,.2); color: #f87171; }
.pill.off { background: rgba(107,114,128,.25); color: #9ca3af; }

.foot { text-align: center; color: #4f6b88; font-size: 12px; padding: 20px; line-height: 1.6; }

@media (max-width: 600px) {
  .topbar h1 { font-size: 18px; }
  .tile .v { font-size: 24px; }
  .wrap { padding: 12px; }
  .chart-box { height: 240px; }
}
