:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dcdad3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --series-1: #2a78d6;
  --pos: #2a78d6;
  --neg: #e34948;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --flash: #fff1c2;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #91908a;
    --accent: #3987e5;
    --accent-soft: #184f95;
    --series-1: #3987e5;
    --pos: #3987e5;
    --neg: #e66767;
    --flash: #4a3f1c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border: #383835;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #91908a;
  --accent: #3987e5;
  --accent-soft: #184f95;
  --series-1: #3987e5;
  --pos: #3987e5;
  --neg: #e66767;
  --flash: #4a3f1c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin-bottom: 12px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 16px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a {
  padding: 6px 12px; border-radius: 8px;
  color: var(--text-secondary);
}
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--text-primary); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid.services { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.stack > * + * { margin-top: 16px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card h3 { font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.tile .label { color: var(--text-secondary); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { color: var(--text-muted); font-size: 12px; }

/* Stato: colore + icona + testo, mai solo colore */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-primary);
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.good::before { background: var(--good); }
.pill.warning::before { background: var(--warning); }
.pill.serious::before { background: var(--serious); }
.pill.critical::before { background: var(--critical); }
.pill.neutral::before { background: var(--text-muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); padding: 6px 8px; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface-1);
}
td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.flash { animation: flash 3s ease-out; }
tr.removed td { text-decoration: line-through; color: var(--text-muted); }
tr.past td { color: var(--text-secondary); }
tr.now td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
@keyframes flash { from { background: var(--flash); } to { background: transparent; } }
.table-wrap { overflow-x: auto; }
.table-wrap.tall { max-height: 70vh; overflow-y: auto; }

.imp { letter-spacing: 1px; color: var(--text-secondary); font-size: 11px; white-space: nowrap; }
.dir { font-size: 10px; margin-left: 4px; }
.dir.pos { color: var(--pos); }
.dir.neg { color: var(--neg); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
input, select, button, textarea {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px;
}
textarea { width: 100%; min-height: 110px; font-family: var(--mono); font-size: 12px; }
button { cursor: pointer; background: var(--surface-2); }
button:hover { border-color: var(--text-muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }

.kind { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); }
.diff { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.diff b { color: var(--text-primary); font-weight: 600; }

/* Grafico a barre (richieste per ora) */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 160px; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .bar.hover { opacity: .75; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; }
.chart .dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}

.feed { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.feed li.flash { animation: flash 3s ease-out; }

.empty { padding: 24px; text-align: center; color: var(--text-muted); }
.error-box {
  border: 1px solid var(--critical); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; background: var(--surface-1);
}
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; }
@media (max-width: 900px) {
  .split, .grid.two { grid-template-columns: 1fr; }
  main { padding: 16px; }
}

/* Login e cambio password */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(380px, 100%); }
.login-card input { width: 100%; }
.stack-label { display: grid; gap: 4px; color: var(--text-secondary); font-size: 13px; }
#pw-form input { width: 100%; max-width: 360px; }
#user-box { display: inline-flex; align-items: center; gap: 8px; }
header[hidden] { display: none; }
