/* Цвета берутся из темы Telegram, поэтому приложение выглядит родным и в светлой, и в тёмной теме. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #EFEFF3);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #FFFFFF));
  --text: var(--tg-theme-text-color, #16181C);
  --hint: var(--tg-theme-hint-color, #6E7480);
  --link: var(--tg-theme-link-color, #2370D4);
  --btn: var(--tg-theme-button-color, #2370D4);
  --btn-text: var(--tg-theme-button-text-color, #FFFFFF);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--btn) 10%, var(--card));
  --ok: #1E9E57;
  --wait: #B26B00;
  --bad: #D6363F;
  --chat: color-mix(in srgb, var(--btn) 7%, var(--bg));
  --r: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #101114; --card: #1C1E23; --text: #F2F3F5; --hint: #959BA6; --link: #6AA8FF; --btn: #3B82F6;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }
h1 { font-size: 28px; line-height: 1.15; font-weight: 700; margin: 12px 0 6px; letter-spacing: -.01em; }
h2 { font-size: 20px; line-height: 1.25; font-weight: 650; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.lead { color: var(--hint); font-size: 17px; margin-bottom: 20px; }
.hint { color: var(--hint); font-size: 15px; }
.small { font-size: 14px; color: var(--hint); }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--btn); outline-offset: 2px; }

#demo-bar { background: #FFF3C4; color: #5B4500; font-size: 14px; text-align: center; padding: 8px 16px; }
@media (prefers-color-scheme: dark) { :root:not([data-tg]) #demo-bar { background: #3D3110; color: #F5DC8A; } }

/* Кнопки */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 52px; padding: 12px 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 17px;
}
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }
.btn.second { background: var(--soft); color: var(--link); }
.btn.plain { background: transparent; color: var(--link); min-height: 44px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .chip-btn { flex: 1 1 auto; }
.chip-btn {
  min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--soft); color: var(--link); font-size: 15px; font-weight: 600;
}
.chip-btn.danger { color: var(--bad); background: color-mix(in srgb, var(--bad) 9%, var(--card)); }
.chip-btn.ok { color: #fff; background: var(--ok); }
.sticky { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); margin-top: 20px; z-index: 2; }
.sticky.no-tabs { bottom: calc(12px + env(safe-area-inset-bottom)); }

/* Блоки как в настройках Telegram: белая секция на сером фоне */
.group { background: var(--card); border-radius: var(--r); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 56px; width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer; color: var(--text); }
.item + .item { border-top: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--hint); font-size: 15px; }
.item .end { color: var(--hint); font-size: 15px; white-space: nowrap; }
.pad { padding: 16px; }

/* Поля */
label.field { display: block; margin-bottom: 18px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; color: var(--hint); font-size: 14px; margin-top: 6px; }
input[type=text], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px; outline: none;
}
input[type=text]:focus, textarea:focus { border-color: var(--btn); }
textarea { min-height: 96px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px;
  font-size: 15px; cursor: pointer; color: var(--text); }

/* Выбор одного варианта */
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer; }
.choice + .choice { border-top: 1px solid var(--line); }
.choice input { appearance: none; flex: none; width: 22px; height: 22px; margin: 2px 0 0; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-content: center; }
.choice input:checked { border-color: var(--btn); background: var(--btn); box-shadow: inset 0 0 0 4px var(--card); }
.choice .title { font-weight: 600; }
.choice .sub { color: var(--hint); font-size: 15px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { font-size: 15px; line-height: 1.2; padding: 6px 4px; border: 0; background: none; border-radius: 9px; min-height: 42px; cursor: pointer; font-weight: 600; color: var(--hint); }
.seg button[aria-pressed=true] { background: var(--btn); color: var(--btn-text); }
.seg button[disabled] { opacity: .35; cursor: default; }

/* Прогресс анкеты: это настоящая последовательность, поэтому шаги пронумерованы */
.progress { display: flex; gap: 6px; margin: 4px 0 6px; }
.progress i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.progress i.on { background: var(--btn); }
.step-label { color: var(--hint); font-size: 15px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--link); background: none; border: 0; padding: 6px 0; cursor: pointer; font-size: 17px; }

/* Главная деталь: канал показан так, как его увидят подписчики */
.tg-head { background: var(--card); border-radius: var(--r); padding: 20px 16px 16px; text-align: center; margin-bottom: 12px; }
.tg-head .ava { width: 84px; height: 84px; margin: 0 auto 10px; }
.tg-head .ava svg { width: 100%; height: 100%; display: block; }
.tg-head .name { font-size: 22px; font-weight: 700; line-height: 1.2; }
.tg-head .meta { color: var(--hint); font-size: 15px; margin-top: 2px; }
.tg-head .about { text-align: left; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 16px; }
.tg-head .about small { display: block; color: var(--hint); font-size: 14px; margin-bottom: 2px; }
.stats { display: flex; justify-content: center; gap: 28px; margin-top: 14px; }
.stats b { display: block; font-size: 20px; }
.stats span { color: var(--hint); font-size: 14px; }

