/* Radar Progetti — dashboard. Token di colore in un solo posto, tema chiaro e scuro. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b02a2a;
  --neutral: #a8a7a0;
  /* rampa ordinale (blu) per l'attività: fermo → attivo */
  --act-fermo: #86b6ef;
  --act-pausa: #5598e7;
  --act-recente: #2a78d6;
  --act-attivo: #184f95;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #252523; --ink: #f0efec; --ink-2: #c3c2b7;
    --muted: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --accent-ink: #86b6ef; --good-ink: #0ca30c; --critical-ink: #e66767; --neutral: #5f5e5a;
    --act-fermo: #184f95; --act-pausa: #256abf; --act-recente: #3987e5; --act-attivo: #86b6ef;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #252523; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-ink: #86b6ef; --good-ink: #0ca30c; --critical-ink: #e66767; --neutral: #5f5e5a;
  --act-fermo: #184f95; --act-pausa: #256abf; --act-recente: #3987e5; --act-attivo: #86b6ef;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 80px; }
body { margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 16px 60px; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- topbar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 700; font-size: 16px; text-decoration: none !important; }
.brand span { color: var(--ink); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--ink-2); white-space: nowrap; text-decoration: none; }
.tabs a:hover { background: var(--surface-2); }
.tabs a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.actions { display: flex; align-items: center; gap: 8px; }
.last-scan { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.readonly .local-only { display: none !important; }
.locked .tabs, .locked .actions > :not(#themeBtn) { display: none !important; }
.login { max-width: 400px; margin: 72px auto; display: grid; gap: 14px; }
.login h1 { font-size: 20px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400 !important; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical-ink); }
.btn.icon { padding: 7px 10px; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.scan-control { position: relative; display: flex; }
.scan-control .btn:first-child { border-radius: 8px 0 0 8px; }
.scan-control .caret { border-radius: 0 8px 8px 0; border-left: 1px solid rgba(255,255,255,.35); padding: 7px 9px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); width: 310px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu b { display: block; font-weight: 600; }
.menu span { display: block; color: var(--muted); font-size: 12.5px; }

.progress { max-width: 1320px; margin: 0 auto; padding: 0 16px 10px; display: flex; align-items: center; gap: 12px; }
.progress-bar { flex: 1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .4s ease; }
.progress span { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }

/* ---------------------------------------------------------------- layout */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.banner { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: 8px;
  padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.empty { text-align: center; padding: 60px 20px; }
.empty h2 { font-size: 18px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 0 18px; }

/* ---------------------------------------------------------------- KPI */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
@media (max-width: 1080px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; cursor: pointer; text-align: left; display: block; width: 100%; }
.kpi:hover { border-color: var(--accent); }
.kpi .label { color: var(--ink-2); font-size: 12.5px; }
.kpi .value { font-size: 28px; font-weight: 600; line-height: 1.15; margin-top: 2px; }
.kpi .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; min-height: 20px; }
.delta { font-size: 12px; color: var(--muted); }
.delta.good { color: var(--good-ink); }
.delta.bad { color: var(--critical-ink); }
.spark { width: 72px; height: 20px; overflow: visible; }
.spark polyline { fill: none; stroke: var(--baseline); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

/* ---------------------------------------------------------------- grafici */
.stack { display: flex; height: 22px; gap: 2px; margin: 4px 0 12px; }
.stack .seg { min-width: 4px; height: 100%; }
.stack .seg:first-child { border-radius: 4px 0 0 4px; }
.stack .seg:last-child { border-radius: 0 4px 4px 0; }
.stack .seg:only-child { border-radius: 4px; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 14px; }
.legend button { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 2px 0; cursor: pointer; text-align: left; }
.legend button:hover .lname { text-decoration: underline; }
.legend .lcount { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr; align-items: center; gap: 10px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.bar-row:hover { background: var(--surface-2); }
.bar-row .bname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar { height: 14px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 3px; flex: none; }
.bar-val { font-size: 12px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.axis-note { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin: 6px 4px 0 calc(min(160px, 30%) + 14px); border-top: 1px solid var(--baseline); padding-top: 4px; }

/* ---------------------------------------------------------------- live / non live */
.sec { margin-top: 22px; }
.sec-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sec-head h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.live-card { cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.live-card:hover { border-color: var(--accent); }
.live-card h3 { font-size: 15px; }
.live-card .card-head { align-items: center; }
.lc-what { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.lc-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nl-group { margin-top: 16px; }
.nl-group h3 { font-size: 14px; margin-bottom: 2px; }
.nl-group .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- badge e stato */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); white-space: nowrap; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.c-good { background: var(--good); } .c-info { background: var(--accent); } .c-warning { background: var(--warning); }
.c-serious { background: var(--serious); } .c-critical { background: var(--critical); } .c-neutral { background: var(--neutral); }
.c-attivo { background: var(--act-attivo); } .c-recente { background: var(--act-recente); }
.c-pausa { background: var(--act-pausa); } .c-fermo { background: var(--act-fermo); }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------------------------------------------------------------- liste */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--grid); }
.list li:first-child { border-top: 0; }
.list .ico { width: 20px; height: 20px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; margin-top: 1px; }
.ico.bad { background: var(--critical); } .ico.warn { background: var(--warning); color: #0b0b0b; }
.ico.good { background: var(--good); } .ico.info { background: var(--accent); }
.list .what { flex: 1; min-width: 0; }
.list .what a { font-weight: 600; }
.more { margin-top: 8px; }

/* ---------------------------------------------------------------- tabelle */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select, .field input, .field select, .field textarea {
  font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.toolbar input[type=search] { flex: 1 1 260px; min-width: 0; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--grid); vertical-align: top; }
thead th { border-top: 0; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
thead th[data-sort] { cursor: pointer; user-select: none; }
thead th[data-sort]:hover { color: var(--ink); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td .pname { font-weight: 600; }
td .pwhat { color: var(--ink-2); font-size: 12.5px; max-width: 460px; }
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.pager-size { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.pager-size select { font: inherit; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.sort-ind { margin-left: 4px; font-size: 10px; color: var(--accent-ink); }
thead th[aria-sort="ascending"], thead th[aria-sort="descending"] { color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11.5px; background: var(--surface-2); color: var(--ink-2); padding: 1px 7px; border-radius: 5px; white-space: nowrap; }
.warns { color: var(--critical-ink); font-size: 12px; white-space: nowrap; }

/* ---------------------------------------------------------------- drawer */
.drawer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); opacity: 0; transition: opacity .2s; }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--surface); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .22s ease; overflow-y: auto; padding: 22px 24px 40px; }
.drawer.open { pointer-events: auto; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer.open .drawer-panel { transform: none; }
.drawer-close { position: absolute; top: 14px; right: 14px; }
.d-head h1 { font-size: 22px; padding-right: 40px; }
.d-head .badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.d-sec { border-top: 1px solid var(--grid); padding-top: 14px; margin-top: 16px; }
.d-sec h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.d-sec ul { margin: 4px 0 0; padding-left: 18px; }
.d-sec li { margin: 3px 0; }
.lead { font-size: 15px; font-weight: 600; margin: 6px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.host-row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 4px 0; }
.d-sec.first { border-top: 0; margin-top: 6px; padding-top: 0; }
dl.comp { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 6px 14px; margin: 10px 0 0; font-size: 13.5px; }
dl.comp dt { font-weight: 600; overflow-wrap: anywhere; }
dl.comp dd { margin: 0; color: var(--ink-2); }
ul.missing { list-style: none; padding: 0; margin: 8px 0 0; }
ul.missing li { padding: 8px 0; border-top: 1px solid var(--grid); margin: 0; }
ul.missing li:first-child { border-top: 0; }
.m-head { display: flex; gap: 8px; align-items: center; margin-bottom: 2px; flex-wrap: wrap; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- form */
.form { display: grid; gap: 16px; max-width: 720px; }
.field { display: grid; gap: 5px; }
.field label { font-weight: 600; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field textarea { min-height: 80px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------------------------------------------------------- log */
.log { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; max-height: 320px; overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.6; }
.log .t { color: var(--muted); margin-right: 8px; }
.log .ph { color: var(--accent-ink); font-weight: 600; }

/* ---------------------------------------------------------------- tooltip e toast */
.tooltip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 12px; padding: 6px 9px;
  border-radius: 6px; max-width: 280px; box-shadow: var(--shadow); }
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px;
  box-shadow: var(--shadow); max-width: 360px; }
.toast.bad { border-left-color: var(--critical); }
.toast.good { border-left-color: var(--good); }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  .last-scan { display: none; }
  .actions { margin-left: auto; }
  .bar-row { grid-template-columns: minmax(80px, 110px) 1fr; }
  .axis-note { margin-left: 124px; }
  th.hide-sm, td.hide-sm { display: none; }
  dl.comp { grid-template-columns: 1fr; gap: 2px; }
  dl.comp dd { margin-bottom: 6px; }
}
