:root {
  --bg: #0d1015;
  --panel: #151a21;
  --panel-2: #1b222b;
  --line: #262f3a;
  --text: #e6edf3;
  --muted: #8b97a6;
  --accent: #5b8cff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 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; }

/* ---------- layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 650;
  color: var(--text);
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand:hover { text-decoration: none; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(63,185,80,.15);
}

.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 14px;
}
.topbar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.topbar nav a.on { background: var(--panel-2); color: var(--text); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.narrow { max-width: 420px; margin: 0 auto; padding: 12vh 24px; }

/* ---------- type ---------- */

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 14px; letter-spacing: -.01em; }
.subtitle { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.small { font-size: 13px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

/* ---------- panels ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .n { font-size: 30px; font-weight: 620; letter-spacing: -.03em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 3px; }
.stat.bad .n { color: var(--err); }
.stat.good .n { color: var(--ok); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 0 12px 8px; border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.table-scroll { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { color: var(--muted); text-align: center; padding: 34px 0; font-size: 14px; }

/* ---------- badges ---------- */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.5;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.sent, .badge.routed, .badge.on { background: rgba(63,185,80,.13); color: var(--ok); border-color: rgba(63,185,80,.3); }
.badge.failed, .badge.error, .badge.off { background: rgba(248,81,73,.13); color: var(--err); border-color: rgba(248,81,73,.3); }
.badge.pending, .badge.sending, .badge.received { background: rgba(91,140,255,.13); color: var(--accent); border-color: rgba(91,140,255,.3); }
.badge.no_match, .badge.ignored, .badge.cancelled { background: rgba(210,153,34,.13); color: var(--warn); border-color: rgba(210,153,34,.3); }

/* ---------- forms ---------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=email], input[type=number], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}
textarea { min-height: 76px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,140,255,.16);
}
.field { margin-bottom: 16px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.field .err { color: var(--err); font-size: 12px; margin-top: 5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.check input { width: auto; }
.check label { margin: 0; color: var(--text); font-size: 14px; }

button, .btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  padding: 9px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.1); text-decoration: none; }
button.secondary, .btn.secondary {
  background: var(--panel-2); color: var(--text); border-color: var(--line);
}
button.danger, .btn.danger { background: transparent; color: var(--err); border-color: rgba(248,81,73,.4); }
button.danger:hover { background: rgba(248,81,73,.1); filter: none; }
button.small, .btn.small { padding: 5px 10px; font-size: 13px; }
button.link {
  background: none; border: none; color: var(--muted); padding: 0;
  font-size: 14px; text-decoration: none;
}
button.link:hover { color: var(--text); filter: none; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.inline-form { display: inline; }

/* ---------- flash ---------- */

.flash {
  padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
  border: 1px solid;
}
.flash.success { background: rgba(63,185,80,.1); border-color: rgba(63,185,80,.3); color: #7ee787; }
.flash.error { background: rgba(248,81,73,.1); border-color: rgba(248,81,73,.3); color: #ff9d96; }
.flash.warn { background: rgba(210,153,34,.1); border-color: rgba(210,153,34,.3); color: #e3b341; }

/* ---------- misc ---------- */

pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px;
  line-height: 1.5; margin: 0;
}
.copyfield {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 11px;
  font-family: var(--mono); font-size: 13px;
  overflow-x: auto;
}
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 150px; }
.filters label { font-size: 12px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 18px; color: var(--muted); font-size: 14px; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 44px; margin-top: 6px; }
.spark i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .8; }
.spark i:hover { opacity: 1; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.rule-line { font-family: var(--mono); font-size: 13px; }
