:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #fafafc;
  --hover: #f7f7fa;
  --line: #e7e8ee;
  --line-strong: #d9dbe3;
  --ink: #111827;
  --muted: #5b6478;
  --faint: #667085;
  --purple: #6d5efc;
  --purple-ink: #5d38f2;
  --purple-cta: #5d38f2;
  --purple-cta-hover: #4c26e6;
  --purple-soft: #f4f1ff;
  --purple-edge: #ddd5ff;
  --green: #0a7346;
  --green-soft: #e9f7ef;
  --amber: #8a5300;
  --amber-soft: #fff4e0;
  --red: #b42318;
  --red-soft: #fdecea;
  --blue: #1d4ed8;
  --blue-soft: #eaf1ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--purple-ink); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 700; font-size: 19px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.brand img { width: 18px; height: 29px; }
.brand small { font-weight: 600; font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 2px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 550; }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--hover); color: var(--ink); }
.nav-link.active { background: var(--purple-soft); color: var(--purple-ink); }
.sidebar-foot { margin-top: auto; display: grid; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple-ink); font-weight: 700; font-size: 12px; flex: none; }
.who b { display: block; font-size: 13px; }
.who span { color: var(--faint); font-size: 12px; }

.main { min-width: 0; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; line-height: 1.2; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Primitives ─────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; white-space: nowrap; transition: background 120ms, border-color 120ms; }
.btn:hover { background: var(--hover); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--purple-cta); border-color: var(--purple-cta); color: #fff; }
.btn.primary:hover { background: var(--purple-cta-hover); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
.input, .select, .textarea { width: 100%; min-height: 38px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); outline: none; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.15); }
.select { appearance: none; padding-right: 32px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23667085' stroke-width='2'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E") no-repeat right 11px center; }
.label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.hint { color: var(--faint); font-size: 12.5px; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--faint); }
.search .input { padding-left: 34px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.active { background: var(--green-soft); color: var(--green); }
.pill.waitlist { background: var(--amber-soft); color: var(--amber); }
.pill.unsubscribed { background: var(--hover); color: var(--faint); }
.pill.bounced, .pill.failed { background: var(--red-soft); color: var(--red); }
.pill.sent, .pill.delivered { background: var(--green-soft); color: var(--green); }
.pill.queued, .pill.sending, .pill.partial { background: var(--blue-soft); color: var(--blue); }
.pill.skipped, .pill.cancelled { background: var(--hover); color: var(--faint); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--hover); color: var(--muted); font-size: 12px; font-weight: 550; }
.count-badge { display: inline-block; min-width: 22px; padding: 1px 8px; border-radius: 999px; background: var(--purple-soft); color: var(--purple-ink); font-size: 12px; font-weight: 700; text-align: center; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, var(--hover) 25%, #eff0f4 37%, var(--hover) 63%); background-size: 400% 100%; animation: shimmer 1.2s ease infinite; border-radius: 6px; color: transparent !important; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ── Stats ──────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; gap: 14px; padding: 18px; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple-ink); flex: none; }
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.pink { background: #fdeef3; color: #c0265b; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--faint); }

/* ── Audience tabs ──────────────────────────────────────────────────────── */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; background: var(--surface); }
.tab { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border: 0; border-right: 1px solid var(--line); background: var(--subtle); text-align: left; position: relative; }
.tab:last-child { border-right: 0; }
.tab svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.tab b { font-size: 14.5px; }
.tab span.sub { display: block; font-size: 12.5px; color: var(--faint); }
.tab.active { background: var(--surface); }
.tab.active svg { color: var(--purple-ink); }
.tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--purple-cta); }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.subtab { border: 0; background: none; padding: 9px 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtab.active { color: var(--purple-ink); border-color: var(--purple-cta); }

/* ── Email workspace ────────────────────────────────────────────────────── */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }
.toolbar { display: grid; grid-template-columns: minmax(200px, 1.6fr) repeat(3, minmax(120px, 1fr)) auto; gap: 8px; margin-bottom: 10px; }
.filters-more { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.filters-more .select, .filters-more .input { width: auto; min-width: 150px; }
.selectbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; margin-bottom: 10px; }
.selectbar .left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.selectbar .notice { color: var(--purple-ink); font-weight: 600; }
.check { width: 16px; height: 16px; accent-color: var(--purple-cta); cursor: pointer; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--faint); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--subtle); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: var(--hover); }
table.data tbody tr.selected td { background: var(--purple-soft); }
table.data tbody tr.selected td.name { color: var(--purple-ink); }
table.data td.name { font-weight: 550; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
table.data td.email { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px; color: var(--muted); }
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager .page { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none; }
.pager .page.current { border-color: var(--purple-edge); background: var(--purple-soft); color: var(--purple-ink); font-weight: 700; }

.composer { position: sticky; top: 20px; padding: 18px; }
.composer h2 { margin: 0; font-size: 18px; }
.composer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.editor { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.editor:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.15); }
.editor-body { min-height: 190px; max-height: 360px; overflow-y: auto; padding: 12px 14px; outline: none; line-height: 1.6; }
.editor-body:empty::before { content: attr(data-placeholder); color: var(--faint); }
.editor-body p { margin: 0 0 10px; }
.editor-tools { display: flex; align-items: center; gap: 2px; padding: 5px 6px; border-top: 1px solid var(--line); background: var(--subtle); }
.tool { width: 30px; height: 30px; border: 0; border-radius: 6px; background: none; display: grid; place-items: center; color: var(--muted); }
.tool:hover { background: var(--hover); color: var(--ink); }
.tool svg { width: 16px; height: 16px; }
.tools-right { margin-left: auto; }
.tools-right .select { min-height: 30px; padding: 2px 28px 2px 8px; font-size: 12.5px; width: auto; }
.recipients { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 12px 0; margin-top: 4px; border-top: 1px solid var(--line); }
.recipients b { display: block; font-size: 13px; }
.send-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.secure-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 12.5px; color: var(--muted); }
.secure-note svg { width: 18px; height: 18px; color: var(--purple-ink); flex: none; margin-top: 1px; }
.secure-note b { color: var(--ink); display: block; }

