:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --sunken: #eef0f3;
  --text: #1a1e24;
  --muted: #5d6877;
  --border: #d8dde4;
  --accent: #2457c5;
  --on-accent: #ffffff;
  --hover: #edf2fb;
  --focus: #2f6fef;
  --critical: #b4151c;
  --high: #c2410c;
  --medium: #946200;
  --low: #1d64d8;
  --info: #5d6877;
  --ok: #18794e;
  --bad: #b4151c;
  --warn: #946200;
  --shadow: #7c3aed;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161a21;
    --sunken: #1c212a;
    --text: #e4e8ee;
    --muted: #97a2b1;
    --border: #2b323d;
    --accent: #6c9cff;
    --on-accent: #0b0e13;
    --hover: #1e2633;
    --focus: #8ab0ff;
    --critical: #ff6b6b;
    --high: #ff9350;
    --medium: #e8b440;
    --low: #6ca8ff;
    --info: #97a2b1;
    --ok: #4ccb8a;
    --bad: #ff6b6b;
    --warn: #e8b440;
    --shadow: #b494ff;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 20px 0 8px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Header */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  min-height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .04em; color: var(--text); text-decoration: none; }
#nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
#nav a, .tabs a {
  padding: 13px 10px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
#nav a:hover, .tabs a:hover { color: var(--text); }
#nav a[aria-current], .tabs a[aria-current] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); }

main { padding: 16px 20px 48px; max-width: 1600px; margin: 0 auto; }

/* Shadow mode: unmistakable everywhere it applies */

body.shadow .top { border-bottom: 3px solid var(--shadow); }
body.shadow main {
  background: repeating-linear-gradient(135deg, transparent 0 18px, color-mix(in srgb, var(--shadow) 5%, transparent) 18px 36px);
}
.shadow-banner {
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1px solid var(--shadow);
  border-left-width: 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--shadow) 10%, var(--panel));
  font-weight: 600;
}
.mode-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-toggle button { border: 0; border-radius: 0; padding: 7px 16px; font-weight: 600; }
.mode-toggle .mode-production[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.mode-toggle .mode-shadow[aria-pressed="true"] { background: var(--shadow); color: var(--on-accent); }

/* Layout pieces */

.view-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 4px 0 12px; }
.view-head h1, .view-head h2 { margin: 0; margin-right: auto; }
h2 + .view-head, .table-wrap + .view-head, .empty + .view-head { margin-top: 28px; }
.filters, .row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters { margin-bottom: 12px; }
.filters > .field:first-child { flex: 1 1 280px; }
.field .row { flex-wrap: nowrap; }
.field .row input { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.card h2 { margin-top: 0; }
.warning-card { border-color: var(--warn); border-left-width: 6px; }
.buttons { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.bulk { display: flex; gap: 8px; align-items: center; padding: 8px 10px; margin-bottom: 8px; background: var(--hover); border-radius: 6px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 10px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs a { padding: 8px 12px; }

.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.detail aside { position: sticky; top: 64px; }
.detail section { margin-bottom: 8px; }
.alert-head { margin: 4px 0 12px; }
.alert-head h1 { margin: 6px 0 2px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.ages { display: flex; gap: 32px; flex-wrap: wrap; margin: 0 0 8px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.ages dt { font-size: 12px; color: var(--muted); }
.ages dd { margin: 0; font-weight: 600; font-size: 16px; }
.ages small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }

/* Text helpers */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.wrap { overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: 12px; }
.loading { color: var(--muted); }
.empty { color: var(--muted); padding: 16px; border: 1px dashed var(--border); border-radius: 8px; text-align: center; }
.error, .warning { padding: 8px 12px; border-radius: 6px; border-left: 4px solid; margin: 8px 0; }
.error { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--panel)); }
.warning { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--panel)); }

/* Forms */

input, select, textarea, button, .button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
}
textarea { width: 100%; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; tab-size: 2; }
input:disabled, select:disabled, textarea:disabled { opacity: .75; }
button, .button { cursor: pointer; font-weight: 500; text-decoration: none; display: inline-block; }
button:hover:not(:disabled), .button:hover { background: var(--hover); }
button:disabled { cursor: default; opacity: .55; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, var(--text)); }
button.danger { color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12px; }
button.icon { padding: 0 6px; border: 0; background: none; }
button.chip { padding: 1px 8px; border-radius: 999px; margin: 2px; }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.field > span { font-weight: 600; }
.field input, .field select, .field textarea { color: var(--text); font-size: 14px; }
.field small { font-size: 12px; }
.check { display: inline-flex; gap: 6px; align-items: center; margin-right: 12px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.inline legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 3px; }
.examples { color: var(--muted); font-size: 12px; margin: -4px 0 12px; }
.composer { display: grid; gap: 6px; margin-top: 8px; justify-items: end; }
.stack .row > .field:first-child, .editor .row > .field:first-child { flex: 1 1 260px; }
input[type="number"] { max-width: 12rem; }

/* Tables */

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
thead th { position: sticky; top: 0; background: var(--sunken); font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover, tbody tr:focus-within { background: var(--hover); }
td.summary { min-width: 220px; font-weight: 500; white-space: normal; }
td.summary a { color: var(--text); text-decoration: none; }
td.summary a:hover, td.summary a:focus-visible { color: var(--accent); text-decoration: underline; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; }
table.logs td.msg { max-width: 0; width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
tr.expand > td { background: var(--sunken); }

/* Badges: color plus a text label, never color alone */

.badge {
  --c: var(--muted);
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.b-critical { --c: var(--critical); background: var(--critical); color: var(--panel); }
.b-high { --c: var(--high); }
.b-medium { --c: var(--medium); }
.b-low { --c: var(--low); }
.b-info { --c: var(--info); }
.b-shadow { --c: var(--shadow); }
.b-production, .b-ok, .b-done, .b-closed { --c: var(--ok); }
.b-error, .b-failed { --c: var(--bad); }
.b-new, .b-open, .b-running, .b-replay { --c: var(--accent); }
.b-triaged, .b-unconfigured, .b-disabled, .b-silent, .b-stale { --c: var(--warn); }

/* Records */

.event { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--panel); }
.event-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.event-meta strong, .event-meta code { color: var(--text); }
.raw-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
pre {
  margin: 6px 0;
  padding: 10px 12px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
}
pre.secret { font-size: 14px; user-select: all; }
details > summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
details .table-wrap { margin-top: 6px; }
.ids { columns: 2 360px; padding-left: 18px; font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 10px; margin: 0; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.notes { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.notes li { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.note-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.note-body { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Login */

.login { max-width: 360px; margin: 10vh auto; display: grid; gap: 14px; }
.login form { display: grid; gap: 12px; }
.login .button { text-align: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Overlays */

dialog {
  width: min(600px, 94vw);
  padding: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin-top: 0; }
dialog form { display: grid; gap: 12px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(420px, 90vw); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--panel); box-shadow: 0 6px 24px rgb(0 0 0 / .2); }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 1100px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .detail aside { position: static; }
}

@media (max-width: 760px) {
  main { padding: 12px; }
  .top { gap: 8px; padding: 0 12px; }
  .ages { gap: 16px; }
}
