:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --sunken: #f4f4f5;
  --fg: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #18181b;
  --accent-fg: #ffffff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --panel: #111113;
    --sunken: #18181b;
    --fg: #fafafa;
    --muted: #a1a1aa;
    --line: #27272a;
    --accent: #fafafa;
    --accent-fg: #09090b;
    --good: #4ade80;
    --good-bg: #14532d55;
    --warn: #facc15;
    --warn-bg: #713f1255;
    --bad: #f87171;
    --bad-bg: #7f1d1d55;
    --info: #60a5fa;
    --info-bg: #1e3a8a55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: inherit; }
code, pre, textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand .logo { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-size: 13px; }
.side h6 { margin: 8px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ws-link { display: flex; justify-content: space-between; gap: 8px; text-decoration: none; padding: 7px 8px; border-radius: 8px; }
.ws-link:hover { background: var(--sunken); }
.ws-link.active { background: var(--sunken); font-weight: 600; }
.ws-link small { color: var(--muted); font-variant-numeric: tabular-nums; }
.ws-link small.warn-text { color: var(--warn); font-weight: 600; }
.side .spacer { flex: 1; }

.main { padding: 24px 32px 64px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin: 0; font-size: 22px; }
.head .sub { color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--fg); border-color: var(--fg); font-weight: 600; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stat { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: 20px; margin-top: 10px; }
.stats div span { display: block; font-size: 12px; color: var(--muted); }
.stats b { font-size: 18px; font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--sunken); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.primary:hover { opacity: .9; }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--muted); }
button.link:hover { color: var(--fg); background: none; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--sunken); }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); }
.badge.active, .badge.sent { background: var(--good-bg); color: var(--good); }
.badge.unsubscribed, .badge.paused, .badge.draft { background: var(--sunken); color: var(--muted); }
.badge.sending, .badge.queued { background: var(--info-bg); color: var(--info); }
.badge.failed, .badge.bounced { background: var(--bad-bg); color: var(--bad); }
.badge.log, .badge.pending { background: var(--warn-bg); color: var(--warn); }

.snippet { position: relative; }
.snippet pre { background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 4px 0 0; overflow-x: auto; white-space: pre; max-height: 220px; }
.snippet button { position: absolute; top: 8px; right: 8px; font-size: 12px; padding: 3px 8px; }

.composer { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.composer textarea { min-height: 420px; line-height: 1.55; }
.preview-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: var(--radius); background: #f4f4f5; }
.progress { height: 8px; background: var(--sunken); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--good); transition: width .4s; }

.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.notice.info { background: var(--info-bg); color: var(--info); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--fg); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
dialog .dlg-body { padding: 16px 20px; overflow-y: auto; }
dialog .dlg-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-fg); padding: 9px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.error { background: var(--bad); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 16px; }
  .composer, .form-grid { grid-template-columns: 1fr; }
  .preview-frame { height: 420px; }
}
.step-title { margin: 6px 0 2px; font-size: 13px; color: var(--muted); font-weight: 600; }
.step-title.current { color: var(--fg); }
