/* Support Bot — админ-панель. Цвета берутся из темы Telegram, поэтому светлая/тёмная тема работает сама. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #8a9199);
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2f8ae8);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --header: var(--tg-theme-section-header-text-color, var(--accent));
  --sep: var(--tg-theme-section-separator-color, color-mix(in srgb, var(--hint) 22%, transparent));
  --bubble-in: var(--surface);
  --bubble-out: color-mix(in srgb, var(--accent) 16%, var(--surface));
  --radius: 14px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --st-new: #2f8ae8;
  --st-in_progress: #e8912f;
  --st-waiting: #8b5cf6;
  --st-postponed: #8a9199;
  --st-closed: #2fb36d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--link); text-decoration: none; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--hint); }
.hidden { display: none !important; }

/* ── загрузка / ошибки ── */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; }
.gate h2 { margin: 12px 0 6px; font-size: 20px; }
.gate p { margin: 0; color: var(--hint); }
.gate .emoji { font-size: 48px; }

/* ── каркас ── */
.view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.view.pushed { z-index: 5; animation: push .22s cubic-bezier(.2,.8,.2,1); }
@keyframes push { from { transform: translateX(28%); opacity: .4; } }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.page { padding: 12px 12px calc(var(--tab-h) + var(--safe-b) + 16px); }

.topbar { background: var(--surface); border-bottom: 1px solid var(--sep); padding: 10px 12px 8px; }
.topbar h1 { font-size: 22px; margin: 2px 4px 10px; letter-spacing: -.01em; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; background: var(--surface);
  border-top: 1px solid var(--sep); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--hint); position: relative; }
.tabs button.on { color: var(--accent); }
.tabs .dot { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; }

/* ── поиск и чипы ── */
.search { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 10px; padding: 0 10px; height: 38px; }
.search input { flex: 1; border: 0; background: none; outline: none; min-width: 0; }
.search svg { width: 18px; height: 18px; color: var(--hint); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px -12px 0; padding: 0 12px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 30px; padding: 0 12px; border-radius: 15px; background: var(--bg); color: var(--text); font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-text); }
.chip .n { font-size: 12px; opacity: .65; }

/* ── список обращений ── */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; gap: 11px; padding: 10px 12px; align-items: center; width: 100%; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--sep); }
.row:active { background: var(--accent-soft); }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff;
  font-weight: 600; font-size: 16px; letter-spacing: .02em; }
