:root {
  --ground: #F4F5EF;
  --surface: #FFFFFF;
  --ink: #16190F;
  --muted: #5A604F;
  --line: #E2E5DA;
  --line-soft: #EEF0E7;
  --field: #D5D9CB;
  --primary: #2F6A1A;
  --primary-hover: #24531300;
  --bar: #3E8A22;
  --lemon: #E4EC3A;
  --lemon-soft: #EEF3C8;
  --lemon-ink: #2F4A10;
  --danger: #A3321C;
  --chat: #DCE5D2;
  --radius: 16px;
  --font: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --head: Onest, Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 14px; }
a { color: var(--primary); }
a:hover { color: #1F4A10; }
h1, h2, h3 { font-family: var(--head); margin: 0; }
h1 { font-size: 30px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
code { font-size: 12px; background: var(--ground); padding: 2px 6px; border-radius: 6px; }
button { font: inherit; }

/* каркас */
.layout { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 232px; max-width: 100%; background: var(--ink); color: #E9ECE2; padding: 24px 16px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 24px; font-family: var(--head); font-weight: 700; font-size: 19px; color: #fff; text-decoration: none; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border-radius: 10px; color: #C3C9B6; text-decoration: none; }
.side nav a:hover { background: #22271A; color: #fff; }
.side nav a.active { background: #2A3020; color: var(--lemon); font-weight: 600; }
.side .bot-card { margin-top: auto; padding: 14px; border-radius: 12px; background: #22271A; display: flex; flex-direction: column; gap: 6px; }
.side .bot-card .st { display: flex; align-items: center; gap: 8px; font-weight: 600; color: #fff; font-size: 13px; }
.side .bot-card small { color: #B4BBA6; font-size: 12px; }
.side .who { display: flex; justify-content: space-between; align-items: center; color: #B4BBA6; font-size: 12px; padding: 8px 4px 0; }
.side .who button { background: none; border: 0; color: #E9ECE2; cursor: pointer; min-height: 32px; text-decoration: underline; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9AA38C; flex: none; }
.dot.on { background: #7BC24B; }
.dot.off { background: #E0725A; }
main.content { flex: 999 1 560px; min-width: 0; padding: 32px 40px 48px; display: flex; flex-direction: column; gap: 24px; }
@media (max-width: 700px) { main.content { padding: 20px 16px 40px; } h1 { font-size: 24px; } }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.empty { padding: 24px; text-align: center; color: var(--muted); border: 1.5px dashed var(--field); border-radius: 12px; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--field); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: #9AA38C; color: var(--ink); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #24531A; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 44px; padding: 0; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.icon.sm { width: 36px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.dashed { border: 1.5px dashed #9AA38C; background: transparent; color: var(--primary); font-weight: 600; width: 100%; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input.i, select.i, textarea.i { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--field); background: var(--surface); font: inherit; font-size: 14px; color: var(--ink); width: 100%; }
textarea.i { padding: 10px 12px; resize: vertical; line-height: 1.45; }
input.i:focus, select.i:focus, textarea.i:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--bar); outline-offset: 1px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.hint { font-size: 12px; color: var(--muted); }

/* чипы и бейджи */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--field); background: var(--surface); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--ground); border: 1px solid var(--line); white-space: nowrap; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; background: var(--line-soft); }
.badge.authorized, .badge.sent, .badge.active { background: #E3F0D6; color: #24501A; }
.badge.new, .badge.scheduled, .badge.sending { background: #FFF1C7; color: #6A4A00; }
.badge.blocked, .badge.failed { background: #FBE1DC; color: #8A2A17; }
.badge.unsubscribed, .badge.draft, .badge.completed, .badge.stopped { background: var(--line-soft); color: #3E4436; }
.pill { font-size: 12px; font-weight: 600; background: var(--lemon-soft); color: var(--lemon-ink); padding: 4px 10px; border-radius: 999px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-weight: 500; color: var(--muted); padding: 8px 8px 8px 0; white-space: nowrap; }
table.t td { padding: 10px 8px 10px 0; border-top: 1px solid var(--line-soft); vertical-align: middle; }
table.t tr.sel td { background: #F7FAF0; }
table.t .actions { display: flex; gap: 4px; justify-content: flex-end; }

/* обзор */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.kpi .v { font-family: var(--head); font-size: 32px; font-weight: 700; }
.kpi .n { font-size: 13px; color: var(--primary); font-weight: 600; }
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-row .lbl { display: flex; justify-content: space-between; }
.bar { height: 14px; border-radius: 7px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 7px; background: var(--bar); }
.hbar { display: grid; grid-template-columns: 130px minmax(0, 1fr) 48px; gap: 12px; align-items: center; }
.hbar .bar { height: 10px; }
.hbar .bar > i { background: #C9D22A; }
.feed-item { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.ava { width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--lemon-soft); color: var(--lemon-ink); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; }
.ava.lg { width: 48px; height: 48px; background: var(--lemon); color: var(--ink); font-family: var(--head); font-weight: 700; font-size: 15px; }

/* сценарий */
.flow-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.flow-card span:last-child { color: var(--muted); font-size: 13px; line-height: 1.45; }

/* предпросмотр Telegram */
.chat { background: var(--chat); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.msg { max-width: 88%; background: #fff; border-radius: 14px 14px 14px 4px; padding: 10px 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: #EFFDDE; border-radius: 14px 14px 4px 14px; }
.msg.media { padding: 0; overflow: hidden; }
.msg.media .txt { padding: 10px 12px; }
.msg img { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.msg .file { padding: 12px; background: #F7FAF2; display: flex; gap: 8px; align-items: center; font-weight: 600; }
.kb { max-width: 88%; display: flex; flex-direction: column; gap: 6px; }
.kb button, .kb a { min-height: 44px; border: 0; border-radius: 10px; background: #F7FAF2; color: var(--ink); display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; cursor: pointer; padding: 0 12px; text-align: center; }
.kb .go { background: var(--primary); color: #fff; font-weight: 600; }
.box { width: 14px; height: 14px; border: 2px solid #9AA38C; border-radius: 4px; }

/* воронки */
.f-list { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.f-item { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 15px 17px; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: 6px; text-decoration: none; }
.f-item:hover { border-color: #9AA38C; color: var(--ink); }
.f-item.sel { border: 2px solid var(--primary); padding: 14px 16px; }
.f-item .meta { font-size: 12px; color: var(--muted); }
.f-item.sel .meta { color: var(--primary); font-weight: 600; }
.trigger { border-radius: 12px; background: var(--ink); color: #fff; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.trigger small { color: #C3C9B6; display: block; font-size: 12px; }
.connector { display: flex; flex-direction: column; align-items: center; padding: 6px 0; }
.connector i { width: 2px; height: 14px; background: var(--field); }
.step { position: relative; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 15px 17px; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: 8px; width: 100%; }
.step.sel { border: 2px solid var(--primary); padding: 14px 16px; background: #FBFCF8; }
.step .s-text { line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.btn-rows { display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) 44px; gap: 8px; }
.upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.upload .name { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* модальное окно, уведомления, вход */
.modal-bg { position: fixed; inset: 0; background: rgba(22, 25, 15, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 420px; }
.toast.err { background: var(--danger); }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; }
.login .brand { display: flex; align-items: center; gap: 10px; font-family: var(--head); font-weight: 700; font-size: 22px; }
.err-text { color: var(--danger); font-size: 13px; min-height: 18px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 8px; }
dl.kv { margin: 0; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 12px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline div { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 10px; font-size: 13px; }
.timeline div::before { content: ''; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--bar); }
.progress { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--bar); }
