:root {
  color-scheme: light;
  --bg: #f5f5f9;
  --panel: #ffffff;
  --panel-2: #fafafd;
  --ink: #16162a;
  --ink-2: #3c3c55;
  --muted: #74748c;
  --line: #e6e6ef;
  --line-2: #d8d8e5;
  --accent: #5046e5;
  --accent-dark: #4338ca;
  --accent-soft: #eeecff;
  --ok: #0e9f6e;
  --ok-soft: #e6f7f0;
  --warn: #c2740a;
  --warn-soft: #fdf2dc;
  --bad: #d92d20;
  --bad-soft: #fdeceb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(20, 20, 43, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

.app-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
}

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 26px 18px 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand-mark {
  width: 38px; height: 38px; flex: none;
  border-radius: 11px;
  background: linear-gradient(140deg, #6d63ff 0%, #4b3fe0 55%, #3830b8 100%);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; letter-spacing: 0.02em;
  box-shadow: 0 8px 18px rgba(80, 70, 229, 0.32);
}
.brand-text b { display: block; font-size: 14px; line-height: 1.2; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em;
  color: #9a9ab0; font-weight: 700; padding: 0 10px 7px;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--ink-2);
  font-weight: 550;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 11px;
  font-size: 12.5px; min-width: 0;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.user-chip .who { min-width: 0; }
.user-chip .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { color: var(--muted); font-size: 11px; }

.main { min-width: 0; padding: 30px 34px 70px; }
.page { max-width: 1160px; margin: 0 auto; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head .sub { color: var(--muted); margin-top: 5px; font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.back-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); font-size: 12.5px; margin-bottom: 10px; text-decoration: none;
}
.back-link:hover { color: var(--accent); }

/* -------------------------------------------------------------- controls */

.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--ink-2);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s, color 0.12s, box-shadow 0.12s;
}
.btn:hover { border-color: #bdbdce; background: #fff; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 6px 16px rgba(80, 70, 229, 0.22);
}
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--bad); border-color: #f2c7c3; background: #fff; }
.btn.danger:hover { background: var(--bad-soft); border-color: #eeaea8; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--line); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.field .hint.error { color: var(--bad); }

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(80, 70, 229, 0.12);
}
.textarea { resize: vertical; min-height: 110px; }
.textarea.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; min-height: 420px; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.input-sm { padding: 6px 9px; font-size: 12.5px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }

.switch { display: flex; align-items: flex-start; gap: 9px; padding: 5px 0; cursor: pointer; }
.switch input { margin-top: 2px; accent-color: var(--accent); width: 16px; height: 16px; }
.switch span { font-size: 13px; }
.switch .hint { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 0 rgba(20, 20, 43, 0.02);
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 15px; }
.card-body { padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 750; letter-spacing: -0.03em; margin-top: 4px; }
.stat .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.stat.accent { background: linear-gradient(150deg, #f2f0ff, #ffffff 70%); border-color: #ddd8ff; }

.empty {
  text-align: center; padding: 54px 20px; color: var(--muted);
}
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; max-width: 420px; }

/* ----------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); font-weight: 700; padding: 11px 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel-2);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfbff; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .strong { font-weight: 600; color: var(--ink); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .email { font-family: var(--mono); font-size: 12.5px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 8px; font-size: 11.5px; color: var(--ink-2);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip b { font-weight: 650; color: var(--muted); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; max-width: 340px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 3px 9px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
  background: #f0f0f6; color: var(--ink-2);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.75; }
.badge.active, .badge.badge-ok, .badge.sent, .badge.done { background: var(--ok-soft); color: #077a53; }
.badge.draft, .badge.scheduled, .badge.queued, .badge.paused { background: var(--warn-soft); color: var(--warn); }
.badge.sending { background: var(--accent-soft); color: var(--accent-dark); }
.badge.failed, .badge.bounced { background: var(--bad-soft); color: var(--bad); }
.badge.unsubscribed, .badge.skipped, .badge.canceled { background: #f0f0f6; color: #5f5f76; }

/* --------------------------------------------------------------- toolbar */

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar .select { max-width: 320px; }
.search { position: relative; }
.search .input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--muted); }

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 12px 16px; color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------- dashboard */

