:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #14171c; --muted: #6b7280; --line: #e5e7eb;
  --side: #0f1720; --side-ink: #cbd5e1; --accent: #2563eb; --accent-ink: #fff;
  --ok: #15803d; --ok-bg: #dcfce7; --bad: #b91c1c; --bad-bg: #fee2e2; --warn: #a16207; --warn-bg: #fef3c7;
  --info: #1d4ed8; --info-bg: #dbeafe; --radius: 8px;
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 0 10px 2px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: #94a3b8; padding: 0 10px 18px; }
.side a { display: block; color: var(--side-ink); padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
.side a:hover { background: #1e293b; }
.side a.active { background: #1e293b; color: #fff; }
.side .badge { float: right; background: #ef4444; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.top h1 { font-size: 20px; margin: 0; }
.who { color: var(--muted); font-size: 13px; }
.who button { margin-left: 10px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.section > header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.section > header h2 { font-size: 15px; margin: 0; }
.section .body { padding: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8fafc; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.scroll { overflow-x: auto; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #374151; white-space: nowrap; }
.pill.success, .pill.sent, .pill.received, .pill.active, .pill.verified, .pill.delivered, .pill.credited { background: var(--ok-bg); color: var(--ok); }
.pill.failed, .pill.rejected, .pill.blocked, .pill.disabled { background: var(--bad-bg); color: var(--bad); }
.pill.pending, .pill.processing, .pill.pending_approval, .pill.unmatched, .pill.signed, .pill.broadcast { background: var(--warn-bg); color: var(--warn); }
.pill.approved, .pill.created { background: var(--info-bg); color: var(--info); }
.pill.expired, .pill.ignored { background: #f3f4f6; color: #6b7280; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button:hover { border-color: #cbd5e1; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.sm { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; width: 100%; }
textarea { min-height: 80px; font-family: ui-monospace, monospace; font-size: 12.5px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
label.check input { width: auto; margin: 0; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters > * { width: auto; min-width: 120px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.kv > div { word-break: break-all; }
.muted { color: var(--muted); }
.secret { background: #fff7ed; border: 1px solid #fed7aa; padding: 10px 12px; border-radius: 6px; margin: 10px 0; word-break: break-all; }
.chart { width: 100%; height: 180px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.drawer-bg { position: fixed; inset: 0; background: #0006; z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--bg); z-index: 11; overflow-y: auto; padding: 22px; box-shadow: -8px 0 30px #0002; }
.drawer .close { float: right; }
.drawer h2 { margin-top: 0; font-size: 18px; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login .card { width: 360px; padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 20; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 4px 14px #0003; }
#toast div.bad { background: var(--bad); }

.md { line-height: 1.6; max-width: 900px; }
.md pre { background: #0f1720; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.md code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; color: inherit; }
.md table { margin: 10px 0; border: 1px solid var(--line); }
.md h1 { font-size: 22px; } .md h2 { font-size: 18px; margin-top: 28px; } .md h3 { font-size: 15px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: flex; flex-wrap: wrap; gap: 4px; }
  .brand-sub { display: none; }
  .main { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
}
