:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-hover: #f8f9fc;
  --border: #e3e6ec;
  --border-strong: #ccd1db;
  --ink: #171a26;
  --ink-soft: #565c72;
  --ink-faint: #8a90a3;
  --accent: #3454d1;
  --accent-hover: #2842ab;
  --accent-soft: #e8ecfc;
  --accent-ink: #24399c;
  --good: #1b8a4c;
  --good-soft: #e3f6ea;
  --warn: #a8660a;
  --warn-soft: #fbf0dc;
  --bad: #c23b3b;
  --bad-soft: #fbe8e8;
  --neutral-soft: #eef0f4;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(23, 26, 38, 0.06);
  --shadow-md: 0 4px 16px rgba(23, 26, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1 { font-size: 1.55rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 0; }
p { margin: 0 0 10px; }

svg { width: 18px; height: 18px; display: block; }

/* ---------- topbar ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 58px;
}
.brand {
  font-weight: 800;
  color: var(--ink);
  font-size: 1rem;
  letter-spacing: -0.01em;
  margin-right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.brand-mark svg { width: 15px; height: 15px; }

.topbar nav { display: flex; gap: 2px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  position: relative;
}
.nav-link:hover { background: var(--surface-hover); text-decoration: none; color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-link svg { width: 16px; height: 16px; }

.logout-form { display: flex; align-items: center; gap: 12px; }
.whoami { color: var(--ink-faint); font-size: 0.85rem; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--bad);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
}

/* ---------- page shell ---------- */

.page { max-width: 1080px; margin: 0 auto; padding: 28px 24px 96px; }

.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 0.84rem; color: var(--ink-faint); margin-bottom: 14px; }
.breadcrumbs a { color: var(--ink-soft); font-weight: 600; }
.breadcrumbs .sep { color: var(--border-strong); }
.breadcrumbs .current { color: var(--ink); font-weight: 600; }

.auth-card {
  max-width: 380px;
  margin: 100px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-md);
}
.auth-card h1 { text-align: center; margin-bottom: 22px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 40px 0 14px;
}
.section-head h2 { display: flex; align-items: center; gap: 8px; }
.section-head h2 svg { color: var(--ink-faint); width: 17px; height: 17px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- stats ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { font-size: 0.78rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

/* ---------- cards / grids ---------- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
a.entity-card { color: inherit; }
a.entity-card:hover { text-decoration: none; box-shadow: var(--shadow-sm); border-color: var(--border-strong); }

.entity-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.entity-card-title { font-weight: 700; font-size: 0.98rem; }
.entity-card-meta { color: var(--ink-faint); font-size: 0.82rem; line-height: 1.5; }
.entity-card-stats { display: flex; gap: 16px; margin-top: 2px; }
.entity-card-stats .mini-stat { display: flex; flex-direction: column; }
.entity-card-stats .mini-stat-value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
.entity-card-stats .mini-stat-label { font-size: 0.72rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.entity-card-actions { display: flex; justify-content: flex-end; }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.92rem;
}
.empty-state svg { width: 26px; height: 26px; margin: 0 auto 10px; color: var(--border-strong); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table th { background: var(--neutral-soft); font-weight: 700; color: var(--ink-soft); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-hover); }
.table td.wrap { white-space: normal; }

/* ---------- pills / dots ---------- */

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: capitalize;
  background: var(--neutral-soft);
  color: var(--ink-soft);
}
.pill-active, .pill-sent, .pill-completed { background: var(--good-soft); color: var(--good); }
.pill-draft, .pill-paused, .pill-pending { background: var(--warn-soft); color: var(--warn); }
.pill-archived, .pill-failed { background: var(--bad-soft); color: var(--bad); }
.pill-queued, .pill-sending { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: 16px; max-width: 560px; }
.form.wide { max-width: none; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; color: var(--ink-soft); font-weight: 600; }
.form input, .form textarea {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
}
.form input:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form textarea { resize: vertical; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.85rem; }
.form .checkbox { flex-direction: row; align-items: center; gap: 8px; }
.form .checkbox input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.hint { font-size: 0.78rem; color: var(--ink-faint); font-weight: 400; }
.field-with-count { display: flex; align-items: center; justify-content: space-between; }
.recipient-count { font-size: 0.78rem; font-weight: 700; color: var(--ink-faint); }
.recipient-count.has-recipients { color: var(--good); }

.add-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px 18px 18px; margin-top: 10px; }
.add-form summary { cursor: pointer; padding: 13px 0; font-weight: 700; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; }
.add-form summary svg { width: 16px; height: 16px; }
.add-form .form { max-width: none; margin-top: 6px; }

