/* BMS Parrocchia di Pogliano — sistema di stili
   Progettato per lo smartphone: tocco 44px minimo, navigazione in basso,
   una colonna sotto i 640px, griglia sopra. */

:root {
  --bg:        #0a0c14;
  --bg-2:      #0f1220;
  --surface:   rgba(255, 255, 255, .045);
  --surface-2: rgba(255, 255, 255, .075);
  --border:    rgba(255, 255, 255, .10);
  --border-2:  rgba(255, 255, 255, .18);

  --text:      #eef1f8;
  --text-dim:  #a8b0c6;
  --text-mute: #6f7891;

  --ok:    #22c55e;
  --warn:  #f59e0b;
  --err:   #ef4444;
  --info:  #38bdf8;

  --accent:  #6366f1;
  --accent2: #8b5cf6;

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --shadow:    0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);

  --nav-h: 68px;
  --ease: cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; }

/* Rete di sicurezza: nessuna icona puo' finire a dimensione predefinita
   (300x150) per una regola mancante. Le regole specifiche sovrascrivono. */
svg { width: 18px; height: 18px; flex: none; vertical-align: middle; }

.alert svg { width: 17px; height: 17px; flex: 0 0 17px; margin-right: 2px; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Sfondo vivo: due aloni che respirano lentamente dietro tutto. */
body::before {
  content: "";
  position: fixed;
  inset: -30%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42vw 42vw at 18% 8%,  color-mix(in srgb, var(--accent) 32%, transparent), transparent 70%),
    radial-gradient(46vw 46vw at 88% 82%, color-mix(in srgb, var(--accent2) 26%, transparent), transparent 70%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 60%);
  animation: drift 26s var(--ease) infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(2.5%, -2%, 0) scale(1.08); }
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- struttura ---------- */

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.02em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .sub {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-mute);
  letter-spacing: 0;
}

.back {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .18s, transform .18s;
}
.back:active { transform: scale(.92); background: var(--surface-2); }

/* ---------- navigazione in basso ---------- */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-top: 1px solid var(--border);
}

.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 550;
  color: var(--text-mute);
  transition: color .18s, background .18s, transform .18s;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--text); background: var(--surface); }
.nav a.on svg { filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 80%, transparent)); }
.nav a:active { transform: scale(.94); }

/* ---------- schede ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.section { margin-top: 26px; }

.section > h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 9px;
}
.section > h2 svg { width: 16px; height: 16px; opacity: .8; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid.g2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 860px) { .grid.g3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 560px) { .grid.auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); } }

/* ---------- riquadro sito (pagina iniziale) ---------- */

.site-card {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--r-xl);
  padding: 20px;
  min-height: 132px;
  border: 1px solid var(--border-2);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--sa) 26%, transparent),
      color-mix(in srgb, var(--sb) 12%, transparent) 55%,
      rgba(255, 255, 255, .03));
  box-shadow: var(--shadow);
  transition: transform .22s var(--ease), box-shadow .22s;
  animation: rise .5s var(--ease) backwards;
}
.site-card:active { transform: scale(.975); }
.site-card:hover  { box-shadow: var(--shadow-lg); }

/* Riflesso che scorre all'apparire della scheda. */
.site-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 32%,
              rgba(255, 255, 255, .13) 47%, transparent 62%);
  transform: translateX(-100%);
  animation: sheen 5.5s ease-in-out 1.2s infinite;
  pointer-events: none;
}
@keyframes sheen { 0%, 72% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

.site-card .ico {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 14px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--sa) 45%, transparent);
  border: 1px solid color-mix(in srgb, var(--sa) 60%, transparent);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--sa) 45%, transparent);
}
.site-card .ico svg { width: 24px; height: 24px; }

