/* ===== Мини-приложение: цвета берутся из темы Telegram (светлая / тёмная сами) ===== */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #8b9099);
  --link: var(--tg-theme-link-color, #2f7cf6);
  --btn: var(--tg-theme-button-color, #2f7cf6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --head: var(--bg);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --ok: #2fa84f;
  --warn: #d98a00;
  --soft: color-mix(in srgb, var(--btn) 11%, var(--bg));
  --soft2: color-mix(in srgb, var(--text) 5%, var(--bg));
  --out: color-mix(in srgb, var(--btn) 15%, var(--bg));
  --line: color-mix(in srgb, var(--text) 8%, transparent);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --r: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #1c1d21; --bg2: #111214; --text: #eceef1; --hint: #8b9099; --link: #5ea0ff; --btn: #3d8bff; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg2); color: var(--text); font: 15px/1.42 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { opacity: .55; cursor: default; }
input, textarea, select { font: inherit; color: var(--text); background: var(--soft2); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; width: 100%; outline: none; transition: border-color .15s, background .15s; }
input:focus, textarea:focus, select:focus { border-color: color-mix(in srgb, var(--btn) 55%, transparent); background: var(--bg); }
textarea { resize: vertical; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note { font-size: 12.5px; color: var(--hint); }
.dangerc { color: var(--danger); } .warnc { color: var(--warn); } .okc { color: var(--ok); }

/* иконки */
.i { width: 22px; height: 22px; flex: none; display: inline-block; vertical-align: middle; }
.i.sm { width: 16px; height: 16px; }
.i.xs { width: 14px; height: 14px; stroke-width: 2.2; vertical-align: -2px; }
.i.nm { margin-right: 4px; color: var(--hint); }
.i.chev { width: 18px; height: 18px; color: color-mix(in srgb, var(--hint) 70%, transparent); }
.i.ok { color: var(--btn); }

/* ===== каркас ===== */
.app { display: flex; flex-direction: column; height: 100%; max-width: 760px; margin: 0 auto; background: var(--bg2); }
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
main.view { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chatbg { background:
  radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--btn) 6%, transparent) 0, transparent 40%),
  radial-gradient(circle at 85% 70%, color-mix(in srgb, var(--btn) 5%, transparent) 0, transparent 45%), var(--bg2); }

.top { background: var(--head); position: sticky; top: 0; z-index: 5; padding: 8px 14px 10px; box-shadow: 0 1px 0 var(--line); }
.bar { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.ttl { flex: 1; font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.accbtn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px 0 4px; border-radius: 18px; background: var(--soft2); font-size: 14px; font-weight: 600; max-width: 180px; }
.accbtn .an { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.accbtn .i { color: var(--hint); }
.accbtn .ava.xs { width: 28px; height: 28px; margin: 0; font-size: 11px; }
.accbtn .stack { display: inline-flex; }
.accbtn .stack .ava { border: 2px solid var(--soft2); margin-left: -10px; }
.accbtn .stack .ava:first-child { margin-left: 0; }
.accbtn.mini { padding: 0 6px 0 3px; height: 34px; gap: 2px; }
.accbtn.warn { box-shadow: inset 0 0 0 2px var(--danger); }

/* сегменты внутри раздела */
.seg { display: flex; gap: 2px; margin-top: 10px; padding: 3px; border-radius: 12px; background: var(--soft2); overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 7px 7px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--hint); white-space: nowrap; transition: background .15s, color .15s; }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.cnt { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }
.seg button:not(.on) .cnt { background: color-mix(in srgb, var(--hint) 30%, transparent); color: var(--text); }
.seg button[data-tab="crit"]:not(.on) .cnt, .seg button[data-tab="cap"]:not(.on) .cnt { background: var(--danger); color: #fff; }

/* нижняя панель навигации */
.nav { display: flex; background: color-mix(in srgb, var(--head) 92%, transparent); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  box-shadow: 0 -1px 0 var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5; }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--hint); font-size: 11px; font-weight: 600; }
.nav .ni { position: relative; display: grid; place-items: center; width: 52px; height: 30px; border-radius: 15px; transition: background .2s; }
.nav button.on { color: var(--btn); }
.nav button.on .ni { background: var(--soft); }
.nav .cnt.dot { position: absolute; top: -3px; right: 4px; box-shadow: 0 0 0 2px var(--head); }
body.in-view .top, body.in-view .nav { display: none; }

/* ===== аватарки ===== */
.ava { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 650; font-size: 16px; overflow: hidden; }
.ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ava.sm { width: 36px; height: 36px; font-size: 13.5px; }
.ava.xs { width: 22px; height: 22px; font-size: 9.5px; display: inline-grid; vertical-align: middle; margin-right: 6px; }
.ava.xxs { width: 18px; height: 18px; font-size: 8px; }
.iconava, .allava { background: var(--soft) !important; color: var(--btn); }
.iconava .i, .allava .i { width: 20px; height: 20px; }
.avw { position: relative; flex: none; display: inline-grid; }
.avw.online::after, .avw.live::after { content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--bg); }
.avw.live::after { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 25%, transparent); } }
.ownerava { position: absolute; right: -3px; bottom: -3px; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg); display: grid; }
.ownerava .ava { margin: 0; }

