/* ==========================================================================
   NetPulse — design tokens
   ========================================================================== */
:root {
  --bg: #0a0d14;
  --bg-grid-line: #11151f;
  --surface: #121622;
  --surface-2: #161b29;
  --surface-hover: #1b2133;
  --border: #232a3d;

  --text: #e8ebf2;
  --text-dim: #8891a8;
  --text-faint: #5d6478;

  --green: #2ee6a6;
  --green-dim: rgba(46, 230, 166, 0.12);
  --red: #ff4f6e;
  --red-dim: rgba(255, 79, 110, 0.14);
  --amber: #ffb454;
  --blue: #5b8cff;
  --violet: #a78bfa;
  --teal: #2dd4bf;
  --mint: #96e3c6;

  /* Colori che prima erano scritti a mano nei CSS delle pagine (topologia,
     infrastruttura, metriche): ora passano dal tema, così il chiaro non lascia
     macchie scure. Nel tema scuro i valori sono IDENTICI a quelli di prima. */
  --on-green: #06140f;          /* testo sopra un fondo verde/pieno */
  --on-blue: #04122e;
  --link-hover: #fff;           /* link viola al passaggio del mouse */
  --line: #2a3550;              /* rami della topologia, bordi marcati */
  --border-strong: #33405e;
  --border-mid: #2e3750;
  --track: #222a3e;             /* binario delle barre di avanzamento */
  --panel: rgba(18, 22, 34, 0.94);   /* pannelli sovrapposti alla mappa */
  --panel-deep: rgba(10, 14, 24, 0.9);
  --tooltip-bg: rgba(14, 19, 30, 0.97);
  --divider: rgba(35, 42, 61, 0.6);
  --row-hover: rgba(27, 33, 51, 0.5);
  --hilite: rgba(255, 255, 255, 0.07);
  --grid-soft: rgba(255, 255, 255, 0.055);
  --crosshair: rgba(255, 255, 255, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.6);
  --node-a: #151b2b;            /* sfondo dei nodi della topologia (gradiente) */
  --node-b: #111624;
  --node-border: #2b3550;
  --node-root-a: #141d2e;       /* nodo radice (concentratore) */
  --node-root-b: #101522;
  --node-root-border: #2c4a6b;
  --node-stack-a: #171a2b;      /* nodo "N telecamere" a mazzo di carte */
  --node-stack-b: #12152140;
  --node-stack-edge: #171c2b;
  --error-bg: #1e1219;

  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  --radius: 10px;
  --radius-sm: 6px;

  /* Alias: le pagine mappa/impostazioni usano questa naming convention */
  --color-background-primary: var(--surface);
  --color-background-secondary: var(--surface-2);
  --color-background-tertiary: var(--surface-hover);
  --color-background-info: var(--blue);
  --color-border-primary: var(--border);
  --color-border-secondary: var(--border);
  --color-border-tertiary: var(--border);
  --color-text-primary: var(--text);
  --color-text-secondary: var(--text-dim);
  --color-text-info: var(--green);
  --border-radius-md: var(--radius-sm);
  --border-radius-lg: var(--radius);
}

/* Tema chiaro (preferenza per utente, dal 2026-09-25): lo accende tema.js
   mettendo data-theme="light" su <html> PRIMA che la pagina si disegni.
   Bozza approvata: mockup/tema-chiaro.html. Verde, rosso, ambra, blu e viola
   sono più scuri che nel tema scuro: quelli di là, su bianco, non si leggono
   (il verde #2ee6a6 ha contrasto 1,6:1). Qui stanno fra 4,5 e 5,5:1. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-grid-line: #e4e8f0;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-hover: #eef1f7;
  --border: #d8dee9;

  --text: #151b27;
  --text-dim: #566074;
  --text-faint: #8a93a6;

  --green: #0b7f58;
  --green-dim: rgba(11, 127, 88, 0.11);
  --red: #d42a4a;
  --red-dim: rgba(212, 42, 74, 0.1);
  --amber: #9a5b00;
  --blue: #2f5fe0;
  --violet: #6a47d6;
  --teal: #0b7d70;
  --mint: #0b7f58;

  --on-green: #ffffff;
  --on-blue: #ffffff;
  --link-hover: #3f25a8;
  --line: #c3cbd9;
  --border-strong: #b6c0d1;
  --border-mid: #c5cddb;
  --track: #e3e8f0;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-deep: rgba(255, 255, 255, 0.94);
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --divider: rgba(20, 30, 50, 0.1);
  --row-hover: rgba(20, 30, 50, 0.045);
  --hilite: rgba(20, 30, 50, 0.06);
  --grid-soft: rgba(20, 30, 50, 0.07);
  --crosshair: rgba(20, 30, 50, 0.35);
  --shadow-strong: rgba(20, 30, 50, 0.16);
  --node-a: #ffffff;
  --node-b: #f5f7fb;
  --node-border: #cfd7e4;
  --node-root-a: #f2f7ff;
  --node-root-b: #e8f0fc;
  --node-root-border: #9fb5d8;
  --node-stack-a: #ffffff;
  --node-stack-b: #f5f7fb;
  --node-stack-edge: #e9edf4;
  --error-bg: #fdecef;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

/* Dissolvenza in ingresso/uscita per rendere il passaggio tra le pagine più fluido
   (niente "flash" bianco/nero al cambio pagina, anche se è un caricamento HTML classico) */
body {
  animation: page-fade-in 0.18s ease-out;
}

body.page-leaving {
  animation: page-fade-out 0.15s ease-in forwards;
}

@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes page-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  body, body.page-leaving { animation: none !important; }
}

