/* ==========================================================================
   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;

  --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);
}

* { 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: #06140f;
  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.
   ========================================================================== */
body.role-user .add-host-form,
body.role-user .header-actions,
body.role-user .cell-actions,
body.role-user .th-actions,
body.role-user .gear-btn,
body.role-user .del-btn,
body.role-user .icon-btn,
body.role-user .remove-host-btn,
body.role-user .btn-text-danger,
body.role-user .modal-danger-zone,
body.role-user .modal-add-row,
body.role-user .admin-only {
  display: none !important;
}

/* 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);
}

@media (max-width: 640px) {
  .page-nav { padding: 8px 16px 0; }
}

.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; }
}
@media (max-width: 640px) {
  .header-right { gap: 10px; }
  .resource-badge span { display: none; }
}

.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
   ========================================================================== */
main {
  max-width: 1180px;
  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: #06140f;
  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: #06140f;
  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: 150px; } /* Andamento (sparkline 130px) */
#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 10px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 10px 10px;
  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: 130px;
  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;
}

.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: 200px;
  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);
}

.type-detail {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  max-width: 180px;
  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: 240px;
  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: #04122e;
  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);
}

.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;
}

.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: #04122e;
  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); }

/* ==========================================================================
   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));
    }
  }
}
