:root {
  --bg: #f4f4f1;
  --card: #ffffff;
  --text: #17171a;
  --muted: #6b6b73;
  --line: #e4e4de;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --ok-bg: #e5f4ea;
  --warn: #a35a00;
  --warn-bg: #fdf0dc;
  --bad: #c0322b;
  --bad-bg: #fbe6e4;
  --chip: #ececE6;
  --radius: 14px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114; --card: #1c1c21; --text: #f1f1f3; --muted: #9a9aa3; --line: #2c2c33;
    --accent: #5b8cff; --ok: #4cc27c; --ok-bg: #173323; --warn: #f0a646; --warn-bg: #3a2a12;
    --bad: #ff7a70; --bad-bg: #3d1c1a; --chip: #2a2a31;
  }
}
:root[data-theme="dark"] {
  --bg: #111114; --card: #1c1c21; --text: #f1f1f3; --muted: #9a9aa3; --line: #2c2c33;
  --accent: #5b8cff; --ok: #4cc27c; --ok-bg: #173323; --warn: #f0a646; --warn-bg: #3a2a12;
  --bad: #ff7a70; --bad-bg: #3d1c1a; --chip: #2a2a31;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; background: var(--bg); }
.top-title { flex: 1; font-weight: 700; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { color: var(--muted); display: flex; padding: 6px; border-radius: 10px; border: 0; background: none; }
.icon-btn.back { color: var(--accent); margin-left: -8px; }
.view { max-width: 720px; margin: 0 auto; padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 90px); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tab-h) + var(--safe-b)); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; }
.tabs a.on { color: var(--accent); }
body.no-tabs .tabs { display: none; }
body.no-tabs .view { padding-bottom: calc(var(--safe-b) + 90px); }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 26px; font-weight: 700; line-height: 1.15; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .card { margin: 0; }
.stack > * + * { margin-top: 8px; }

.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 2px; margin: 6px 0 4px; }
.seg button { flex: 1; border: 0; background: none; color: var(--text); padding: 7px 4px; border-radius: 9px; font: inherit; font-size: 14px; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
select.chip { appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }

.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin: 10px 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--chip); display: flex; align-items: center;
  justify-content: center; font-weight: 600; color: var(--muted); }

.issue { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--text); margin: 8px 0; }
.issue .grow { flex: 1; font-size: 15px; }
.issue a { font-weight: 600; white-space: nowrap; }

.steps { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.steps li::before { content: counter(s); width: 26px; height: 26px; flex: none; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; background: var(--chip); font-size: 13px; font-weight: 600; }
.steps li.done::before { content: "✓"; background: var(--ok-bg); color: var(--ok); }

input, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.search { margin: 6px 0 4px; }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--accent-text); text-align: center; }
.btn.secondary { background: var(--chip); color: var(--text); }
.btn:disabled { opacity: .5; }
.fab { position: fixed; width: auto; left: 16px; right: 16px; bottom: calc(var(--tab-h) + var(--safe-b) + 12px); z-index: 4; max-width: 688px; margin: 0 auto;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kv:first-of-type { border-top: 0; }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.save-state { font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 4px; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.skel { background: linear-gradient(90deg, var(--chip), var(--card), var(--chip)); background-size: 200% 100%;
  animation: sk 1.2s infinite; border-radius: var(--radius); height: 74px; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 80px); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
.login { max-width: 420px; margin: 12vh auto 0; text-align: center; }

/* рассылки */
.bubble { background: var(--chip); border-radius: 14px; padding: 10px 12px; font-size: 15px; overflow-wrap: anywhere; }
.bubble img { display: block; max-width: 100%; border-radius: 10px; margin-bottom: 8px; }
.bubble blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.bubble pre, .bubble code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.tg-btn { margin-top: 6px; text-align: center; padding: 8px; border-radius: 10px; background: var(--card); color: var(--accent); font-weight: 600; font-size: 14px; }
.radio { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.radio input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.btn-edit { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 6px; }
.progress { height: 8px; border-radius: 99px; background: var(--chip); overflow: hidden; margin-top: 12px; }
.progress div { height: 100%; background: var(--accent); transition: width .4s; }
a.kv { color: var(--text); }

/* диалоги */
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 99px; background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; text-align: center; line-height: 18px; }
.tabs a { position: relative; }
.tab-badge { position: absolute; top: 6px; left: 50%; margin-left: 6px; min-width: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.chat-head { display: block; text-align: center; margin: -4px 0 8px; }
.chat { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.msg { max-width: 82%; padding: 8px 11px 5px; border-radius: 16px; background: var(--card); align-self: flex-start;
  font-size: 15px; overflow-wrap: anywhere; border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-left-radius: 16px; border-bottom-right-radius: 5px; }
.msg.out a { color: var(--accent-text); text-decoration: underline; }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; }
.msg audio { max-width: 220px; height: 36px; }
.msg-time { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--chip); padding: 2px 10px; border-radius: 99px; margin: 6px 0; }
body.chat-open .view { padding-bottom: calc(var(--safe-b) + 90px); }
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 10px calc(8px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line); }
.composer textarea { min-height: 40px; max-height: 160px; resize: none; padding: 9px 12px; border-radius: 20px; flex: 1; }
.composer .send { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; }
.composer .icon-btn { height: 40px; align-items: center; cursor: pointer; }

/* аналитика воронки */
.bar-row { margin-top: 10px; }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar div { height: 100%; background: var(--accent); border-radius: 99px; }
.bar div.good { background: var(--ok); }
.bar div.bad { background: var(--warn); }

/* мастер запуска и советы */
.card.launch.done:not(.open) { opacity: .75; }
.card.launch.open { box-shadow: 0 0 0 2px var(--accent) inset; }
.list label.item { cursor: pointer; }
a.issue.tip { background: var(--card); border: 1px solid var(--line); color: var(--text); }
a.issue.tip b { color: var(--accent); white-space: nowrap; font-size: 14px; }
.qr { position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); z-index: 7; max-height: 50vh; overflow: auto;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0,0,0,.12); padding: 8px 12px; }
.qr .kv { align-items: center; }
.qr .kv > a { flex: 1; min-width: 0; overflow: hidden; }
.qr .kv > a .ellipsis { display: block; }
.qr .kv > .chip { flex: none; }
/* история переписки: сообщения бота и рассылок, действия человека, события */
.msg.out.auto { background: var(--chip); color: var(--text); border: 1px solid var(--line, rgba(127,127,127,.18)); }
.msg.out.auto a { color: var(--accent); }
.msg .who { font-size: 11px; font-weight: 600; opacity: .7; margin-bottom: 2px; }
.msg.act { font-style: italic; opacity: .85; }
.evt { align-self: center; font-size: 12px; color: var(--text); background: var(--ok-bg, var(--chip)); padding: 4px 12px; border-radius: 99px; margin: 2px 0; text-align: center; max-width: 92%; }
.evt .msg-time { display: inline; margin-left: 6px; }
.chips .chip { width: auto; flex: none; }