/* Sottile texture a griglia: richiama una topologia di rete, non un grafico */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(var(--bg-grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid-line) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.5;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 40%, transparent 90%);
}

/* ==========================================================================
   Pagina di accesso
   ========================================================================== */
.login-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 26px 22px;
}

.login-brand { margin-bottom: 8px; }

.login-btn {
  background: var(--green);
  color: var(--on-green);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.login-btn:hover { filter: brightness(1.08); }
.login-btn:disabled { opacity: 0.6; cursor: default; }

/* ==========================================================================
   Ruoli: gli utenti non amministratori sono in sola lettura.
   Il server blocca comunque le scritture (403); qui nascondiamo solo i
   controlli inutilizzabili. La classe sul body la imposta nav.js.
   ========================================================================== */
/* Sezioni riservate all'amministratore: nascoste a ogni utente non admin,
   demo compresa (possono contenere dati sensibili, non solo comandi) */
body.role-user .modal-danger-zone,
body.role-user .admin-only {
  display: none !important;
}

/* Comandi di modifica: nascosti all'utente semplice. In modalità demo restano
   invece VISIBILI — l'app deve sembrare completa — e il click viene
   intercettato da nav.js, che mostra l'avviso di verifica licenza. */
body.role-user:not(.role-demo) .add-host-form,
body.role-user:not(.role-demo) .header-actions,
body.role-user:not(.role-demo) .cell-actions,
body.role-user:not(.role-demo) .th-actions,
body.role-user:not(.role-demo) .gear-btn,
body.role-user:not(.role-demo) .del-btn,
body.role-user:not(.role-demo) .icon-btn,
body.role-user:not(.role-demo) .remove-host-btn,
body.role-user:not(.role-demo) .btn-text-danger,
body.role-user:not(.role-demo) .modal-add-row {
  display: none !important;
}

/* ==========================================================================
   Modalità demo: badge nella topbar, voci "armate" e avviso di licenza
   ========================================================================== */
.demo-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--amber);
  background: rgba(255, 180, 84, 0.12);
  border: 1px solid rgba(255, 180, 84, 0.35);
  border-radius: 999px;
  padding: 5px 11px;
  white-space: nowrap;
}

.page-nav a.demo-locked { opacity: 0.55; }
.page-nav a.demo-locked::after { content: " 🔒"; font-size: 10px; }

.demo-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 7, 12, 0.72);
  backdrop-filter: blur(2px);
}
.demo-overlay.is-open { display: flex; }

.demo-dialog {
  width: min(430px, 100%);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}
.demo-dialog-icon { font-size: 32px; line-height: 1; margin-bottom: 14px; }
.demo-dialog h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--amber);
}
.demo-dialog p {
  margin: 12px 0 0;
  font-size: 13.5px;
  color: var(--text-dim);
}
.demo-dialog-btn {
  margin-top: 22px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 22px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.demo-dialog-btn:hover { border-color: var(--amber); color: var(--amber); }

/* Badge utente e pulsante di uscita nella topbar (creati da nav.js) */
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 6px 5px 11px;
}

.user-chip .user-name { color: var(--text); font-weight: 600; }

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 3px 9px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.logout-btn:hover { color: var(--red); border-color: var(--red); }

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
}

.page-nav {
  display: flex;
  gap: 4px;
  padding: 10px 28px 0;
  border-bottom: 1px solid var(--border);
}

.page-nav a {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  padding: 10px 14px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.page-nav a:hover { color: var(--text); }

.page-nav a.active {
  color: var(--text);
  border-bottom-color: var(--green);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--bg);
  background: linear-gradient(135deg, var(--green), var(--blue));
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  line-height: 1;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.header-btn:hover { color: var(--text); border-color: var(--blue); }

@media (max-width: 760px) {
  .header-right { gap: 8px; }
  .header-btn span { display: none; }
}
/* Sul telefono la topbar e la barra pagine vanno in affanno: si tolgono i
   pulsanti di servizio (Esporta/Importa) e le voci che da telefono non
   si usano (Gruppi, Metriche, Eventi SIA, Impostazioni). Restano tutte da
   computer. Il secondo ramo della media query è il telefono in orizzontale:
   lì la larghezza supera i 640px e, senza, ricomparirebbe tutto.
   Deve stare DOPO le regole di .header-actions/.page-nav: a parità di
   specificità vince l'ultima, e fino alla 1.23.2 il blocco stava sopra, così
   .header-actions { display: flex } lo annullava e i pulsanti restavano. */
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
  .header-actions { display: none; }
  .header-right { gap: 10px; }
  .resource-badge span { display: none; }
  .page-nav a[href="gruppi.html"],
  .page-nav a[href="metriche.html"],
  .page-nav a[href="sia.html"],
  .page-nav a[href="impostazioni.html"] { display: none; }

  /* Le voci rimaste non stanno in 390px: la barra scorre di lato col dito
     invece di allargare la pagina. nav.js centra la voce attiva e accende la
     sfumatura (.scorre-sx/.scorre-dx) solo sul lato dove c'è altro da vedere. */
  .page-nav {
    padding: 8px 16px 0;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .page-nav::-webkit-scrollbar { display: none; }
  .page-nav a {
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
    padding: 10px 12px;
  }
  .page-nav.scorre-dx {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  }
  .page-nav.scorre-sx {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
  }
  .page-nav.scorre-sx.scorre-dx {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  }

  /* Topbar compatta: via sottotitolo e versione, della connessione resta il
     pallino colorato. */
  .topbar .brand-sub,
  #connText { display: none; }
  .user-chip { gap: 6px; padding: 4px 5px 4px 9px; }
}

.resource-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px 5px 9px;
}

