:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #c0262d;
  --bad-soft: #fdebec;
  --code: #f2f4f7;
  --side: #111827;
  --side-text: #c9ced8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --panel: #161b22;
    --text: #e6e8eb;
    --muted: #8b949e;
    --line: #2a313c;
    --accent: #5b8def;
    --accent-soft: #1b2638;
    --ok: #4ade80;
    --ok-soft: #12261a;
    --warn: #f0b155;
    --warn-soft: #2b2112;
    --bad: #f87171;
    --bad-soft: #2d1416;
    --code: #0d1117;
    --side: #0b0e14;
    --side-text: #9aa3b0;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 520px; white-space: pre-wrap; word-break: break-all; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.break { overflow-wrap: break-word; }
.table-wrap table.wide { min-width: 760px; }

/* ---------- khung ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; padding: 4px 10px 18px; }
.brand svg { width: 26px; height: 26px; }
.brand small { display: block; font-weight: 400; color: var(--side-text); font-size: 11.5px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 8px 10px; border-radius: 8px; margin: 1px 0; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .1); color: #fff; }
.side .foot { margin-top: auto; padding: 10px; font-size: 12.5px; }
.side .foot button { background: none; border: 0; color: var(--side-text); padding: 0; cursor: pointer; font: inherit; }
.side .foot button:hover { color: #fff; }
.main { padding: 28px 32px 48px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ---------- thành phần ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.grid.k { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
a.kpi { color: var(--text); }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value.ok { color: var(--ok); }
.kpi .value.warn { color: var(--warn); }
.kpi .value.bad { color: var(--bad); }

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; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--panel); }
tbody tr:hover { background: var(--accent-soft); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--code); color: var(--muted); white-space: nowrap; }
.badge.sent, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.deferred, .badge.queued, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bounced, .badge.expired, .badge.bad, .badge.missing { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--bad); }
.dot.on { background: var(--ok); }

/* ---------- form ---------- */
label { display: block; font-weight: 550; margin-bottom: 4px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
input[type=text], input[type=password], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit;
}
textarea { min-height: 180px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.row > .field { flex: 1 1 180px; margin-bottom: 0; }
.row > .field.grow { flex: 3 1 260px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }
.addr { display: flex; align-items: center; gap: 6px; }
.addr span { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.filters input, .filters select { width: auto; flex: 1 1 140px; }
.filters input[type=search] { flex: 3 1 220px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs label { font-weight: 500; display: flex; gap: 6px; align-items: center; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btn svg { width: 15px; height: 15px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-soft); }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-soft); }
.secret { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; }
.secret .pw { font-size: 16px; font-weight: 600; background: var(--panel); padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); display: inline-block; margin: 6px 6px 6px 0; user-select: all; }

.dns td.value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; min-width: 160px; max-width: 520px; }
.copy { cursor: pointer; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.pager { display: flex; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--line); }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); }

.chart { width: 100%; height: 150px; display: block; }
.chart .sent { fill: var(--ok); }
.chart .failed { fill: var(--bad); }
.chart .deferred { fill: var(--warn); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend .sent { background: var(--ok); }
.legend .failed { background: var(--bad); }
.legend .deferred { background: var(--warn); }

/* ---------- đăng nhập ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { color: var(--text); justify-content: center; padding-bottom: 8px; }
.login .brand small { color: var(--muted); }

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 4px; }
  .brand { padding: 4px 8px; }
  .brand small { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; width: 100%; }
  .nav a { padding: 6px 8px; }
  .nav a span { display: none; }
  .side .foot { margin: 0 0 0 auto; padding: 4px 8px; }
  .main { padding: 18px 16px 40px; }
  .kv { grid-template-columns: 1fr; }
}
