:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #5b6676;
  --faint: #8a94a3;
  --line: #e3e8ef;
  --line-strong: #cfd6e0;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #a16207;
  --warn-soft: #fdf4dc;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #0e7490;
  --info-soft: #e3f5f8;
  --violet: #6d28d9;
  --violet-soft: #f0eafd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e6edf3;
    --muted: #9aa5b1;
    --faint: #6e7781;
    --line: #2a313b;
    --line-strong: #3a434f;
    --accent: #5b8def;
    --accent-hover: #7aa2f3;
    --accent-soft: #1a2640;
    --on-accent: #0d1117;
    --ok: #4ac26b;
    --ok-soft: #12261a;
    --warn: #e3b341;
    --warn-soft: #2b2311;
    --bad: #f47067;
    --bad-soft: #2d1416;
    --info: #39c5cf;
    --info-soft: #0f2629;
    --violet: #a78bfa;
    --violet-soft: #221a36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; font-weight: 650; }
h2 { font-size: 1.02rem; font-weight: 620; }
h3 { font-size: .92rem; font-weight: 620; }
p { margin: 0 0 .6em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .84rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── controls ─────────────────────────────────────────────────────────── */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, .select:focus-visible, .chip-input:focus-visible,
.nav a:focus-visible, .seg button:focus-visible, .mode-card:focus-within {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: .86rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.input, .select, textarea.input {
  width: 100%; min-height: 38px; padding: 7px 11px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
}
textarea.input { min-height: 90px; resize: vertical; }
.input::placeholder { color: var(--faint); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--muted); }
.field { display: grid; gap: 5px; }
.field > label, .label { font-weight: 560; font-size: .88rem; }
.field .hint { font-size: .8rem; color: var(--muted); }
.form-grid { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-unit { position: relative; }
.inline-unit .input { padding-right: 52px; }
.inline-unit span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: .85rem; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; padding: 3px; background: var(--surface-2); gap: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-weight: 560; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button:disabled { cursor: not-allowed; }

/* ── badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.m-filtered { background: var(--info-soft); color: var(--info); }
.m-blocklist { background: var(--violet-soft); color: var(--violet); }
.m-exempt { background: var(--ok-soft); color: var(--ok); }
.m-suspended { background: var(--bad-soft); color: var(--bad); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-muted { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.inherit { font-size: .74rem; color: var(--faint); margin-left: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); margin-right: 7px; vertical-align: 1px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* ── layout ───────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.app-body { min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 750; font-size: .95rem; flex: none;
}
.brand-name { font-weight: 680; line-height: 1.2; }
.brand-sub { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 550; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 6px; }
.nav-label { font-size: .72rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); padding: 4px 10px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.whoami { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 650; font-size: .85rem; flex: none; }
.whoami .who { min-width: 0; }
.whoami .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar { display: none; }
.main { min-width: 0; padding: 28px 32px 56px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.content { max-width: 1240px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.card-body { padding: 16px 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 550; }
.kpi .value { font-size: 1.75rem; font-weight: 680; margin-top: 4px; letter-spacing: -.01em; }
.kpi .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }

.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); font-size: .88rem; }
.callout.warn { background: var(--warn-soft); border-color: transparent; }
.callout.info { background: var(--accent-soft); border-color: transparent; }
.callout strong { font-weight: 640; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 10px; font-size: .86rem; }
.bar-track { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-fill.m-filtered { background: var(--info); }
.bar-fill.m-blocklist { background: var(--violet); }
.bar-fill.m-exempt { background: var(--ok); }
.bar-fill.m-suspended { background: var(--bad); }

/* ── tables ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.scroll-pane { max-height: 520px; overflow: auto; }
.break { overflow-wrap: anywhere; min-width: 7rem; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  font-size: .76rem; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { opacity: .6; margin-left: 4px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tbody tr.selected td { background: var(--accent-soft); }
td.check-col, th.check-col { width: 40px; padding-right: 0; }
.cell-main { font-weight: 560; }
.cell-sub { color: var(--muted); font-size: .8rem; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: .98rem; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar .search { flex: 1 1 240px; min-width: 200px; }
.toolbar .select { width: auto; min-width: 140px; }
.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px;
  background: var(--accent-soft); border-bottom: 1px solid var(--line);
}
.bulkbar strong { color: var(--accent); margin-right: 6px; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; color: var(--muted); font-size: .84rem; border-top: 1px solid var(--line); }

/* ── chips (list editor) ──────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 34px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); max-height: 280px; overflow-y: auto; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line-strong); font-size: .85rem; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--faint); width: 22px; height: 22px; border-radius: 4px; display: grid; place-items: center; }
.chip button:hover { background: var(--bad-soft); color: var(--bad); }
.chips .none { color: var(--faint); font-size: .85rem; padding: 2px 4px; }
.chip-add { display: flex; gap: 8px; margin-top: 8px; }
.chip-input { flex: 1; }
.list-section + .list-section { margin-top: 18px; }
.list-section .label { display: flex; justify-content: space-between; margin-bottom: 6px; }

/* ── mode picker ──────────────────────────────────────────────────────── */
.modes { display: grid; gap: 8px; }
.mode-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 9px; cursor: pointer; }
.mode-card:hover { background: var(--surface-2); }
.mode-card.on { border-color: var(--accent); background: var(--accent-soft); }
.mode-card input { margin-top: 3px; accent-color: var(--accent); }
.mode-card .t { font-weight: 600; }
.mode-card .d { color: var(--muted); font-size: .82rem; }

/* ── overlays ─────────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 40; animation: fade .12s ease-out; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
}
.modal-head { padding: 18px 20px 4px; }
.modal-head p { color: var(--muted); margin: 4px 0 0; }
.modal-body { padding: 14px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.drawer {
  position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(500px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: slide .16s ease-out;
}
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; display: grid; gap: 20px; align-content: start; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.section-title { font-size: .76rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .88rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.secret-box { display: flex; gap: 8px; align-items: center; padding: 12px; border-radius: 9px; background: var(--surface-2); border: 1px dashed var(--line-strong); }
.secret-box code { font-size: 1.05rem; letter-spacing: .04em; flex: 1; word-break: break-all; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }

.toasts { position: fixed; z-index: 60; bottom: 20px; right: 20px; display: grid; gap: 8px; }
.toast {
  min-width: 260px; max-width: 420px; padding: 11px 14px; border-radius: 9px; box-shadow: var(--shadow-lg);
  background: var(--text); color: var(--bg); font-size: .9rem; animation: fade .15s ease-out;
}
.toast.bad { background: var(--bad); color: #fff; }

/* ── auth screens ─────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); padding: 30px 28px; }
.auth-card .brand { padding: 0 0 22px; }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 6px; }
.auth-card .lead { color: var(--muted); margin-bottom: 20px; }
.auth-card .btn.primary { width: 100%; min-height: 40px; }
.form-error { color: var(--bad); font-size: .86rem; min-height: 1.3em; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 10px; border: 1px solid var(--line); margin: 6px 0 14px; }
.qr img { width: 196px; height: 196px; image-rendering: pixelated; }
.code-input { font-size: 1.4rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.steps { display: grid; gap: 4px; margin: 0 0 16px; padding-left: 18px; color: var(--muted); font-size: .9rem; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 28px 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── responsive ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 45; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .18s; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .main { padding: 20px 16px 48px; }
  .grid-2, .grid-3, .two { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 1.4rem; }
  .bar-row { grid-template-columns: 100px 1fr 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── live phone ──────────────────────────────────────────────────────── */
.phone-layout { display: grid; grid-template-columns: minmax(300px, 440px) minmax(0, 1fr); gap: 16px; align-items: start; }
.phone-body { display: grid; justify-items: center; gap: 12px; }
.phone-frame {
  position: relative; display: grid; place-items: center; background: #0b0d10; border-radius: 30px;
  padding: 12px; box-shadow: var(--shadow-lg); max-width: 100%;
}
.phone-screen {
  display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 260px); min-height: 320px;
  border-radius: 20px; background: #000; outline: none; touch-action: none; user-select: none;
}
.phone-screen.interactive { cursor: pointer; }
.phone-screen.interactive:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.phone-overlay {
  position: absolute; inset: 12px; display: grid; place-content: center; justify-items: center; gap: 12px;
  padding: 28px; text-align: center; color: #d6dde6; border-radius: 20px; background: rgba(0, 0, 0, .72);
}
.phone-overlay[hidden] { display: none; }
.phone-overlay p { margin: 0; max-width: 30ch; line-height: 1.45; }
.phone-frame:fullscreen { border-radius: 0; padding: 0; background: #000; }
.phone-frame:fullscreen .phone-screen { max-height: 100vh; border-radius: 0; }
.phone-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.phone-controls[hidden] { display: none; }
.phone-hint { margin: 0; text-align: center; }
.feed { max-height: calc(100vh - 300px); min-height: 320px; }
.feed tr.fresh td { animation: fresh 2.4s ease-out; }
.feed tr.fresh-bad td { animation-name: fresh-bad; }
.feed tr.fresh-warn td { animation-name: fresh-warn; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
@keyframes fresh-bad { from { background: var(--bad-soft); } to { background: transparent; } }
@keyframes fresh-warn { from { background: var(--warn-soft); } to { background: transparent; } }
.phone-notes { padding: 0 4px; }
.phone-notes summary { cursor: pointer; font-weight: 560; color: var(--text); }
.phone-notes ol { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 4px; }
@media (max-width: 960px) {
  .phone-layout { grid-template-columns: minmax(0, 1fr); }
}

/* IP suggestions: resolved name beside the address */
.ip-name { color: var(--muted); font-weight: 400; }