.res-icon {
  width: 14px;
  height: 14px;
  color: var(--blue);
  flex-shrink: 0;
}

/* Elemento distintivo: un "ping" reale — anello che si espande come un'onda ICMP */
.ping-dot {
  position: relative;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  display: inline-block;
}
.ping-dot.online { background: var(--green); }
.ping-dot.offline { background: var(--red); }

.ping-ring {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1.5px solid var(--green);
  opacity: 0;
}
.ping-dot.online .ping-ring {
  animation: ping-wave 1.8s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}

@keyframes ping-wave {
  0%   { transform: scale(1);   opacity: 0.7; }
  70%  { transform: scale(3.2); opacity: 0; }
  100% { transform: scale(3.2); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ping-ring { animation: none !important; }
}

/* ==========================================================================
   Layout
   ========================================================================== */
/* Tutte le pagine usano la stessa larghezza della dashboard: la tabella host
   ha 10 colonne e su schermi grandi deve mostrarle tutte senza scroll */
main {
  max-width: 1720px;
  margin: 0 auto;
  padding: 24px 28px 60px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card h3 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.widgets-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.3fr;
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 880px) {
  .widgets-row { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Skeleton loading
   ========================================================================== */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton {
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-bar {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  height: 26px;
  width: 60%;
  margin: 0 auto;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-bar-sm {
  height: 12px;
  width: 40%;
  margin: 6px auto 0;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton, .skeleton-bar { animation: none !important; opacity: 0.5; }
}

/* ==========================================================================
   Gauge widget
   ========================================================================== */
.gauge {
  width: 100%;
  height: 170px;
}

/* ==========================================================================
   Stats widget
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  height: 170px;
  align-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 16px 6px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat.is-up .stat-value { color: var(--green); }
.stat.is-down .stat-value { color: var(--red); }

/* ==========================================================================
   Form widget
   ========================================================================== */
.form-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}

.field-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
  cursor: pointer;
}

.field input,
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.field textarea {
  resize: vertical;
  min-height: 44px;
  font-size: 12px;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--blue);
}

.field input:invalid:not(:placeholder-shown) {
  border-color: var(--red);
}

.form-card button {
  margin-top: 4px;
  background: var(--green);
  color: var(--on-green);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.form-card button:hover { filter: brightness(1.08); }
.form-card button:active { filter: brightness(0.94); }

.form-error {
  margin: 0;
  font-size: 12px;
  color: var(--red);
  min-height: 14px;
}

/* ==========================================================================
   Form aggiungi host (Dashboard)
   ========================================================================== */
.add-host-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--border);
}

.add-host-form input,
.add-host-form select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s ease;
}

.add-host-form input:focus,
.add-host-form select:focus {
  border-color: var(--blue);
}

.add-host-form input[type="text"] { flex: 1 1 140px; min-width: 120px; }
.add-host-form select { flex: 0 1 160px; min-width: 130px; }
.add-host-form input[type="number"] { flex: 0 0 90px; width: 90px; }

.add-host-form button {
  background: var(--green);
  color: var(--on-green);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease;
}
.add-host-form button:hover { filter: brightness(1.08); }
.add-host-form button:active { filter: brightness(0.94); }

.add-host-form .form-error {
  flex-basis: 100%;
  min-height: 0;
}
.add-host-form .form-error:empty { display: none; }

/* ==========================================================================
   Tabella host
   ========================================================================== */
.table-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.interval-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}
.table-scroll::-webkit-scrollbar { height: 4px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 2px; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

/* Griglia host: tutte le celle su UNA riga (niente a-capo che creano righe di
   altezze diverse); sotto i 960px la tabella scorre in orizzontale in .table-scroll */
#hostsTable {
  min-width: 960px;
}

#hostsTable tbody td,
#hostsTable thead th {
  white-space: nowrap;
}

/* Larghezze indicative delle colonne strette: stabilizzano la griglia quando i
   valori cambiano ad ogni aggiornamento (il contenuto non le supera mai) */
#hostsTable th:nth-child(6) { width: 84px;  } /* Latenza */
#hostsTable th:nth-child(7) { width: 125px; } /* Andamento (sparkline 105px) */
#hostsTable th:nth-child(8) { width: 78px;  } /* Uptime */
#hostsTable th:nth-child(9) { width: 82px;  } /* Timeout */

/* Colonne numeriche allineate a destra: le cifre si incolonnano correttamente */
#hostsTable th:nth-child(6),
#hostsTable th:nth-child(8),
#hostsTable th:nth-child(9),
#hostsTable .cell-latency,
#hostsTable .cell-uptime,
#hostsTable .cell-threshold {
  text-align: right;
}

thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

.mono { font-family: var(--font-mono); color: var(--text-dim); }

/* Badge di stato — netti e ben visibili, come richiesto */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 5px 9px;
  border-radius: 999px;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge.up {
  color: var(--green);
  background: var(--green-dim);
}
.badge.up::before { background: var(--green); }

.badge.down {
  color: var(--red);
  background: var(--red-dim);
}
.badge.down::before { background: var(--red); }

.badge.unknown {
  color: var(--text-dim);
  background: var(--surface-2);
}
.badge.unknown::before { background: var(--text-faint); }

/* Riga in evidenza leggera quando l'host è down; il bordo trasparente sulle
   altre righe mantiene identico l'ingombro (nessuno sfasamento di 2px) */
tr.row-down td:first-child { border-left: 2px solid var(--red); }
tr.row-up td:first-child,
tr.row-unknown td:first-child { border-left: 2px solid transparent; }

