:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #17202e;
  --muted: #5d6878;
  --border: #e2e6ec;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --spam: #d9483b;
  --spam-bg: #fdecea;
  --would: #b4690e;
  --would-bg: #fdf1e1;
  --ham: #2f8a57;
  --ham-bg: #e6f4ec;
  --uncertain: #8a94a6;
  --uncertain-bg: #eef0f4;
  --rescued: #6750c9;
  --rescued-bg: #efebfb;
  --accent-bg: #e9eefd;
  --banner-bg: #fff6e0;
  --banner-border: #f2d38a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #171c24;
    --surface-2: #1e2430;
    --text: #e6e9ef;
    --muted: #9aa4b4;
    --border: #2a313d;
    --accent: #6b8cff;
    --accent-text: #0f1319;
    --spam: #f07067;
    --spam-bg: #3a1e1c;
    --would: #f0a94c;
    --would-bg: #3a2c17;
    --ham: #5cc28a;
    --ham-bg: #173226;
    --uncertain: #8a94a6;
    --uncertain-bg: #262c37;
    --rescued: #a593f5;
    --rescued-bg: #2a2445;
    --accent-bg: #1f2947;
    --banner-bg: #33290f;
    --banner-border: #6b5520;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: .9rem; margin: 0 0 .25rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt { margin-top: 1rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ellipsis { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.brand-lg { font-size: 1.3rem; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

.banner { background: var(--banner-bg); border-bottom: 1px solid var(--banner-border); }
.banner-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 10px; padding-bottom: 10px; font-size: .9rem; }

/* buttons & forms */
button { font: inherit; cursor: pointer; }
.btn, .btn-ghost, .btn-small {
  border-radius: 8px; border: 1px solid transparent; padding: 7px 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn { background: var(--accent); color: var(--accent-text); }
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn-small { padding: 3px 9px; font-size: .8rem; background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-small:hover { background: var(--surface-2); }
.btn-danger { color: var(--spam); }
.btn-block { width: 100%; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-weight: 600; font-size: .88rem; }

/* layout */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 { margin-bottom: 16px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; margin: 0; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
a.tile-link { color: inherit; display: block; }
a.tile-link:hover { text-decoration: none; border-color: var(--accent); }
.tone-sorted { color: var(--accent); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.tile-value { font-size: 2rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.tile-of { font-size: 1rem; color: var(--muted); font-weight: 500; }
.tile-sub { color: var(--muted); font-size: .8rem; }
.tone-spam { color: var(--spam); }
.tone-ham { color: var(--ham); }
.tone-uncertain { color: var(--uncertain); }

/* status */
.status { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--uncertain); }
.status-ok .dot { background: var(--ham); box-shadow: 0 0 0 3px var(--ham-bg); }
.status-bad .dot { background: var(--spam); box-shadow: 0 0 0 3px var(--spam-bg); }

/* chart */
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw-spam, .bar-spam { background: var(--spam); fill: var(--spam); }
.sw-uncertain, .bar-uncertain { background: var(--uncertain); fill: var(--uncertain); }
.sw-ham, .bar-ham { background: var(--ham); fill: var(--ham); }
.bar-uncertain { opacity: .55; }
.bar-ham { opacity: .8; }
.chart-svg { width: 100%; height: auto; max-height: 240px; display: block; }
.axis { stroke: var(--border); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; text-anchor: middle; }

/* badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-spam { color: var(--spam); background: var(--spam-bg); }
.badge-would { color: var(--would); background: var(--would-bg); }
.badge-ham { color: var(--ham); background: var(--ham-bg); }
.badge-uncertain { color: var(--muted); background: var(--uncertain-bg); }
.badge-rescued { color: var(--rescued); background: var(--rescued-bg); }
.badge-sorted { color: var(--accent); background: var(--accent-bg); }

/* feed & facts */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 10px 0; border-top: 1px solid var(--border); min-width: 0; }
.feed li:first-child { border-top: 0; padding-top: 0; }
.feed-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.feed-subject { font-weight: 600; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facts { margin: 0; }
.facts div { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--border); }
.facts div:first-child { border-top: 0; padding-top: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

/* filters */
.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: .85rem; font-weight: 500; cursor: pointer; }
.chip input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.search { display: flex; gap: 8px; align-items: center; flex: 1; max-width: 460px; min-width: 240px; }
.search input[type="search"] { flex: 1; }
.card .search { max-width: none; margin-bottom: 12px; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; white-space: nowrap; }

/* table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table th.num { text-align: right; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot th { border-bottom: 0; border-top: 1px solid var(--border); }
.cell-main { min-width: 260px; max-width: 520px; }
.subject { font-weight: 600; word-break: break-word; }
.reason summary { cursor: pointer; color: var(--accent); font-size: .8rem; margin-top: 4px; }
.reason p { margin: 6px 0 0; font-size: .82rem; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }

/* lists */
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 140px; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); min-width: 0; }
.item-list li > div { min-width: 0; }
.item-list li:first-child { border-top: 0; }
.item-list.scroll { max-height: 440px; overflow-y: auto; padding-right: 4px; }
.item-list.columns { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 24px; }
.item-list.columns li:nth-child(-n+3) { border-top: 0; }

/* sorteren */
.callout { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.callout p { margin: 4px 0 0; }
.rule-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.rule-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .8rem; color: var(--muted); }
.rule-form label.grow { flex: 1; min-width: 150px; }
.rule-form label.grow input { width: 100%; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; border: 1px solid var(--border); }
.flash-ok { background: var(--ham-bg); color: var(--ham); border-color: transparent; }
.flash-error { background: var(--spam-bg); color: var(--spam); border-color: transparent; }

/* logs */
.log-card { padding: 0; overflow: hidden; }
.log { list-style: none; margin: 0; padding: 8px 0; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; max-height: calc(100vh - 260px); min-height: 300px; overflow: auto; }
.log li { display: grid; grid-template-columns: 150px 74px 1fr; gap: 10px; padding: 1px 16px; }
.log li:hover { background: var(--surface-2); }
.log .t { color: var(--muted); white-space: nowrap; }
.log .lv { font-weight: 700; }
.log .m { white-space: pre-wrap; word-break: break-word; }
.lv-INFO { color: var(--muted); }
.lv-WARNING { color: var(--would); }
.lv-ERROR, .lv-CRITICAL { color: var(--spam); }
.log mark { background: var(--would-bg); color: inherit; border-radius: 2px; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.login-card .brand svg { color: var(--accent); }
.login-card p { margin: 0 0 8px; }
.login-card input { width: 100%; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .item-list.columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .topbar-inner { gap: 10px; }
  .brand { font-size: 0; gap: 0; }
  .logout .btn-ghost { padding: 6px 10px; font-size: .82rem; }
  .banner-inner, .callout { flex-direction: column; align-items: flex-start; }
  .rule-form > label, .rule-form .btn { width: 100%; }
  .rule-form select { width: 100%; }
  .tile-value { font-size: 1.6rem; }
  .item-list.columns { grid-template-columns: 1fr; }
  .item-list.columns li:nth-child(-n+3) { border-top: 1px solid var(--border); }
  .item-list.columns li:first-child { border-top: 0; }
  .log li { grid-template-columns: 1fr; gap: 0; padding: 4px 16px; }
  .search { min-width: 0; max-width: none; width: 100%; }
  .row-actions { justify-content: flex-start; }
}