.site-card h3 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
.site-card p  { margin: 3px 0 0; font-size: 13px; color: var(--text-dim); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(255, 255, 255, .09);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip svg { width: 13px; height: 13px; }
.chip.ok   { color: #86efac; background: rgba(34, 197, 94, .15);  border-color: rgba(34, 197, 94, .3); }
.chip.warn { color: #fcd34d; background: rgba(245, 158, 11, .15); border-color: rgba(245, 158, 11, .3); }
.chip.err  { color: #fca5a5; background: rgba(239, 68, 68, .16);  border-color: rgba(239, 68, 68, .34); }
.chip.on   { color: #fde68a; background: rgba(251, 191, 36, .17); border-color: rgba(251, 191, 36, .32); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dot.live { animation: pulse 1.9s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- interruttore luce ---------- */

.light {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 15px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background .2s, border-color .2s, transform .12s;
}
.light:active { transform: scale(.98); }

.light.on {
  background: linear-gradient(135deg, rgba(251, 191, 36, .16), rgba(251, 191, 36, .05));
  border-color: rgba(251, 191, 36, .34);
}

.light .bulb {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: rgba(255, 255, 255, .06);
  color: var(--text-mute);
  transition: color .25s, background .25s, box-shadow .25s;
}
.light .bulb svg { width: 20px; height: 20px; }
.light.on .bulb {
  color: #fbbf24;
  background: rgba(251, 191, 36, .2);
  box-shadow: 0 0 22px rgba(251, 191, 36, .45);
}

.light .txt { flex: 1; min-width: 0; }
.light .txt b { display: block; font-size: 14.5px; font-weight: 600; }
.light .txt small { color: var(--text-mute); font-size: 11.5px; }

.light .sw {
  flex: 0 0 46px;
  width: 46px; height: 27px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid var(--border);
  position: relative;
  transition: background .25s var(--ease);
}
.light .sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #e7ebf5;
  transition: transform .25s var(--ease);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.light.on .sw { background: #fbbf24; border-color: #fbbf24; }
.light.on .sw::after { transform: translateX(19px); }
.light.unknown .sw { opacity: .4; }
.light.busy { opacity: .55; pointer-events: none; }

/* ---------- scenari ---------- */

.scene {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px;
  border-radius: var(--r);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--sa) 20%, transparent), rgba(255, 255, 255, .04));
  border: 1px solid var(--border-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: transform .14s, filter .2s;
  -webkit-tap-highlight-color: transparent;
}
.scene:active { transform: scale(.975); }
.scene.danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, .2), rgba(255, 255, 255, .03));
  border-color: rgba(239, 68, 68, .38);
}
.scene .ico {
  display: grid; place-items: center;
  flex: 0 0 40px; width: 40px; height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .1);
}
.scene .ico svg { width: 21px; height: 21px; }
.scene b { font-size: 15px; font-weight: 600; }
.scene small { display: block; color: var(--text-mute); font-size: 11.5px; }

.scene.running { filter: brightness(1.12); }
.scene.running::before {
  content: "";
  position: absolute;
  left: 0; bottom: 0; height: 3px; width: 100%;
  background: linear-gradient(90deg, transparent, var(--sa), transparent);
  animation: sweep 1.4s linear infinite;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- campane: doppio comando ---------- */

.bell {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-2);
  background: linear-gradient(150deg,
    color-mix(in srgb, var(--sa) 15%, transparent), rgba(255, 255, 255, .035));
  padding: 16px;
  transition: border-color .25s, box-shadow .25s, background .25s;
}

.bell-head { display: flex; align-items: center; gap: 12px; margin-bottom: 13px; }
.bell-head .ico {
  display: grid; place-items: center;
  flex: 0 0 42px; width: 42px; height: 42px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--sa) 32%, transparent);
  border: 1px solid color-mix(in srgb, var(--sa) 45%, transparent);
}
.bell-head .ico svg { width: 23px; height: 23px; }
.bell-head b { font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; }
.bell-head small { display: block; color: var(--text-mute); font-size: 11.5px; }

.bell .act {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--border-2);
  transition: all .22s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.bell .act svg { width: 19px; height: 19px; }
.bell .act:active { transform: scale(.97); }

/* stato 2: armato — il pulsante diventa rosso e pulsa */
.bell.armed {
  border-color: rgba(239, 68, 68, .55);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, .3), 0 12px 40px rgba(239, 68, 68, .22);
  background: linear-gradient(150deg, rgba(239, 68, 68, .16), rgba(255, 255, 255, .04));
}
.bell.armed .act {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: #f87171;
  color: #fff;
  animation: breathe 1.15s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .55); }
  60%      { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
}