.spark {
  width: 105px;
  height: 36px;
}

.del-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.del-btn:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-dim);
}

.empty-msg {
  display: none;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 28px 10px 6px;
}

/* 2 pulsanti da 26px + spazio 6px + padding cella 20px */
.th-actions { width: 78px; }

.cell-actions {
  white-space: nowrap;
  text-align: right;
}

/* Colonne bloccate: quando la tabella scorre in orizzontale, Stato+Nome
   restano ancorati a sinistra e i pulsanti azione a destra. Servono uno sfondo
   pieno (le celle normali sono trasparenti sul fondo della card) e una
   larghezza fissa su Stato, perché il left del Nome deve coincidere con la
   fine della colonna precedente. */
#hostsTable th:nth-child(1),
#hostsTable .cell-status,
#hostsTable th:nth-child(2),
#hostsTable .cell-name,
#hostsTable .th-actions,
#hostsTable .cell-actions {
  position: sticky;
  z-index: 2;
  background: var(--surface);
}
#hostsTable th:nth-child(1), #hostsTable .cell-status { left: 0; width: 104px; }
#hostsTable th:nth-child(2), #hostsTable .cell-name { left: 104px; }
#hostsTable .th-actions, #hostsTable .cell-actions { right: 0; }

/* Le celle sticky hanno sfondo proprio: all'hover della riga va scurito anche
   il loro, altrimenti restano del colore base */
#hostsTable tbody tr:hover .cell-status,
#hostsTable tbody tr:hover .cell-name,
#hostsTable tbody tr:hover .cell-actions {
  background: var(--surface-hover);
}

/* Ombra sui bordi delle colonne bloccate, ma solo quando c'è davvero overflow
   orizzontale (classe gestita da app.js): a tabella intera niente ombre */
.table-scroll.has-overflow #hostsTable th:nth-child(2),
.table-scroll.has-overflow #hostsTable .cell-name {
  box-shadow: 8px 0 12px -8px rgba(0, 0, 0, 0.55);
}
.table-scroll.has-overflow #hostsTable .th-actions,
.table-scroll.has-overflow #hostsTable .cell-actions {
  box-shadow: -8px 0 12px -8px rgba(0, 0, 0, 0.55);
}

/* Su schermi piccoli il Nome bloccato coprirebbe mezzo viewport: resta fisso
   solo lo Stato (l'ombra passa di conseguenza alla prima colonna) */
@media (max-width: 640px) {
  #hostsTable th:nth-child(2),
  #hostsTable .cell-name {
    position: static;
    box-shadow: none;
  }
  .table-scroll.has-overflow #hostsTable th:nth-child(1),
  .table-scroll.has-overflow #hostsTable .cell-status {
    box-shadow: 8px 0 12px -8px rgba(0, 0, 0, 0.55);
  }
}

.cell-actions button {
  vertical-align: middle;
}

.cell-actions button + button {
  margin-left: 6px;
}

/* Stessa dimensione del pulsante modifica (.icon-btn, 26px) per un'unica linea */
.cell-actions .del-btn {
  width: 26px;
  height: 26px;
}

tr.row-editing { background: var(--surface-hover); }

tr.row-editing .edit-name-input,
tr.row-editing .edit-ip-input,
tr.row-editing .edit-threshold-input {
  background: var(--surface-2);
  border: 1px solid var(--blue);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  width: 100%;
}

.group-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--blue);
  background: rgba(91, 140, 255, 0.12);
  border-radius: 999px;
  padding: 3px 9px;
  /* Su una sola riga: i nomi lunghi (es. "Castelletto Monferrato") non devono
     andare a capo e rendere le righe di altezze diverse; oltre il tetto → ellissi */
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* NB: niente display:flex direttamente sui <td> — toglie loro il comportamento
   da cella di tabella (vertical-align, altezza riga) e disallinea le righe.
   Il layout interno è affidato a elementi figli (.type-row, ecc.). */
.cell-type {
  overflow: hidden;
}

.type-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.type-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 3px 8px;
}

.type-tag.type-ping {
  color: var(--text-faint);
  background: var(--surface-2);
}

.type-tag.type-snmp {
  color: var(--amber);
  background: rgba(255, 180, 84, 0.12);
}

.type-tag.type-onvif {
  color: var(--green);
  background: var(--green-dim);
}

/* host che resta monitorato via ping ma legge anche SNMP (banda, salute, porte) */
.type-tag.type-pingsnmp {
  color: var(--amber);
  background: rgba(255, 180, 84, 0.12);
  border: 1px solid rgba(255, 180, 84, 0.28);
  padding: 2px 7px;
}

.type-tag.type-elmo {
  color: var(--blue);
  background: rgba(91, 140, 255, 0.12);
}

.type-detail {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-detail.type-detail-error {
  color: var(--red);
}

.gear-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 22px;
  height: 22px;
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
}
.gear-btn:hover { color: var(--blue); border-color: var(--blue); }

/* ==========================================================================
   Icona telecamere nella cella del nome (Dashboard)
   ========================================================================== */
.cell-name { overflow: hidden; }

/* Wrapper flex DENTRO il td (non sul td stesso): il nome lungo si tronca
   con l'ellissi ma l'icona telecamera resta sempre visibile e allineata */
.cell-name-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.host-name-text {
  max-width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cam-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  background: transparent;
  text-decoration: none;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.cam-icon-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}

.cam-icon-btn:hover {
  color: var(--blue);
  border-color: var(--blue);
  background: rgba(91, 140, 255, 0.12);
}

