@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  --brand: #1f5bff;
  --brand-600: #1748d6;
  --brand-50: #eef3ff;
  --brand-100: #dde7ff;
  --ink: #0b1220;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f0;
  --line-2: #eef1f6;
  --bg: #f6f8fb;
  --card: #ffffff;
  --ok: #0f9d58;
  --ok-50: #e8f6ee;
  --warn: #b45309;
  --warn-50: #fff6e6;
  --bad: #d92d20;
  --bad-50: #fdecea;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; min-width: 0; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mb-20 { margin-bottom: 20px; }
.center { text-align: center; }
.label-text { font-weight: 500; color: var(--ink-2); font-size: 13px; }
.search-input { max-width: 320px; }
.btn-lg { padding: 12px 16px; font-size: 14px; }

/* ------------------------------------------------------------------ layout */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img, .brand-mini img { height: 30px; width: 30px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: var(--ink); white-space: nowrap; }
.brand-mini { display: inline-flex; align-items: center; gap: 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; padding: 14px 10px 6px; }
.nav button {
  all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 500;
}
.nav button:hover { background: var(--bg); color: var(--ink); }
.nav button.active { background: var(--brand-50); color: var(--brand-600); }
.nav button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 10px 0; }

.main { min-width: 0; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.mobile-bar { display: none; }
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.sticky { position: sticky; top: 20px; }

/* ------------------------------------------------------------------ cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 20px; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand-600); font-weight: 700; font-size: 13px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); }

/* ------------------------------------------------------------------ stats */
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.meter { height: 6px; background: var(--line-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s; }
.meter.warn > span { background: #f59e0b; }

/* ------------------------------------------------------------------ forms */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; color: var(--ink-2); font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12.5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: #fff; width: 100%;
  border: 1px solid #d5dbe5; border-radius: var(--radius-sm); padding: 9px 11px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
textarea.body-editor { min-height: 260px; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
input::placeholder, textarea::placeholder { color: #9aa5b5; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand); }

.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  all: unset; cursor: pointer; padding: 6px 12px; border-radius: 7px; font-weight: 500; color: var(--ink-2); font-size: 13px;
}
.segmented button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.segmented button:focus-visible { outline: 2px solid var(--brand); }

/* ------------------------------------------------------------------ buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid #d5dbe5;
  background: #fff; color: var(--ink); transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-danger { color: var(--bad); border-color: #f3c3be; }
.btn-danger:hover { background: var(--bad-50); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ chips, pills */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: 500 12px var(--mono); cursor: pointer; border: 1px dashed #b9c6e6; color: var(--brand-600);
  background: var(--brand-50); padding: 3px 8px; border-radius: 6px;
}
.chip:hover { border-style: solid; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.ok { background: var(--ok-50); color: var(--ok); }
.pill.warn { background: var(--warn-50); color: var(--warn); }
.pill.bad { background: var(--bad-50); color: var(--bad); }
.pill.info { background: var(--brand-50); color: var(--brand-600); }
.pill.plain::before { display: none; }

/* ------------------------------------------------------------------ alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; border: 1px solid; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.warn { background: var(--warn-50); border-color: #fde3b0; color: #7a3e06; }
.alert.info { background: var(--brand-50); border-color: var(--brand-100); color: #1c3a8a; }
.alert.bad { background: var(--bad-50); border-color: #f7c6c1; color: #8f1d14; }
.alert.ok { background: var(--ok-50); border-color: #bfe6cf; color: #0b5d35; }

/* ------------------------------------------------------------------ dropzone */
.dropzone {
  display: block;
  border: 1.5px dashed #c5cfdf; border-radius: var(--radius); padding: 28px; text-align: center;
  background: #fbfcfe; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-50); }
.dropzone svg { width: 28px; height: 28px; color: var(--brand); }
.dropzone b { display: block; margin-top: 8px; font-weight: 600; }
.file-list { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; font-size: 12.5px; }
.file-chip button { all: unset; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 15px; line-height: 1; }
.file-chip button:hover { color: var(--bad); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 360px; }
.card > .table-wrap { border: none; border-radius: 0 0 var(--radius) var(--radius); max-height: none; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; background: #f9fafc; text-align: left; font-weight: 600; color: var(--muted);
  font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #fafbfd; }
td.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.dim td { color: #9aa5b5; text-decoration: line-through; }
.progress-cell { min-width: 140px; }
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; color: #b6c1d3; margin-bottom: 8px; }
.empty b { display: block; color: var(--ink-2); margin-bottom: 4px; }

/* ------------------------------------------------------------------ preview */
.email-preview { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.email-preview .meta { padding: 12px 14px; background: #fafbfd; border-bottom: 1px solid var(--line); font-size: 13px; }
.email-preview .meta div { display: flex; gap: 8px; }
.email-preview .meta span:first-child { color: var(--muted); width: 56px; flex: none; }
.email-preview pre { margin: 0; padding: 16px; white-space: pre-wrap; word-break: break-word;
  font: 14px/1.6 Inter, sans-serif; color: var(--ink); max-height: 420px; overflow: auto; }

.summary-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.summary-line:last-of-type { border-bottom: none; }
.summary-line span:first-child { color: var(--muted); }
.summary-line span:last-child { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ modal & toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11, 18, 32, .45); display: grid; place-items: center;
  z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.modal .card-head { border-bottom: 1px solid var(--line-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: #fafbfd; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13px; max-width: 380px; animation: slide .2s; display: flex; gap: 10px; align-items: flex-start; }
.toast.bad { background: var(--bad); }
.toast.ok { background: #0b7a45; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------ public pages (login, unsubscribe) */
.public-page { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #e6edff 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #efe8ff 0%, transparent 55%), var(--bg); }
.public-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.public-card h1 { font-size: 22px; }
.public-card p { color: var(--ink-2); }
.public-card .logo { height: 40px; width: auto; align-self: flex-start; margin-bottom: 6px; }
.public-card form { display: flex; flex-direction: column; gap: 14px; }

/* ------------------------------------------------------------------ send page */
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 42px; }
.icon-btn { all: unset; cursor: pointer; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  color: var(--muted); padding: 4px; border-radius: 6px; display: grid; }
.icon-btn:hover { color: var(--ink); background: var(--bg); }
.icon-btn svg { width: 18px; height: 18px; }
.warn-text { color: var(--warn); font-weight: 500; }
.table-wrap.short { max-height: none; }
.table-more { padding: 8px; border-top: 1px solid var(--line-2); }
.status-card { border-left: 4px solid var(--brand); }
.nowrap { white-space: nowrap; }
.detail-row td { background: #fafbfd; }
.message-body { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; font: 13.5px/1.6 Inter, sans-serif;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; max-height: 360px; overflow: auto; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky { position: static; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; left: 0; width: 248px; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
    background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mobile-bar img { height: 26px; width: 26px; }
  .main { padding: 20px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head { flex-direction: column; align-items: flex-start; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

.builder > *, .stack > *, .grid > * { min-width: 0; }

/* ------------------------------------------------------------------ accounts */
.logo-sm { height: 32px; width: 32px; }
.auth-tabs { display: flex; }
.auth-tabs button { flex: 1; text-align: center; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 2px; }
.user-chip .stack-0 { display: flex; flex-direction: column; min-width: 0; }
.user-chip .trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand-600); font-weight: 700; }

/* ------------------------------------------------------------------ formatted email editor */
.rich { border: 1px solid #d5dbe5; border-radius: var(--radius-sm); background: #fff; overflow: hidden; }
.rich:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line-2); background: #fafbfd; }
.toolbar button { all: unset; cursor: pointer; min-width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 6px; color: var(--ink-2); font-size: 14px; }
.toolbar button:hover { background: var(--line-2); color: var(--ink); }
.toolbar button:focus-visible { outline: 2px solid var(--brand); }
.toolbar svg { width: 17px; height: 17px; }
.toolbar-sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.rich-editor { min-height: 260px; max-height: 560px; overflow: auto; padding: 12px 14px; outline: none; line-height: 1.6; font-size: 14px; }
.rich { position: relative; }
.rich-editor.is-empty::before { content: attr(data-placeholder); color: #9aa5b5; position: absolute; pointer-events: none; }
.rich-editor p, .pv-html p { margin: 0 0 12px; }
.rich-editor ul, .rich-editor ol, .pv-html ul, .pv-html ol { margin: 0 0 12px; padding-left: 22px; }
.pv-html { padding: 16px; font-size: 14px; line-height: 1.6; max-height: 420px; overflow: auto; }

/* ------------------------------------------------------------------ dashboard & settings */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.settings-grid > * { min-width: 0; }
@media (max-width: 860px) {
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
  td.trunc { max-width: 150px; }
  .progress-cell { min-width: 110px; }
}
.setup-step { padding: 10px 0; border-top: 1px dashed var(--line); }
.setup-step:first-of-type { border-top: none; }
.stat { min-width: 0; }
