  :root{
  --bg-1:#0b1020;      /* fascia scura */
  --fg-1:#e8eefc;      /* testo chiaro */
  --card:#121a33;
  --muted:#99a3b8;
  --ok:#19b36b;
  --warn:#ffb020;
  --bad:#ff4d4f;
  --pill:#1b2443;
  --pill-br:#2a3768;
  --shadow:0 2px 10px rgba(0,0,0,.25);
}
:root{
  --header-h: 54px;   /* altezza header “fisso” */
  --strip-h: 0px;     /* la riempiamo via JS */
}

* { box-sizing: border-box; }

body { margin:0; font-family: system-ui, Arial; background:var(--bg); color:var(--fg); }
header { display:flex; justify-content:space-between; align-items:center; padding:12px 16px; background:#0f1730; border-bottom:1px solid #18244a; }
header h1 { margin:0; font-size:18px; color:#e8eefc}
nav a { color:var(--muted); margin-left:10px; text-decoration:none; }
/* Se non già fatto nel tuo CSS, dai un’altezza alla mappa */
/* #map {
  height: calc(100vh - 54px);
  position: relative;
  z-index: 0;
} */
#map{
  height: calc(100vh - (var(--header-h) + var(--strip-h)));
}
#legend{
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 2001;           /* <— più alto di Leaflet (controls ~1000) */
  display: inline-block;
  background: var(--card);
  padding: 6px 10px;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0,0,0,.3);
  color: #e8eefc;
  font-size: 12px;
  width: auto;
  height: auto;
  pointer-events: auto;     /* cliccabile se mai servisse */
}
#legend div{ white-space:nowrap; display:flex; align-items:center; margin:2px 0; }
#legend .dot{ display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; }
#legend .ok{ background:#3ddc84 } .warn{ background:#ffb703 } .off{ background:#e63946 }

.dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; }
.dot.ok{ background:#3ddc84; } .dot.warn{ background:#ffb703; } .dot.off{ background:#e63946; }

main.sensor { display:grid; gap:16px; padding:16px; }
.card { 
  background:var(--card); 
  padding:16px; 
  border-radius:16px; 
  box-shadow:0 3px 10px rgba(0,0,0,.3); 
  color: #e8eefc;
}
.prose { padding:16px; line-height:1.6; color:var(--muted); }
.chart-wrap{
  position: relative;
  height: 320px;      /* altezza controllata del grafico */
  max-width: 100%;
  overflow: hidden;   /* impedisce lo "sbordo" */
}
#chart1{
  display: block !important;
  width: 100% !important;
  height: 100% !important;
}
.card canvas{ min-height: 0; }  /* non forzare altezze al canvas */

/* --- Sensor status chips --- */
.status-grid{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px,1fr));
  gap:10px;
  margin-top:8px;
}
.status-card{
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  border-radius:12px;
  padding:10px 12px;
}
.status-card h3{
  margin:0 0 6px 0;
  font-size:13px;
  color: var(--muted);
  font-weight:600;
  letter-spacing:.2px;
}

.kv{ display:flex; align-items:center; justify-content:space-between; margin:6px 0; gap:8px; }
.kv .label{ opacity:.8; font-size:13px; }
.kv .val{ font-weight:600; font-variant-numeric: tabular-nums; }

