/* =====================================================================
   Design tokens. Everything below uses these, so re-theming = editing this block.
   ===================================================================== */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f3f4fb;
  --surface-3: #eceefa;
  --text: #141a30;
  --muted: #646e8a;
  --line: #e3e6f2;
  --line-strong: #cfd4e8;

  --brand: #5b5ef0;
  --brand-2: #8b5cf6;
  --brand-d: #4649d6;
  --brand-soft: #ebecff;
  --grad: linear-gradient(135deg, #5b5ef0 0%, #8b5cf6 100%);
  --grad-soft: linear-gradient(135deg, #eef0ff 0%, #f5eeff 100%);
  --glow: 0 8px 20px -8px rgba(91, 94, 240, .65);

  --ok: #0f9d6b;      --ok-soft: #dff5ec;
  --bad: #de3f58;     --bad-soft: #fde9ed;
  --warn: #b7740a;    --warn-soft: #fff2d6;
  --info: #2877dc;    --info-soft: #e4f0fd;

  --chat-bg: #e9e1d4;
  --bubble: #ffffff;
  --code-bg: #0f1330;
  --code-text: #dfe4ff;

  --shadow: 0 1px 2px rgba(20, 26, 60, .04), 0 10px 28px -10px rgba(20, 26, 60, .12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0b0e1d;
  --surface: #131830;
  --surface-2: #181e3a;
  --surface-3: #1f2646;
  --text: #e8ebf8;
  --muted: #8f99bb;
  --line: #242b4c;
  --line-strong: #323b66;

  --brand: #7f82ff;
  --brand-2: #a78bfa;
  --brand-d: #9a9dff;
  --brand-soft: #232860;
  --grad: linear-gradient(135deg, #6a6df5 0%, #9468f7 100%);
  --grad-soft: linear-gradient(135deg, #1b2050 0%, #261e50 100%);
  --glow: 0 8px 22px -8px rgba(127, 130, 255, .55);

  --ok: #3ccf94;      --ok-soft: #12362b;
  --bad: #ff7388;     --bad-soft: #3b1a25;
  --warn: #f0b24a;    --warn-soft: #3a2e12;
  --info: #6fa8f5;    --info-soft: #172a4a;

  --chat-bg: #0e1620;
  --bubble: #1e2736;
  --code-bg: #090b1c;
  --code-text: #dfe4ff;

  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 30px -12px rgba(0, 0, 0, .55);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.55 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { letter-spacing: -.015em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace; }
code { background: var(--surface-3); border-radius: 6px; padding: 1px 6px; font-size: .88em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { margin-left: auto; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Form controls ---------- */
label.field { display: block; font-weight: 600; font-size: 13px; margin: 16px 0 6px; }
label.field:first-child { margin-top: 0; }
label.field .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=number], input:not([type]), textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
input[type=checkbox] { accent-color: var(--brand); width: 17px; height: 17px; margin: 2px 0 0; flex: none; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; cursor: pointer; }
.check b { display: block; font-weight: 600; }
.check span { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: transform .12s, box-shadow .15s, border-color .15s, background .15s;
}
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: var(--glow); }
.btn.primary:hover { filter: brightness(1.07); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; align-items: center; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.badge.sent, .badge.ok, .badge.completed { background: var(--ok-soft); color: var(--ok); }
.badge.failed, .badge.bad, .badge.invalid { background: var(--bad-soft); color: var(--bad); }
.badge.skipped, .badge.warn, .badge.paused, .badge.test { background: var(--warn-soft); color: var(--warn); }
.badge.pending, .badge.sending, .badge.info, .badge.queued { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--brand-soft); color: var(--brand); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 248px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 22px; }
.brand b { font-size: 17px; letter-spacing: -.02em; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11.5px; display: block; }
.logo { width: 38px; height: 38px; border-radius: 12px; background: var(--grad); display: grid; place-items: center; color: #fff; box-shadow: var(--glow); flex: none; }
.logo svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 11px; color: var(--muted);
  font-weight: 600; margin-bottom: 2px; transition: background .15s, color .15s; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .count { margin-left: auto; font-size: 11.5px; background: var(--surface-3); color: var(--muted); border-radius: 99px; padding: 0 8px; }
.nav a.active .count { background: var(--surface); color: var(--brand); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.worker-pill { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 11px; background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.side-foot .btn { white-space: nowrap; }
.side-foot .row { display: flex; gap: 8px; }
.side-foot .row .btn { flex: 1; }

main { flex: 1; min-width: 0; padding: 30px 34px 70px; max-width: 1240px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 26px; letter-spacing: -.025em; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 62ch; }
.page-head.with-action { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { position: static; height: auto; width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px 12px; gap: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 0; } .brand small, .nav-label, .worker-pill { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; order: 3; width: 100%; }
  .nav a { margin: 0; padding: 7px 10px; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; }
  main { padding: 20px 16px 56px; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card + .card { margin-top: 18px; }
.card h2 { font-size: 17px; margin-bottom: 4px; }
.card .sub { color: var(--muted); margin-bottom: 18px; }

/* ---------- Wizard ---------- */
.send-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 24px; align-items: start; }
@media (max-width: 1060px) { .send-grid { grid-template-columns: 1fr; } }
.send-side { position: sticky; top: 24px; }
@media (max-width: 1060px) { .send-side { position: static; } }

.stepper { display: flex; gap: 10px; list-style: none; padding: 0; margin: 0 0 18px; }
.stepper li {
  flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; color: var(--muted); font-weight: 600; cursor: pointer; transition: .15s;
}
.stepper li b { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-size: 12.5px; flex: none; }
.stepper li.active { color: var(--text); border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.stepper li.active b { background: var(--grad); color: #fff; }
.stepper li.done b { background: var(--ok-soft); color: var(--ok); }
@media (max-width: 560px) { .stepper li span { display: none; } .stepper li { justify-content: center; } }

.var { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.var .tag { flex: none; min-width: 52px; text-align: center; padding: 9px 6px; border-radius: 9px; background: var(--surface-3); color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

.tabs { display: flex; gap: 4px; background: var(--surface-3); border-radius: 12px; padding: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { flex: 1; padding: 8px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: .15s; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.drop {
  display: block; text-align: center; padding: 26px 14px; border: 2px dashed var(--line-strong); border-radius: 14px; cursor: pointer; color: var(--muted);
  transition: .15s; background: var(--surface-2);
}
.drop:hover, .drop.over { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.drop input { display: none; }

#extraFields { margin-top: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { padding: 2px 11px; border-radius: 99px; font-size: 12.5px; cursor: pointer; background: var(--brand-soft); font-family: ui-monospace, Consolas, monospace; color: var(--brand); border: 0; }
.chip:hover { filter: brightness(.96); }

.summary { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.tile { flex: 1; min-width: 100px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.tile b { display: block; font-size: 22px; line-height: 1.2; letter-spacing: -.02em; }
.tile span { color: var(--muted); font-size: 12.5px; }
.tile.ok b { color: var(--ok); } .tile.bad b { color: var(--bad); } .tile.warn b { color: var(--warn); } .tile.info b { color: var(--info); }

.notice { margin-top: 14px; padding: 11px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 13.5px; }
.notice.info { background: var(--info-soft); color: var(--info); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }

.speed { display: flex; gap: 10px; flex-wrap: wrap; }
.speed label { flex: 1; min-width: 130px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 11px 14px; cursor: pointer; background: var(--surface); transition: .15s; }
.speed label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-soft); }
.speed input { display: none; }
.speed b { display: block; }
.speed span { color: var(--muted); font-size: 12.5px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.td-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; display: flex; min-width: 90px; }
.progress i { display: block; height: 100%; transition: width .3s; }
.progress .p-sent { background: var(--ok); } .progress .p-failed { background: var(--bad); }
.progress .p-skipped { background: var(--warn); } .progress .p-invalid { background: color-mix(in srgb, var(--bad) 55%, var(--surface-3)); }

.feed { margin-top: 16px; max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
.feed div { display: flex; gap: 10px; align-items: center; padding: 7px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.feed div:last-child { border-bottom: 0; }
.feed .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Dashboard cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat b { display: block; font-size: 28px; letter-spacing: -.03em; line-height: 1.25; }
.stat small { color: var(--muted); }
.stat.hero { background: var(--grad); border-color: transparent; color: #fff; }
.stat.hero span, .stat.hero small { color: rgba(255, 255, 255, .8); }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.tpl { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 7px; }
.tpl h3 { font-size: 15.5px; }
.tpl .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl .txt { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tpl .row-actions { margin-top: auto; padding-top: 10px; }

/* ---------- Developers view ---------- */
.dev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; margin-bottom: 18px; }
.dev-grid .card { margin: 0; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 6px 6px 6px 12px; margin-top: 8px; }
.copybox code { background: none; padding: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
pre.code { background: var(--code-bg); color: var(--code-text); border-radius: 12px; padding: 14px 16px; overflow: auto; font: 12.5px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace; margin: 10px 0 0; }
.keyshow { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 12px 14px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; font-weight: 600; margin: 10px 0; }

/* ---------- Phone preview ---------- */
.phone { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.phone-top { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: #075e54; color: #fff; font-weight: 600; }
:root[data-theme="dark"] .phone-top { background: #12332e; }
.phone-top .who { font-weight: 400; opacity: .8; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-top button { margin-left: auto; background: rgba(255, 255, 255, .16); border: 0; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; }
.phone-top button + button { margin-left: 4px; }
.chat { background: var(--chat-bg); padding: 18px 12px 20px; min-height: 270px; }
.bubble { background: var(--bubble); border-radius: 4px 14px 14px 14px; padding: 4px; max-width: 94%; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); font-size: 14px; }
.bubble .hdr img { width: 100%; border-radius: 11px 11px 4px 4px; display: block; background: var(--surface-2); }
.bubble .hdr .ph { height: 120px; border-radius: 11px 11px 4px 4px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: 13px; text-align: center; padding: 8px; }
.bubble .hdr .ht { font-weight: 700; padding: 6px 8px 0; }
.bubble .txt { padding: 6px 8px; white-space: pre-wrap; word-break: break-word; }
.bubble .txt mark { background: var(--brand-soft); color: var(--brand-d); border-radius: 5px; padding: 0 3px; }
.bubble .time { text-align: right; font-size: 11px; color: var(--muted); padding: 0 8px 4px; }
.bubble .cta { border-top: 1px solid var(--line); margin-top: 2px; text-align: center; color: var(--info); font-weight: 600; padding: 8px; }
.phone-foot { padding: 10px 16px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- Dialogs / toasts ---------- */
dialog { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(8, 10, 30, .4); max-width: min(980px, calc(100vw - 24px)); width: 100%; }
dialog::backdrop { background: rgba(8, 10, 28, .6); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 18px; }
.dlg-body { padding: 20px 22px; max-height: 70vh; overflow: auto; }
.dlg-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog.small { max-width: 440px; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 8px; }
.pill { padding: 4px 13px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.pill.active { background: var(--grad); border-color: transparent; color: #fff; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; max-width: 360px; animation: pop .2s ease-out; }
.toast.err { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-art { background: var(--grad); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.login-art::before, .login-art::after { content: ""; position: absolute; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .18); }
.login-art::before { width: 520px; height: 520px; right: -200px; top: -160px; box-shadow: 0 0 0 70px rgba(255, 255, 255, .05), 0 0 0 140px rgba(255, 255, 255, .04); }
.login-art::after { width: 320px; height: 320px; left: -120px; bottom: -120px; }
.login-art .logo { background: rgba(255, 255, 255, .2); box-shadow: none; width: 48px; height: 48px; }
.login-art h2 { font-size: 40px; line-height: 1.1; letter-spacing: -.03em; margin: 26px 0 14px; max-width: 14ch; }
.login-art p { font-size: 16px; opacity: .88; max-width: 38ch; }
.login-art ul { list-style: none; padding: 0; margin: 30px 0 0; display: grid; gap: 12px; position: relative; z-index: 1; }
.login-art li { display: flex; align-items: center; gap: 10px; opacity: .95; }
.login-art li svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 26px; margin-bottom: 4px; }
@media (max-width: 860px) { .login-page { grid-template-columns: 1fr; } .login-art { display: none; } }
