:root {
  --bg: #0b0f14; --panel: #121820; --panel-2: #18202a; --line: #232d3a; --text: #e6edf3; --muted: #8b98a8;
  --accent: #3b82f6; --accent-2: #60a5fa; --ok: #22c55e; --warn: #f59e0b; --high: #f97316; --crit: #ef4444;
  --low: #64748b; --med: #eab308; --ai: #a78bfa; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f7fa; --panel: #ffffff; --panel-2: #f0f3f7; --line: #dfe5ec; --text: #0f172a; --muted: #5b6878;
  --accent: #2563eb; --accent-2: #1d4ed8; --shadow: 0 1px 3px rgba(15,23,42,.08); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent-2); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--ai)); display: grid; place-items: center; color: #fff; font-weight: 800; }
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; text-decoration: none; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-2); font-weight: 600; }
.nav .count { margin-left: auto; background: var(--crit); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.nav .count.ai { background: var(--ai); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { padding: 22px 28px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.tight { padding: 0; overflow: hidden; }
.card.tight > h2 { padding: 14px 16px 0; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .s { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.kpi.alert { border-color: color-mix(in srgb, var(--crit) 50%, var(--line)); }
.kpi.alert .v { color: var(--crit); }
.kpi.ai .v { color: var(--ai); }
.kpi.go { cursor: pointer; }
.kpi.go:hover { border-color: var(--accent); }

/* now-panel */
.now { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.now .item { flex: 1; min-width: 240px; display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.now .item:hover { border-color: var(--accent); }
.now .big { font-size: 28px; font-weight: 750; min-width: 36px; text-align: center; }
.now .item.warn .big { color: var(--warn); }
.now .item.ai .big { color: var(--ai); }
.now .item.crit .big { color: var(--crit); }
.now .t { font-weight: 600; }
.now .d { color: var(--muted); font-size: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow: auto; max-height: 70vh; }
.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.sev-critical { background: color-mix(in srgb, var(--crit) 18%, transparent); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.sev-high { background: color-mix(in srgb, var(--high) 16%, transparent); color: var(--high); }
.sev-medium { background: color-mix(in srgb, var(--med) 16%, transparent); color: var(--med); }
.sev-low { background: color-mix(in srgb, var(--low) 22%, transparent); color: var(--muted); }
.st { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.st-escalated, .st-pending, .st-investigating { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.st-active, .st-confirmed, .st-accepted, .st-contained { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.st-failed, .st-rejected { color: var(--crit); }
.st-triaging, .st-executing { color: var(--accent-2); }
.ai-badge { background: color-mix(in srgb, var(--ai) 16%, transparent); color: var(--ai); }
.v-true_positive { color: var(--crit); } .v-needs_escalation { color: var(--warn); }
.v-false_positive, .v-benign { color: var(--ok); }
.dry { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.live { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip { display: inline-block; font-family: var(--mono); font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); margin: 1px 4px 1px 0; }
.chip.k { color: var(--muted); }

/* buttons & inputs */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 550; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { background: transparent; border-color: color-mix(in srgb, var(--crit) 60%, transparent); color: var(--crit); }
button.ghost { background: transparent; }
button.sm { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sep { height: 1px; background: var(--line); margin: 14px 0; }
.right { margin-left: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; text-decoration: none; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.hunt { display: flex; gap: 8px; margin-bottom: 12px; }
.hunt input { flex: 1; font-family: var(--mono); }

/* review / approval cards */
.cards { display: grid; gap: 12px; }
.rc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.rc .hd { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rc .title { font-weight: 650; font-size: 15px; }
.rc .sum { font-size: 14px; }
.rc .why { color: var(--muted); font-size: 13px; }
.rc .acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rc.pending { border-left: 3px solid var(--warn); }
.rc.ai { border-left: 3px solid var(--ai); }
.target { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.conf { height: 6px; border-radius: 99px; background: var(--panel-2); overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.conf > i { display: block; height: 100%; background: var(--ai); }
.risk { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; min-width: 80px; }
.risk > i { display: block; height: 100%; }

/* timeline */
.tl { position: relative; padding-left: 18px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl .e { position: relative; padding: 6px 0 8px; }
.tl .e::before { content: ""; position: absolute; left: -17px; top: 11px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); }
.tl .e.bad::before { border-color: var(--crit); }
.tl .e .t { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.note { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); white-space: pre-wrap; }
.note.ai { border-color: color-mix(in srgb, var(--ai) 40%, var(--line)); }
.note .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }

/* feed */
.feed { max-height: 330px; overflow: auto; font-size: 12.5px; }
.feed div { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.feed .ts { color: var(--muted); font-family: var(--mono); font-size: 11px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: var(--crit); box-shadow: none; }

/* bars chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bars i { flex: 1; background: color-mix(in srgb, var(--accent) 70%, transparent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars i:hover { background: var(--accent-2); }

/* drawer, modal, toast */
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(720px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 30; padding: 20px; overflow: auto; box-shadow: -12px 0 40px rgba(0,0,0,.35); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 29; }
.modal { position: fixed; top: 12vh; left: 50%; transform: translateX(-50%); width: min(520px, 94vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; z-index: 31; padding: 20px; display: grid; gap: 12px; }
pre.json { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; font-size: 12px; max-height: 60vh; white-space: pre-wrap; word-break: break-all; }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 40; display: grid; gap: 8px; }
.toast div { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; }
.toast div.err { border-left-color: var(--crit); }
.toast div.crit { border-left-color: var(--crit); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); padding: 28px; border-radius: 14px; }
.login .brand { padding: 0 0 8px; }
.err-msg { color: var(--crit); font-size: 13px; min-height: 18px; }

@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0,1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .side-foot { display: none; }
  .main { padding: 16px; }
  .kpis, .g2, .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
details summary { cursor: pointer; }
details[open] summary { margin-bottom: 6px; }