.avatar.lg { width: 76px; height: 76px; font-size: 28px; }
.row .main { flex: 1; min-width: 0; }
.row .line { display: flex; align-items: center; gap: 6px; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { margin-left: auto; font-size: 12.5px; color: var(--hint); flex: none; }
.row .prev { flex: 1; min-width: 0; color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .prev b { color: var(--text); font-weight: 500; }
.badge { flex: none; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.pill { flex: none; display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 10px;
  font-size: 11.5px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.flag { font-size: 13px; flex: none; }
.ico-warn { color: var(--danger); font-size: 12px; flex: none; }
.tagdots { display: inline-flex; gap: 3px; flex: none; }
.tagdots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.empty { text-align: center; padding: 56px 24px; color: var(--hint); }
.empty .emoji { font-size: 40px; display: block; margin-bottom: 8px; }
.more { display: block; width: 100%; padding: 14px; color: var(--link); }

/* ── чат ── */
.chathead { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--sep); }
.chathead .who { flex: 1; min-width: 0; text-align: left; }
.chathead .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chathead .who small { color: var(--hint); font-size: 12.5px; }
.chathead .avatar { width: 38px; height: 38px; font-size: 14px; }
.chathead .pill { height: 28px; padding: 0 11px; font-size: 12.5px; border-radius: 14px; }
.banner { padding: 8px 14px; font-size: 13px; text-align: center; background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.msgs { padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; padding: 3px 10px; border-radius: 12px; font-size: 12.5px; font-weight: 500;
  background: color-mix(in srgb, var(--hint) 18%, transparent); color: var(--sub); }
.sys { align-self: center; max-width: 86%; text-align: center; margin: 4px 0; padding: 4px 10px; border-radius: 12px; font-size: 12.5px;
  color: var(--sub); background: color-mix(in srgb, var(--hint) 12%, transparent); }
.b { max-width: min(82%, 520px); padding: 7px 10px 6px; border-radius: 16px; background: var(--bubble-in); position: relative;
  word-wrap: break-word; white-space: pre-wrap; box-shadow: 0 1px 0.5px rgba(0,0,0,.08); }
.b.in { align-self: flex-start; border-bottom-left-radius: 6px; }
.b.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 6px; }
.b.media { padding: 3px; }
.b.media .cap { padding: 5px 7px 3px; }
.b.bare { background: none; box-shadow: none; padding: 0; }
.b .meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--hint); white-space: nowrap; }
.b.media .meta { position: absolute; right: 9px; bottom: 7px; float: none; margin: 0; padding: 1px 6px; border-radius: 8px; background: rgba(0,0,0,.45); color: #fff; }
.b.media:has(.cap) .meta { position: static; float: right; background: none; color: var(--hint); margin: 6px 4px -2px 10px; padding: 0; }
.b .who { display: block; font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 1px; }
.b .who.auto { color: var(--hint); font-weight: 500; }
.b img.ph, .b video.ph { display: block; max-width: 100%; width: 300px; max-height: 360px; object-fit: cover; border-radius: 13px; background: var(--bg); }
.b img.st { width: 150px; height: 150px; object-fit: contain; }
.b video.st { width: 150px; height: 150px; }
.b video.round { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; }
.b audio { width: 250px; max-width: 100%; height: 40px; }
.b .emoji-big { font-size: 64px; line-height: 1.1; }
.vwrap { position: relative; display: block; }
.vwrap .play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 46px; height: 46px; border-radius: 50%;
  background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; font-size: 17px; padding-left: 3px; pointer-events: none; }
.viewer video { background: #000; }
.file { display: flex; align-items: center; gap: 10px; padding: 4px 4px 2px; color: var(--text); min-width: 200px; }
.file .fi { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.file .fn { font-weight: 500; word-break: break-all; }
.file small { color: var(--hint); }
.b.sel { outline: 2px solid var(--accent); }
.b.pending { opacity: .6; }

.composer { background: var(--surface); border-top: 1px solid var(--sep); padding: 6px 8px calc(6px + var(--safe-b)); }
.composer .bar { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; resize: none; border: 0; outline: none; background: var(--bg); border-radius: 19px; padding: 9px 14px;
  max-height: 140px; min-height: 38px; line-height: 20px; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--hint); flex: none; }
.iconbtn:active { background: var(--accent-soft); }
.iconbtn.send { background: var(--accent); color: var(--accent-text); }
.iconbtn.send:disabled { opacity: .45; }
.editing, .attach { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; font-size: 13.5px; }
.editing b, .attach b { color: var(--accent); display: block; font-size: 13px; }
.editing .t, .attach .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 2px solid var(--accent); padding-left: 8px; }
.attach img { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; }

/* ── секции / формы ── */
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--header); margin: 18px 16px 6px; font-weight: 500; }
.sec-title:first-child { margin-top: 6px; }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.card + .note, .note { font-size: 13px; color: var(--hint); margin: 6px 16px 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; width: 100%; text-align: left; position: relative; }
.item + .item::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
button.item:active { background: var(--accent-soft); }
.item .k { flex: 1; min-width: 0; }
.item .k small { display: block; color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .v { color: var(--hint); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.item.danger { color: var(--danger); }
.item.accent { color: var(--link); }
.field { display: block; padding: 10px 14px; }
.field + .field { border-top: 1px solid var(--sep); }
.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; border: 0; outline: none; background: none; padding: 2px 0; }
.field textarea { resize: vertical; min-height: 80px; }
.field select { appearance: none; -webkit-appearance: none; color: var(--link); }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; margin-top: 14px; }

.profile { text-align: center; padding: 18px 12px 6px; }
.profile .avatar { margin: 0 auto 10px; }
.profile h2 { margin: 0; font-size: 21px; }
.profile p { margin: 3px 0 0; color: var(--hint); }
.taglist { display: flex; flex-wrap: wrap; gap: 7px; padding: 12px 14px; }
.tag { height: 28px; line-height: 1; padding: 0 11px; border-radius: 14px; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--c); color: var(--c); }
.tag.on { background: var(--c); color: #fff; }
.swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 0; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: var(--text); }

/* ── статистика ── */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 2px; }
.seg button { flex: 1; height: 30px; border-radius: 8px; font-size: 13.5px; color: var(--hint); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; }
.kpi small { display: block; color: var(--hint); font-size: 12.5px; }
.kpi b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi em { font-style: normal; font-size: 12.5px; color: var(--hint); }
.chart { background: var(--surface); border-radius: var(--radius); padding: 12px 12px 8px; }
.chart .head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.chart .head b { font-size: 20px; font-variant-numeric: tabular-nums; }
.chart svg { display: block; width: 100%; height: 150px; }
.chart .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--hint); margin-top: 4px; }
.chart .tip { font-size: 12.5px; color: var(--hint); min-height: 18px; }
.bars rect { fill: var(--accent); }
.bars rect.hi { fill: color-mix(in srgb, var(--accent) 60%, var(--text)); }
.meter { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }

/* ── рассылка ── */
.progress { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 8px; display: flex; }
.progress i { display: block; height: 100%; }
.btnrow { display: flex; gap: 8px; align-items: center; padding: 8px 14px; }
.btnrow input { flex: 1; min-width: 0; border: 0; outline: none; background: var(--bg); border-radius: 8px; padding: 8px 10px; }

/* ── шторки и модалки ── */
#layer .scrim { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); animation: fade .18s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 8px 10px calc(10px + var(--safe-b)); max-height: 86vh; overflow-y: auto; animation: rise .24s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { transform: translateY(100%); } }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 10px; }
.sheet h3 { margin: 2px 6px 10px; font-size: 17px; text-align: center; }
.sheet .card + .card { margin-top: 8px; }
.viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; place-items: center; animation: fade .15s; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px); z-index: 70;
  background: rgba(20,22,26,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: .2s; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
