:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --fg: #1d232b;
  --muted: #525b66;
  --line: #c9ced6;
  --card: #fff;
  --thead: #eef1f4;
  --zebra: #f3f5f8;
  --input-bg: #fff;
  --accent: #1c4a77;
  --button: #2b5c8a;
  --danger: #b33a3a;
  --on-strong: #fff;
  --topbar: #1f2d3d;
  --topbar-fg: #dfe7ef;
  --topbar-muted: #b9c4cf;
  --topbar-active: #8fb8de;
  --ok: #e3f4e6;
  --ok-line: #9fd2a8;
  --behind: #fff4c2;
  --drift: #ffe3c4;
  --drift-mark: #e08a1e;
  --eolsoon: #ffd8a8;
  --eol: #f8d0d0;
  --eol-line: #e08f8f;
  --cve: #f8caca;
  --kev: #a4262c;
  --badge-bg: #fff;
  --badge-fg: #8f1d1d;
  --secret-bg: #fffbe6;
  --secret-line: #c9a400;
  --light-ok: #2e9e4f;
  --light-degraded: #e0912b;
  --light-down: #d6343b;
  --light-unknown: #8a939e;
  --light-ring: rgba(255, 255, 255, 0.35);
}

/* Dark theme: explicit choice (data-theme, set by theme.js), or the system
   preference when no choice was made and JavaScript did not run. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161c;
  --fg: #e3e8ee;
  --muted: #a3adb9;
  --line: #3a4450;
  --card: #1b2129;
  --thead: #232a33;
  --zebra: #20272f;
  --input-bg: #10141a;
  --accent: #8cc4ff;
  --button: #2f6aa3;
  --danger: #b8403d;
  --on-strong: #fff;
  --topbar: #0b0f14;
  --topbar-fg: #dfe7ef;
  --topbar-muted: #b9c4cf;
  --topbar-active: #8fb8de;
  --ok: #1e3a26;
  --ok-line: #2f6b3c;
  --behind: #3d3613;
  --drift: #4a2f12;
  --drift-mark: #e08a1e;
  --eolsoon: #553212;
  --eol: #4d1f22;
  --eol-line: #8a3a3a;
  --cve: #5a1f24;
  --kev: #c4343b;
  --badge-bg: #3a1d20;
  --badge-fg: #ffb3b3;
  --secret-bg: #2e2a12;
  --secret-line: #a88b00;
  --light-ok: #2e9e4f;
  --light-degraded: #e0912b;
  --light-down: #d6343b;
  --light-unknown: #8a939e;
  --light-ring: rgba(255, 255, 255, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161c;
    --fg: #e3e8ee;
    --muted: #a3adb9;
    --line: #3a4450;
    --card: #1b2129;
    --thead: #232a33;
    --zebra: #20272f;
    --input-bg: #10141a;
    --accent: #8cc4ff;
    --button: #2f6aa3;
    --danger: #b8403d;
    --on-strong: #fff;
    --topbar: #0b0f14;
    --topbar-fg: #dfe7ef;
    --topbar-muted: #b9c4cf;
    --topbar-active: #8fb8de;
    --ok: #1e3a26;
    --ok-line: #2f6b3c;
    --behind: #3d3613;
    --drift: #4a2f12;
    --drift-mark: #e08a1e;
    --eolsoon: #553212;
    --eol: #4d1f22;
    --eol-line: #8a3a3a;
    --cve: #5a1f24;
    --kev: #c4343b;
    --badge-bg: #3a1d20;
    --badge-fg: #ffb3b3;
    --secret-bg: #2e2a12;
    --secret-line: #a88b00;
    --light-ok: #2e9e4f;
    --light-degraded: #e0912b;
    --light-down: #d6343b;
    --light-unknown: #8a939e;
    --light-ring: rgba(255, 255, 255, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--topbar);
  color: var(--on-strong);
}
.topbar a { color: var(--topbar-fg); text-decoration: none; }
.topbar nav a:hover { text-decoration: underline; }
.topbar .brand { font-weight: 700; font-size: 17px; color: var(--on-strong); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a.active { color: var(--on-strong); border-bottom: 2px solid var(--topbar-active); }
.topbar .user {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: auto;
  color: var(--topbar-muted);
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--topbar-fg);
}
.theme-toggle:hover { border-color: var(--topbar-muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--topbar-active); outline-offset: 1px; }
.theme-toggle[hidden] { display: none; }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun, :root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }
h1 { margin: 0 0 12px; font-size: 22px; }
h2 { margin: 24px 0 8px; font-size: 17px; }
h3 { margin: 16px 0 6px; font-size: 14px; }

table {
  border-collapse: collapse;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
}
th, td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
thead th { background: var(--thead); font-weight: 600; white-space: nowrap; }
.scroll { overflow-x: auto; }
table.matrix td { text-align: center; white-space: nowrap; font-size: 13px; }

.st-ok { background: var(--ok); }
.st-behind { background: var(--behind); }
.st-drift { background: var(--drift); }
.st-eolsoon { background: var(--eolsoon); }
.st-eol { background: var(--eol); }
.st-cve { background: var(--cve); }
.st-kev { background: var(--kev); color: var(--on-strong); }
.st-kev a { color: var(--on-strong); }
tr.drift td:first-child { border-left: 4px solid var(--drift-mark); }

.legend { display: flex; gap: 6px; list-style: none; padding: 0; margin: 8px 0 12px; }
.legend li { padding: 2px 8px; border-radius: 3px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--badge-bg);
  color: var(--badge-fg);
  font-size: 11px;
  font-weight: 600;
}
.badge.kev { background: var(--kev); color: var(--on-strong); }

.muted { color: var(--muted); font-size: 12px; }
.ver { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.sub { margin: 0 0 12px; }
.empty { color: var(--muted); font-style: italic; }
.summary { max-width: 520px; }
.detail { font-family: ui-monospace, monospace; font-size: 11px; word-break: break-all; }
.comment { white-space: pre-wrap; font-size: 12px; }

.flash { padding: 8px 12px; margin-bottom: 12px; border-radius: 4px; }
.flash.ok { background: var(--ok); border: 1px solid var(--ok-line); }
.flash.err { background: var(--eol); border: 1px solid var(--eol-line); }

.filters, .card {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin: 0 0 12px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 12px;
  margin-top: 12px;
}
label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 4px; }
input, select, textarea, button { font: inherit; }
input[type=text], input[type=date], select, textarea {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--input-bg);
  color: var(--fg);
}
button, .button {
  text-decoration: none;
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--button);
  border-radius: 3px;
  background: var(--button);
  color: var(--on-strong);
  cursor: pointer;
}
button.small { padding: 2px 8px; font-size: 12px; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--topbar-fg); padding: 0; }
form.inline { display: inline-flex; gap: 4px; align-items: center; margin: 0; }
form.ack { display: flex; flex-direction: column; gap: 4px; }

.subnav { display: flex; gap: 16px; margin: 0 0 16px; }
ul.plain, ul.targets { list-style: none; padding: 0; margin: 0 0 6px; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }

.newtoken code {
  display: block;
  padding: 8px;
  background: var(--secret-bg);
  border: 1px dashed var(--secret-line);
  font-size: 15px;
  word-break: break-all;
  user-select: all;
}

.login { max-width: 420px; margin: 80px auto; text-align: center; }

.constraint {
  display: inline-block;
  padding: 0 4px;
  border: 1px dashed var(--muted);
  border-radius: 3px;
  color: var(--muted);
  font-size: 12px;
}
.st-kev .muted { color: var(--on-strong); }

.pager { display: flex; gap: 16px; align-items: center; margin: 0 0 12px; }
.badge.uncovered {
  background: var(--card);
  color: var(--muted);
  border: 1px dashed var(--muted);
  font-weight: normal;
}

/* Status light: the dot carries the color, the text or aria-label the
   meaning, so color is never the only signal. */