/* ===== кнопки ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 12px; background: var(--soft2); font-weight: 600; font-size: 14.5px; white-space: nowrap; transition: transform .08s, background .15s, opacity .15s; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn .i { width: 18px; height: 18px; }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.ghost { background: transparent; color: var(--hint); }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); }
.btn.icon { width: 40px; padding: 0; flex: none; }
.btn.icon.on { background: var(--soft); color: var(--btn); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.icon.sm { width: 34px; padding: 0; }
.btn.wide { width: 100%; }
.btn.grow { flex: 1; min-width: 0; }
.btn span { overflow: hidden; text-overflow: ellipsis; }
.hb { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--link); }
.hb:active { background: var(--soft2); }
.back { flex: none; width: 36px; height: 36px; display: grid; place-items: center; color: var(--link); margin-left: -6px; border-radius: 50%; }
.back .i { width: 26px; height: 26px; }
.acts, .btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pad { padding: 4px 14px 10px; }
/* плитки действий: иконка над подписью */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); gap: 8px; padding: 2px 0; }
.tiles::-webkit-scrollbar { display: none; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 6px 8px; border-radius: 14px; background: var(--soft2); font-size: 12px; font-weight: 600; color: var(--text); }
.tile .i { color: var(--btn); }
.tile.danger, .tile.danger .i { color: var(--danger); }
.tile:active { transform: scale(.96); }
.tiles.wide { padding: 0 12px 6px; }
.tiles.wide .tile, .pad .btn:not(.ghost) { background: var(--bg); box-shadow: var(--shadow); }

/* фильтры-пилюли */
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 12px 14px 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 16px; background: var(--bg); font-size: 13.5px; font-weight: 550; box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; }
.filters .chip.on { background: var(--text); color: var(--bg); box-shadow: none; }
.filters.sub { padding-top: 2px; }
.filters.sub .lbl { flex: none; align-self: center; font-size: 13px; color: var(--hint); }
.filters.sub .chip { font-size: 12.5px; padding: 4px 10px; }
.chip.more { display: flex; margin: 10px auto 16px; }

