:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d232b;
  --muted: #5d6875;
  --line: #dfe3e8;
  --brand: #1f5f8b;
  --brand-ink: #ffffff;
  --ok: #1e7b4d;
  --ok-bg: #e7f5ee;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --err: #a32121;
  --err-bg: #fdeaea;
  --demo: #b54708;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
pre { background: #f0f2f5; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

.demo-banner { position: sticky; top: 0; z-index: 50; background: var(--demo); color: #fff; padding: .45rem 1rem; font-size: .9rem; text-align: center; }
.demo-banner .sim-time { margin-left: .75rem; background: rgba(0,0,0,.2); padding: .1rem .5rem; border-radius: 4px; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; flex: 1; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.mode { font-size: .75rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; }
.mode-demo { background: #fde7d6; color: var(--demo); }
.mode-live { background: var(--ok-bg); color: var(--ok); }
.mode-blocked { background: var(--warn-bg); color: var(--warn); }
.pause-form, .logout-form { display: flex; align-items: center; gap: .5rem; margin: 0; }
.paused-label { color: var(--err); font-weight: 700; font-size: .85rem; }

.shell { display: flex; min-height: calc(100vh - 56px); }
.sidenav { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .5rem; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { padding: .45rem .75rem; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: .93rem; }
.sidenav a.active, .sidenav a:hover { background: #e9f1f7; color: var(--brand); }
main { flex: 1; padding: 1.5rem; min-width: 0; max-width: 1200px; }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: .45rem .9rem; border-radius: 6px; font-size: .9rem; cursor: pointer; text-decoration: none; font-family: inherit; }
.btn:hover { border-color: #b8c0ca; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-danger { background: var(--err); color: #fff; border-color: var(--err); }
.btn-pause { background: #fff; color: var(--err); border-color: var(--err); font-weight: 600; }
.btn-resume { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 600; }
.btn-link { border: none; background: none; color: var(--muted); padding: .2rem; }
.btn-small { padding: .25rem .6rem; font-size: .82rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .5rem 0; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.callout { background: var(--warn-bg); color: var(--warn); padding: .7rem 1rem; border-radius: var(--radius); margin: .75rem 0; }
.callout.info { background: #e9f1f7; color: #174a6d; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.metric .value { font-size: 1.7rem; font-weight: 700; }
.metric .label { font-weight: 600; font-size: .9rem; }
.metric .def { color: var(--muted); font-size: .78rem; margin-top: .3rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f0f2f5; font-weight: 600; font-size: .82rem; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eceff3; color: var(--muted); white-space: nowrap; }
.pill-sent, .pill-succeeded, .pill-ok, .pill-booked, .pill-active, .pill-acknowledged, .pill-delivered { background: var(--ok-bg); color: var(--ok); }
.pill-replied, .pill-contacted, .pill-pending, .pill-running, .pill-completed { background: #e9f1f7; color: #174a6d; }
.pill-held, .pill-ambiguous, .pill-paused, .pill-needs_restart, .pill-draft, .pill-new { background: var(--warn-bg); color: var(--warn); }
.pill-failed, .pill-cancelled, .pill-declined, .pill-spam, .pill-stopped, .pill-bounced_hard, .pill-complained { background: var(--err-bg); color: var(--err); }

form.stack { display: grid; gap: .8rem; max-width: 640px; }
label { font-weight: 600; font-size: .9rem; display: grid; gap: .3rem; }
label.inline { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=time], select, textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid #c7ced6; border-radius: 6px; background: #fff; width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
.hint { color: var(--muted); font-size: .82rem; font-weight: 400; }
.field-error { color: var(--err); font-size: .82rem; font-weight: 600; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.empty { color: var(--muted); font-style: italic; }
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; word-break: break-word; }
.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 28px 1fr; gap: .4rem; }
.check-list li:last-child { border-bottom: none; }
.check-ok { color: var(--ok); font-weight: 700; }
.check-no { color: var(--err); font-weight: 700; }
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1rem 1rem 3.2rem; margin-bottom: .75rem; position: relative; }
.steps > li::before { content: counter(step); position: absolute; left: 1rem; top: 1rem; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.steps > li.done::before { background: var(--ok); content: "✓"; }
.outbox-label { background: #fde7d6; color: var(--demo); font-weight: 700; padding: .5rem .8rem; border-radius: var(--radius); margin-bottom: 1rem; }
.mail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .8rem; }
.mail header { padding: .6rem .9rem; border-bottom: 1px solid var(--line); font-size: .87rem; display: grid; gap: .15rem; }
.mail pre { margin: 0; border: none; border-radius: 0 0 var(--radius) var(--radius); background: #fbfbfc; }

.public main.public-main, .public-main { max-width: 640px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.public-brand { font-size: 1.4rem; font-weight: 700; margin: 1rem 0 1.2rem; color: var(--brand); }
.public-footer { margin-top: 2rem; color: var(--muted); font-size: .82rem; }
.login-box { max-width: 380px; margin: 3rem auto; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidenav { width: 100%; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: .5rem; }
  .sidenav a { white-space: nowrap; }
  main { padding: 1rem 16px; }
  .two-col { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: .4rem; }
}
.btn-row select, .btn-row input[type=text], .btn-row input[type=email] { width: auto; min-width: 0; }
.btn-row form { margin: 0; }
.reason-attn { color: var(--warn); font-weight: 600; }
table.queue td { min-width: 110px; }