/* Host senza telecamere configurate: icona più tenue, resta comunque cliccabile per aggiungerle */
.cam-icon-btn.is-empty {
  color: var(--text-faint);
  opacity: 0.7;
}
.cam-icon-btn.is-empty:hover {
  opacity: 1;
  color: var(--blue);
}

/* Almeno una telecamera offline: evidenzia in rosso */
.cam-icon-btn.has-down {
  color: var(--red);
  border-color: rgba(255, 79, 110, 0.4);
}
.cam-icon-btn.has-down:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-dim);
}

.cam-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
}

/* ==========================================================================
   Pagina Gruppi — cartelle + modale di dettaglio
   ========================================================================== */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-top: 4px;
}

.group-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.12s ease, border-color 0.15s ease;
  text-align: left;
}

.group-card:hover {
  transform: translateY(-2px);
  border-color: var(--blue);
}

.group-folder-icon {
  width: 30px;
  height: 30px;
  color: var(--text-faint);
}

.group-card.status-up { border-color: rgba(46, 230, 166, 0.4); }
.group-card.status-up .group-folder-icon { color: var(--green); }

.group-card.status-down {
  border-color: var(--red);
  background: var(--red-dim);
}
.group-card.status-down .group-folder-icon { color: var(--red); }

.group-card.status-unknown .group-folder-icon,
.group-card.status-empty .group-folder-icon { color: var(--text-faint); }

.group-name {
  font-weight: 600;
  font-size: 14px;
}

.group-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.group-card.status-down .group-meta { color: var(--red); }
.group-card.status-up .group-meta { color: var(--green); }

/* Modale di dettaglio gruppo */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 11, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px 22px 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 10px;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-title-input {
  background: var(--surface-2);
  border: 1px solid var(--blue);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-ui);
  outline: none;
  min-width: 160px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.icon-btn:hover { color: var(--blue); border-color: var(--blue); }
.icon-btn.save-host-btn:hover { color: var(--green); border-color: var(--green); }
.icon-btn.cancel-host-btn:hover { color: var(--red); border-color: var(--red); }

.hidden { display: none !important; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); }

.modal-section { margin-top: 18px; }

.modal-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 8px;
  font-weight: 600;
}

.modal-host-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.modal-host-row:last-child { border-bottom: none; }

.modal-host-info {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  min-width: 0;
}

.modal-host-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.modal-edit-form {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.modal-edit-form input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--blue);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
}

.modal-add-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-add-row select,
.modal-add-row input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
}

.modal-add-row select { flex: 1 1 100%; }
.modal-add-row input { flex: 1 1 110px; }
.modal-add-row select.report-period-select { flex: 1 1 220px; }
.modal-add-row input[type="time"] { flex: 0 1 120px; }

.modal-add-row select:focus,
.modal-add-row input:focus { border-color: var(--blue); }

.modal-add-row button {
  background: var(--blue);
  color: var(--on-blue);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.modal-add-row button:hover { filter: brightness(1.08); }

.modal-add-row button.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.modal-add-row button.btn-secondary:hover {
  border-color: var(--blue);
  filter: none;
}

.test-notify-result {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.test-notify-result:last-child { border-bottom: none; }
.test-notify-result.ok { color: var(--green); }
.test-notify-result.fail { color: var(--red); }
.test-notify-result .chat-id { color: var(--text); font-weight: 600; }

.remove-host-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.remove-host-btn:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-dim);
}

.modal-danger-zone {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.btn-text-danger {
  background: transparent;
  border: none;
  color: var(--red);
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--font-ui);
  white-space: nowrap;
}
.btn-text-danger:hover { text-decoration: underline; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .spark { width: 90px; }
  .add-host-form { gap: 6px; }
  .add-host-form input[type="text"] { flex: 1 1 100%; }
  .add-host-form select { flex: 1 1 100%; }
}


/* ==========================================================================
   Pagina Gruppi — layout a due colonne con log eventi a destra
   ========================================================================== */
.gruppi-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  align-items: start;
}

.gruppi-col-left,
.gruppi-col-right {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

@media (max-width: 900px) {
  .gruppi-layout { grid-template-columns: 1fr; }
}

.event-log-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.event-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}

.event-log-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-log-controls select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  outline: none;
}

.event-log-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  margin-top: 10px;
}

.event-entry {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.event-entry:last-child { border-bottom: none; }

.event-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.5;
}

.event-line + .event-line { margin-top: 3px; }

.event-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
  width: 118px;
}

.event-text { color: var(--text); }
.event-text strong { font-weight: 600; }

.event-line.down .event-text { color: var(--red); }
.event-line.up .event-text { color: var(--green); }

.event-duration {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}

/* ==========================================================================
   Card CPU/RAM nello spazio libero della colonna sinistra
   ========================================================================== */
.system-stats-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  max-width: 420px;
}

.system-stat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 14px;
}

.system-stat-card h3 { margin-bottom: 10px; }

.system-stat-label {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 8px;
}

.gauge-svg-wrap {
  position: relative;
  width: 96px;
  height: 96px;
}

.gauge-svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.gauge-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 9;
}

.gauge-fill {
  fill: none;
  stroke: var(--green);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 263.9; /* 2 * PI * 42 */
  stroke-dashoffset: 263.9;
  transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease;
}

.gauge-svg-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.ram-icon-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 96px;
  gap: 8px;
}

.ram-icon {
  width: 34px;
  height: 34px;
  color: var(--blue);
}

.ram-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

@media (max-width: 900px) {
  .system-stats-row { max-width: none; }
}

/* ==========================================================================
   Pagina Grafici — pannelli host stile "muro NOC"
   ========================================================================== */
.host-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}