/* ===== списки ===== */
.list { background: var(--bg); margin: 10px 12px; border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.list:empty { display: none; }
.list .empty { background: none; }
.row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; background: var(--bg); width: 100%; text-align: left; position: relative; }
.row + .row::before, .row + .sec + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 72px; height: 1px; background: var(--line); }
.row:active:not(:disabled) { background: var(--soft2); }
.row:disabled { opacity: 1; cursor: default; }
.rtop { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.rtop .name, .rtop .sub { flex: 1; min-width: 0; }
.rtop + .rtop { margin-top: 1px; align-items: center; }
.name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--hint); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub2 { color: var(--hint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.sub b, .sub2 b, .oursbar b { color: var(--text); font-weight: 600; }
.meta { flex: none; font-size: 12px; color: var(--hint); text-align: right; display: inline-flex; align-items: center; gap: 3px; }
.badge { flex: none; display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--btn); color: var(--btn-text); font-size: 12px; font-weight: 700; }
.badge.soft { background: var(--soft2); color: var(--hint); font-weight: 600; }
.ourtag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--soft); color: var(--btn); vertical-align: 1px; text-transform: lowercase; }
.sec { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--hint); padding: 16px 18px 4px; }
.sec .note { font-weight: 400; }
.list .sec { padding: 12px 14px 4px; }
.row.golink .name { color: var(--link); }
.tdot { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: var(--tc, #6fb9f0); background: color-mix(in srgb, var(--tc, #6fb9f0) 16%, var(--bg)); }

.search { display: flex; align-items: center; gap: 8px; margin: 12px 12px 0; padding: 0 12px; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); position: sticky; top: 8px; z-index: 2; }
.search .i { color: var(--hint); width: 18px; height: 18px; }
.search input { border: 0; background: none; padding: 11px 0; }
.search input:focus { background: none; border: 0; }

.empty { padding: 48px 24px; text-align: center; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty .eic { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); color: var(--btn); margin-bottom: 6px; }
.empty .eic .i { width: 30px; height: 30px; }
.empty .et { color: var(--text); font-weight: 650; font-size: 16px; }
.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; flex: none; }
.spin.lg { width: 28px; height: 28px; border-width: 3px; color: var(--btn); margin-bottom: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.app > .empty { margin: auto; }

/* ===== карточки ===== */
.qlist { padding: 8px 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.qcard { background: var(--bg); border-radius: var(--r); padding: 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 9px; width: 100%; box-shadow: var(--shadow); position: relative; transition: opacity .2s, transform .2s; }
.qcard.tap:active { transform: scale(.99); }
.qcard.gone { opacity: 0; transform: translateX(30px); }
.qcard.k-bad { box-shadow: var(--shadow), inset 3px 0 0 var(--danger); }
.qcard.k-good { box-shadow: var(--shadow), inset 3px 0 0 var(--ok); }
.qcard.fresh { box-shadow: var(--shadow), inset 3px 0 0 var(--btn); }
.qcard.deleted .qtext { text-decoration: line-through; opacity: .6; }
.qhead { display: flex; align-items: center; gap: 10px; min-width: 0; }
.qhead .name { font-size: 14.5px; }
.qhead .sub { font-size: 12.5px; display: flex; align-items: center; gap: 3px; }
.qtext { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
.qtext b { font-weight: 650; margin-right: 2px; }
.qreply { background: var(--soft); border-radius: 12px; padding: 8px 11px; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.qreply b { color: var(--btn); font-weight: 650; margin-right: 3px; }
.reason { display: flex; gap: 6px; font-size: 13px; color: var(--hint); }
.reason .i { margin-top: 2px; color: var(--warn); }
.reason span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.tag { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 8px; background: var(--soft2); color: var(--hint); white-space: nowrap; }
.tag.hl { background: var(--soft); color: var(--btn); }
.tag.st-pending, .tag.st-clicked, .tag.st-answered, .tag.sc3 { background: color-mix(in srgb, var(--warn) 15%, var(--bg)); color: var(--warn); }
.tag.st-sent, .tag.st-gone, .tag.praise { background: color-mix(in srgb, var(--ok) 14%, var(--bg)); color: var(--ok); }
.tag.st-dry, .tag.st-approved, .tag.st-scheduled { background: color-mix(in srgb, #7c5cff 14%, var(--bg)); color: #7c5cff; }
.tag.st-error, .tag.st-failed, .tag.st-new { background: color-mix(in srgb, var(--danger) 13%, var(--bg)); color: var(--danger); }
.tag.sc { color: var(--hint); }
.tag.sc4, .tag.sc5 { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--bg)); }
.plabel { font-size: 12px; font-weight: 650; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; flex: none; }
.pick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 1px; align-items: center; }
.pick::-webkit-scrollbar { display: none; }
.pchip { flex: none; display: inline-flex; align-items: center; gap: 2px; height: 32px; padding: 0 11px 0 4px; border-radius: 16px; background: var(--soft2); font-size: 13.5px; font-weight: 600; transition: background .15s; }
.pchip .ava.xs { width: 24px; height: 24px; margin-right: 4px; }
.pchip.on { background: var(--btn); color: var(--btn-text); }
.pchip.blocked { opacity: .5; }
.pchip.blocked .i { color: var(--danger); margin-left: 4px; }
.pick.from { padding: 8px 12px 0; background: var(--bg); }
.pick.from .plabel { margin-right: 2px; }

/* ===== шапка переписки ===== */
.head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--head); box-shadow: 0 1px 0 var(--line); z-index: 3; min-height: 56px; }
.head .name { font-size: 16px; }
.head .sub { font-size: 12.5px; }
#joinbox, #hbtns, #headacc { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.oursbar { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--hint); padding: 6px 14px; background: var(--head); box-shadow: 0 1px 0 var(--line); white-space: nowrap; overflow-x: auto; scrollbar-width: none; z-index: 2; }
.oursbar:empty { display: none; }

/* ===== сообщения ===== */
.msgs { padding: 12px 10px 16px; display: flex; flex-direction: column; gap: 4px; }
.mrow { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.mrow.right { justify-content: flex-end; }
.mrow > .ava.sm { width: 32px; height: 32px; font-size: 12px; margin-bottom: 2px; }
.msg { max-width: min(86%, 520px); padding: 7px 11px 6px; border-radius: 18px 18px 18px 6px; background: var(--bg); overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0,0,0,.05); position: relative; transition: box-shadow .2s; }
.mrow.right .msg, .msg.out, .msg.mine-acc { border-radius: 18px 18px 6px 18px; background: var(--out); }
.msg[data-id], .msg[data-m] { cursor: pointer; }
.msg.ours:not(.out) { background: var(--out); }
.msg.sel { box-shadow: 0 0 0 2px var(--btn); }
.msg.target { box-shadow: 0 0 0 2px var(--danger); }
.msg.flash { box-shadow: 0 0 0 2px var(--link); }
.msg.fresh:not(.out) { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 70%, transparent); animation: arrive .35s ease-out; }
@keyframes arrive { from { transform: translateY(8px); opacity: 0; } }
.msg.pend { opacity: .8; }
.msg.err { box-shadow: 0 0 0 1.5px var(--danger); }
.msg .who { font-size: 13px; font-weight: 650; color: var(--link); margin-bottom: 1px; }
.msg .mark { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--danger); font-weight: 700; margin-bottom: 3px; }
.mt { white-space: pre-wrap; }
.msg .time { display: flex; justify-content: flex-end; align-items: center; gap: 2px; font-size: 11px; color: var(--hint); margin-top: 2px; min-height: 18px; }
.msg .time .tm { margin-left: auto; padding-left: 8px; }
.msg .qr { display: grid; place-items: center; width: 28px; height: 24px; border-radius: 8px; color: var(--link); opacity: .75; }
.msg .qr:first-child { margin-left: -6px; }
.msg .qr:active { background: var(--soft2); opacity: 1; }
.msg.pend .time > span:first-child, .msg.pend .time .st, .msg.pend .time .clockic { margin-left: auto; }
.msg .st { color: var(--btn); display: inline-flex; margin-left: 2px; }
.msg .st.read { color: var(--ok); }
.msg .q { font-size: 11px; color: var(--hint); }
.clockic { display: inline-flex; color: var(--hint); }
.rq { display: flex; flex-direction: column; min-width: 0; border-left: 3px solid var(--link); background: color-mix(in srgb, var(--link) 9%, transparent); border-radius: 4px 8px 8px 4px; padding: 3px 8px; margin: 2px 0 4px; font-size: 13px; cursor: pointer; }
.rq b { color: var(--link); font-weight: 650; font-size: 12.5px; }
.rq span { color: var(--text); opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.r { font-size: 12.5px; padding: 2px 8px; border-radius: 12px; background: var(--soft); color: var(--btn); font-weight: 600; }
.r.mine { background: var(--btn); color: var(--btn-text); }
.svc, .daysep { align-self: center; max-width: 90%; text-align: center; font-size: 12.5px; font-weight: 550; color: var(--text); background: color-mix(in srgb, var(--bg) 70%, transparent); border-radius: 12px; padding: 4px 11px; margin: 6px auto; backdrop-filter: blur(4px); }
.daysep { color: var(--hint); }
.svc .rq { display: none; }
.more { align-self: center; display: inline-flex; align-items: center; gap: 6px; color: var(--link); font-size: 13.5px; font-weight: 600; padding: 7px 14px; border-radius: 16px; background: var(--bg); margin: 2px auto 8px; }
.newpill { position: relative; z-index: 4; align-self: center; display: inline-flex; align-items: center; gap: 6px; margin: -50px auto 10px; padding: 8px 15px; border-radius: 20px; background: var(--btn); color: var(--btn-text); font-size: 13.5px; font-weight: 650; box-shadow: 0 4px 14px rgba(0,0,0,.18); animation: arrive .25s ease-out; }
.tlink { color: var(--link); text-decoration: none; cursor: pointer; word-break: break-all; }
.goto { cursor: pointer; }

/* меню сообщения */
.sheet, .msheet { background: var(--bg); padding: 8px 12px 10px; box-shadow: 0 -1px 0 var(--line), 0 -8px 24px rgba(0,0,0,.06); border-radius: 18px 18px 0 0; animation: up .2s ease-out; z-index: 3; }
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
.mshead { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.mshead b { color: var(--text); }
.mshead .hb { width: 30px; height: 30px; color: var(--hint); }
.emojis { display: flex; gap: 2px; overflow-x: auto; margin: 0 -4px 8px; padding: 4px; border-radius: 24px; background: var(--soft2); scrollbar-width: none; }
.emojis::-webkit-scrollbar { display: none; }
.emojis button { flex: none; font-size: 24px; width: 42px; height: 42px; border-radius: 50%; transition: transform .1s; }
.emojis button:active { transform: scale(1.25); }
.emojis button.on { background: var(--soft); }

/* поле ввода */
.compose { display: flex; gap: 6px; align-items: flex-end; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--head); box-shadow: 0 -1px 0 var(--line); z-index: 3; }
.compose .field { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--soft2); border-radius: 21px; padding-right: 3px; }
.compose textarea { flex: 1; resize: none; min-height: 42px; max-height: 140px; border: 0; background: none; border-radius: 21px; padding: 10px 6px 10px 14px; line-height: 1.4; }
.compose textarea:focus { background: none; border: 0; }
.ib { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--hint); }
.ib:active { background: var(--soft2); }
.ib.ai { width: 36px; height: 36px; margin-bottom: 3px; color: var(--btn); }
.ib.send { background: var(--soft2); color: var(--hint); transition: background .15s, color .15s, transform .1s; }
.ib.send.ready { background: var(--btn); color: var(--btn-text); }
.ib.send:active { transform: scale(.92); }
.ib.send .i { margin-left: -2px; margin-top: 1px; }
.attach { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px 0; background: var(--head); }
.attach:empty { display: none; }
.attach .ph { position: relative; flex: none; }
.attach img { width: 68px; height: 68px; object-fit: cover; border-radius: 12px; display: block; }
.attach .ph button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 11px; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.replying { display: flex; align-items: center; gap: 10px; padding: 8px 8px 0 14px; background: var(--head); }
.replying > .i { color: var(--link); }
.replying .rq { margin: 0; background: none; padding: 0 8px; border-radius: 0; }
.replying .hb { color: var(--hint); }
.gen { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--btn); padding: 8px 14px 0; background: var(--head); }
.gen:empty { display: none; }
.gen b { color: var(--text); }
textarea.generating, .compose .field:has(textarea.generating) { background: linear-gradient(90deg, var(--soft2) 0%, var(--soft) 50%, var(--soft2) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.compose .field:has(textarea.generating) textarea { background: none; animation: none; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* кнопки ботов под сообщением */
.kb { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.kb .kr { display: flex; gap: 4px; }
.kb button { flex: 1; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 8px 6px; border-radius: 10px; background: var(--soft); color: var(--link); font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb button.na { color: var(--hint); font-weight: 400; }

/* ===== карточка сообщения: пост, контекст, панель ответа ===== */
.post { background: var(--bg); margin: 10px 10px 4px; padding: 11px 13px; border-radius: var(--r); overflow-wrap: anywhere; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.post.target { box-shadow: var(--shadow), 0 0 0 2px var(--danger); }
.post .lbl { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--hint); font-weight: 550; flex-wrap: wrap; }
.post .lbl .tgt { color: var(--danger); }
.post .ptxt { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.post.open .ptxt { display: block; }
.post.thead { margin: 0 0 8px; }
.posts { display: flex; flex-direction: column; padding: 4px 0 12px; }
.posts .post { margin: 6px 10px; padding: 11px 13px 0; }
.pfoot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.pfoot .note { display: inline-flex; align-items: center; gap: 2px; }
.pcom { display: flex; align-items: center; gap: 8px; margin: 2px -13px 0; padding: 10px 13px; border-top: 1px solid var(--line); color: var(--link); font-size: 14px; font-weight: 600; text-align: left; }
.pcom span { flex: 1; }
.pcom.off { color: var(--hint); font-weight: 400; }
.why { display: flex; gap: 6px; font-size: 13px; color: var(--hint); padding: 2px 16px 12px; }
.why .i { margin-top: 2px; color: var(--warn); }
.ctxraw { white-space: pre-wrap; font-size: 13.5px; background: var(--bg); border-radius: 12px; padding: 10px 12px; color: var(--hint); }
.panel { background: var(--head); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 9px; box-shadow: 0 -1px 0 var(--line), 0 -8px 24px rgba(0,0,0,.05); border-radius: 18px 18px 0 0; z-index: 3; max-height: 62vh; overflow-y: auto; }
.panel .btns { flex-wrap: nowrap; }
.pstate { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--hint); }
.pstate .i { flex: none; }
.pstate.warnc { color: var(--warn); } .pstate.okc { color: var(--ok); }
.pstate .spin { margin-left: auto; }
.ptext { white-space: pre-wrap; background: var(--soft); border-radius: 12px; padding: 9px 12px; }
.rtext { min-height: 92px; max-height: 220px; line-height: 1.45; }
#hint { min-height: 60px; }
.askfact { display: flex; gap: 6px; font-size: 13px; color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, var(--bg)); border-radius: 10px; padding: 8px 10px; }
.askfact .i { margin-top: 2px; }

/* ===== «Защита» ===== */
.dhero { display: flex; align-items: center; gap: 10px; padding: 12px 14px 4px; }
.dhero .name { font-size: 17px; }
.stack.row2 { display: flex; align-items: center; padding: 6px 14px 10px; }
.stack.row2 .ava { border: 2px solid var(--bg2); margin-left: -8px; width: 30px; height: 30px; font-size: 11px; }
.stack.row2 .ava:first-child { margin-left: 0; }
.stack.row2 .note { margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qcard.defq:not(.open) { cursor: pointer; }
.qcard.defq.open { box-shadow: var(--shadow), 0 0 0 2px var(--btn); }
.qcard.defq textarea { min-height: 90px; }
.drow { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--hint); }
.drow select { flex: 1; min-width: 0; padding: 9px 10px; }
.drow input[type=number] { width: 84px; flex: none; }

/* ===== настройки ===== */
.form { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--bg); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 550; }
.card .hint { font-size: 12.5px; color: var(--hint); font-weight: 400; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--soft); color: var(--btn); flex: none; }
.who2 { display: inline-flex; align-items: center; }
.two { display: flex; gap: 8px; }
.warn { display: flex; gap: 8px; align-items: flex-start; background: color-mix(in srgb, var(--warn) 13%, var(--bg)); color: color-mix(in srgb, var(--warn) 70%, var(--text)); font-size: 13px; padding: 10px 12px; border-radius: 12px; }
.warn .i { margin-top: 2px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: color-mix(in srgb, var(--hint) 35%, transparent); border-radius: 16px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ===== выдвижная панель и подтверждения ===== */
.sheetwrap { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,0); display: flex; align-items: flex-end; justify-content: center; transition: background .2s; }
.sheetwrap.in { background: rgba(0,0,0,.38); }
.sheetbox { width: 100%; max-width: 560px; max-height: 82vh; overflow-y: auto; background: var(--bg); border-radius: 20px 20px 0 0; padding: 6px 0 calc(12px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
.sheetwrap.in .sheetbox { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 6px; background: color-mix(in srgb, var(--hint) 35%, transparent); }
.shead { font-size: 17px; font-weight: 700; padding: 6px 18px 8px; }
.slist { padding: 0 8px; }
.srow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 14px; }
.srow:active { background: var(--soft2); }
.srow.on { background: var(--soft); }
.srow.dim .name { opacity: .55; }
.ask { padding: 6px 18px 4px; display: flex; flex-direction: column; gap: 10px; }
.asktitle { font-size: 17px; font-weight: 700; line-height: 1.35; }
.asktext { font-size: 14px; color: var(--hint); white-space: pre-wrap; }
.askbtns { display: flex; gap: 8px; margin-top: 6px; }
.askbtns .btn { flex: 1; height: 46px; font-size: 15.5px; }
.askbtns .btn.ghost { background: var(--soft2); color: var(--text); }
.askbtns .btn.danger { background: var(--danger); color: #fff; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(24,25,28,.92); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; z-index: 80; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); animation: toast .2s ease-out; backdrop-filter: blur(8px); }
@keyframes toast { from { transform: translate(-50%, 10px); opacity: 0; } }
.login { padding: 40px 22px; display: flex; flex-direction: column; gap: 12px; }
.login b { font-size: 22px; }
.save { background: var(--btn); color: var(--btn-text); height: 46px; border-radius: 12px; font-weight: 650; }

/* ===== вложения ===== */
.media { position: relative; margin: 4px -6px 3px; border-radius: 12px; overflow: hidden; background: var(--soft2); min-height: 90px; min-width: 160px; display: grid; place-items: center; cursor: zoom-in; }
.media img { display: block; max-width: 100%; max-height: 340px; object-fit: contain; }
.media .ph { color: var(--hint); display: grid; place-items: center; }
.media .ph .i { width: 30px; height: 30px; }
.media .badge2 { position: absolute; left: 7px; bottom: 7px; background: rgba(0,0,0,.55); color: #fff; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 9px; }
.media.sticker { background: none; min-width: 0; min-height: 0; cursor: default; }
.media.sticker img, .media.sticker video { max-width: 140px; max-height: 140px; }
.media video { display: block; width: 100%; height: 100%; max-height: 340px; object-fit: contain; }
.media.sized img, .media.sized video { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; object-fit: cover; }
.media.sized { max-height: 340px; }
.media .play { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; pointer-events: none; backdrop-filter: blur(4px); }
.media .play .i { width: 22px; height: 22px; }
.media.gif, .media.video { cursor: pointer; }
.media.playing .play, .media.playing .badge2.gb { display: none; }
.media.round { width: 200px; height: 200px; min-width: 0; border-radius: 50%; margin: 4px 0; cursor: pointer; }
.media.round img, .media.round video { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; object-fit: cover; }
.media[data-tg] { cursor: pointer; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin: 4px -6px 3px; border-radius: 12px; overflow: hidden; }
.gallery .media { margin: 0; border-radius: 0; min-width: 0; min-height: 0; aspect-ratio: 1; max-height: none; }
.gallery .media img, .gallery .media video { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; object-fit: cover; }
.gallery.odd .media:first-child { grid-column: span 2; aspect-ratio: 16 / 9; }
.file { display: flex; gap: 10px; align-items: center; margin: 4px 0; padding: 8px 10px; border-radius: 12px; background: var(--soft2); font-size: 14px; }
.file .fic { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--btn); color: var(--btn-text); flex: none; }
.file .fic .i { width: 18px; height: 18px; }
.file .note { display: block; }
.file.dl { cursor: pointer; }
.file .get { color: var(--link); display: grid; place-items: center; }
.audio { margin: 4px 0; padding: 8px 10px; border-radius: 12px; background: var(--soft2); font-size: 13px; }
.audio .ahead { display: flex; align-items: center; gap: 6px; color: var(--hint); }
.audio .ahead .i { width: 16px; height: 16px; color: var(--btn); }
.audio audio { display: block; width: 100%; min-width: 220px; height: 36px; margin-top: 4px; }
.vnote { font-size: 12.5px; color: var(--hint); margin: 2px 0 4px; cursor: pointer; }
.vnote b { color: var(--link); font-weight: 600; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 90; display: grid; place-items: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.lightbox img, .lightbox video { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox .x { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 1; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; }

/* выбор отвечающего выпадающим списком */
.pline { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pline .note { margin-left: auto; white-space: nowrap; }
.pline.from { padding: 8px 12px 0; background: var(--head); }
.pickbtn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px 0 4px; border-radius: 18px; background: var(--soft2); font-size: 14px; font-weight: 600; min-width: 0; max-width: 220px; }
.pickbtn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pickbtn .ava.xs { width: 28px; height: 28px; margin: 0; font-size: 11px; }
.pickbtn .i { color: var(--hint); }
.pickbtn:active { transform: scale(.97); }
.pickbtn.warn { box-shadow: inset 0 0 0 2px var(--danger); }
/* шкала 0–100 */
.meter { display: flex; flex-direction: column; gap: 5px; --mc: var(--ok); }
.meter.bad.lv1 { --mc: #34a853; } .meter.bad.lv2 { --mc: #e0a400; } .meter.bad.lv3 { --mc: #f07b13; } .meter.bad.lv4 { --mc: var(--danger); }
.meter.good { --mc: var(--ok); }
.mtop { display: flex; align-items: baseline; gap: 3px; font-size: 13px; }
.mtop .ml { color: var(--hint); font-weight: 600; margin-right: 4px; }
.mtop b { font-size: 17px; font-weight: 750; color: var(--mc); line-height: 1; }
.mtop .mof { color: var(--hint); font-size: 12px; }
.mtop .mw { margin-left: auto; font-size: 12px; font-weight: 650; color: var(--mc); padding: 2px 8px; border-radius: 8px; background: color-mix(in srgb, var(--mc) 13%, var(--bg)); }
.mbar { height: 6px; border-radius: 3px; background: var(--soft2); overflow: hidden; }
.mbar i { display: block; height: 100%; border-radius: 3px; background: var(--mc); }
.whym { padding: 2px 16px 8px; }

/* меню «Ещё»: опасные действия красным */
.srow.dangerrow .iconava { background: color-mix(in srgb, var(--danger) 12%, var(--bg)) !important; color: var(--danger); }
.srow.dangerrow .name { color: var(--danger); }
.asktext { max-height: 50vh; overflow-y: auto; }
