:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --border-strong: #d3d8e0;
  --text: #1a1d24;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --accent: #0b7a75;
  --accent-hover: #0a6b66;
  --accent-weak: #e7f2f1;
  --danger: #d64545;
  --danger-weak: #fbeaea;
  --ok: #1a8f5a;
  --ok-weak: #e6f4ec;
  --warn: #9a6b00;
  --warn-weak: #fbf1da;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 32px rgba(16,24,40,.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--accent); }
button { font-family: inherit; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #eaf3f2, var(--bg));
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 32px;
}
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-card h1 { font-size: 20px; }
.login-card p.sub { color: var(--muted); margin: 4px 0 22px; }
.login-error {
  background: var(--danger-weak); color: var(--danger);
  border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 14px; font-size: 13px;
}

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 58px;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; }
.logo {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #12a89f);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-weak); color: var(--accent); }
.top-right { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-weak); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; }

.container { max-width: 960px; margin: 0 auto; padding: 24px; }
.page-head { margin-bottom: 18px; }
.page-head h2 { font-size: 22px; }
.page-head p { color: var(--muted); margin: 4px 0 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card > .card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card h3 { font-size: 15px; }
.card .step { color: var(--faint); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 600; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input:not([type]), input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
/* checkbox inputs must not stretch */
.checkbox input, input[type=checkbox] { width: auto; }
textarea { resize: vertical; min-height: 72px; }
.checkbox { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface); user-select: none; }
.checkbox:hover { background: var(--surface-2); }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }
.checkbox span { font-size: 13px; }
.checkbox.on { border-color: var(--accent); background: var(--accent-weak); }
.filter-group-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 14px 0 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #edc9c9; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 7px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13.5px; }
.segmented button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.segmented button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Preview / stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat .n { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .n.accent { color: var(--accent); }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
table.sample { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 12.5px; }
table.sample th { text-align: left; color: var(--faint); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.sample td { padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.clients { background: var(--accent-weak); color: var(--accent); }
.badge.hosts { background: #efe9fb; color: #6b46c1; }
.badge.sent { background: var(--ok-weak); color: var(--ok); }
.badge.dry { background: var(--warn-weak); color: var(--warn); }
.badge.draft, .badge.skipped { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.push { background: #eaf1fd; color: #2563a8; }
.badge.email { background: #fdeef4; color: #b03a72; }

/* ---------- Blocks editor ---------- */
.block { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.block-head select { width: auto; padding: 5px 8px; font-size: 12.5px; }
.block-head .spacer { flex: 1; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; width: 28px; height: 28px; cursor: pointer; color: var(--muted); font-size: 14px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.email-preview { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* ---------- History ---------- */
.hist-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; background: var(--surface); cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.hist-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.hist-row .name { font-weight: 650; }
.hist-row .meta { color: var(--faint); font-size: 12.5px; margin-top: 2px; }
.hist-row .chips { display: flex; gap: 6px; }
.hist-row .size { text-align: right; }
.hist-row .size .n { font-weight: 700; }
.hist-row .size .l { color: var(--faint); font-size: 11.5px; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(16,24,40,.4); display: grid; place-items: center; padding: 24px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); max-width: 640px; width: 100%; max-height: 84vh; overflow: auto; padding: 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
pre.json { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-family: var(--mono); font-size: 12px; overflow: auto; white-space: pre-wrap; color: var(--muted); }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 360px; animation: slide-in .2s ease; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.muted { color: var(--muted); }
.hint { color: var(--faint); font-size: 12.5px; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
.btn:not(.primary) .spinner { border-color: rgba(0,0,0,.15); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.warn-banner { background: var(--warn-weak); color: var(--warn); border: 1px solid #eeddb0; border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; margin-top: 10px; }
