/* ============================================================
   KSM Mission Control — stile
   Token colore dal design system (palette validata light+dark)
   ============================================================ */

:root {
  --surface: #fcfcfb;
  --plane: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4; --s8: #eb6834;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --sidebar-bg: #12222f;
  --sidebar-ink: #d7e2ea;
  --sidebar-active: #1d3a52;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1a1a19;
    --plane: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181; --s8: #d95926;
    --good-text: #0ca30c;
    --accent: #3987e5;
    --sidebar-bg: #101a22;
    --sidebar-ink: #c3ccd4;
    --sidebar-active: #1c3348;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--plane);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- layout ---------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.brand h1 { font-size: 15px; color: #fff; line-height: 1.15; }
/* Brand con logo Klinik Sankt Moritz (impilato) al posto del quadrato "K". */
.brand--ksm { flex-direction: column; align-items: flex-start; gap: 6px; padding: 6px 10px 16px; }
.brand--ksm .ksm-logo { width: 100%; max-width: 196px; height: auto; }
.brand-title { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.15; }
.brand-title small { display: block; font-weight: 400; font-size: 11px; color: var(--sidebar-ink); opacity: .8; }
.brand small { display: block; font-size: 11px; font-weight: 400; color: var(--sidebar-ink); opacity: 0.75; }

.nav { list-style: none; margin-top: 6px; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--sidebar-ink);
  font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: 0.9; }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { font-size: 21px; }
.page-head p { color: var(--ink-2); margin-top: 2px; max-width: 720px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.demo-banner {
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--ink); border-radius: 10px; padding: 8px 14px; margin-bottom: 18px;
  font-size: 13px; display: flex; gap: 8px; align-items: center;
}

/* ---------------- card & griglie ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 12px;
  padding: 16px 18px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.card h3 { font-size: 14px; margin-bottom: 12px; }
.card h3 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
}
.mt { margin-top: 14px; }

/* ---------------- stat tile / hero ---------------- */
.hero-figure { font-size: 48px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.05; }
.stat-label { color: var(--ink-2); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.stat-delta { font-size: 12.5px; margin-top: 4px; color: var(--ink-2); }
.stat-delta.up { color: var(--good-text); }
.stat-delta.down { color: var(--critical); }

/* ---------------- tabelle ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }

/* ---------------- badge di stato ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok      { color: var(--good-text); background: color-mix(in srgb, var(--good) 14%, transparent); }
.badge.warn    { color: var(--ink);       background: color-mix(in srgb, var(--warn) 22%, transparent); }
.badge.bad     { color: var(--critical);  background: color-mix(in srgb, var(--critical) 13%, transparent); }
.badge.off     { color: var(--muted);     background: color-mix(in srgb, var(--muted) 15%, transparent); }
.badge.info    { color: var(--accent);    background: color-mix(in srgb, var(--accent) 12%, transparent); }

.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--ring); color: var(--ink-2); }

/* ---------------- bottoni & form ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--ring); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--ring); border-radius: 8px; padding: 7px 10px; font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------------- modale ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 60;
}
.modal {
  background: var(--surface); border-radius: 14px; border: 1px solid var(--ring);
  width: 100%; max-width: 680px; max-height: 86vh; overflow-y: auto; padding: 20px 22px;
}
.modal h3 { font-size: 17px; margin-bottom: 14px; }
.modal .modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------------- grafici ---------------- */
.ct-grid { stroke: var(--grid); stroke-width: 1; }
.ct-tick { fill: var(--muted); font-size: 11px; }
.ct-label { fill: var(--ink-2); font-size: 12px; }
.ct-value { fill: var(--ink); font-size: 12px; font-weight: 600; }
.ct-cross { stroke: var(--axis); stroke-width: 1; }
.dn-total { fill: var(--ink); font-size: 17px; font-weight: 650; }
.hb-row:focus { outline: none; }
.hb-row:focus rect:first-of-type { fill: color-mix(in srgb, var(--accent) 8%, transparent); }

.chart-tip {
  position: fixed; display: none; z-index: 80; pointer-events: none;
  background: var(--ink); color: var(--surface);
  border-radius: 8px; padding: 7px 11px; font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); max-width: 260px;
}
.chart-tip .tip-hint { opacity: 0.75; }

.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.chart-legend { list-style: none; flex: 1; min-width: 180px; }
.chart-legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12.5px; }
.chart-legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 11px; }
.chart-legend .lg-label { color: var(--ink-2); flex: 1; }
.chart-legend .lg-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------- dashboard delle dashboard ---------------- */
.dash-card { display: flex; flex-direction: column; gap: 8px; }
.dash-card .dash-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.dash-card h4 { font-size: 14.5px; }
.dash-card .desc { color: var(--ink-2); font-size: 12.5px; flex: 1; }
.dash-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.dash-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

/* ---------------- matrice attivazioni ---------------- */
.matrix-wrap { overflow-x: auto; }
.matrix td.cell { text-align: center; cursor: pointer; user-select: none; font-size: 15px; }
.matrix td.cell:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.matrix th.svc { writing-mode: initial; font-size: 11px; }
.matrix .st-attivo { color: var(--good-text); }
.matrix .st-sospeso { color: var(--ink); }
.matrix .st-disattivo, .matrix .st-none { color: var(--muted); opacity: 0.6; }

/* ---------------- drawer dettaglio cliente ---------------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }

.muted { color: var(--muted); }
.right { text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; }

/* ---------------- stato M20 in sidebar ---------------- */
.m20-badge { margin-top: 18px; padding: 0 10px; }
.m20-chip {
  display: block; text-align: center; padding: 7px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--sidebar-ink);
  border: 1px solid rgba(255, 255, 255, 0.14); text-decoration: none;
}
.m20-chip:hover { text-decoration: none; filter: brightness(1.15); }
.m20-chip.ok   { background: color-mix(in srgb, var(--good) 22%, transparent); }
.m20-chip.bad  { background: color-mix(in srgb, var(--critical) 26%, transparent); }
.m20-chip.info { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.m20-chip.off  { background: rgba(255, 255, 255, 0.06); opacity: 0.8; }

/* ---------------- toast ---------------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  background: var(--surface); color: var(--ink); border-radius: 10px;
  border: 1px solid var(--ring); border-left: 4px solid var(--good);
  padding: 10px 14px; font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  transition: opacity 0.35s, transform 0.35s;
}
.toast.warn { border-left-color: var(--warn); }
.toast.err  { border-left-color: var(--critical); }
.toast.gone { opacity: 0; transform: translateY(6px); }

/* ---------------- pulsante "?" spiegazione ---------------- */
.help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: none; padding: 0;
  border-radius: 50%; border: 1px solid var(--accent);
  background: transparent; color: var(--accent);
  font-size: 12px; font-weight: 700; line-height: 1; cursor: pointer;
  vertical-align: middle;
}
.help-btn:hover { background: var(--accent); color: var(--accent-ink); }
.help-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.help-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 700; flex: none;
}
.role-line { color: var(--accent); font-size: 12px; font-weight: 600; margin: -4px 0 8px; }
.agent-card .dash-top h4 { display: flex; align-items: center; gap: 7px; }