/* barra del conto alla rovescia */
.bell .countdown {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
  margin-bottom: 11px;
  display: none;
}
.bell.armed .countdown { display: block; }
.bell .countdown i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #f87171, #ef4444);
  transform-origin: left;
  animation: drain var(--arm-window, 10s) linear forwards;
}
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.bell .hint {
  display: none;
  margin: 9px 0 0;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: #fca5a5;
}
.bell.armed .hint { display: block; }

/* stato 3: in esecuzione */
.bell.ringing { border-color: rgba(56, 189, 248, .5); }
.bell.ringing .act {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  border-color: #38bdf8; color: #fff;
  pointer-events: none;
}
.bell.ringing .ico svg { animation: swing .55s ease-in-out infinite; transform-origin: 50% 12%; }
@keyframes swing {
  0%, 100% { transform: rotate(-13deg); }
  50%      { transform: rotate(13deg); }
}

/* bobina alta letta dal Modbus: la campana sta suonando davvero, anche se
   il comando e' partito da un altro sistema o dal pulsante in sacrestia */
.bell.active {
  border-color: rgba(56, 189, 248, .6);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, .35), 0 12px 36px rgba(56, 189, 248, .2);
}
.bell.active .ico { animation: swing .55s ease-in-out infinite; transform-origin: 50% 15%; }
.bell .now {
  display: none;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  background: rgba(56, 189, 248, .18);
  border: 1px solid rgba(56, 189, 248, .42);
  color: #bae6fd;
  width: fit-content;
}
.bell.active .now { display: inline-flex; }

