:root {
  --bg: #0e1017;
  --panel: #171a23;
  --panel-2: #1e2230;
  --border: #262b3a;
  --text: #e6e8ee;
  --muted: #98a1b3;
  --accent: #6d5efc;
  --accent-2: #2bd4c4;
  --st-delivered: #22c55e;
  --st-sent: #3b82f6;
  --st-queued: #94a3b8;
  --st-undelivered: #f59e0b;
  --st-failed: #ef4444;
  --ch-sms: #6d5efc;
  --ch-telegram: #2bd4c4;
  --ch-email: #64748b;
  --radius: 14px;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(109, 94, 252, 0.16), transparent),
    radial-gradient(900px 500px at 0% 110%, rgba(43, 212, 196, 0.12), transparent),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 28px;
  box-shadow: var(--shadow);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 20px;
}
.auth-sub { color: var(--muted); margin-bottom: 22px; }
.auth-tabs {
  display: flex;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.auth-tabs button {
  flex: 1;
  padding: 9px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
}
.auth-tabs button.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Form controls ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.input, textarea.input, select.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, textarea.input:focus, select.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.18);
}
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: #34405a; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #7c6ffd; }
.btn.accent-2 {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #06231f;
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--st-failed); border-color: rgba(239, 68, 68, 0.4); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.12); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.err {
  color: var(--st-failed);
  font-size: 12.5px;
  margin-top: 8px;
  min-height: 16px;
}

/* ---------- App shell ---------- */
.app { display: none; min-height: 100vh; }
.app.on { display: block; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(23, 26, 35, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.brand .logo-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-block;
}
.topbar .spacer { flex: 1; }
.topbar .proj-select { min-width: 190px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); }
.user-email { color: var(--muted); font-size: 12.5px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout {
  display: grid;
  grid-template-columns: 224px 1fr;
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

.sidenav {
  position: sticky;
  top: 78px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.navitem {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.navitem:hover { background: var(--panel); color: var(--text); }
.navitem.active {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}
.navitem svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.navitem.active svg { color: var(--accent); }

.content { min-width: 0; }
.section { display: none; }
.section.on { display: block; }
.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.section-head h1 { font-size: 20px; margin: 0; }
.section-head .sub { color: var(--muted); font-size: 13px; }
.section-head .spacer { flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin: -8px 0 14px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* KPI */
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi .k-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .k-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .k-value .unit { font-size: 15px; color: var(--muted); font-weight: 600; margin-left: 3px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tbl th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover td { background: var(--panel-2); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.empty {
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge.ch-sms { color: var(--ch-sms); background: rgba(109, 94, 252, 0.14); border-color: rgba(109, 94, 252, 0.32); }
.badge.ch-telegram { color: var(--ch-telegram); background: rgba(43, 212, 196, 0.13); border-color: rgba(43, 212, 196, 0.3); }
.badge.ch-email { color: #a7b3c7; background: rgba(100, 116, 139, 0.18); border-color: rgba(100, 116, 139, 0.4); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.st-delivered { color: var(--st-delivered); background: rgba(34, 197, 94, 0.14); }
.pill.st-sent { color: var(--st-sent); background: rgba(59, 130, 246, 0.14); }
.pill.st-queued, .pill.st-sending { color: var(--st-queued); background: rgba(148, 163, 184, 0.16); }
.pill.st-undelivered { color: var(--st-undelivered); background: rgba(245, 158, 11, 0.14); }
.pill.st-failed { color: var(--st-failed); background: rgba(239, 68, 68, 0.14); }

/* ---------- Overview visuals ---------- */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 88px 1fr 44px; align-items: center; gap: 10px; }
.bar-track { height: 12px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s; }

.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-step { display: grid; grid-template-columns: 130px 1fr 60px; align-items: center; gap: 10px; }
.funnel-bar { height: 26px; border-radius: 8px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); display: flex; align-items: center; padding-left: 10px; color: #fff; font-weight: 700; font-size: 12px; }

.spark { width: 100%; height: 60px; }

/* ---------- Send / detail layouts ---------- */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.kv-rows { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 12px; padding: 6px 0; align-items: flex-start; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--accent); }
.tl-body { flex: 1; }
.tl-time { color: var(--muted); font-size: 12px; }

.detail-panel { position: sticky; top: 78px; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: 0; }
.detail-row .dk { color: var(--muted); }
.detail-row .dv { text-align: right; word-break: break-word; }

.code-block {
  background: #0b0d14;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  color: #cdd6e6;
}
.collapse-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--muted);
  font-weight: 600;
}
.collapse-head .caret { transition: transform 0.15s; }
.collapse-head.open .caret { transform: rotate(90deg); }

.keybox {
  background: #0b0d14;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.keybox .mono { flex: 1; word-break: break-all; color: var(--accent-2); }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: rgba(43, 212, 196, 0.25); border-color: var(--accent-2); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--accent-2); }

.sandbox-note {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent-2); font-size: 12px; font-weight: 600;
}
.sandbox-note::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-2); }

/* ---------- Plans ---------- */
.plan-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(109, 94, 252, 0.25); }
.plan-card.popular { border-color: var(--accent-2); }
.plan-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.plan-price { font-size: 24px; font-weight: 700; }
.plan-price .per { font-size: 13px; color: var(--muted); font-weight: 600; }
.plan-kzt { color: var(--muted); font-size: 12.5px; }
.plan-feat { color: var(--muted); font-size: 12.5px; flex: 1; }
.tag {
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: rgba(43, 212, 196, 0.16); color: var(--accent-2);
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  box-shadow: var(--shadow);
  font-weight: 600;
  animation: slidein 0.18s ease;
}
.toast.ok { border-left: 3px solid var(--st-delivered); }
.toast.err { border-left: 3px solid var(--st-failed); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 4px;
  }
  .navitem { white-space: nowrap; }
  .navitem span.lbl { display: none; }
  .navitem { padding: 10px 12px; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
  .topbar .proj-select { min-width: 130px; }
  .user-email { display: none; }
}
