:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --border: #e5e9f2;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --primary-soft: #eef2ff;
  --accent: #8b5cf6;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --amber: #f59e0b;
  --amber-soft: #fffbeb;
  --red: #ef4444;
  --red-soft: #fef2f2;
  --blue: #3b82f6;
  --blue-soft: #eff6ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.05);
  --shadow: 0 4px 6px -1px rgba(15,23,42,.07), 0 2px 4px -2px rgba(15,23,42,.05);
  --shadow-lg: 0 20px 40px -12px rgba(15,23,42,.18);
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--ink-3); font-size: 13.5px; }
.error { color: var(--red); font-size: 13px; margin-top: 8px; font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  font: 600 14px 'Inter', sans-serif; cursor: pointer; transition: all .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 14px -4px rgba(99,102,241,.55); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: rgba(255,255,255,.08); color: #fff; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { filter: brightness(.97); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn svg { width: 16px; height: 16px; }
.btn-ghost svg { width: 17px; height: 17px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: 8px; border: none; background: transparent; color: var(--ink-3); cursor: pointer; transition: all .15s;
}
.icon-btn:hover { background: var(--red-soft); color: var(--red); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------- Login ---------- */
#login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1000px 500px at 80% -10%, rgba(139,92,246,.15), transparent 60%),
              radial-gradient(800px 400px at -10% 110%, rgba(99,102,241,.14), transparent 60%),
              var(--bg); }
.login-wrap { width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 26px; font-size: 22px; font-weight: 800; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; box-shadow: 0 6px 16px -4px rgba(99,102,241,.5);
}
.logo-mark svg { width: 22px; height: 22px; }
.login-card {
  background: var(--surface); border-radius: var(--radius); padding: 34px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-card .muted { margin: 6px 0 4px; line-height: 1.5; }
.login-card button { margin-top: 18px; }
.login-card label { margin-top: 16px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input, textarea, select {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: 400 14px 'Inter', sans-serif; color: var(--ink); background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
textarea.editor {
  min-height: 280px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.6;
  resize: vertical; background: #0f172a; color: #e2e8f0;
}
.hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; line-height: 1.5; }

/* ---------- App layout ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 22px 22px 18px; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.sidebar nav { flex: 1; padding: 6px 12px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px; color: #94a3b8; text-decoration: none;
  font-size: 14px; font-weight: 500; border-radius: 10px; margin-bottom: 2px; transition: all .15s;
}
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav a:hover { color: #e2e8f0; background: rgba(255,255,255,.05); }
.sidebar nav a.active { color: #fff; background: linear-gradient(135deg, rgba(99,102,241,.28), rgba(139,92,246,.22)); box-shadow: inset 0 0 0 1px rgba(139,92,246,.35); }
.sidebar-foot { padding: 16px 14px; border-top: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--accent)); font-weight: 700; font-size: 14px; color: #fff;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
#user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tag { font-size: 11px; color: var(--ink-3); }

#content { flex: 1; padding: 28px 32px; max-width: 1180px; }
.page-loading { display: flex; align-items: center; justify-content: center; min-height: 50vh; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.page-head .sub { color: var(--ink-3); font-size: 13.5px; margin-top: 3px; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.stat .num { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.stat .lbl { color: var(--ink-3); font-size: 12.5px; font-weight: 500; margin-top: 3px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
td { color: var(--ink); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fafbff; }
td.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.empty-row td { text-align: center; padding: 42px 16px; color: var(--ink-3); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.draft { background: var(--surface-2); color: var(--ink-2); }
.badge.queued { background: var(--amber-soft); color: #92400e; }
.badge.sending { background: var(--blue-soft); color: #1d4ed8; }
.badge.sent { background: var(--green-soft); color: #047857; }
.badge.failed { background: var(--red-soft); color: #b91c1c; }
.badge.active { background: var(--green-soft); color: #047857; }
.badge.unsubscribed { background: var(--surface-2); color: var(--ink-3); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; }
.search-box { position: relative; max-width: 260px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-3); }
.search-box input { padding-left: 34px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 26px; width: 680px; max-width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: popIn .18s ease;
}
.modal h3 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; margin-bottom: 18px; }
.modal .modal-close { float: right; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.97) translateY(6px); } }

/* ---------- Toasts ---------- */
#toast-wrap { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .2s ease;
  max-width: 360px;
}
.toast.success { background: linear-gradient(135deg, #059669, #10b981); }
.toast.error { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Progress ---------- */
.progress-bar { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 90px; }
.progress-bar > div { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--primary), var(--accent)); }

/* ---------- Misc ---------- */
.import-hint { background: var(--primary-soft); border-radius: 10px; padding: 14px 16px; font-size: 13px; color: var(--primary-2); margin-bottom: 16px; line-height: 1.5; }
.code { background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-family: ui-monospace, monospace; font-size: 12.5px; }
.dns-table { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--ink-3); }
.kv .v { font-weight: 600; }
.row { display: flex; gap: 14px; }
.row > div { flex: 1; }
.flex { display: flex; gap: 10px; align-items: center; }

@media (max-width: 860px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .sidebar nav { display: flex; overflow-x: auto; padding: 8px; }
  .sidebar nav a { white-space: nowrap; margin-bottom: 0; }
  .sidebar .brand { padding: 14px 16px; }
  .sidebar-foot { display: none; }
  #content { padding: 18px; }
  .row { flex-direction: column; }
}
