:root {
  color-scheme: dark;
  --page: #121212;
  --panel: #1c1c1c;
  --panel-2: #232323;
  --line: #2c2c2a;
  --line-2: #383835;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --accent: #3ee0a1;
  --accent-ink: #062a1c;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line-2); font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #55554f; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: #ff8a8a; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input { height: 36px; padding: 0 12px; border-radius: 9px; background: #151515; border: 1px solid var(--line-2); outline: 0; min-width: 0; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.field small { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.seg { display: inline-flex; background: #151515; border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { height: 28px; padding: 0 12px; border-radius: 7px; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.seg button.on { background: #2e2e2e; color: var(--ink); }
.switch { position: relative; width: 38px; height: 22px; border-radius: 11px; background: #3a3a3a; transition: background .15s; flex: none; }
.switch::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #ddd; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(16px); background: #fff; }
.switch:disabled { opacity: .5; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.brand svg { width: 26px; height: 26px; }
.err { color: #ff8a8a; font-size: 13px; min-height: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.side { position: sticky; top: 0; height: 100vh; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); background: #161616; overflow: auto; }
.side .brand { padding: 4px 10px 18px; }
.nav { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; border-radius: 10px; color: var(--ink-2); font-weight: 600; text-decoration: none; }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav:hover { background: #202020; color: var(--ink); }
.nav.on { background: #262626; color: var(--ink); box-shadow: inset 3px 0 0 var(--accent); }
.nav-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 12px 6px; }
.side .me { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.main { min-width: 0; padding: 22px 28px 40px; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { font-size: 24px; font-weight: 800; }
.menu-btn { display: none; }

/* ---------- cards & KPIs ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 14px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.kpi .label { color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .delta { font-size: 12.5px; margin-top: 2px; color: var(--muted); }
.kpi .delta.up { color: #0ca30c; }
.kpi .delta.down { color: #ec835a; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--line-2); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: #0b0b0b; border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(0,0,0,.5); min-width: 140px; }
.tip b { display: block; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 16px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .k { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 12px; border-radius: 0 4px 4px 0; background: transparent; position: relative; }
.hbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.hbar .v { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 40px; text-align: right; }
.empty { color: var(--muted); font-size: 13px; padding: 18px 0; text-align: center; }

/* ---------- tables ---------- */
.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; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #212121; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, ui-monospace, monospace; font-size: 12.5px; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }

/* ---------- status / badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: #2a2a2a; color: var(--ink-2); white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.st-good { color: #55d655; }
.st-warning { color: var(--warning); }
.st-serious { color: var(--serious); }
.st-critical { color: #ff6b6b; }
.badge.st-good { background: rgba(12,163,12,.14); }
.badge.st-warning { background: rgba(250,178,25,.13); }
.badge.st-serious { background: rgba(236,131,90,.14); }
.badge.st-critical { background: rgba(208,59,59,.18); }
.checks { display: flex; flex-direction: column; }
.check { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check .ico svg { width: 20px; height: 20px; }

/* ---------- policy matrix ---------- */
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix td .switch { display: inline-block; }

/* ---------- modal / drawer / toast ---------- */
.back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line-2); z-index: 41; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; box-shadow: -20px 0 50px rgba(0,0,0,.5); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0b0b0b; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 16px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px); }
.toast.bad { border-color: var(--critical); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 45; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .cols-2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 14px; }
  .seg { flex-wrap: wrap; }
  .seg button { white-space: nowrap; }
  td { white-space: nowrap; }
  .row > .input { width: 100% !important; }
}