.compose-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 760px) { .compose-grid { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */

.btn, .btn-secondary, button[type="submit"] {
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn, button[type="submit"] { background: var(--accent); color: #fff; }
.btn:hover, button[type="submit"]:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { background: var(--neutral-soft); color: var(--ink-faint); cursor: not-allowed; }
.btn-secondary { background: var(--neutral-soft); color: var(--ink-soft); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }
a.btn, a.btn-secondary { display: inline-flex; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-soft); }
.icon-btn svg { width: 15px; height: 15px; }

.link-btn { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--bad); }

.inline-form { display: inline-flex; }

/* ---------- alerts ---------- */

.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 0.88rem; margin: 0 0 16px; }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-warning { background: var(--warn-soft); color: var(--warn); }

/* ---------- step indicator ---------- */

.steps { display: flex; align-items: center; gap: 0; margin: 4px 0 28px; max-width: 480px; }
.step { display: flex; align-items: center; gap: 9px; color: var(--ink-faint); font-size: 0.84rem; font-weight: 700; }
.step-dot {
  width: 24px; height: 24px;
  border-radius: 999px;
  border: 2px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.74rem;
  flex-shrink: 0;
  background: var(--surface);
}
.step.done .step-dot { background: var(--good); border-color: var(--good); color: #fff; }
.step.done .step-dot svg { width: 12px; height: 12px; }
.step.active .step-dot { border-color: var(--accent); color: var(--accent); }
.step.active { color: var(--ink); }
.step.done { color: var(--ink-soft); }
.step-line { flex: 1; height: 2px; background: var(--border-strong); margin: 0 10px; min-width: 24px; }
.step-line.done { background: var(--good); }

/* ---------- review / preview ---------- */

.review-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px 24px; max-width: 640px; margin-bottom: 20px; }
.review-meta { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; font-size: 0.88rem; color: var(--ink-soft); }
.review-meta strong { color: var(--ink); }
.email-preview { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.email-preview-bar { background: var(--neutral-soft); padding: 10px 16px; font-size: 0.82rem; color: var(--ink-soft); border-bottom: 1px solid var(--border); }
.email-preview-bar strong { color: var(--ink); }
.email-preview-body { padding: 18px 16px; font-size: 0.92rem; background: var(--surface); }

/* ---------- quick-track snippets ---------- */

.snippet-block { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 6px; }
.snippet-textarea {
  flex: 1;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.82rem;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--neutral-soft);
  color: var(--ink);
  resize: vertical;
}
.snippet-block .btn-secondary { flex-shrink: 0; }
.snippet-block .btn-secondary.copied { background: var(--good-soft); color: var(--good); }

.note-callout {
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  max-width: 640px;
  margin-top: 16px;
}
.note-callout p { font-size: 0.88rem; color: var(--ink-soft); margin: 0 0 10px; }
.note-callout p:last-child { margin-bottom: 0; }
.note-callout strong { color: var(--ink); }

/* ---------- progress ---------- */

.progress-bar { height: 8px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; margin: 6px 0 2px; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }

/* ---------- activity feed ---------- */

.activity-feed { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.activity-feed li { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.88rem; display: flex; align-items: center; gap: 10px; }
.activity-feed li:last-child { border-bottom: none; }
.activity-feed li.unread { background: var(--accent-soft); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 999px; background: var(--ink-faint); flex-shrink: 0; }
.dot-open { background: var(--good); }
.dot-click { background: var(--accent); }
.muted { color: var(--ink-faint); font-size: 0.8rem; margin-left: auto; font-weight: 400; white-space: nowrap; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .nav-link span.nav-label { display: none; }
}