/* ── Modal / drawer ─────────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.36); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade 120ms ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--subtle); border-radius: 0 0 16px 16px; }
.drawer-overlay { place-items: stretch end; padding: 0; }
.drawer { width: min(520px, 100vw); height: 100vh; overflow-y: auto; background: var(--surface); box-shadow: var(--shadow-lg); animation: slide 160ms ease; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; font-weight: 550; }
.confirm-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--subtle); }
.confirm-box .big { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; color: var(--purple-ink); }
.warning { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--amber-soft); color: var(--amber); font-weight: 550; margin-top: 12px; }
.error-box { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--red-soft); color: var(--red); font-weight: 550; }
.preview-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: var(--radius); background: #f6f6f9; }
.preview-frame.mobile { width: 390px; margin: 0 auto; display: block; }
.preview-meta { display: grid; grid-template-columns: 70px 1fr; gap: 4px 10px; margin-bottom: 12px; font-size: 13px; }
.preview-meta dt { color: var(--faint); }
.preview-meta dd { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); padding: 6px 12px; font-weight: 600; font-size: 13px; }
.segmented button.active { background: var(--purple-soft); color: var(--purple-ink); }
.import-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.import-grid .card { padding: 12px 14px; }
.import-grid .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.import-grid .card.good .n { color: var(--green); }
.import-grid .card.bad .n { color: var(--red); }
.dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 26px; text-align: center; background: var(--subtle); }
.dropzone.drag { border-color: var(--purple); background: var(--purple-soft); }
.progress { height: 8px; border-radius: 99px; background: var(--hover); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--purple-cta); transition: width 300ms ease; }

/* ── Pages ──────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.section-title h2 { margin: 0; font-size: 16px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.check-row { display: flex; align-items: center; gap: 8px; }
.ok { color: var(--green); font-weight: 700; }
.bad { color: var(--red); font-weight: 700; }
.pending-state { color: var(--amber); font-weight: 700; }
.template-card { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.template-card h3 { margin: 0; font-size: 15px; }
.template-card .snippet { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.template-card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; }
.templates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.rate { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--subtle); }
.login .card { width: min(380px, 100%); padding: 28px; }
.login h1 { font-size: 20px; margin: 18px 0 4px; }
.login p { margin: 0 0 20px; color: var(--muted); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 80; font-weight: 550; max-width: calc(100vw - 40px); }
.toast.error { background: var(--red); }

@media (max-width: 1280px) {
  .workspace { grid-template-columns: 1fr; }
  .composer { position: static; }
  .toolbar { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 10px; }
  .sidebar-foot { margin-top: 0; border-top: 0; padding-top: 0; flex-direction: row; display: flex; margin-left: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabs { grid-template-columns: 1fr; }
  .tab { border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 20px 16px 40px; }
  .grid-2, .import-grid { grid-template-columns: 1fr; }
}

/* Import "as" choice: unmistakable which one is selected. */
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); text-align: left; }
.choice b { display: block; font-size: 14px; }
.choice small { color: var(--faint); font-size: 12.5px; }
.choice .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; }
.choice.active { border-color: var(--purple-cta); background: var(--purple-soft); }
.choice.active .radio { border: 5px solid var(--purple-cta); }
