:root {
  color-scheme: light dark;
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f1f1f6;
  --border: #e3e3ec;
  --text: #17171f;
  --muted: #646478;
  --accent: #5b3df5;
  --accent-ink: #ffffff;
  --accent-soft: #ece8ff;
  --bar: #6d4aff;
  --grid: #e8e8f0;
  --good: #11804a;     --good-bg: #e3f5ec;
  --warn: #8a5a00;     --warn-bg: #fdf1d8;
  --serious: #b24a00;  --serious-bg: #fde8da;
  --critical: #c0242c; --critical-bg: #fde4e5;
  --neutral: #55556a;  --neutral-bg: #ececf2;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f15;
    --surface: #17171f;
    --surface-2: #1f1f2a;
    --border: #2b2b38;
    --text: #ececf3;
    --muted: #9a9ab0;
    --accent: #9b85ff;
    --accent-ink: #120c2e;
    --accent-soft: #2a2350;
    --bar: #9b85ff;
    --grid: #262632;
    --good: #4cd48f;     --good-bg: #133524;
    --warn: #f0be4f;     --warn-bg: #3a2e10;
    --serious: #ff9a5c;  --serious-bg: #3d2314;
    --critical: #ff6b72; --critical-bg: #3f1719;
    --neutral: #b4b4c6;  --neutral-bg: #272732;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--critical); min-height: 1.2em; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px;
  padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; padding: 0 8px; }
.brand .muted { font-weight: 500; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #6d4aff, #b07cff); flex: none; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a, .sidebar-foot a { color: var(--text); padding: 7px 10px; border-radius: 8px; font-weight: 500; }
nav a:hover, .sidebar-foot a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active, .sidebar-foot a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .btn { justify-content: flex-start; padding: 0 10px; color: var(--muted); }
.view { padding: 28px 32px 64px; max-width: 1240px; width: 100%; outline: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; }
  .view { padding: 20px 16px 48px; }
}

/* ---------- Cards / tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); }
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .hint { font-size: 12px; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--neutral-bg); color: var(--neutral); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.serious { background: var(--serious-bg); color: var(--serious); }
.badge.critical { background: var(--critical-bg); color: var(--critical); }
.badge.plain::before { display: none; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 12px; margin: 2px 4px 2px 0; }
.chip.extra { border-style: dashed; border-color: var(--accent); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.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.danger.solid { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; font: inherit; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; height: 34px; min-width: 0;
}
textarea { height: auto; min-height: 70px; resize: vertical; }
input[type="checkbox"] { height: auto; width: 16px; height: 16px; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form .full { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="search"] { width: 280px; }

.key { font-family: var(--mono); font-size: 13px; letter-spacing: .02em; }
.key-big { font-family: var(--mono); font-size: 18px; font-weight: 600; letter-spacing: .03em; overflow-wrap: anywhere; }
.copy { cursor: pointer; }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(10 10 20 / .45); }
dialog form > header { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: center; }
dialog form > header h2 { margin: 0; font-size: 16px; }
dialog .body { padding: 16px 20px; max-height: 70vh; overflow: auto; }
dialog footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 360px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { padding: 0; font-size: 17px; }
.login-card p { margin: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-weight: 500; box-shadow: 0 8px 24px rgb(0 0 0 / .2); max-width: 380px; }
.toast.err { background: var(--critical); color: #fff; }

/* ---------- Chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { filter: brightness(1.15); }
.chart .tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgb(0 0 0 / .12); transform: translate(-50%, calc(-100% - 8px)); white-space: nowrap;
}
.chart .tooltip strong { display: block; margin-bottom: 2px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 9px 18px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0 0; }
.docs h2 { margin-top: 8px; }
.docs p { margin: 6px 0; }