.bell.done .act { background: linear-gradient(135deg, #16a34a, #15803d); border-color: #4ade80; color: #fff; }
.bell.failed .act { background: rgba(239, 68, 68, .25); border-color: var(--err); color: #fca5a5; }

/* STOP: comando di sicurezza, sempre a un tocco */
.bell.stop {
  background: linear-gradient(150deg, rgba(239, 68, 68, .2), rgba(255, 255, 255, .04));
  border-color: rgba(239, 68, 68, .42);
}
.bell.stop .act { background: linear-gradient(135deg, #dc2626, #b91c1c); border-color: #ef4444; color: #fff; }

/* ---------- allarme ---------- */

.prog {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 15px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .25s, border-color .25s;
}
.prog.armed {
  background: linear-gradient(135deg, rgba(239, 68, 68, .15), rgba(255, 255, 255, .03));
  border-color: rgba(239, 68, 68, .35);
}
.prog.alarm {
  border-color: var(--err);
  animation: alarmflash 1s ease-in-out infinite;
}
@keyframes alarmflash {
  0%, 100% { background: rgba(239, 68, 68, .14); }
  50%      { background: rgba(239, 68, 68, .34); }
}
.prog .txt { flex: 1; min-width: 0; }
.prog .txt b { display: block; font-size: 15px; font-weight: 600; }
.prog .st { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.prog .st.off   { color: #86efac; }
.prog .st.armed { color: #fca5a5; }
.prog .st.unknown { color: var(--text-mute); }

/* ---------- pulsanti ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 13px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .14s, filter .2s, background .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 42%, transparent);
}
.btn.danger { background: linear-gradient(135deg, #dc2626, #b91c1c); border-color: #ef4444; color: #fff; }
.btn.ghost  { background: transparent; }
.btn.wide   { width: 100%; }

/* ---------- sensori ---------- */

.sensors { display: flex; gap: 9px; flex-wrap: wrap; }

.metric {
  flex: 1 1 96px;
  padding: 13px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}
.metric .v {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  transition: color .3s;
}
.metric .v.temp { color: #fb923c; }
.metric .v.hum  { color: #38bdf8; }
.metric .v.co2  { color: #a78bfa; }
.metric .v.co2.warn { color: var(--warn); }
.metric .v.co2.bad  { color: var(--err); }
.metric .k {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-top: 2px;
}
.metric .v.updated { animation: flash .8s ease-out; }
@keyframes flash {
  0% { text-shadow: 0 0 22px currentColor; transform: scale(1.1); }
  100% { text-shadow: none; transform: scale(1); }
}

/* ---------- avvisi a comparsa ---------- */

#toasts {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 15px;
  border-radius: 14px;
  background: rgba(22, 26, 40, .96);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  font-size: 14px;
  font-weight: 550;
  animation: toastin .32s var(--ease);
  pointer-events: auto;
}
.toast.out { animation: toastout .26s var(--ease) forwards; }
.toast svg { width: 19px; height: 19px; flex: 0 0 19px; }
.toast.ok  { border-color: rgba(34, 197, 94, .45);  color: #bbf7d0; }
.toast.err { border-color: rgba(239, 68, 68, .5);   color: #fecaca; }
.toast.info{ border-color: rgba(56, 189, 248, .45); color: #bae6fd; }

@keyframes toastin  { from { opacity: 0; transform: translateY(18px) scale(.96); } }
@keyframes toastout { to   { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ---------- accesso ---------- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login {
  width: 100%;
  max-width: 400px;
  padding: 32px 26px;
  border-radius: var(--r-xl);
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--border-2);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  box-shadow: var(--shadow-lg);
  animation: rise .55s var(--ease);
}

.login .crest {
  width: 66px; height: 66px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 14px 38px color-mix(in srgb, var(--accent) 48%, transparent);
  animation: float 4.5s ease-in-out infinite;
}
.login .crest svg { width: 34px; height: 34px; color: #fff; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.login h1 { margin: 0; text-align: center; font-size: 22px; font-weight: 680; letter-spacing: -.02em; }
.login p  { margin: 5px 0 26px; text-align: center; color: var(--text-mute); font-size: 13.5px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 13px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--border);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.45;
  margin-bottom: 16px;
  background: rgba(239, 68, 68, .14);
  border: 1px solid rgba(239, 68, 68, .38);
  color: #fecaca;
  animation: shake .42s var(--ease);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.alert.info { background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .35); color: #bae6fd; animation: none; }
.alert.warn { background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .38); color: #fde68a; animation: none; }

/* ---------- giornale eventi ---------- */

.log-row {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-mute);
  font-size: 13.5px;
  align-items: flex-start;
}
.log-row.campane   { border-left-color: #0ea5e9; }
.log-row.allarme   { border-left-color: #ef4444; }
.log-row.luce      { border-left-color: #fbbf24; }
.log-row.scenario  { border-left-color: #a78bfa; }
.log-row.varchi    { border-left-color: #22c55e; }
.log-row.accesso   { border-left-color: #64748b; }
.log-row.errore    { border-left-color: var(--err); background: rgba(239, 68, 68, .08); }
.log-row time { flex: 0 0 68px; color: var(--text-mute); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.log-row .who { color: var(--text-mute); font-size: 11.5px; }

/* ---------- tabelle ---------- */

.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left;
  padding: 9px 10px;
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-mute);
  border-bottom: 1px solid var(--border);
}
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--border); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- varie ---------- */

.muted { color: var(--text-mute); font-size: 13px; }
.empty { text-align: center; padding: 34px 18px; color: var(--text-mute); font-size: 14px; }
.empty svg { width: 42px; height: 42px; opacity: .32; margin-bottom: 10px; }

.badge-verify {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  background: rgba(245, 158, 11, .18);
  border: 1px solid rgba(245, 158, 11, .4);
  color: #fde68a;
}

.stagger > * { animation: rise .42s var(--ease) backwards; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .06s; }
.stagger > *:nth-child(3) { animation-delay: .10s; }
.stagger > *:nth-child(4) { animation-delay: .14s; }
.stagger > *:nth-child(5) { animation-delay: .18s; }
.stagger > *:nth-child(6) { animation-delay: .22s; }
.stagger > *:nth-child(7) { animation-delay: .26s; }
.stagger > *:nth-child(8) { animation-delay: .30s; }

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

/* ================= ANTIFURTO ================= */

/* Riquadro di stato d'insieme: la prima cosa che si guarda entrando. */
.hero {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 24px 16px 20px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border-2);
  background: var(--surface);
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .55;
  transition: background .4s;
  pointer-events: none;
}
.hero.off::before { background: radial-gradient(400px 160px at 50% 0, rgba(34,197,94,.30), transparent 70%); }
.hero.armed::before { background: radial-gradient(400px 160px at 50% 0, rgba(239,68,68,.32), transparent 70%); }
.hero.part::before { background: radial-gradient(400px 160px at 50% 0, rgba(245,158,11,.32), transparent 70%); }
.hero.alarm::before { background: radial-gradient(500px 200px at 50% 0, rgba(239,68,68,.55), transparent 70%); }
.hero.unknown::before { background: radial-gradient(400px 160px at 50% 0, rgba(148,163,184,.28), transparent 70%); }

.hero > * { position: relative; }

.hero-ico {
  width: 54px; height: 54px;
  margin: 0 auto 8px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--border);
}
.hero-ico svg { width: 28px; height: 28px; }
.hero.off     .hero-ico { color: #86efac; }
.hero.armed   .hero-ico,
.hero.alarm   .hero-ico { color: #fca5a5; }
.hero.part    .hero-ico { color: #fcd34d; }
.hero.unknown .hero-ico { color: var(--text-mute); }

.hero-st {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: .04em;
}
.hero-sub { margin-top: 3px; font-size: 13px; color: var(--text-dim); }
.hero .chips { margin-top: 14px; }

.hero.alarm { border-color: var(--err); animation: alarmflash 1s ease-in-out infinite; }

/* Righe dei programmi */
.prow {
  display: flex;
  align-items: center;
  gap: 11px;
  flex-wrap: wrap;
  padding: 13px 14px;
  border-top: 1px solid var(--border);
  transition: background .2s;
}
.prow:first-child { border-top: none; }
.prow.armed { background: rgba(239, 68, 68, .07); }
.prow.alarm { background: rgba(239, 68, 68, .18); }
.prow.busy  { opacity: .5; pointer-events: none; }

.prow .pn {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700;
  color: var(--text-mute);
}
.prow .nm { flex: 1 1 120px; min-width: 0; font-weight: 600; font-size: 14.5px; }
.prow .pact { display: flex; gap: 6px; }

.btn.sm { min-height: 36px; padding: 0 13px; font-size: 12.5px; border-radius: 10px; }

/* Tensioni */
.gauge {
  padding: 13px;
  border-radius: var(--r);
  background: rgba(0, 0, 0, .22);
  border: 1px solid var(--border);
}
.gauge .k { font-size: 11.5px; color: var(--text-mute); font-weight: 600; }
.gauge .v {
  font-size: 24px; font-weight: 800; margin: 3px 0 8px;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.gauge .v.low { color: var(--warn); }
.gauge .bar { height: 7px; border-radius: 6px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.gauge .bar i {
  display: block; height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, #22c55e, #38bdf8);
  transition: width .5s var(--ease);
}
.gauge .bar i.low { background: linear-gradient(90deg, #f59e0b, #ef4444); }

/* Sinottico zone */
.zgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(102px, 1fr));
  gap: 9px;
}
.ztile {
  border-radius: 13px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, .22);
  text-align: center;
}
.ztile .zn { font-size: 11px; font-weight: 700; color: var(--text-mute); }
.ztile .znm {
  font-size: 12.5px; font-weight: 600; margin: 2px 0;
  min-height: 32px; line-height: 1.15;
  display: flex; align-items: center; justify-content: center;
}
.ztile .zst { font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 2px 0; }
.ztile .zbtn {
  margin-top: 8px; width: 100%;
  font-size: 11px; font-weight: 600;
  padding: 7px 0; border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .07);
  color: var(--text-dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ztile .zbtn:active { transform: scale(.95); }
.ztile .zbtn:disabled { opacity: .4; pointer-events: none; }

.ztile.ok   { border-color: rgba(34, 197, 94, .35); }
.ztile.ok   .zst { color: #86efac; }
.ztile.open { border-color: rgba(239, 68, 68, .5); box-shadow: inset 0 0 0 1px rgba(239,68,68,.2); }
.ztile.open .zst { color: #fca5a5; }
.ztile.exc  { border-color: rgba(245, 158, 11, .5); background: rgba(245, 158, 11, .09); }
.ztile.exc  .zst { color: #fde68a; }
.ztile.exc  .zbtn { background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; border-color: #4ade80; }
