:root {
  --bg: #0b1017;
  --surface: #121924;
  --surface-2: #18212f;
  --border: #243044;
  --text: #e6edf5;
  --muted: #8b98ab;
  --accent: #38bdf8;
  --link: #cfe3ff;

  --sev-critical: #f05252;
  --sev-high: #f59e0b;
  --sev-elevated: #eab308;
  --sev-guarded: #3b82f6;
  --sev-low: #22c55e;

  --radius: 10px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --border: #dde3ec;
    --text: #111827;
    --muted: #5b6678;
    --accent: #0284c7;
    --link: #0b3a75;
    --sev-elevated: #ca8a04;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand h1 { font-size: 17px; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12px; }

.status { display: flex; align-items: stretch; gap: 10px; justify-content: center; flex-wrap: wrap; }
.level, .metric {
  display: flex; flex-direction: column; justify-content: center;
  padding: 6px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  min-width: 96px;
}
.level { --lv: var(--muted); border-color: var(--lv); box-shadow: inset 4px 0 0 var(--lv); padding-left: 16px; }
.level[data-level="critical"] { --lv: var(--sev-critical); }
.level[data-level="high"] { --lv: var(--sev-high); }
.level[data-level="elevated"] { --lv: var(--sev-elevated); }
.level[data-level="low"] { --lv: var(--sev-low); }
.level-label, .metric-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.level-value { font-size: 18px; font-weight: 700; color: var(--lv); text-transform: uppercase; letter-spacing: .5px; }
.metric-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric[data-warn] .metric-value { color: var(--sev-high); }

.controls { display: flex; gap: 8px; }
.controls input, .controls button {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
}
.controls input { width: 220px; }
.controls input:focus, .controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.controls button { cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.controls button[disabled] { opacity: .6; cursor: progress; }

main { padding: 20px 24px; display: flex; flex-direction: column; gap: 20px; flex: 1; min-width: 0; }
main > * { min-width: 0; }

.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }

/* ---------- incidents ---------- */
.incident-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px;
}
.incident {
  --sev: var(--sev-elevated);
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--sev);
  border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.incident[data-sev="critical"] { --sev: var(--sev-critical); }