.host-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.host-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.host-status-dot.up { background: var(--green); }
.host-status-dot.down { background: var(--red); }

.host-panel-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.host-panel-ip {
  color: var(--text-faint);
  font-size: 11px;
}

.host-panel-meta {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 11px;
  font-family: var(--font-mono);
}

.metric-rows {
  display: flex;
  flex-direction: column;
}

.metric-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.metric-row:last-child { border-bottom: none; }

.metric-label {
  width: 150px;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-chart-wrap {
  flex: 1;
  position: relative;
  height: 36px;
  min-width: 0;
}

.metric-value {
  width: 110px;
  flex-shrink: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-del-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  border-radius: var(--radius-sm);
  width: 22px;
  height: 22px;
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
}
.metric-del-btn:hover { color: var(--red); border-color: var(--red); background: var(--red-dim); }

@media (max-width: 700px) {
  .metric-label { width: 90px; font-size: 10px; }
  .metric-value { width: 80px; font-size: 12px; }
  .host-panel-meta { display: none; }
}

/* Risorse di sistema — 4 riquadri 2x2 dentro la card della widgets-row */
.metrics-card { display: flex; flex-direction: column; }

.metrics-grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  flex: 1;
  margin-top: 4px;
}

.metric-box {
  background: var(--bg-elevated, rgba(255,255,255,0.03));
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
}

.metric-box-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-box-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.metric-box-value small {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 2px;
}

.metric-box-sub {
  font-size: 10px;
  color: var(--text-faint);
}

/* ==========================================================================
   Pagina Telecamere (per singolo host)
   ========================================================================== */
.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.15s ease;
}
.back-link:hover { color: var(--text); }

.cam-page-card { padding: 20px 22px; }

.cam-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cam-page-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.cam-host-meta {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.cam-add-btn { white-space: nowrap; }

.cam-hint {
  margin: 14px 0 16px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.cam-hint .mono { font-size: 11.5px; }

.cam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.cam-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cam-card.cam-openable { cursor: pointer; }
.cam-card.cam-openable:hover {
  border-color: var(--blue);
  background: var(--surface-hover);
}
.cam-card.cam-not-openable { opacity: 0.72; }

.cam-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cam-icon {
  color: var(--text-dim);
  display: inline-flex;
}
.cam-icon svg { width: 18px; height: 18px; display: block; }
.cam-card.cam-openable:hover .cam-icon { color: var(--blue); }

.cam-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cam-ext {
  color: var(--blue);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.cam-card.cam-openable:hover .cam-ext { opacity: 1; }

.cam-card-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.cam-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-faint);
}
.cam-dot.up { background: var(--green); }
.cam-dot.down { background: var(--red); }

.cam-ip { color: var(--text-dim); font-size: 11.5px; }

.cam-status-label { margin-left: auto; font-size: 11px; color: var(--text-faint); }
.cam-status-label.up { color: var(--green); }
.cam-status-label.down { color: var(--red); }

.cam-card-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}

/* Form aggiungi/modifica telecamera */
.cam-card-editing {
  border-color: var(--blue);
  background: var(--surface-hover);
  cursor: default;
}
.cam-card-new { margin-bottom: 12px; }

.cam-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.cam-form-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.cam-form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.cam-form-field input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s ease;
}
.cam-form-field input:focus { border-color: var(--blue); }

.cam-form-actions { display: flex; gap: 8px; margin-top: 2px; }
.cam-form-actions .header-btn { cursor: pointer; }
.cam-form-save:hover { color: var(--green); border-color: var(--green); }

/* ==========================================================================
   Gestione utenti (pagina Impostazioni, solo amministratore)
   ========================================================================== */
.users-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 10px 0 14px;
  line-height: 1.5;
}

.user-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.user-row-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.user-row-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
}

.user-role-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}
.user-role-tag.is-admin {
  color: var(--amber);
  border-color: rgba(255, 180, 84, 0.4);
}

/* Abilitato / disabilitato: spinto a destra nella testa della riga. Un utente
   disabilitato resta modificabile (per riabilitarlo), ma si legge spento. */
.user-attivo {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.user-attivo input { accent-color: var(--green); cursor: pointer; }
.user-row.is-disabilitato { opacity: 0.6; }
.user-row.is-disabilitato .user-attivo span { color: var(--red); }

.user-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 10px;
}

.user-pages-note {
  font-size: 11.5px;
  color: var(--text-faint);
}

.page-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.page-toggle input { accent-color: var(--green); cursor: pointer; }

.user-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Comandi della modalità demo nella riga utente */
.user-demo {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 9px 11px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 180, 84, 0.04);
}