.feed { background: var(--chat); border-radius: var(--r); padding: 12px; }
.bubble { background: var(--card); border-radius: 16px 16px 16px 6px; padding: 10px 14px 8px; margin-bottom: 10px;
  font-size: 16px; line-height: 1.45; max-width: 100%; overflow-wrap: anywhere; box-shadow: 0 1px 1px color-mix(in srgb, #000 8%, transparent); }
.bubble:last-child { margin-bottom: 0; }
.bubble .txt { white-space: pre-wrap; }
.bubble .foot { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-top: 6px; color: var(--hint); font-size: 13px; }
.bubble .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.bubble.edit textarea { min-height: 180px; margin-top: 4px; }
.status { font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.status.draft { color: var(--wait); background: color-mix(in srgb, var(--wait) 12%, var(--card)); }
.status.scheduled { color: var(--link); background: var(--soft); }
.status.published { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--card)); }

.tabs2 { display: flex; gap: 6px; overflow-x: auto; margin: 4px 0 12px; scrollbar-width: none; }
.tabs2 button { flex: none; border: 0; border-radius: 999px; padding: 8px 14px; background: var(--card); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; }
.tabs2 button[aria-pressed=true] { background: var(--text); color: var(--card); }
.tabs2 .n { color: var(--hint); font-weight: 500; margin-left: 4px; }
.tabs2 button[aria-pressed=true] .n { color: inherit; opacity: .7; }

/* Шаги подключения */
.steps { counter-reset: s; }
.steps .st { display: flex; gap: 14px; padding: 16px; }
.steps .st + .st { border-top: 1px solid var(--line); }
.steps .st::before { counter-increment: s; content: counter(s); flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--soft); color: var(--link); font-weight: 700; display: grid; place-items: center; font-size: 15px; }
.steps .st b { display: block; margin-bottom: 2px; }
.steps code { background: var(--soft); padding: 1px 6px; border-radius: 6px; font-size: 15px; }

/* Тарифы */
.plan { padding: 16px; cursor: pointer; display: block; }
.plan + .plan { border-top: 1px solid var(--line); }
.plan .top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.plan .pname { font-size: 19px; font-weight: 700; }
.plan .price { font-size: 19px; font-weight: 700; white-space: nowrap; }
.plan .rub { color: var(--hint); font-size: 14px; text-align: right; white-space: nowrap; }
.plan ul { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.plan li { font-size: 14px; background: var(--bg); border-radius: 8px; padding: 3px 9px; }
.plan[aria-checked=true] { box-shadow: inset 4px 0 0 var(--btn); background: var(--soft); }
.plan .cur { font-size: 13px; font-weight: 600; color: var(--ok); }

.empty { text-align: center; padding: 28px 16px 8px; }
.empty .pic { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 22px; background: var(--soft); display: grid; place-items: center; }
.empty .pic svg { width: 36px; height: 36px; fill: none; stroke: var(--link); stroke-width: 1.8; stroke-linejoin: round; }

.note { background: var(--soft); border-radius: 12px; padding: 12px 14px; font-size: 15px; margin-bottom: 12px; }
.note.warn { background: color-mix(in srgb, var(--wait) 12%, var(--card)); }
.err { color: var(--bad); font-size: 15px; margin: 8px 0 0; }

.loading { text-align: center; padding: 64px 16px; }
.spin { width: 36px; height: 36px; margin: 0 auto 16px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--btn); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Нижнее меню */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); }
#tabs a { flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; color: var(--hint); font-size: 12px; font-weight: 600; border-radius: 10px; }
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
#tabs a.on { color: var(--btn); }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 520px;
  background: var(--text); color: var(--card); padding: 13px 16px; border-radius: 12px; font-size: 15px; z-index: 20;
  animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

dialog#sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  background: var(--card); color: var(--text); max-height: 90vh; }
dialog#sheet::backdrop { background: rgb(0 0 0 / .45); }
dialog#sheet[open] { animation: sheet .22s ease-out; }
@keyframes sheet { from { transform: translateY(30px); opacity: .6; } }
.sheet-body { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-body h2 { margin-top: 0; }
.sum { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.sum:first-of-type { border-top: 0; }
.sum b { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

.choice #own { flex: 1; min-width: 0; font-weight: 600; }

/* Счётчик постов в день */
.stepper { display: inline-flex; align-items: center; background: var(--soft); border-radius: 12px; padding: 4px; gap: 2px; flex: none; }
.stepper button { width: 44px; height: 44px; border: 0; border-radius: 9px; background: var(--card); color: var(--link); font-size: 24px; line-height: 1; cursor: pointer; }
.stepper button[disabled] { opacity: .35; cursor: default; }
.stepper output { min-width: 44px; text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row input { flex: 1; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }
.line { border-top: 1px solid var(--line); }
.group > .line:first-child { border-top: 0; }
.toggle { cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--ok); flex: none; }
.status.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--card)); }
.spin.inline { display: inline-block; width: 15px; height: 15px; margin: 0 6px -2px 0; border-width: 2px; }
.bubble .fail { color: var(--bad); font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .04em; }
select, input[type=number], input[type=password] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: 48px; }
select:focus, input[type=number]:focus, input[type=password]:focus { border-color: var(--btn); outline: none; }
.code { display: block; width: 100%; margin: 14px 0 12px; padding: 14px; border: 1.5px dashed var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font-size: 30px; font-weight: 700; letter-spacing: .12em; cursor: pointer; text-align: center; }
.code small { display: block; font-size: 13px; letter-spacing: 0; font-weight: 400; color: var(--hint); margin-top: 2px; }
code { font-size: 13px; word-break: break-all; }
.status { white-space: nowrap; }
