:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #d9dce1;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok-bg: #e7f6ec; --ok-fg: #1a7f37;
  --warn-bg: #fff4e0; --warn-fg: #9a6700;
  --err-bg: #fdeaea; --err-fg: #b42318;
  --sent: #1a7f37; --deferred: #9a6700; --bounced: #b42318;
  --hold: #6b46c1; --queued: #6b7280;
  --radius: 8px;
}
:root[data-theme="dark"], :root:not([data-theme="light"]) {
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-2: #23262c;
    --border: #33373f;
    --text: #e7e9ee;
    --muted: #9aa1ab;
    --accent: #4f86f7;
    --accent-text: #0b0d10;
    --ok-bg: #12351f; --ok-fg: #4ade80;
    --warn-bg: #3a2c0f; --warn-fg: #f5c451;
    --err-bg: #3a1616; --err-fg: #f87171;
    --sent: #4ade80; --deferred: #f5c451; --bounced: #f87171;
    --hold: #a78bfa; --queued: #9aa1ab;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1c1f24;
  --surface-2: #23262c;
  --border: #33373f;
  --text: #e7e9ee;
  --muted: #9aa1ab;
  --accent: #4f86f7;
  --accent-text: #0b0d10;
  --ok-bg: #12351f; --ok-fg: #4ade80;
  --warn-bg: #3a2c0f; --warn-fg: #f5c451;
  --err-bg: #3a1616; --err-fg: #f87171;
  --sent: #4ade80; --deferred: #f5c451; --bounced: #f87171;
  --hold: #a78bfa; --queued: #9aa1ab;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.nowrap { white-space: nowrap; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand a { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--text); }
/* The logo is designed for a light background, so give it a white plate so it
   stays legible on both themes. */
.brand .logo { height: 30px; width: auto; display: block; background: #fff; padding: 3px 7px; border-radius: 6px; }
.brand .appname { font-weight: 700; }
.authlogo { display: block; height: 40px; width: auto; margin: 0 auto 1rem; background: #fff; padding: 5px 10px; border-radius: 8px; }
.mainnav { display: flex; gap: 1rem; flex: 1; }
.mainnav a { color: var(--muted); padding: .2rem 0; border-bottom: 2px solid transparent; }
.mainnav a.on { color: var(--text); border-bottom-color: var(--accent); }
.tools { display: flex; align-items: center; gap: .75rem; }
.tool { font-size: 1.1rem; text-decoration: none; }
.langtoggle a { color: var(--muted); padding: 0 .2rem; }
.langtoggle a.on { color: var(--text); font-weight: 700; }
.logout button {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: .3rem .6rem; border-radius: var(--radius); cursor: pointer;
}

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
main.centered { display: flex; justify-content: center; align-items: flex-start; padding-top: 6vh; }

.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.pagehead h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1.2rem;
}
.card.auth { width: 380px; }
.card.auth.wide { width: 560px; }

/* alerts */
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); }
.alert.error { background: var(--err-bg); color: var(--err-fg); }

/* forms */
label { display: block; margin-bottom: .9rem; font-weight: 600; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  padding: .5rem .6rem; font: inherit;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
textarea { font-family: ui-monospace, monospace; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 1.2rem; padding: 1rem 1.2rem; }
legend { font-weight: 700; padding: 0 .4rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > label { flex: 1; }
.small-field { max-width: 220px; }
button {
  font: inherit; cursor: pointer; padding: .5rem .9rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.secondary { background: var(--surface-2); }
button.danger { color: var(--bounced); }

/* stats */
.stats { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.4rem; min-width: 120px;
  display: flex; flex-direction: column;
}
.stat .num { font-size: 1.8rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stat.total { margin-left: auto; }

/* key-value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.2rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* tables */
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.grid th, table.grid td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
table.grid tr:last-child td { border-bottom: none; }
td.reason { color: var(--muted); max-width: 320px; }
.addrcell .line-from { color: var(--muted); font-size: .92em; margin-top: .1rem; }
.dur { color: var(--muted); font-size: .8em; margin-top: .2rem; }
td.actions { white-space: nowrap; }
td.actions form { display: inline; }
td.actions button { padding: .2rem .45rem; margin-left: .15rem; }

/* badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; }
.st-sent { color: var(--sent); }
.st-deferred { color: var(--deferred); }
.st-bounced { color: var(--bounced); }
.st-hold { color: var(--hold); }
.st-queued { color: var(--queued); }

/* tabs */
.tabs { display: flex; gap: .5rem; }
.tab { padding: .3rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); }
.tab.on { background: var(--surface); color: var(--text); font-weight: 600; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.timeline .ts { color: var(--muted); min-width: 160px; }
.timeline .prog { color: var(--accent); min-width: 80px; }
.timeline .txt { font-family: ui-monospace, monospace; font-size: .88em; word-break: break-word; }

/* raw log */
.rawlog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; overflow-x: auto; font-size: .85em; white-space: pre; max-height: 75vh; }

@media (max-width: 640px) {
  .mainnav { order: 3; width: 100%; }
  .card.auth, .card.auth.wide { width: 100%; }
}
