:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ea;
  --text: #1d231f;
  --muted: #64706a;
  --line: #dde2da;
  --accent: #2f5d3a;
  --accent-text: #ffffff;
  --good: #1f7a3a;
  --info: #2563a6;
  --warn: #a8640c;
  --bad: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513;
    --surface: #181d1a;
    --surface-2: #20271f;
    --text: #e3e8e1;
    --muted: #97a39b;
    --line: #2b332e;
    --accent: #80b98c;
    --accent-text: #0e140f;
    --good: #6cc785;
    --info: #79aef0;
    --warn: #e8a64a;
    --bad: #f0857b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111513;
  --surface: #181d1a;
  --surface-2: #20271f;
  --text: #e3e8e1;
  --muted: #97a39b;
  --line: #2b332e;
  --accent: #80b98c;
  --accent-text: #0e140f;
  --good: #6cc785;
  --info: #79aef0;
  --warn: #e8a64a;
  --bad: #f0857b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; }
pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; font-size: 0.82rem; white-space: pre-wrap; word-break: break-word; }
.muted, .c-muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.c-good { color: var(--good); } .c-info { color: var(--info); } .c-warn { color: var(--warn); } .c-bad { color: var(--bad); }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .brand { display: flex; gap: 8px; align-items: center; font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--surface-2); font-weight: 600; }
.topbar .count { display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 0.75rem; font-weight: 700; }
.topbar .right { margin-left: auto; display: flex; gap: 14px; align-items: center; }
main { max-width: 1280px; margin: 0 auto; padding: 18px 16px 60px; }

/* Buttons and forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 8px; font-size: 0.85rem; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
form.inline { display: inline; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; max-width: 100%; }
textarea { width: 100%; }
.form { max-width: 760px; display: flex; flex-direction: column; gap: 12px; }
.form > label, .grid-form > label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.9rem; }
.form input:not([type="checkbox"]), .form select, .grid-form input:not([type="checkbox"]) { width: 100%; font-weight: 400; }
label.check { flex-direction: row !important; align-items: center; gap: 8px; font-weight: 400 !important; }
.inline-check { display: inline-flex; margin-right: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.grid-form .span2 { grid-column: span 2; }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
.actions-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.page-head > div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.flash { padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--good) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--good) 35%, var(--line)); margin-bottom: 14px; white-space: pre-wrap; }
.flash.error { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); text-transform: lowercase; vertical-align: middle; }
.badge.good { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.badge.info { background: color-mix(in srgb, var(--info) 16%, var(--surface)); color: var(--info); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, var(--surface)); color: var(--bad); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.table th, .table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: var(--surface-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.table tr.row-bad td { background: color-mix(in srgb, var(--bad) 6%, var(--surface)); }
.table.log td { padding: 4px 10px; font-size: 0.88rem; }
.table.log tr.lvl-error td { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.table.log tr.lvl-warn td { background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.table.log tr.lvl-debug td { color: var(--muted); }
.counts { display: inline-flex; flex-wrap: wrap; gap: 10px; font-size: 0.88rem; }
.pager { display: flex; justify-content: space-between; margin: 12px 0; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 3px 10px; border-radius: 6px; text-decoration: none; }
.tabs a.active { background: var(--surface-2); font-weight: 700; color: var(--text); }

/* Dashboard */
.status-banner { padding: 16px 18px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.status-banner h1 { margin: 0 0 4px; }
.status-banner p { margin: 0; }
.status-banner.good { background: color-mix(in srgb, var(--good) 10%, var(--surface)); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.status-banner.bad { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.status-banner.warn { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.status-banner.warn h1 { color: var(--warn); }
.status-banner.good h1 { color: var(--good); } .status-banner.bad h1 { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { display: flex; flex-direction: column; padding: 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.stat strong { font-size: 1.8rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.stat.warn { border-color: var(--warn); }
.stat.warn strong { color: var(--warn); }

/* Run detail */
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0 6px; }
.counter { display: flex; flex-direction: column; padding: 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: 0.85rem; }
.counter strong { font-size: 1.5rem; color: var(--text); }
.counter.zero strong { color: var(--muted); }
.counter.k-created strong { color: var(--good); }
.counter.k-updated strong { color: var(--info); }
.counter.k-pending strong { color: var(--warn); }
.counter.k-error strong { color: var(--bad); }
.error-box { border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line)); background: color-mix(in srgb, var(--bad) 7%, var(--surface)); padding: 4px 14px; border-radius: 8px; }

/* Review / events */
.review-card { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.review-card header { font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
.review-card .notes { background: color-mix(in srgb, var(--warn) 9%, var(--surface)); padding: 6px 10px; border-radius: 6px; font-size: 0.88rem; }
.source-text { max-height: 360px; }
.empty { font-size: 1.1rem; padding: 30px 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; }
.side .preview { width: 100%; border-radius: 8px; }
.help { margin: 18px 0; max-width: 760px; }
.fetcher-help h3 { font-size: 1rem; margin-bottom: 0; }
.danger-zone { margin-top: 40px; padding-top: 16px; border-top: 1px dashed var(--line); }
.cats-table input[type="color"] { padding: 0; width: 42px; height: 30px; }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box { background: var(--surface); padding: 26px; border-radius: 12px; border: 1px solid var(--line); width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { display: flex; gap: 10px; align-items: center; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }

@media (max-width: 760px) {
  .grid-form, .two-col { grid-template-columns: minmax(0, 1fr); }
  .grid-form .span2 { grid-column: auto; }
  .topbar .right { margin-left: 0; }
}

/* Exclusion rules */
.rule-form { margin: 8px 0; }
.rule-fields { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.rule-fields > label { display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; font-weight: 600; }
.rule-fields > label.grow { flex: 1 1 200px; }
.rule-fields > label.grow input { width: 100%; }
.rule-fields > label.check { padding-bottom: 8px; }
.inline-edit { display: inline-block; }
.inline-edit[open] { display: block; margin-bottom: 6px; }
.inline-edit[open] > form { padding: 10px; margin-top: 6px; background: var(--surface-2); border-radius: 8px; white-space: normal; min-width: min(640px, 80vw); }
.inline-edit > summary { list-style: none; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.page-tabs { margin-bottom: 10px; }
.rule-group { margin-bottom: 22px; }
.rule-group h2 { margin-bottom: 6px; }
.snooze { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 4px; }
.snooze form.inline { display: inline; }
