/* Broadgram Mini App — стиль «как родной Telegram»: системный шрифт, серый
   фон, белые группы, цвета из themeParams (переменные --tg-theme-*), в
   прогоне — моноширинные цифры и чипы статусов. */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #6d6d72);
  /* приглушённый текст прямо на сером фоне страницы (не в белой группе):
     hint-цвет Telegram там сливается с фоном, поэтому подмешиваем основной */
  --hint-bg: var(--hint);
  --link: var(--tg-theme-link-color, #3390ec);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.1));
  --danger: var(--tg-theme-destructive-text-color, #d12b2b);
  --ok: #34c759;
  --warn: #ff9500;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@supports (color: color-mix(in srgb, red, blue)) {
  :root { --hint-bg: color-mix(in srgb, var(--hint) 45%, var(--text)); }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  min-height: 100vh;
}

.center { text-align: center; padding: 48px 16px; }
.muted { color: var(--hint); }
.muted-bg, .center .muted, .center.muted { color: var(--hint-bg); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.bold { font-weight: 600; }
.pre { white-space: pre-wrap; word-break: break-word; }
.nowrap { white-space: nowrap; }
.grow { flex-grow: 1; min-width: 0; }
.danger { color: var(--danger); }

/* --- шапка ------------------------------------------------------------- */
.top {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0 12px;
}
.top h1 { font-size: 20px; font-weight: 600; margin: 0; flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { font-size: 13px; color: var(--hint-bg); font-weight: 400; display: block; }
.top .back {
  width: 36px; height: 36px; margin-left: -8px; border: 0; background: transparent;
  color: var(--link); display: flex; align-items: center; justify-content: center; border-radius: 18px;
}
.chip-btn {
  height: 32px; padding: 0 12px; border-radius: 16px; border: 0;
  background: var(--card); color: var(--link); font-weight: 600; font-size: 14px;
}

/* --- секции и ячейки --------------------------------------------------- */
.section { margin: 0 0 20px; }
.section > .label {
  font-size: 13px; color: var(--hint-bg); text-transform: uppercase; letter-spacing: 0.02em;
  padding: 0 16px 6px;
}
.section > .footer { font-size: 13px; color: var(--hint-bg); padding: 6px 16px 0; }
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.cell {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 16px;
  width: 100%; border: 0; background: transparent; text-align: left; color: var(--text);
  position: relative;
}
.cell + .cell::before {
  content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep);
}
.cell.tap:active { background: var(--sep); }
.cell .ico {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.cell .title { font-size: 16px; }
.cell .meta { font-size: 13px; color: var(--hint); margin-top: 2px; }
.cell .value { color: var(--hint); font-size: 15px; flex-shrink: 0; }
.cell .chev { color: var(--sep); flex-shrink: 0; }
.cell .chev svg { stroke: #c7c7cc; }
.cell.block { display: block; }
.cell.stack { flex-direction: column; align-items: stretch; gap: 6px; }

/* --- формы ------------------------------------------------------------- */
.field { padding: 10px 16px 12px; }
.field label, .field .label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.field input[type="text"], .field input[type="number"], .field textarea {
  width: 100%; border: 0; border-radius: 8px; padding: 10px 12px;
  background: var(--bg); color: var(--text); outline: none; font-size: 16px;
}
.field textarea { min-height: 120px; resize: vertical; }
.field .hint { font-size: 13px; color: var(--hint); margin-top: 8px; }
.field .error { font-size: 13px; color: var(--danger); margin-top: 8px; }
.field .counter { font-size: 12px; color: var(--hint); text-align: right; margin-top: 4px; font-family: var(--mono); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 15px; background: #c7c7cc; transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 13px;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* --- кнопки ------------------------------------------------------------ */
.actions { display: flex; flex-direction: column; gap: 8px; margin: 0 0 20px; }
.btn {
  height: 48px; border-radius: 10px; border: 0; padding: 0 16px; width: 100%;
  font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); color: var(--link);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.plain { background: transparent; height: 44px; }
.btn.small { height: 36px; font-size: 14px; padding: 0 14px; width: auto; }
.btn.outline { background: transparent; border: 1px solid var(--sep); color: var(--text); }
.btn:disabled { opacity: .5; }
.btn:active { opacity: .7; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex-grow: 1; }

/* --- чипы и прогресс --------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 12px;
  font-size: 12px; font-weight: 600; font-family: var(--mono); letter-spacing: .02em; white-space: nowrap;
}
.chip.ok { background: rgba(52,199,89,.15); color: #1f8f3d; }
.chip.warn { background: rgba(255,149,0,.15); color: #b36b00; }
.chip.info { background: rgba(51,144,236,.15); color: var(--link); }
.chip.bad { background: rgba(209,43,43,.12); color: var(--danger); }
.chip.gray { background: var(--sep); color: var(--hint-bg); }
.chip .dot { width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.chip .dot.live { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.bar { height: 6px; border-radius: 3px; background: var(--sep); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }
.counter { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 14px; color: var(--hint); }

/* --- баланс ------------------------------------------------------------ */
.balance { padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.balance .amount { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.balance .hint { font-size: 13px; color: var(--hint); margin-top: 2px; }
.balance .btn { width: auto; height: 44px; }

/* --- сообщения рассылки ------------------------------------------------ */
.msg { display: flex; gap: 12px; padding: 12px 16px; position: relative; }
.msg + .msg::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep); }
.msg .thumb {
  width: 56px; height: 56px; border-radius: 8px; flex-shrink: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--link);
}
.msg .thumb img { width: 100%; height: 100%; object-fit: cover; }
.msg .body { min-width: 0; flex-grow: 1; }
.msg .head { font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.msg .text { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.msg .text.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.media-preview { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.media-preview .thumb { width: 64px; height: 64px; border-radius: 8px; background: var(--bg); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--link); flex-shrink: 0; }
.media-preview .thumb img { width: 100%; height: 100%; object-fit: cover; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* --- прочее ------------------------------------------------------------ */
.steps { font-size: 13px; color: var(--hint-bg); padding: 0 16px 8px; }
.empty { padding: 28px 16px; text-align: center; color: var(--hint); font-size: 15px; white-space: pre-line; }
.notice { padding: 12px 16px; font-size: 14px; color: var(--hint-bg); }
.notice.warn { color: #b36b00; }
.rules { padding: 14px 16px; font-size: 15px; line-height: 1.45; white-space: pre-line; }
.rules b { font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; position: relative; }
.kv + .kv::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep); }
.kv .k { color: var(--text); }
.kv .v { color: var(--hint); text-align: right; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + var(--safe-bottom)); }
.sheet p { margin: 0 0 16px; font-size: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; z-index: 100; text-align: center;
}
@media (prefers-color-scheme: dark) {
  #toast { background: rgba(255,255,255,.92); color: #000; }
  .cell .chev svg { stroke: #5a5a5e; }
}
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
