:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e5e5e8;
  --text: #16171a;
  --text-muted: #6b6f76;
  --accent: #16171a;
  --accent-contrast: #ffffff;
  --green: #16803c;
  --green-bg: #e8f5ec;
  --blue: #1d5fd6;
  --blue-bg: #eaf0fd;
  --red: #c22a2a;
  --red-bg: #fbe9e9;
  --amber: #a66a00;
  --amber-bg: #fdf3e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,17,20,0.04), 0 4px 16px rgba(16,17,20,0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand-mark { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.topbar nav { display: flex; gap: 18px; align-items: center; font-size: 13px; color: var(--text-muted); }
.topbar nav a:hover { color: var(--text); }
.topbar form { margin: 0; }
.topbar button.link { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0; }
.topbar button.link:hover { color: var(--text); }

.container { max-width: 1080px; margin: 0 auto; padding: 32px 28px 80px; }
.container.narrow { max-width: 760px; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: 13px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.brand-list { display: grid; gap: 14px; }
.brand-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; text-decoration: none; box-shadow: var(--shadow); transition: transform .08s ease, border-color .08s ease;
}
.brand-card:hover { border-color: #cfd0d4; }
.brand-card .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 10px; }
.brand-card .name { font-weight: 600; font-size: 15px; }
.brand-card .meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.brand-card .stats { display: flex; gap: 22px; text-align: right; }
.brand-card .stats .num { font-weight: 700; font-size: 16px; }
.brand-card .stats .lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-tile .num { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat-tile .lbl { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--text-muted); font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active, .badge.delivered, .badge.sent { background: var(--green-bg); color: var(--green); }
.badge.opened { background: var(--blue-bg); color: var(--blue); }
.badge.clicked { background: #eee7fb; color: #6528d6; }
.badge.unsubscribed, .badge.failed, .badge.bounced { background: var(--red-bg); color: var(--red); }
.badge.queued, .badge.draft, .badge.deferred { background: var(--amber-bg); color: var(--amber); }
.badge.sending { background: var(--blue-bg); color: var(--blue); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #c7c8cc; }
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--red); border-color: #f0cfcf; }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=color], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit;
  background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: #a8a9ae; }
.help { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-row { margin-bottom: 0; flex: 1; min-width: 160px; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state h2 { color: var(--text); }

.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(16,17,20,.4); z-index: 50;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: 12px; padding: 24px; width: 420px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.editor-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; height: 70vh; }
.editor-wrap textarea#htmlSource { height: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.editor-wrap iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }

.merge-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.merge-tags code { background: #f1f1f3; padding: 3px 7px; border-radius: 6px; font-size: 11px; cursor: pointer; }
.merge-tags code:hover { background: #e6e6e9; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; }
.error-box { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width .3s ease; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.text-muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