.chip{
  display:inline-flex; align-items:center; gap:6px;
  padding:3px 8px; border-radius:999px; font-size:12px; font-weight:600;
  background: rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.08);
}
.dot{ width:8px; height:8px; border-radius:50%; display:inline-block; }
.dot.ok{ background:#3ddc84 } .dot.warn{ background:#ffb703 } .dot.off{ background:#e63946 }

.badge{ padding:2px 6px; border-radius:6px; font-size:12px; font-weight:700; }
.badge.ok{ background:#12361f; color:#3ddc84; border:1px solid #1e6b43; }
.badge.warn{ background:#3a2e12; color:#ffcd70; border:1px solid #8b6b2a; }
.badge.err{ background:#3a1212; color:#ff8f8f; border:1px solid #8b2a2a; }
.badge.neutral{ background:#1b2544; color:#9bb0d3; border:1px solid #25335e; }

.small{ font-size:12px; opacity:.8; }
.mono{ font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }

/* Help panel (più piccolo e laterale) */
.modal[hidden]{ display:none !important; }
.modal{ position:fixed; inset:0; z-index:1000; }
.modal__backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.15); } /* meno coprente */

.modal__dialog{
  position:relative;
  margin: 10px 12px 10px auto;        /* appoggia a destra */
  width: min(420px, calc(100vw - 24px));
  max-height: 86vh;
  background:#fff; border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.2);
  display:flex; flex-direction:column; overflow:hidden;   /* header+content+footer */
}

.modal__header{
  display:flex; align-items:center; justify-content:space-between;
  gap:8px; padding:10px 12px; border-bottom:1px solid #eee;
}
.modal__header h2{ font-size:1.05rem; margin:0; }

.modal__close{
  font-size:18px; width:32px; height:32px; border-radius:8px;
  border:1px solid #ddd; background:#fafafa; cursor:pointer;
}
.modal__close:hover{ background:#f0f0f0; }

.modal__content{ padding:10px 12px; overflow:auto; }
.modal__content h3{ margin:.6rem 0 .35rem; }
.modal__content ul{ margin:.25rem 0 .5rem 1.25rem; }
.modal__content code{ background:#f6f8fa; padding:.05rem .35rem; border-radius:4px; }

.modal__footer{
  display:flex; justify-content:flex-end; gap:8px;
  padding:10px 12px; border-top:1px solid #eee; background:#fafbfd;
}

.btn{ border:1px solid #cfd8ea; background:#eef3ff; color:#153b95; border-radius:8px;
      padding:6px 10px; font-weight:600; cursor:pointer; }
.btn:hover{ background:#e2e9ff; }
.btn.secondary{ background:#f6f7f9; color:#333; border-color:#e1e5ee; }


/* === HELP PANEL — DARK THEME OVERRIDES === */
.help-btn{
  width:28px;height:28px;border-radius:50%;
  border:1px solid #25335e; background:#1b2544; color:#9bb0d3;
  font-weight:700; line-height:1; cursor:pointer;
}
.help-btn:hover{ background:#223057; }

.modal__backdrop{ background: rgba(0,0,0,.35); } /* un filo più scuro per staccare */

.modal__dialog{
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}

.modal__header,
.modal__footer{ border-color:#25335e; }

.modal__close{
  color: var(--fg);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
}
.modal__close:hover{ background: rgba(255,255,255,.10); }

.modal__content h3{ color: var(--fg); }
.modal__content p,
.modal__content li{ color: var(--fg); }
.modal__content code{ background:#0f1730; color:var(--fg); }

/* Tabella soglie in dark */
.thresholds table{ width:100%; border-collapse:collapse; font-size:.95rem; color:var(--fg); }
.thresholds th, .thresholds td{ border:1px solid #25335e; padding:.45rem .5rem; text-align:left; }
.thresholds thead th{ background:#0f1730; }
.thresholds tbody tr:nth-child(even){ background: rgba(255,255,255,.03); }

/* Bottoni footer */
.btn{
  border:1px solid #25335e; background:#1b2544; color:var(--fg);
  border-radius:8px; padding:6px 10px; font-weight:600; cursor:pointer;
}
.btn:hover{ background:#223057; }
.btn.secondary{ background:#0f1730; color:var(--fg); border-color:#25335e; }

/* Accessibilità focus */
.modal__dialog:focus{ outline:2px solid #3ddc84; outline-offset:2px; }




/* Per il Layer TEC sulla mappa */
/* Pannello layer flottante (a destra di default) */
#layers-panel{
  position:absolute;
  top: 82px;         /* sotto la status-strip */
  right: 12px;
  z-index: 1003;     /* sopra la mappa/tooltip */
  width: 340px;
  max-width: calc(100% - 24px);
  pointer-events: auto;
}
/* il corpo si nasconde quando è "compact" */
#layers-panel.compact .panel-body{ display:none; }
/* rotazione freccia in stato compattato */
#layers-panel.compact .chev{ transform: rotate(-90deg); display:inline-block; }

/* opzionale: ombra/bordo per staccarlo dalla mappa */
#layers-panel .panel{
  background: #0b1220;    /* o il tuo colore tema */
  color: #eef2ff;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.08);
}
#layers-toggle{
  width: 100%;
  text-align: left;
  cursor: pointer;  /* sarà anche “grab” in modalità drag */
}
#layersPanel .tec-controls{ display:grid; gap:6px; margin-top:6px; }
#layersPanel input[type="datetime-local"]{
  background:#111827; color:#e5e7eb; border:1px solid #374151; border-radius:8px; padding:6px;
}
#layersPanel button{
  background:#1f2937; color:#f3f4f6; border:1px solid #374151; border-radius:8px; padding:6px 10px; cursor:pointer;
}
#layersPanel button:hover{ filter:brightness(1.1); }
#layersPanel .tec-legend{ margin-top:8px; display:flex; gap:10px; align-items:center; font-size:12px; }
#layersPanel .swatch{ display:inline-block; width:16px; height:12px; border-radius:3px; border:1px solid rgba(255,255,255,.25); margin-right:4px; }

#layersPanel .tec-style,
#layersPanel .tec-opacity { margin-top:6px; display:grid; gap:6px; }
#layersPanel select{
  background:#111827; color:#e5e7eb; border:1px solid #374151; border-radius:8px; padding:6px;
}
/* === LAYERS PANEL OVERRIDES === */
#layers-panel{
  right: 12px !important;
  left: auto !important;
  width: 340px !important;
}
#layers-panel .panel-toggle{
  justify-content: space-between;
}
#layers-panel .panel-toggle .title{
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#layers-panel.compact{
  /* abbastanza largo per leggere "Layer" */
  width: 150px !important;
}
#layers-panel.compact .panel-toggle{
  justify-content: space-between;
}




/* Modale per SWPC */
  .modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.65);
    display: none; align-items: center; justify-content: center; z-index: 9999;
  }
  .modal-backdrop.show { display: flex; }
  .modal-card {
    background: #0b1020; color: #e5e7eb; max-width: 96vw; max-height: 92vh;
    border-radius: 12px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5);
    display: flex; flex-direction: column; width: 1100px;
  }
  .modal-toolbar {
    display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .modal-toolbar .title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .modal-toolbar button, .modal-toolbar a {
    background: #1f2937; color: #e5e7eb; border: 0; padding: .45rem .7rem; border-radius: 8px; cursor: pointer;
    text-decoration: none; display: inline-flex; align-items: center;
  }
  .modal-body { padding: .6rem; display: flex; justify-content: center; align-items: center; }
  .modal-body img { max-width: 100%; max-height: 78vh; display: block; }

  /* Barra superiore */ 

#status-strip{
  position: sticky; top: 0; z-index: 500;
  display: flex; gap: .75rem; align-items: center; justify-content: space-between;
  padding: .5rem .75rem;
  background: var(--bg-1); color: var(--fg-1);
  border-bottom: 1px solid rgba(255,255,255,.06);
  box-shadow: var(--shadow);
  font-family: system-ui, Segoe UI, Roboto, sans-serif;
  user-select: none;
}
#status-strip .strip-left{
  display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center;
}
.metric{ display:flex; align-items:center; gap:.4rem; }
.metric .label{ font-size:.86rem; color:var(--muted); letter-spacing:.02em; }
.metric.ts{ color:var(--muted); font-size:.82rem; margin-left:.25rem; }

.pill{
  display:inline-flex; align-items:center; justify-content:center;
  min-width: 2.2rem; height: 1.6rem; padding: 0 .55rem;
  border:1px solid var(--pill-br); border-radius:999px;
  background: var(--pill); font-weight:600; font-size:.9rem;
}
.pill-ok{ color:#fff; background: linear-gradient(180deg, #17c97a, #0e9c5b); border-color:transparent; }
.pill-warn{ color:#1b1400; background: linear-gradient(180deg, #ffd37a, #ffb020); border-color:transparent; }
.pill-bad{ color:#fff; background: linear-gradient(180deg, #ff6a6b, #ff4d4f); border-color:transparent; }
.pill-muted{ color:var(--muted); }

.strip-right{ display:flex; align-items:center; gap:.5rem; min-width: 30%; }
.alerts{ display:flex; gap:.4rem; overflow:auto; scrollbar-width: thin; }
.alert{
  white-space: nowrap;
  padding:.35rem .6rem; border-radius: .6rem; font-weight:600; font-size:.88rem;
  border:1px solid rgba(255,255,255,.1); background:rgba(255,255,255,.05);
}
.alert-ok{ border-color: rgba(25,179,107,.25); color:#c8ffe8; }
.alert-warn{ background:rgba(255,176,32,.15); border-color:rgba(255,176,32,.35); color:#ffd589; }
.alert-bad{ background:rgba(255,77,79,.15); border-color:rgba(255,77,79,.35); color:#ffc9c9; }


/* Pannello per Layer */

#layers-panel{
  position:absolute; left: .75rem; top: calc( var(--header-h, 56px) + 48px );
  width: 300px; max-height: 70vh; overflow: hidden;
  background:#0f1530; color:#e8eefc; border:1px solid rgba(255,255,255,.08);
  border-radius: .8rem; box-shadow: var(--shadow);
}
#layers-panel .panel-toggle{
  all: unset; cursor:pointer; width:100%;
  display:flex; align-items:center; gap:.5rem;
  padding:.6rem .75rem; font-weight:700;
  border-bottom:1px solid rgba(255,255,255,.08);
}
#layers-panel .panel-toggle .chev{ transition: transform .2s ease; }
#layers-panel .panel-body{
  padding:.65rem .75rem; overflow:auto; max-height: 60vh;
}
#layers-panel.compact{ width: 52px; }
#layers-panel.compact .panel-body{ display:none; }
#layers-panel.compact .panel-toggle{ justify-content:center; }
#layers-panel.compact .chev{ transform: rotate(-90deg); }



@media (max-width: 900px){
  #status-strip{ flex-direction: column; align-items: stretch; gap:.5rem; }
  .strip-right{ min-width: 100%; }
  .modal__dialog{
    margin: auto 8px 8px;             /* più in basso */
    width: calc(100vw - 16px);
    max-height: 75vh;
  }
  #layers-panel{ left:.5rem; width:min(88vw, 360px); }
}

/* OpenWeather Map Legenda */
.owm-legend {
  background: rgba(20,20,20,0.9);
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  font: 12px/1.2 system-ui, sans-serif;
  min-width: 210px;
}
.owm-legend h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
}
.owm-legend .scale {
  margin: 6px 0 2px 0;
}
.owm-legend .ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  opacity: 0.9;
}


/* Legenda H3 allineata in X alla OWM, ma più in alto (Y) */
.hex-legend.leaflet-control {
  /* top | right | bottom | left */
  margin: 0 10px 84px 10px;   /* ⬅️ 10px a sinistra come i controlli Leaflet */
  padding: 6px 8px;
  background: rgba(0,0,0,.65);
  color: #fff;
  border-radius: 6px;
  font: 12px/1.2 system-ui, sans-serif;
}