.status-light {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  margin-left: -16px;
  border-radius: 50%;
}
.status-light:focus-visible { outline: 2px solid var(--topbar-active); outline-offset: 1px; }
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--light-unknown);
  box-shadow: 0 0 0 2px var(--light-ring);
}
.st-light-ok .dot { background: var(--light-ok); }
.st-light-degraded .dot { background: var(--light-degraded); }
.st-light-down .dot { background: var(--light-down); }
.st-light-down.status-light .dot { animation: blink 1.2s step-start infinite; }
@media (prefers-reduced-motion: reduce) {
  .st-light-down.status-light .dot { animation: none; }
}
@keyframes blink { 50% { opacity: 0.35; } }
.status-overall { display: flex; gap: 8px; align-items: center; font-size: 16px; }
.state { display: inline-flex; gap: 6px; align-items: center; }
.status-details { margin: 4px 0 0; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* One row in two slightly darker. :where() keeps the specificity at zero,
   so the status colors of the cells always win. */
:where(tbody tr:nth-child(even) > td, tbody tr:nth-child(even) > th) {
  background: var(--zebra);
}

/* Matrix: the header row and the client column stay visible while the
   table scrolls in both directions inside its own box. */
.matrix-scroll {
  max-height: calc(100vh - 230px);
  overflow: auto;
  border: 1px solid var(--line);
}
.matrix-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
table.matrix { border: 0; }
table.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--thead);
  box-shadow: inset 0 -1px 0 var(--line);
}
table.matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 180px;
  max-width: 260px;
  background: var(--card);
  box-shadow: inset -1px 0 0 var(--line);
  text-align: left;
}
table.matrix tbody tr:nth-child(even) th { background: var(--zebra); }
table.matrix thead th:first-child {
  left: 0;
  z-index: 3;
  box-shadow: inset -1px -1px 0 var(--line);
}