.demo-toggle,
.demo-days {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.demo-toggle input { accent-color: var(--amber); cursor: pointer; }
.demo-days-input {
  width: 62px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 6px;
}

.demo-reset-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.demo-reset-btn:hover { color: var(--amber); border-color: var(--amber); }

.demo-state {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.demo-state.is-active { color: var(--amber); }
.demo-state.is-wait { color: var(--blue); }
.demo-state.is-expired { color: var(--red); font-weight: 600; }

.user-pass-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  flex: 0 1 240px;
}
.user-pass-input:focus { border-color: var(--blue); }

.user-save-btn {
  background: var(--blue);
  color: var(--on-blue);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.user-save-btn:hover { filter: brightness(1.08); }

.user-row-msg { font-size: 12px; font-family: var(--font-mono); }
.user-row-msg.ok { color: var(--green); }
.user-row-msg.err { color: var(--red); }

/* Profilo "Cliente · solo Pocket" nella riga utente (dal 2026-09-26) */
.user-pocket {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.user-row.is-pocket .user-pocket { border-color: rgba(46, 230, 166, 0.45); }
.pocket-testa { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pocket-label { font-size: 12px; color: var(--text-dim); }
.pocket-seg { display: flex; border: 1px solid var(--border-mid); border-radius: var(--radius-sm); overflow: hidden; }
.pocket-seg-btn {
  background: var(--surface-2);
  color: var(--text-dim);
  border: none;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.pocket-seg-btn + .pocket-seg-btn { border-left: 1px solid var(--border-mid); }
.pocket-seg-btn.is-on { background: var(--green-dim); color: var(--green); font-weight: 600; }
.pocket-seg-btn[data-profilo="normale"].is-on { background: rgba(91, 140, 255, 0.14); color: var(--text); }
.pocket-etichetta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.pocket-etichetta-input {
  width: 220px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
}
/* Col profilo normale restano solo i due pulsanti: nome e Comuni non servono */
.user-row:not(.is-pocket) .pocket-etichetta,
.user-row:not(.is-pocket) .pocket-corpo { display: none; }
/* Col profilo Cliente le pagine spuntate non contano: vede solo Pocket */
.user-row.is-pocket .user-pages { display: none; }

.pocket-nota { margin: 10px 0 8px; font-size: 11.5px; line-height: 1.5; color: var(--text-dim); }
.pocket-riepilogo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; font-family: var(--font-mono); font-size: 11.5px; }
.pr-attivi { color: var(--green); }
.pr-vetrina { color: var(--amber); }
.pr-nascosti { color: var(--text-dim); }
.pocket-spazio { flex: 1; }
.pocket-tabella-box { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pocket-tabella { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.pocket-tabella th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.pocket-tabella th.pk-attivo { color: var(--green); }
.pocket-tabella th.pk-vetrina { color: var(--amber); }
.pocket-tabella td { padding: 4px 10px; border-bottom: 1px solid var(--divider); }
.pocket-tabella tr:last-child td { border-bottom: none; }
.pocket-tabella tr.is-nascosto .pocket-nome,
.pocket-tabella tr.is-nascosto .pocket-num { color: var(--text-faint); }
.pocket-nome { font-weight: 500; white-space: nowrap; }
.pocket-num { font-family: var(--font-mono); color: var(--text-dim); }
.pocket-radio { text-align: center; }
.pocket-radio input { width: 16px; height: 16px; margin: 8px 0; cursor: pointer; accent-color: var(--green); }
.pocket-radio input[value="vetrina"] { accent-color: var(--amber); }
.pocket-radio input[value="nascosto"] { accent-color: var(--text-dim); }
.pocket-scade {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 6px;
}
.pocket-scade:disabled { opacity: 0.4; }
:root:not([data-theme="light"]) .pocket-scade { color-scheme: dark; }
.pocket-esito { font-size: 12px; white-space: nowrap; }
.pocket-esito.is-attivo { color: var(--green); }
.pocket-esito.is-vetrina { color: var(--amber); }
.pocket-esito.is-scaduto { color: var(--red); }
.pocket-esito.is-off { color: var(--text-faint); }

/* Rinomina utente (matita accanto al nome) */
.user-rename-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}
.user-rename-btn:hover { color: var(--blue); border-color: var(--blue); }
.user-rename {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--blue);
  border-radius: var(--radius-sm);
  background: rgba(91, 140, 255, 0.06);
}
.user-rename-label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.user-rename-input {
  width: 220px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.user-rename-nota { flex-basis: 100%; font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
/* Modifiche della riga non ancora salvate */
.user-row-dirty { font-size: 12px; font-family: var(--font-mono); color: var(--amber); }
.user-row.is-dirty { border-color: rgba(255, 180, 84, 0.55); }
.user-row.is-dirty .user-row-actions .user-save-btn { box-shadow: 0 0 0 2px rgba(255, 180, 84, 0.55); }

/* display:flex vincerebbe sull'attributo hidden */
.user-rename[hidden],
.pocket-pw-esito[hidden] { display: none; }

/* Password del cliente (dentro il riquadro del profilo Cliente) */
.pocket-pw {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pocket-pw-testa { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pocket-pw-titolo { font-size: 13px; font-weight: 600; color: var(--text); }
.pocket-pw-stato { font-size: 11.5px; font-family: var(--font-mono); color: var(--amber); }
.pocket-pw-genera {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(46, 230, 166, 0.45);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pocket-pw-spunta { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.pocket-pw-spunta input { accent-color: var(--green); cursor: pointer; }
.pocket-pw-esito { display: flex; flex-direction: column; gap: 10px; }
.pocket-pw-riga { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pocket-pw-valore {
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 0.03em;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-mid);
  color: var(--text);
  user-select: all;
}
.pocket-pw-nota { font-size: 11.5px; color: var(--text-dim); }
.pocket-pw-messaggio {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px dashed var(--border-mid);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.pocket-pw-etichetta { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-dim); }
.pocket-pw-testo { margin: 0; font-size: 12.5px; line-height: 1.55; white-space: pre-line; color: var(--text); }
.pocket-pw-azioni { display: flex; gap: 8px; }
.pocket-pw-wa { text-decoration: none; display: inline-flex; align-items: center; }

/* ==========================================================================
   Controlli tabella host: ricerca, filtro gruppo, offline in cima
   ========================================================================== */
.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 0 4px;
}

.table-controls input[type="search"],
.table-controls select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

.table-controls input[type="search"] { flex: 1 1 180px; min-width: 140px; }
.table-controls select { flex: 0 1 170px; }

.table-controls input[type="search"]:focus,
.table-controls select:focus { border-color: var(--blue); }

.offline-first-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.offline-first-toggle input { accent-color: var(--green); cursor: pointer; }

/* Intestazioni ordinabili */
#hostsTable thead th[data-sort] { cursor: pointer; user-select: none; }
#hostsTable thead th[data-sort]:hover { color: var(--text); }
#hostsTable thead th.sorted-asc::after { content: " ▲"; color: var(--green); font-size: 9px; }
#hostsTable thead th.sorted-desc::after { content: " ▼"; color: var(--green); font-size: 9px; }

/* Pulsante "aggiungi host" mobile: visibile solo sotto il breakpoint */
.mobile-add-btn {
  display: none;
  width: 100%;
  margin: 12px 0 0;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
body.role-user .mobile-add-btn { display: none !important; }

/* ==========================================================================
   Toast di cambio stato (in basso a destra)
   ========================================================================== */
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.25s ease-out;
  max-width: 320px;
}

.toast-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.toast-down { border-color: rgba(255, 79, 110, 0.5); }
.toast-down .toast-dot { background: var(--red); }
.toast-up { border-color: rgba(46, 230, 166, 0.5); }
.toast-up .toast-dot { background: var(--green); }

.toast-hide { opacity: 0; transform: translateY(6px); transition: all 0.3s ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ==========================================================================
   Mobile (≤700px): la tabella host diventa un elenco di card compatte.
   ATTENZIONE: i td perdono il layout tabellare e vengono disposti in una
   griglia con aree nominate; Tipo e Timeout sono nascosti (gestione da desktop).
   ========================================================================== */
@media (max-width: 700px) {
  /* Widget superiori più compatti */
  .widgets-row { gap: 12px; margin-bottom: 14px; }
  .gauge { height: 130px; }
  .stats-grid { height: auto; padding: 2px 0 4px; }
  .stat { padding: 12px 6px; }
  .stat-value { font-size: 22px; }
  .metric-box { padding: 9px; }
  .metric-box-value { font-size: 18px; }

  /* Form aggiungi host ripiegato dietro il pulsante */
  .mobile-add-btn { display: block; }
  .add-host-form { display: none; }
  .add-host-form.open { display: flex; }

  /* Tabella -> card */
  #hostsTable { min-width: 0; }
  #hostsTable thead { display: none; }
  #hostsTable tbody { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }

  #hostsTable tbody tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "status  name    name    actions"
      "ip      ip      group   group"
      "spark   spark   latency uptime";
    align-items: center;
    row-gap: 7px;
    column-gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: var(--radius);
    padding: 12px 12px 10px;
  }

  #hostsTable tbody tr:hover { background: var(--surface-2); }
  #hostsTable tbody tr.row-down { border-left-color: var(--red); }

  #hostsTable tbody td {
    display: block;
    padding: 0;
    border-bottom: none;
  }
  /* Il bordo rosso di stato è sul tr (sopra), non più sulla prima cella */
  tr.row-down td:first-child,
  tr.row-up td:first-child,
  tr.row-unknown td:first-child { border-left: none; }

  .cell-status { grid-area: status; }
  .cell-name { grid-area: name; min-width: 0; }
  .cell-actions { grid-area: actions; }
  .cell-ip { grid-area: ip; font-size: 11.5px; }
  .cell-group { grid-area: group; justify-self: end; min-width: 0; }
  .cell-group .group-tag { max-width: 150px; }
  .cell-spark { grid-area: spark; }
  .cell-latency { grid-area: latency; font-size: 12px; }
  .cell-uptime { grid-area: uptime; font-size: 12px; }
  .cell-type, .cell-threshold { display: none; }

  .spark { width: 110px; height: 30px; }

  /* Topbar e widget: meno spazio sprecato sui telefoni */
  .brand-sub { display: none; }
  .conn-status span:last-child { display: none; }
  .table-controls select { flex: 1 1 120px; }
}

/* Rispetta il notch di iPhone in modalità app (PWA standalone) */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(28px, env(safe-area-inset-left));
    padding-right: max(28px, env(safe-area-inset-right));
    padding-top: max(18px, env(safe-area-inset-top));
  }
  @media (max-width: 640px) {
    .topbar {
      padding-left: max(16px, env(safe-area-inset-left));
      padding-right: max(16px, env(safe-area-inset-right));
      padding-top: max(14px, env(safe-area-inset-top));
    }
  }
}

/* ==========================================================================
   Assistente vocale (voice.js): pulsante microfono + pannello domanda/risposta
   ========================================================================== */
.voice-btn.rec {
  color: var(--red);
  border-color: var(--red);
  animation: voice-pulse 1.2s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--red-dim); }
  50% { box-shadow: 0 0 0 6px var(--red-dim); }
}

.voice-panel {
  position: fixed;
  top: 76px;
  right: 18px;
  z-index: 300;
  width: min(420px, calc(100vw - 36px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.voice-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.voice-panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.voice-panel-close {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
}
.voice-panel-close:hover { color: var(--text); }

.voice-q, .voice-a {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.voice-label {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding-top: 2px;
  width: 58px;
}

.voice-q .voice-q-text { color: var(--text-dim); font-style: italic; }
/* pre-line: la risposta può contenere elenchi con un host per riga */
.voice-a .voice-a-text { color: var(--text); white-space: pre-line; }
.voice-a .voice-label { color: var(--green); }

.voice-status {
  font-size: 0.8rem;
  color: var(--text-dim);
}
.voice-status:empty { display: none; }

.voice-setup-btn {
  display: block;
  margin-top: 8px;
  cursor: pointer;
}
.voice-setup-btn:disabled { opacity: 0.6; cursor: wait; }
