/* ===== Token semantici (dark desaturato, non invertito) ===== */
:root {
  --bg: #0b0f14;
  --surface: #131a24;
  --surface-2: #18212e;
  --border: #243042;
  --border-soft: #1c2633;
  --text: #e6edf3;        /* primario, contrasto >7:1 su --bg */
  --text-dim: #9aa7b8;    /* secondario, >3:1 */
  --text-faint: #64718a;
  --accent: #4aa8ff;
  --ok: #43d089;
  --warn: #f5c451;
  --crit: #ff6b6b;
  --rx: #4aa8ff;
  --tx: #b07cff;
  --track: #20293680;
  --radius: 14px;
  --gap: 16px;            /* ritmo 8px */
  --shadow: 0 1px 0 #ffffff08, 0 8px 24px #00000040;
  --topbar-bg: #0d131bcc;
  --glow: #16263a40;
  --surface-inset: #0e151ec0;
  --bulk-grad: linear-gradient(180deg, #1b2433, #141b27);
  font-synthesis: none;
}

/* ===== Tema chiaro ===== */
[data-theme="light"] {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f3f6fb;
  --border: #d3dae6;
  --border-soft: #e4e9f1;
  --text: #1a2230;
  --text-dim: #51607a;
  --text-faint: #8a94a6;
  --accent: #2f6fe0;
  --ok: #1f9d57;
  --warn: #c4870a;
  --crit: #d83a3a;
  --rx: #2f6fe0;
  --tx: #7a4fd0;
  --track: #dde3ee;
  --shadow: 0 1px 0 #ffffff80, 0 8px 24px #1a223014;
  --topbar-bg: #ffffffcc;
  --glow: #2f6fe015;
  --surface-inset: #f5f7fb;
  --bulk-grad: linear-gradient(180deg, #eef3fb, #e3ebf7);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--glow), transparent),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 30px; height: 30px; color: var(--accent); }
.topbar h1 { font-size: 16px; margin: 0; letter-spacing: .2px; font-weight: 650; }
.subtitle { font-size: 11.5px; color: var(--text-dim); }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.conn .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint);
  box-shadow: 0 0 0 0 transparent; transition: background .2s;
}
.conn.live .dot { background: var(--ok); box-shadow: 0 0 10px 1px #43d08966; animation: pulse 2s infinite; }
.conn.off .dot { background: var(--crit); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }
.brand-accent { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.theme-toggle {
  border: 1px solid var(--border-soft); background: var(--surface); color: var(--text);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 15px;
  display: grid; place-items: center; transition: border-color .15s, background .15s;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ===== Layout + Sidebar ===== */
.layout { display: flex; align-items: stretch; }
.sidebar {
  position: sticky; top: 59px; align-self: flex-start;
  width: 214px; flex: 0 0 214px; height: calc(100vh - 59px);
  background: var(--surface); border-right: 1px solid var(--border-soft);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto;
}
.navbtn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; color: var(--text-dim);
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; text-align: left;
  transition: background .15s, color .15s;
}
.navbtn:hover { background: var(--surface-2); color: var(--text); }
.navbtn.active { background: #4aa8ff1f; color: var(--accent); }
.navbtn .ico { font-size: 15px; width: 20px; text-align: center; flex: 0 0 auto; }
.nav-badge {
  margin-left: auto; background: var(--crit); color: #fff; font-size: 10.5px;
  font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px;
  display: inline-grid; place-items: center; padding: 0 5px;
}
.nav-badge[hidden] { display: none; }
.nav-spacer { flex: 1; }
.nav-role {
  margin-top: 8px; padding: 8px 12px; font-size: 11.5px; color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
}
.nav-role a { color: var(--accent); text-decoration: none; }
.nav-role a:hover { text-decoration: underline; }

/* non-admin (operatore + viewer): niente controlli di gestione (admin-only) */
body.not-admin #bulkbar,
body.not-admin .sel-chk,
body.not-admin .rename-btn,
body.not-admin .del-btn,
body.not-admin .admin-only { display: none !important; }
/* "+ Router" e' un permesso configurabile: nascosto solo se non concesso */
body.no-addrouter #btn-add { display: none !important; }
.lg-err { color: var(--crit); font-size: 12.5px; margin: 4px 0 0; }

/* F10 / utenti / login Google */
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.th-row { display: flex; align-items: center; gap: 8px; }
.th-row input[type="number"] { width: 90px; }
.users-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.users-add input { flex: 1; min-width: 180px; }
.users-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.user-row .if-name { flex: 1; }
.btn-google { display: flex; align-items: center; gap: 10px; width: 100%; justify-content: center;
  background: #fff; color: #3c4043; border: 1px solid #dadce0; border-radius: 8px;
  padding: 10px; font-weight: 600; cursor: pointer; }
.btn-google:hover { background: #f7f8f8; }
.lg-sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 12px 0; }
.lg-sep::before, .lg-sep::after { content: ""; flex: 1; height: 1px; background: var(--border, #333); }

/* impostazioni: permessi + auto-ping */
.perm-tbl { width: 100%; border-collapse: collapse; margin: 6px 0; }
.perm-tbl th, .perm-tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border, #333); text-align: left; }
.perm-tbl .ctr { text-align: center; }
.perm-tbl .perm-admin { color: var(--ok); font-weight: 700; }
.perm-locked { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.perm-locked-head { font-weight: 600; margin-bottom: 4px; }
.perm-locked ul { margin: 0; padding-left: 18px; }
#ap-min { width: 80px; }
body.no-ping #btn-ping-all, body.no-ping .btn-ping, body.no-ping .ping-row { display: none !important; }
.content { flex: 1; min-width: 0; }
.view[hidden] { display: none; }

.view-head { padding: 20px 22px 4px; }
.view-head h2 { margin: 0 0 2px; font-size: 18px; font-weight: 700; }
.view-sub { color: var(--text-dim); font-size: 12.5px; margin: 0; }
.placeholder {
  margin: 22px; padding: 46px 24px; text-align: center; color: var(--text-faint);
  border: 1px dashed var(--border); border-radius: 14px; background: var(--surface);
}

.quicklinks { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 22px 0; }
.qlink {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-soft); background: var(--surface); color: var(--text-dim);
  padding: 7px 13px; border-radius: 10px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: border-color .15s, color .15s, background .15s;
}
.qlink:hover { border-color: var(--accent); color: var(--text); background: var(--surface-2); }
.qlink .ico { font-size: 14px; }

/* ===== Sezione Interfacce ===== */
.view-toolbar { display: flex; align-items: center; gap: 14px; padding: 12px 22px; flex-wrap: wrap; }
.view-toolbar .search { max-width: 320px; }
.chk { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.chk input { accent-color: var(--accent); }
.iface-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(480px, 1fr)); gap: 14px; padding: 4px 22px 26px; }
.iface-card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 14px; overflow: hidden; }
.iface-scroll { overflow-x: auto; }
.iface-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 15px; border-bottom: 1px solid var(--border-soft); font-weight: 650; font-size: 13.5px;
}
.iface-card-head .muted { font-weight: 500; font-size: 11.5px; color: var(--text-faint); }
.iface-tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.iface-tbl th {
  text-align: right; font-weight: 600; color: var(--text-faint); padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft); white-space: nowrap;
}
.iface-tbl th:first-child, .iface-tbl td:first-child { text-align: left; }
.iface-tbl td { padding: 6px 10px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.iface-tbl tr:not(:last-child) td { border-bottom: 1px solid var(--border-soft); }
.iface-tbl .if-name { font-weight: 600; color: var(--text); }
.iface-tbl .if-type { color: var(--text-faint); font-size: 10px; margin-left: 5px; }
.if-badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 10.5px; font-weight: 700; }
.if-badge.up { color: var(--ok); background: #43d0891f; }
.if-badge.down { color: var(--text-faint); background: var(--surface-2); }
.if-badge.off { color: var(--warn); background: #f5c4511f; }
.iface-tbl .now { color: var(--text); }
.iface-tbl .peak { color: var(--text-dim); }
.iface-tbl .tot { color: var(--text-faint); }
.dhcp-sum { margin-left: auto; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.lan-actions { padding: 9px 14px; border-bottom: 1px solid var(--border-soft); }
.lan-actions .btn { font-size: 12px; padding: 6px 13px; }
.if-badge.up, .if-badge.down { font-weight: 700; }
.if-badge.bad { color: #fff; background: var(--crit); font-weight: 700; }

/* ===== Impostazioni ===== */
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; padding: 4px 22px 26px; align-items: start; }
.settings-form { padding: 14px; display: flex; flex-direction: column; gap: 11px; }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-dim); }
.settings-form input { background: var(--surface-inset); border: 1px solid var(--border-soft); border-radius: 8px; color: var(--text); padding: 7px 10px; font-size: 13px; max-width: 160px; }
.th-saved { color: var(--ok); font-size: 12px; margin-left: 8px; }

/* ===== World Meter Ping ===== */
.wp-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; padding: 4px 22px 26px; align-items: start; }
@media (max-width: 900px) { .wp-grid { grid-template-columns: 1fr; } }
.wp-map { padding: 10px; }
.wp-svg { width: 100%; height: auto; display: block; border-radius: 10px; }
.wp-ocean { fill: var(--surface-inset); }
.wp-grat line { stroke: var(--border); stroke-width: 0.3; }
.wp-label { fill: var(--text-dim); font-size: 4px; font-family: "Segoe UI", system-ui; }
.dotc { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.wp-legend .lg { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 1px 0 7px; vertical-align: middle; }
.wp-legend .lg.g { background: #3fb950; } .wp-legend .lg.y { background: #9acd32; }
.wp-legend .lg.o { background: #f5c451; } .wp-legend .lg.r { background: #ff6b6b; }
.wp-legend .lg.x { background: #7d8590; }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: static; width: 100%; flex: none; height: auto;
    flex-direction: row; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--border-soft);
  }
  .nav-spacer, .nav-role { display: none; }
  .navbtn { white-space: nowrap; }
}

/* ===== Toolbar (viste + chip metriche) ===== */
.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 22px 0;
}
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; padding: 3px; }
.seg-btn {
  border: 0; background: transparent; color: var(--text-dim); cursor: pointer;
  padding: 6px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  transition: background .15s, color .15s;
}
.seg-btn.active { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 #ffffff10; }
.chips { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-faint);
  cursor: pointer; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  transition: background .15s, color .15s, border-color .15s;
}
.chip.active { color: var(--text); border-color: var(--accent); background: #4aa8ff14; }
.chip:not(.active) { text-decoration: line-through; opacity: .7; }
.toolbar-right { margin-left: auto; }
.muted { color: var(--text-faint); font-size: 11.5px; }

/* Toggle metriche: nascondi elementi quando il grid ha la classe h-* */
.grid.h-cpu .gauge-wrap { display: none; }
.grid.h-ram .m-ram { display: none; }
.grid.h-hdd .m-hdd { display: none; }
.grid.h-temp .m-temp { display: none; }
.grid.h-traffic .cb-traffic { display: none; }
.grid.h-charts .charts { display: none; }
.grid.h-cpu.h-ram.h-hdd.h-temp .panel-body { display: none; }

/* Vista compatta: dimensioni come prima (denso) + ISP visibili + nome prioritario */
.grid.compact { grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); }
/* nascosti in compatta: solo i grafici grandi CPU/traffico + riga meta */
.grid.compact .charts,
.grid.compact .panel-meta { display: none; }
/* head: nome COMPLETO (va a capo, niente ellissi), prioritario sull'uptime */
.grid.compact .panel-head { align-items: flex-start; }
.grid.compact .panel-name { font-size: 12.5px; white-space: normal; line-height: 1.25; }
.grid.compact .panel-uptime { font-size: 10px; flex: 0 0 auto; margin-top: 1px; }
/* ping in compatta: tasto + min/med/max + orario, su colonna */
.grid.compact .ping-row { flex-direction: column; align-items: flex-start; gap: 5px; padding: 0 14px 9px; }
.grid.compact .btn-ping { padding: 3px 11px; font-size: 10.5px; }
.grid.compact .ping-stats { font-size: 9.5px; line-height: 1.55; }
/* ISP compatti (la novita' richiesta) */
.grid.compact .panel-isp { padding: 0 14px 9px; gap: 5px; }
.grid.compact .isp-chip { font-size: 10px; padding: 2px 7px; }
.grid.compact .isp-slots { font-size: 9.5px; padding: 2px 6px; }
/* body invariato rispetto alla compatta originale */
.grid.compact .panel-body { padding: 12px 14px; gap: 12px; }
.grid.compact .gauge { width: 62px; height: 62px; }
.grid.compact .gauge::before { inset: 7px; }
.grid.compact .gauge-val { font-size: 15px; }
.grid.compact .gauge-val::after { font-size: 9px; }
.grid.compact .gauge-cap { display: none; }
.grid.compact .meters { gap: 7px; }
.grid.compact .meter-top { margin-bottom: 3px; font-size: 10.5px; }
.grid.compact .bar { height: 6px; }

/* ===== KPI ===== */
.kpis {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: var(--gap); padding: var(--gap) 22px 4px;
}
.kpi {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
/* Throughput tot. = card larga (ultima): totale a sinistra, top-3 a destra con
   spazio sufficiente a non troncare i nomi dei router. */
.kpi-thru { grid-column: span 4; flex-direction: row; align-items: stretch; justify-content: space-between; gap: 14px; }
.kpis > .kpi:not(.kpi-thru) { padding: 12px 13px; }   /* le 4 card piccole piu' compatte */
.kpis > .kpi:not(.kpi-thru) .kpi-value { font-size: 23px; }
.thru-main { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.thru-top3 {
  list-style: none; margin: 0; padding: 0; min-width: 0; flex: 1;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
/* riga singola fissa: nome troncato, download+upload sempre sulla stessa riga,
   la card non cambia dimensione al variare della lunghezza del nome */
.thru-top3 li { display: flex; justify-content: space-between; column-gap: 8px; font-size: 11px; align-items: baseline; flex-wrap: nowrap; white-space: nowrap; }
.thru-top3 .t-name { color: var(--text-dim); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thru-top3 .t-val { font-variant-numeric: tabular-nums; font-weight: 600; flex: 0 0 auto; display: inline-flex; gap: 8px; white-space: nowrap; }
.t-dl { color: var(--ok); }    /* download ▼ verde (rx sull'uplink) */
.t-ul { color: var(--crit); }  /* upload ▲ rosso (tx sull'uplink) */
.thru-top3:empty { display: none; }
/* lato sinistro: totale grande + sotto download/upload totali */
.thru-main { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.thru-split { display: inline-flex; gap: 12px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; }
.kpi-value { font-size: 26px; font-weight: 680; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; color: var(--text-dim); font-weight: 500; }
.kpi-value.ok { color: var(--ok); }
.kpi-click { cursor: pointer; transition: border-color .15s; }
.kpi-click:hover { border-color: var(--accent); }
.kpi-click.active { border-color: var(--crit); box-shadow: 0 0 0 1px #ff6b6b55 inset; }

/* ===== Grid pannelli ===== */
.grid {
  display: grid; gap: var(--gap); padding: var(--gap) 22px 28px;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}
.panel {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  transition: border-color .2s, transform .2s;
}
.panel:hover { border-color: var(--border); transform: translateY(-2px); }
.panel.crit { border-color: #ff6b6b66; }
.panel.warn { border-color: #f5c45155; }

.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft);
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.panel.crit .status-dot { background: var(--crit); }
.panel.warn .status-dot { background: var(--warn); }
.panel-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.panel-name { font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-meta { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-uptime { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.panel-body { display: flex; gap: 16px; padding: 16px; align-items: center; }

/* Gauge CPU radiale */
.gauge-wrap { flex: 0 0 auto; }
.gauge {
  --val: 0; --col: var(--ok);
  width: 104px; height: 104px; border-radius: 50%;
  background: conic-gradient(var(--col) calc(var(--val) * 1%), var(--track) 0);
  display: grid; place-items: center; position: relative;
  transition: background .4s ease;
}
.gauge::before {
  content: ""; position: absolute; inset: 11px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border-soft);
}
.gauge-val { position: relative; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.gauge-val::after { content: "%"; font-size: 12px; color: var(--text-dim); margin-left: 1px; }
.gauge-cap { position: relative; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: -2px; }

/* Barre RAM/Disco/Temp */
.meters { flex: 1; display: flex; flex-direction: column; gap: 11px; min-width: 0; }
.meter-top { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-dim); margin-bottom: 5px; }
.meter-top span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--track); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 6px; transition: width .4s ease, background .3s; }
.bar-fill.ram { background: linear-gradient(90deg, #3a7bd5, #4aa8ff); }
.bar-fill.hdd { background: linear-gradient(90deg, #7a5cff, #b07cff); }
.bar-fill.temp { background: linear-gradient(90deg, #2fae6a, #f5c451); }

/* Charts */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px 16px; }
.chart-block { background: var(--surface-inset); border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px 10px 4px; }
.chart-title { font-size: 11.5px; color: var(--text-dim); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.chart-sub { color: var(--text-faint); font-size: 10.5px; }
.legend { display: inline-flex; gap: 10px; align-items: center; color: var(--text-dim); }
.sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 3px; vertical-align: -1px; }
.sw.rx { background: var(--rx); } .sw.tx { background: var(--tx); }
.chart { width: 100%; height: 78px; }

/* uPlot dark overrides */
.uplot, .u-wrap { width: 100% !important; }
.u-axis { color: var(--text-faint); }
.u-legend { display: none; }

/* Footer */
.foot {
  display: flex; justify-content: space-between;
  padding: 10px 22px 22px; color: var(--text-faint); font-size: 11.5px;
}

@media (max-width: 1200px) {
  /* schermo medio: 4 card piccole in fila, Throughput a tutta larghezza sotto */
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi-thru { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi-thru { grid-column: 1 / -1; }   /* su schermo stretto: a tutta larghezza */
  .grid { grid-template-columns: 1fr; padding-left: 14px; padding-right: 14px; }
  .charts { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===== Bottoni / search ===== */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; padding: 7px 14px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(180deg, #3a86d8, #2f6fc0); border-color: #3a86d8; }
.btn.primary:hover { filter: brightness(1.08); }
.search {
  flex: 1; min-width: 160px; max-width: 320px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 9px;
  color: var(--text); padding: 7px 12px; font-size: 12.5px;
}
.search::placeholder { color: var(--text-faint); }
.icon-btn {
  border: 0; background: transparent; color: var(--text-faint); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 4px 6px; border-radius: 6px;
}
.icon-btn:hover { background: #ff6b6b22; color: var(--crit); }
.rename-btn:hover { background: #4aa8ff22; color: var(--accent); }
.sortsel {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 9px;
  color: var(--text); padding: 7px 10px; font-size: 12.5px; cursor: pointer;
}
.sel-chk { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; }

.bulkbar {
  position: sticky; top: 60px; z-index: 39;
  display: flex; align-items: center; gap: 12px;
  margin: 0 22px; padding: 10px 16px;
  background: var(--bulk-grad);
  border: 1px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow);
}
.bulkbar[hidden] { display: none; }
.bulkbar #bulk-count { font-weight: 700; color: var(--text); margin-right: auto; }
.bulkbar #bulk-del:hover { border-color: var(--crit); color: var(--crit); }

/* ===== ISP chips ===== */
.panel-isp { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.isp-chip {
  border: 1px solid var(--border); background: var(--surface-inset); color: var(--text-dim);
  border-radius: 7px; padding: 3px 9px; font-size: 11px; cursor: pointer;
  font-weight: 600; transition: border-color .15s, color .15s;
}
.isp-chip:hover { border-color: var(--accent); color: var(--text); }
.isp-chip.manual { border-color: var(--ok); color: var(--ok); }
.isp-chip.active { border-color: var(--accent); color: var(--text); background: #4aa8ff1f; }
.isp-chip.active.manual { border-color: var(--ok); color: var(--ok); background: #43d0891f; }
.isp-chip.dim { color: var(--text-faint); cursor: default; font-style: italic; }
.isp-slots {
  font-size: 10.5px; font-weight: 700; color: var(--text-dim); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; align-self: center;
}
.traffic-now {
  font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600;
  margin-left: 4px; font-size: 11px;
}

/* ===== Ping ===== */
.ping-row { display: flex; align-items: center; gap: 12px; padding: 0 16px 12px; }
.btn-ping {
  border: 1px solid var(--border); background: var(--surface); color: var(--ok);
  cursor: pointer; padding: 5px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
}
.btn-ping:hover { border-color: var(--ok); background: #43d08914; }
.ping-stats { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.ping-stats .pv { color: var(--text); font-weight: 700; }
.ping-stats .pu { color: var(--text-dim); font-size: .85em; margin-left: 1px; }
.ping-stats .pmm { color: var(--text-faint); }
.ping-stats .pw { color: var(--accent); font-weight: 700; }
.ping-stats .pt { color: var(--text-faint); }
.ping-stats .pl-ok { color: var(--ok); }
.ping-stats .pl-bad { color: var(--crit); font-weight: 700; }
.ping-chart-wrap { padding: 0 16px 12px; }
.ping-chart { width: 100%; height: 70px; }

/* ===== Offline ===== */
.panel.offline { opacity: .55; }
.panel.offline .status-dot { background: var(--text-faint); }
.panel.offline .panel-body, .panel.offline .charts, .panel.offline .ping-row { filter: grayscale(1); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: #000a; backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(440px, 92vw); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 16px; font-size: 16px; }
.modal-card label { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 10px; }
.modal-card input {
  width: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 8px; color: var(--text); padding: 8px 10px; font-size: 13px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 11px; color: var(--text-faint); margin: 4px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 13px;
}
.modal-actions .primary { background: linear-gradient(180deg, #3a86d8, #2f6fc0); border-color: #3a86d8; }

/* ============================ Insight (NOC wall, full-screen real-time) ============================ */
body.insight-mode .topbar,
body.insight-mode .sidebar { display: none; }
body.insight-mode .layout { display: block; }
body.insight-mode .content { padding: 0; }
body.insight-mode { overflow: hidden; }

.view.insight { --ins-accent: #4aa8ff; --ins-accent2: #b07cff; --insbg: #080b11; --insfg: #e9eff8; }
[data-theme="light"] .view.insight { --insbg: #eef2f8; --insfg: #18212f; }

.view.insight:not([hidden]) {
  display: flex; flex-direction: column; gap: 9px;
  height: 100vh; box-sizing: border-box; padding: 11px 13px; color: var(--insfg);
  background:
    radial-gradient(1100px 620px at 86% -16%, rgba(74,168,255,.12), transparent 60%),
    radial-gradient(900px 520px at -6% 116%, rgba(176,124,255,.12), transparent 60%),
    linear-gradient(rgba(120,170,255,.045) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(90deg, rgba(120,170,255,.045) 1px, transparent 1px) 0 0 / 42px 42px,
    var(--insbg);
}

.insight-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.insight-back { background: rgba(255,255,255,.06); border: 1px solid var(--border-soft); color: var(--insfg);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 12.5px; }
.insight-back:hover { background: rgba(74,168,255,.2); border-color: var(--ins-accent); }
[data-theme="light"] .insight-back { background: rgba(0,0,0,.05); }
.insight-brand { font-size: 17px; letter-spacing: .4px; display: flex; align-items: center; gap: 8px; }
.insight-brand b { background: linear-gradient(90deg, var(--ins-accent), var(--ins-accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.ins-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 9px var(--ok); animation: inspulse 1.7s infinite; }
@keyframes inspulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.ins-clock { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 13px; }
.insight-stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.ins-stat { background: rgba(255,255,255,.045); border: 1px solid var(--border-soft); border-radius: 10px;
  padding: 5px 12px; display: flex; flex-direction: column; min-width: 76px; }
[data-theme="light"] .ins-stat { background: rgba(0,0,0,.035); }
.ins-stat-l { font-size: 9px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-dim); }
.ins-stat-v { font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.15; }
.ins-stat.ok .ins-stat-v, .ins-stat.dl .ins-stat-v { color: var(--ok); }
.ins-stat.warn .ins-stat-v { color: var(--warn); }
.ins-stat.crit .ins-stat-v, .ins-stat.ul .ins-stat-v { color: var(--crit); }

.insight-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(266px, 1fr));
  grid-auto-rows: 1fr; gap: 9px; align-content: stretch; overflow: auto; padding-right: 2px; }
.ins-cell { position: relative; background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
  border: 1px solid var(--border-soft); border-radius: 10px; padding: 8px 9px 9px; display: flex; flex-direction: column;
  gap: 5px; overflow: hidden; transition: transform .12s, border-color .12s; }
[data-theme="light"] .ins-cell { background: rgba(0,0,0,.03); }
.ins-cell::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 3px;
  background: linear-gradient(var(--ins-accent), var(--ins-accent2)); opacity: .85; }
.ins-cell:hover { transform: translateY(-2px); border-color: var(--ins-accent); }
.ins-cell.off { opacity: .5; filter: grayscale(.6); }
.ins-cell.alarm { border-color: var(--crit); animation: insalarm 1.9s infinite; }
.ins-cell.alarm::before { background: var(--crit); }
@keyframes insalarm { 0%,100% { box-shadow: 0 0 0 1px var(--crit), 0 0 13px rgba(255,70,70,.18); }
  50% { box-shadow: 0 0 0 1px var(--crit), 0 0 22px rgba(255,70,70,.45); } }
.ins-c-top { display: flex; align-items: center; gap: 6px; }
.ins-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 6px var(--ok); flex: 0 0 auto; }
.ins-cell.off .ins-dot { background: var(--text-dim); box-shadow: none; }
.ins-name { font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ins-isp { font-size: 8.5px; color: var(--ins-accent); border: 1px solid var(--border-soft); border-radius: 5px;
  padding: 1px 4px; flex: 0 0 auto; max-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* corpo: gauge CPU a sinistra + barre RAM/Disco/Temp a destra */
.ins-c-body { display: flex; align-items: center; gap: 10px; }
.ins-gauge { position: relative; width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--track) 0); }
.ins-gauge::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--insbg); }
.ins-gauge span { position: absolute; inset: 0; top: 4px; display: grid; place-items: center; font-size: 12.5px; font-weight: 750; font-variant-numeric: tabular-nums; z-index: 1; }
.ins-gauge small { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-size: 7px; letter-spacing: .5px; color: var(--text-dim); z-index: 1; }
.ins-bars { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ins-bar-row { display: flex; align-items: center; gap: 7px; font-size: 9.5px; }
.ins-bar-l { color: var(--text-dim); width: 24px; flex: 0 0 auto; letter-spacing: .4px; }
.ins-bar { flex: 1; height: 5px; border-radius: 3px; background: var(--track); overflow: hidden; }
.ins-bar-f { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--ins-accent), var(--ins-accent2)); }
/* stessi colori delle barre della dashboard classica */
.ins-bar-f.ram { background: linear-gradient(90deg, #3a7bd5, #4aa8ff); }
.ins-bar-f.hdd { background: linear-gradient(90deg, #7a5cff, #b07cff); }
.ins-bar-f.temp { background: linear-gradient(90deg, #2fae6a, #f5c451); }
.ins-bar-v { width: 38px; text-align: right; flex: 0 0 auto; font-variant-numeric: tabular-nums; color: var(--insfg); font-weight: 600; }
.ins-c-tr { display: flex; gap: 9px; font-size: 11px; font-variant-numeric: tabular-nums; align-items: baseline; flex-wrap: nowrap; }
.ins-c-tr .ins-ping { color: var(--warn); }
.ins-c-tr .ins-up { color: var(--text-dim); margin-left: auto; }
.ins-c-spark { height: 28px; }
.spark { width: 100%; height: 100%; display: block; }
.spark polyline { fill: none; stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.spark .sp-rx { stroke: var(--rx); }
.spark .sp-tx { stroke: var(--tx); }
.ins-c-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 9px; color: var(--text-faint); white-space: nowrap; overflow: hidden; }
.ins-c-foot > span { overflow: hidden; text-overflow: ellipsis; }
.ins-c-al { color: var(--crit); flex: 0 0 auto; max-width: 50%; overflow: hidden; text-overflow: ellipsis; }

/* ===== Sezione Regole ===== */
.if-badge.rule-whatsapp { color: #2db35f; background: #2db35f1f; }
.if-badge.rule-trovapod { color: var(--accent); background: #4aa8ff1f; }
.if-badge.rule-static   { color: var(--warn); background: #f5c4511f; }
.if-badge.rule-idle     { color: var(--text-faint); background: var(--surface-2); }
/* Righe disabilitate: grigie + barrate */
.rule-off td { opacity: .55; }
.rule-off .if-name { text-decoration: line-through; }
/* Permessi: nascondi azioni non consentite via body class */
body.no-rules-view [data-view="regole"],
body.no-rules-view [data-nav="regole"] { display: none !important; }
body.no-rules-view .no-rules-view { display: none !important; }
body.no-rules-create .no-rules-create { display: none !important; }
body.no-rules-modify .no-rules-modify { display: none !important; }
body.no-rules-delete .no-rules-delete { display: none !important; }

/* ---------- Login: schermo full, rete di nodi animata, glass card ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 9999; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 800px at 70% 10%, #11294a 0%, #0a1326 45%, #060a17 100%);
}
#login-bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.login-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: .25;
  background-image: linear-gradient(rgba(56,189,248,.08) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(56,189,248,.08) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(circle at 50% 45%, #000 40%, transparent 80%);
          mask-image: radial-gradient(circle at 50% 45%, #000 40%, transparent 80%);
}
.login-card {
  position: relative; z-index: 2; width: min(92vw, 400px);
  padding: 38px 34px 26px; text-align: center; border-radius: 20px;
  background: rgba(13, 22, 42, .62); backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgba(94, 234, 212, .28);
  box-shadow: 0 0 0 1px rgba(56,189,248,.10), 0 20px 70px rgba(0,0,0,.55),
              0 0 60px rgba(56,189,248,.18);
  animation: lg-rise .5s ease both;
}
@keyframes lg-rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.login-brand { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.login-hex { color: #5eead4; font-size: 28px; filter: drop-shadow(0 0 8px rgba(94,234,212,.7)); }
.login-name { font-size: 28px; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(90deg,#e6f0ff,#7dd3fc); -webkit-background-clip: text;
  background-clip: text; color: transparent; }
.login-net { font-size: 12px; font-weight: 700; letter-spacing: 4px; color: #5eead4; align-self: center; }
.login-tag { margin: 8px 0 22px; font-size: 12.5px; letter-spacing: .4px; color: #9fb4d6; }
.login-card .btn-google { width: 100%; justify-content: center; font-size: 15px; padding: 12px; }
.login-card #lg-pw-box label { display: block; text-align: left; color: #cfe0fb; font-size: 13px; margin-bottom: 8px; }
.login-card #lg-pw-box input { width: 100%; margin-top: 3px; box-sizing: border-box; }
.login-hint { margin: 18px 0 0; font-size: 12px; color: #8aa0c4; line-height: 1.5; }
.login-foot { margin-top: 14px; font-size: 11.5px; letter-spacing: .3px; color: #5eead4; opacity: .85; }
.login-card .lg-err { margin-top: 12px; color: #fca5a5; font-size: 13px; }

/* tabella permessi: colonna operatore */
.perm-tbl .perm-admin { color: var(--ok, #16a34a); font-weight: 700; }
.perm-tbl th, .perm-tbl td.ctr { text-align: center; }
.perm-tbl td:first-child, .perm-tbl th:first-child { text-align: left; }