.incident[data-sev="high"] { --sev: var(--sev-high); }
.incident-head { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.rank { font: 700 20px/1 var(--mono); color: var(--sev); }
.sev {
  text-transform: uppercase; font-weight: 700; font-size: 11px; letter-spacing: .6px;
  color: var(--sev); border: 1px solid var(--sev); border-radius: 4px; padding: 1px 6px;
}
.incident-head time { margin-left: auto; }
.incident h3 { font-size: 15px; line-height: 1.35; }
.incident .summary {
  margin: 0; color: var(--muted); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.reasons { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.reasons li {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.sources { margin: 0; font-size: 12px; }
.related summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.related ul { margin: 6px 0 0; padding-left: 16px; font-size: 12px; }
.related li { margin-bottom: 3px; }
.incident-empty { grid-column: 1 / -1; padding: 18px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--border); }

.kev-strip {
  margin-top: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.kev-row { display: flex; align-items: center; gap: 12px; padding: 8px 14px; min-width: 0; }
.kev-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--sev-critical); font-weight: 700; white-space: nowrap; }
.kev-row ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 18px; overflow-x: auto; white-space: nowrap; font-size: 12.5px; scrollbar-width: thin; flex: 1; min-width: 0; }
.kev-toggle {
  margin-left: auto; flex: none; font: inherit; font-size: 12px; cursor: pointer; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px;
}
.kev-toggle::after { content: " ▾"; color: var(--muted); }
.kev-toggle[aria-expanded="true"]::after { content: " ▴"; }
.kev-toggle:hover { border-color: var(--accent); }
.kev-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.kev-detail { border-top: 1px solid var(--border); overflow-x: auto; }
.kev-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kev-table th {
  text-align: left; font-weight: 500; color: var(--muted); background: var(--surface-2);
  padding: 7px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.kev-table td { padding: 8px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kev-table tr:last-child td { border-bottom: 0; }
.kev-date, .kev-score { white-space: nowrap; font-variant-numeric: tabular-nums; }
.kev-table td:nth-child(2) { white-space: nowrap; }
.kev-score span:first-child { font-weight: 700; }
.kev-ver { font-size: 11px; }
.kev-title a { font-weight: 500; }
.kev-desc { font-size: 12px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kev-ransom {
  margin-left: 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--sev-critical); border: 1px solid currentColor; border-radius: 3px; padding: 0 4px;
}
.cvss-sev {
  --c: var(--muted);
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; white-space: nowrap;
  color: var(--c); border: 1px solid var(--c); border-radius: 4px; padding: 1px 6px;
}
.cvss-sev[data-sev="critical"] { --c: var(--sev-critical); }
.cvss-sev[data-sev="high"] { --c: var(--sev-high); }
.cvss-sev[data-sev="medium"] { --c: var(--sev-elevated); }
.cvss-sev[data-sev="low"] { --c: var(--sev-low); }
.kev-note { margin: 0; padding: 8px 14px; font-size: 11.5px; border-top: 1px solid var(--border); }
.kev-strip code { font-family: var(--mono); color: var(--accent); }

/* ---------- panels ---------- */
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0; height: 520px;
}
.panel > header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 12px 16px 8px;
}
.panel h2 { font-size: 15px; }
.panel .subtitle { margin: 2px 0 0; font-size: 12px; }
.count { font: 600 12px var(--mono); color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 3px 8px; white-space: nowrap; }

.chips { display: flex; gap: 6px; padding: 0 16px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.chips button {
  font: inherit; font-size: 11.5px; cursor: pointer; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}
.chips button:hover { color: var(--text); }
.chips button[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.items { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; scrollbar-width: thin; }
.item { padding: 9px 16px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item-meta { display: flex; gap: 8px; align-items: center; font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.item-source { font-weight: 600; color: var(--accent); }
.provider-icon { width: 16px; height: 16px; border-radius: 4px; flex: none; box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 22%, transparent); }
.item-new { font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--sev-low); border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; }
.item a { font-weight: 500; }
.item p {
  margin: 3px 0 0; font-size: 12.5px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.items .empty { padding: 24px 16px; color: var(--muted); text-align: center; }

/* ---------- footer ---------- */
.health { padding: 0 24px 24px; font-size: 12.5px; }
.health summary { cursor: pointer; color: var(--muted); }
.health summary[data-warn] { color: var(--sev-high); }
.health table { margin-top: 10px; border-collapse: collapse; width: 100%; max-width: 900px; }
.health th, .health td { text-align: left; padding: 4px 10px; border-bottom: 1px solid var(--border); }
.health th { color: var(--muted); font-weight: 500; }
.health .bad { color: var(--sev-critical); }

.error-banner {
  background: color-mix(in srgb, var(--sev-critical) 15%, var(--surface));
  border: 1px solid var(--sev-critical); border-radius: var(--radius); padding: 10px 14px;
}

/* ---------- all-items dialog ---------- */
#all-dialog {
  width: min(1100px, 94vw); max-height: 86vh; padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: none; flex-direction: column;
}
#all-dialog[open] { display: flex; }
#all-dialog::backdrop { background: rgb(0 0 0 / .55); }
.dialog-head { display: flex; align-items: baseline; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 16px; }
.dialog-head button {
  margin-left: auto; font: inherit; cursor: pointer; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 2px 9px;
}
.dialog-head button:hover { color: var(--text); border-color: var(--accent); }
.dialog-body { overflow-y: auto; }
.all-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.all-table th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left;
  font-weight: 500; color: var(--muted); padding: 7px 14px; border-bottom: 1px solid var(--border);
}
.all-table td { padding: 7px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.all-table tr:hover td { background: var(--surface-2); }
.all-date { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.all-table td:last-child { white-space: nowrap; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .topbar { grid-template-columns: 1fr auto; }
  .status { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
}
@media (max-width: 1000px) {
  .incident-list, .panels { grid-template-columns: minmax(0, 1fr); }
  .panel { height: 440px; }
}
@media (max-width: 640px) {
  .topbar, main { padding-left: 12px; padding-right: 12px; }
  .topbar { grid-template-columns: 1fr; }
  .controls input { width: auto; flex: 1; min-width: 0; }
  .controls { width: 100%; }
  .section-head { flex-direction: column; gap: 2px; }
}
