:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2b7de9);
  --btn: var(--tg-theme-button-color, #2b7de9);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --line: rgba(127, 127, 127, 0.18);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--link); }

#tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; overflow-x: auto; padding: 8px; background: var(--bg2); scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabs button { flex: 0 0 auto; border: 0; background: transparent; padding: 6px 10px; border-radius: 16px; white-space: nowrap; cursor: pointer; }
#tabs button.active { background: var(--btn); color: var(--btn-text); }

main { padding: 0 0 80px; }
.pad { padding: 12px 16px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { border: 0; background: var(--btn); color: var(--btn-text); padding: 8px 14px; border-radius: var(--radius); cursor: pointer; }
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
input[type=text], input[type=search], input[type=tel], input[type=password], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
textarea { resize: vertical; min-height: 40px; }

.filters { display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; }
.chip .mi { vertical-align: -3px; }
.group-head { display: flex; align-items: center; gap: 6px; padding: 12px 16px 4px; font-weight: 600; font-size: 14px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 4px 10px; white-space: nowrap; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.chip .n { opacity: .75; margin-left: 4px; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.item:active { background: var(--bg2); }
.avatar { flex: 0 0 40px; height: 40px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; font-size: 18px; }
.badge { min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--btn); color: var(--btn-text); font-size: 12px; text-align: center; }
.badge.warn { background: var(--warn); color: #000; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; background: var(--bg2); color: var(--hint); margin-right: 4px; }

.card { margin: 10px 16px; padding: 12px; border-radius: var(--radius); background: var(--bg2); }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.status-online { color: var(--ok); }
.status-error, .status-logged_out { color: var(--danger); }
.status-qr, .status-connecting, .status-offline { color: var(--warn); }
.qr { display: block; margin: 10px auto; width: 240px; height: 240px; background: #fff; border-radius: 8px; }

/* Диалог */
.chat-head { position: sticky; top: 49px; z-index: 4; background: var(--bg); padding: 8px 16px; border-bottom: 1px solid var(--line); }
.messages { padding: 10px 12px 140px; display: flex; flex-direction: column; gap: 6px; }
#older { align-self: center; }
.msg { max-width: 82%; padding: 6px 10px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { align-self: flex-start; background: var(--bg2); }
.msg.out { align-self: flex-end; background: var(--btn); color: var(--btn-text); }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 2px; text-align: right; }
.msg.failed { outline: 2px solid var(--danger); }
.composer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.composer .row { align-items: flex-end; }
.tpl-bar { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; padding: 10px 16px; }
.kpi { background: var(--bg2); border-radius: var(--radius); padding: 10px; }
.kpi b { display: block; font-size: 22px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
form .field { margin-bottom: 8px; }
label.check { display: flex; gap: 8px; align-items: center; }

#toast { position: fixed; left: 16px; right: 16px; bottom: 90px; z-index: 20; background: #222; color: #fff; padding: 10px 14px; border-radius: var(--radius); text-align: center; }

/* Знаки мессенджеров */
.mi { display: inline-block; vertical-align: -4px; flex: 0 0 auto; }
.avatar:has(.mi) { background: transparent; display: flex; flex-wrap: wrap; gap: 2px; align-content: center; justify-content: center; }
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }

/* Пространство на паузе (пробный период закончился): текст замылен. Настоящего
   текста в DOM нет — сервер его не отдаёт, здесь только заглушка той же длины. */
.blur { filter: blur(5px); user-select: none; -webkit-user-select: none; pointer-events: none; }
#access-bar { position: sticky; top: 49px; z-index: 4; padding: 8px 16px; background: var(--warn); color: #000; font-size: 13px; display: flex; gap: 8px; align-items: center; }
#access-bar[hidden] { display: none; }
#access-bar.locked { background: var(--danger); color: #fff; }
#access-bar .btn { background: rgba(0, 0, 0, .25); color: inherit; white-space: nowrap; }
.paywall { text-align: center; }
.paywall .btn { margin-top: 6px; }
