:root {
  --bg: #f4f6f8;
  --surface: #fff;
  --surface-soft: #eef2f5;
  --text: #17212b;
  --muted: #687583;
  --line: #d9e0e7;
  --brand: #0277b6;
  --brand-dark: #01598a;
  --brand-blue: #009fe3;
  --brand-orange: #f39200;
  --warning: #b7791f;
  --critical: #b42318;
  --ok: #287d3c;
  --shadow: 0 18px 40px rgba(24, 35, 46, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  background: #13232f;
  color: #fff;
}

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

.brand.compact { margin-bottom: 22px; }

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  font-weight: 800;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #b8c4ce;
}

.nav { display: grid; gap: 6px; }

.nav-item {
  width: 100%;
  border-radius: 8px;
  padding: 11px 12px;
  color: #d8e0e7;
  text-align: left;
  text-decoration: none;
}

.nav-item.active { background: rgba(255, 255, 255, 0.1); color: #fff; }
.nav-item.muted { opacity: 0.55; }

.app { padding: 28px; min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.15; }
.topbar p { margin-top: 6px; color: var(--muted); }

.top-actions { display: flex; gap: 10px; align-items: center; }

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 700;
  text-decoration: none;
}

.primary-button { background: var(--brand); color: #fff; }
.primary-button:disabled { opacity: 0.55; cursor: not-allowed; }
.secondary-button { background: #e6ebef; color: var(--text); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric { padding: 18px; }
a.metric { text-decoration: none; color: inherit; }
a.metric:hover { border-color: var(--brand); }

.flash {
  background: #e7f6ea;
  color: var(--ok);
  border: 1px solid #bfe6c8;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.search { display: flex; gap: 8px; margin: 0; }
.search input[type="search"] { min-width: 240px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.vps-select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; color: var(--text); font: inherit; max-width: 200px; }
.vps-link { color: var(--brand-dark); text-decoration: none; }
.vps-link:hover { text-decoration: underline; }
.hlegend a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.hlegend a:hover { color: var(--brand-dark); text-decoration: underline; }
.rep-link { color: inherit; text-decoration: none; }
.rep-link:hover { color: var(--brand-dark); text-decoration: underline; }
.filter {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  background: #fff;
}
.filter.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.table-wrap { overflow-x: auto; }
/* Elenchi lunghi (tante righe): scorrono dentro il loro riquadro */
.table-wrap { max-height: 62vh; overflow-y: auto; }
.scroll-rows { max-height: 360px; overflow-y: auto; padding-right: 4px; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid-table th, .grid-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.grid-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.grid-table th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.grid-table th.th-sort:hover { color: var(--text); }
.grid-table th.th-sort::after { content: "↕"; opacity: 0.35; margin-left: 6px; font-size: 10px; }
.grid-table th.th-sort[data-dir="asc"]::after { content: "↑"; opacity: 1; color: var(--brand); }
.grid-table th.th-sort[data-dir="desc"]::after { content: "↓"; opacity: 1; color: var(--brand); }
.grid-table td a { color: var(--brand-dark); font-weight: 700; text-decoration: none; }
.grid-table small { color: var(--muted); }
.muted-cell { color: var(--muted); }
.cell-site { display: flex; gap: 8px; align-items: center; }
.ext-link { color: var(--muted); text-decoration: none; font-weight: 800; padding: 0 3px; border-radius: 4px; }
.ext-link:hover { color: var(--brand); background: var(--surface-soft); }
.row-name-link { color: inherit; text-decoration: none; }
.row-name-link:hover { color: var(--brand-dark); text-decoration: underline; }

/* Punteggio di salute */
.health-ok { color: var(--ok); }
.health-warning { color: var(--warning); }
.health-critical { color: var(--critical); }
.health-row { display: flex; align-items: center; gap: 16px; margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.health-gauge { display: flex; align-items: baseline; gap: 2px; min-width: 96px; justify-content: center; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 2px solid currentColor; }
.health-score { font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.health-max { font-size: 13px; color: var(--muted); font-weight: 700; }
.health-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.health-meta .label { color: var(--muted); }
.health-word { font-size: 16px; }
.health-meta small { color: var(--muted); }
.health-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.health-avg { font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.health-chip { display: inline-grid; place-items: center; min-width: 30px; height: 24px; padding: 0 6px; border-radius: 8px; font-weight: 800; font-size: 12px; font-variant-numeric: tabular-nums; border: 1.5px solid currentColor; }
.card-right { display: flex; gap: 8px; align-items: center; }

/* Sparkline performance (TTFB) */
.perf-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.spark-wrap { color: var(--brand); margin: 6px 0; }
.spark-wrap.spark-warning { color: var(--warning); }
.spark-wrap.spark-critical { color: var(--critical); }
.spark-wrap.spark-ok { color: var(--ok); }
.spark { width: 100%; height: auto; display: block; }

/* Area cliente (senza sidebar) */
body.client-page { display: block; }
.client-topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 24px; background: #13232f; color: #fff; }
.client-topbar .brand { margin: 0; }
.client-topbar .brand small { color: #b8c4ce; }
.client-main { padding: 24px; max-width: 1000px; margin: 0 auto; }
.nis2-box { margin-top: 18px; }

.reg-add { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 10px; }
.reg-add input[type="text"] { flex: 1; min-width: 160px; }
.reg-import { margin: 0 0 18px; display: inline-block; }

.finding-actions { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.ignore-form { margin: 0; }
.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}
.link-btn:hover { color: var(--critical); }

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-left: 6px;
  vertical-align: middle;
}
.panel.attention { margin-top: 24px; margin-bottom: 18px; }
.att-flex { display: flex; gap: 12px; align-items: center; }
.att-body { min-width: 0; flex: 1; }
.attention-row { text-decoration: none; color: inherit; }
.attention-row:hover { border-color: var(--brand); background: #eef7fc; }
.grid-table td div { margin-bottom: 3px; }

/* Panoramica */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 18px; text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi:hover { border-color: var(--brand); }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 700; }
.kpi-num { font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi-alert .kpi-num { color: var(--critical); }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.chart-card h2 { font-size: 18px; }
.chart-sub { font-size: 12px; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; font-weight: 700; }

.hbar { display: flex; gap: 2px; height: 16px; border-radius: 8px; overflow: hidden; background: var(--surface-soft); }
.hbar.mini { width: 140px; height: 10px; display: inline-flex; vertical-align: middle; }
.hbar .seg { height: 100%; }
.seg-ok { background: var(--ok); }
.seg-warning { background: var(--warning); }
.seg-critical { background: var(--critical); }
.seg-unknown { background: #c3ccd4; }

.hlegend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0 0; padding: 0; font-size: 13px; color: var(--muted); }
.hlegend li { display: flex; align-items: center; gap: 6px; }
.hlegend strong { color: var(--text); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }
.dot-unknown { background: #c3ccd4; }

.sevlist { display: flex; flex-direction: column; gap: 10px; }
.sev { display: grid; grid-template-columns: 64px 1fr 32px; align-items: center; gap: 10px; }
.sev-lbl { font-size: 12px; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.sev-track { background: var(--surface-soft); border-radius: 6px; height: 12px; overflow: hidden; }
.sev-fill { display: block; height: 100%; border-radius: 6px; min-width: 2px; }
.fill-critical { background: var(--critical); }
.fill-warning { background: var(--warning); }
.fill-unknown { background: #9fb0bd; }
.sev-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

@media (max-width: 1050px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}

.metric span,
.label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

.metric strong { display: block; margin-top: 8px; font-size: 28px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(520px, 1.4fr);
  gap: 18px;
  align-items: start;
}

.panel { padding: 18px; }
.panel-header { margin-bottom: 14px; }
.panel-header h2, .detail-head h2 { font-size: 20px; }

.site-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.site-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}

.site-card:hover,
.site-card.active {
  border-color: var(--brand);
  background: #eef7fc;
}

.site-card { grid-template-columns: auto 1fr auto; align-items: center; }
.site-card strong,
.site-card small { display: block; }
.site-card small { margin-top: 4px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-card-text { min-width: 0; }

/* Avatar sito (favicon o monogramma) e monogrammi plugin */
.avatar {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  display: inline-grid; place-items: center; overflow: hidden; background: var(--surface-soft);
}
.avatar img { width: 100%; height: 100%; object-fit: contain; }
.avatar.mono { color: #fff; font-weight: 800; font-size: 15px; }
.avatar-lg { width: 46px; height: 46px; border-radius: 10px; font-size: 20px; }
.detail-id { display: flex; gap: 14px; align-items: center; }

.plugin-row { display: flex; gap: 10px; align-items: flex-start; }
.plugin-body { min-width: 0; flex: 1; }
.plugin-mono { flex: none; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 12px; }

details.more { margin-top: 8px; }
details.more > summary { cursor: pointer; color: var(--brand-dark); font-weight: 700; font-size: 13px; padding: 6px 0; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }
details.more .rows { margin-top: 8px; }

.status-pill,
.mini-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.status-ok { background: #e7f6ea; color: var(--ok); }
.status-warning { background: #fff3d8; color: var(--warning); }
.status-critical { background: #fde7e5; color: var(--critical); }
/* Stato usato per i siti censiti da RunCloud ma senza dati delle sonde. */
.status-unknown { background: var(--surface-soft); color: var(--muted); }

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-head a {
  display: inline-block;
  margin-top: 6px;
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.detail-grid > div {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  min-width: 0;
}

.detail-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title h3,
.notes-section h3 { font-size: 16px; }

.section-title span {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  font-weight: 800;
}

.rows { display: grid; gap: 8px; }

.row {
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.row-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.row small { color: var(--muted); }

.notes-section,
.security-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.sec-summary { color: var(--muted); margin: 4px 0 10px; }

.actions { margin: 10px 0 0; padding-left: 20px; }
.actions li { margin-bottom: 7px; }

.login-page {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card .brand small { color: var(--muted); }

form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 700; }
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
}

.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fde7e5;
  color: var(--critical);
  font-weight: 700;
}

@media (max-width: 1050px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .workspace, .columns { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app { padding: 18px; }
  .topbar, .detail-head { display: grid; }
  .metrics, .detail-grid { grid-template-columns: 1fr 1fr; }
  .nav { grid-template-columns: 1fr 1fr; }
}

/* Logo Cawipa Elise (SVG virgolette) */
.brand-logo { display: block; flex: none; }

/* Footer con riferimenti normativi/societari */
.legal-footer {
  margin-top: 26px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  align-items: flex-start;
  font-size: 12px;
  color: var(--muted);
}
.legal-brand { display: flex; gap: 10px; align-items: center; }
.legal-brand strong { display: block; color: var(--text); font-size: 14px; }
.legal-brand span { color: var(--muted); }
.legal-cols { display: flex; flex-wrap: wrap; gap: 14px 28px; flex: 1; min-width: 220px; }
.legal-entity { display: grid; gap: 2px; }
.legal-entity strong { color: var(--text); }
.legal-links { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legal-footer a { color: var(--brand-dark); font-weight: 700; text-decoration: none; }
.legal-footer a:hover { text-decoration: underline; }

/* Riga legale compatta sotto il login */
.login-legal { width: min(420px, 100%); margin: 16px auto 0; text-align: center; font-size: 11px; color: var(--muted); line-height: 1.5; }
.login-legal a { color: var(--brand-dark); text-decoration: none; }