.bars {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px;
  align-items: end; height: 150px; padding: 8px 4px 0;
}
.bar-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; }
.bar-stack { width: 100%; max-width: 38px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; flex: 1; }
.bar {
  width: 100%; border-radius: 4px 4px 2px 2px; background: var(--accent);
  min-height: 2px; transition: height 0.3s ease;
}
.bar.open { background: #b9b3ff; }
.bar-col .day { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bar-col .count { font-size: 11px; font-weight: 650; color: var(--ink-2); }

.progress { height: 7px; background: #ededf5; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.progress.ok > div { background: var(--ok); }

.setup-list { display: flex; flex-direction: column; gap: 2px; }
.setup-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.setup-item:last-child { border-bottom: 0; }
.setup-item .icon {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--warn-soft); color: var(--warn);
}
.setup-item .icon.ok { background: var(--ok-soft); color: var(--ok); }
.setup-item .text { flex: 1; min-width: 0; }
.setup-item .text b { display: block; font-size: 13px; }
.setup-item .text span { font-size: 11.5px; color: var(--muted); }

/* ----------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(18, 18, 35, 0.42);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 18px 30px;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border-radius: 18px; width: 100%; max-width: 520px;
  box-shadow: 0 30px 80px rgba(15, 15, 35, 0.28);
  animation: pop 0.15s ease-out;
}
.modal.wide { max-width: 760px; }
.modal.narrow { max-width: 420px; }
@keyframes pop { from { transform: translateY(6px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px 14px;
}
.modal-head h2 { font-size: 17px; }
.modal-close {
  border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted);
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.modal-close:hover { background: var(--panel-2); color: var(--ink); }
.modal-body { padding: 4px 22px 8px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 22px 20px; border-top: 1px solid var(--line); margin-top: 8px;
}
.modal .form-error {
  display: none; background: var(--bad-soft); color: var(--bad);
  border-radius: 8px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 12px;
}
.modal .form-error.show { display: block; }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 90;
  background: #1d1d33; color: #fff; padding: 12px 16px;
  border-radius: 11px; font-size: 13px; box-shadow: 0 16px 40px rgba(10, 10, 25, 0.3);
  max-width: 420px;
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: #7f1d1d; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----------------------------------------------------------------- login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line);
  border-radius: 20px; padding: 34px 30px 28px; box-shadow: var(--shadow);
}
.login-card .brand { padding: 0; margin-bottom: 26px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card .btn { margin-top: 6px; }
.login-foot { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 18px; }
.login-error {
  display: none; background: var(--bad-soft); color: var(--bad);
  border-radius: 9px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px;
}
.login-error.show { display: block; }

/* ---------------------------------------------------------------- editor */

.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.editor-pane { position: sticky; top: 20px; }
.preview-frame {
  width: 100%; height: 620px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.subject-line {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); margin-bottom: 12px;
}
.subject-line span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.subject-line b { font-size: 13px; font-weight: 600; }

.var-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.var-chips button {
  border: 1px dashed var(--line-2); background: #fff; color: var(--ink-2);
  border-radius: 7px; padding: 3px 8px; font-family: var(--mono); font-size: 11.5px; cursor: pointer;
}
.var-chips button:hover { border-color: var(--accent); color: var(--accent); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button {
  border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 13.5px;
  color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.kv { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.kv .input { min-width: 0; }

.dns-row { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.dns-row:last-child { border-bottom: 0; }
.dns-row .kind { width: 62px; flex: none; font-size: 11px; font-weight: 700; color: var(--muted); padding-top: 2px; text-transform: uppercase; }
.dns-row .value { flex: 1; min-width: 0; }
.dns-row .value .name { font-family: var(--mono); font-size: 12px; font-weight: 650; word-break: break-all; }
.dns-row .value .txt { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; margin-top: 3px; }

.check-list { display: flex; flex-direction: column; gap: 8px; }
.check {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
}
.check .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.check.ok .dot { background: var(--ok); }
.check.warn .dot { background: var(--warn); }
.check.fail .dot { background: var(--bad); }
.check .body { min-width: 0; }
.check b { font-size: 12.5px; display: block; }
.check span { font-size: 11.5px; color: var(--muted); word-break: break-word; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .input { max-width: 280px; }

@media (max-width: 1080px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-pane { position: static; }
  .preview-frame { height: 480px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    padding: 10px 12px; gap: 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand-text, .nav-label, .sidebar-foot { display: none; }
  .brand { padding: 0; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; }
  .nav { flex: 1; flex-direction: row; flex-wrap: wrap; row-gap: 2px; gap: 0; align-items: center; }
  .nav a { padding: 6px 8px; font-size: 12px; gap: 5px; }
  .nav a span { display: inline; }
  .nav a svg { width: 15px; height: 15px; }
  .main { padding: 20px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 21px; }
  .toolbar { padding: 12px; }
  .toolbar .input, .toolbar .select { max-width: none; }
  .card-head { flex-wrap: wrap; }
  .bars { height: 120px; gap: 6px; }
  .bar-col .day { font-size: 9.5px; }
}

@media print {
  .sidebar, .page-actions, .toolbar { display: none; }
}
