:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #16191f;
  --muted: #646b78;
  --primary: #2f5bea;
  --primary-text: #ffffff;
  --green: #12805c;
  --green-bg: #e3f5ed;
  --red: #c4302b;
  --red-bg: #fbe7e6;
  --amber: #a15c00;
  --amber-bg: #fdf1dc;
  --gray-bg: #eceef2;
  --blue-bg: #e6ecfd;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --border: #2a2f39;
    --text: #e8eaee; --muted: #9aa2b1; --primary: #6c8cff; --primary-text: #0f1115;
    --green: #4fd1a1; --green-bg: #12352a; --red: #ff7a73; --red-bg: #3d1a19;
    --amber: #f2b35b; --amber-bg: #3a2b12; --gray-bg: #262a33; --blue-bg: #1c2645;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  background: var(--primary); color: var(--primary-text); border-radius: 6px;
  padding: 2px 6px; font-size: 12px; font-family: var(--mono);
}
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-weight: 500;
}
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--blue-bg); color: var(--primary); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stack > * + * { margin-top: 16px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stat.bad .stat-value { color: var(--red); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
label { display: block; font-weight: 550; margin-bottom: 12px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 160px; margin-bottom: 0; }
.filters { margin-bottom: 12px; }
.filters label { flex: 1 1 130px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* Toggle */
.switch { display: flex; align-items: center; gap: 12px; font-weight: 550; cursor: pointer; }
.switch input { display: none; }
.switch .track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--gray-bg); position: relative; flex: none;
  border: 1px solid var(--border); transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .track { background: var(--green); border-color: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trunc { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-FORWARDED { background: var(--green-bg); color: var(--green); }
.b-FILTERED { background: var(--gray-bg); color: var(--muted); }
.b-FAILED, .b-UNAUTHORIZED { background: var(--red-bg); color: var(--red); }
.b-INVALID, .b-DUPLICATE { background: var(--amber-bg); color: var(--amber); }
.b-PENDING { background: var(--blue-bg); color: var(--primary); }
.b-PASS { background: var(--blue-bg); color: var(--primary); margin-left: 4px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.on { background: var(--green-bg); color: var(--green); }
.pill.off { background: var(--amber-bg); color: var(--amber); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-warn { background: var(--amber-bg); color: var(--amber); }
.alert-info { background: var(--blue-bg); color: var(--primary); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Code boxes */
.codebox {
  font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; word-break: break-all; white-space: pre-wrap; margin: 0;
}
.copy-row { display: flex; gap: 8px; align-items: flex-start; }
.copy-row .codebox { flex: 1; }

/* Key/value list */
dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; }
@media (max-width: 640px) { dl.kv { grid-template-columns: 1fr; } dl.kv dd { margin-bottom: 6px; } }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); }
.modal-panel { position: relative; width: 100%; max-width: 860px; }
.modal-close { position: absolute; top: 12px; right: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 550;
}

/* Login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; margin-top: 4px; }

.steps { counter-reset: step; }
.step-title { display: flex; align-items: center; gap: 10px; }
.step-title::before {
  counter-increment: step; content: counter(step);
  width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: var(--primary-text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex: none;
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 12px; }
  .topbar-right { margin-left: 0; }
}
