/* ===== Темы ===== */
:root {
  --accent: #2481cc;
  --accent-soft: rgba(36, 129, 204, .14);
  --header: #527da3;
  --header-text: #fff;
  --header-sub: rgba(255, 255, 255, .72);
  --bg: #fff;
  --bg-alt: #f0f2f5;
  --card: #fff;
  --text: #0f1419;
  --sub: #7e8b97;
  --line: #e4e8ec;
  --hover: #f2f5f8;
  --active: #e3effa;
  --badge: #4fae4e;
  --badge-muted: #bcc3c9;
  --bubble-in: #fff;
  --bubble-out: #effdde;
  --bubble-in-text: #0f1419;
  --bubble-out-text: #0f1419;
  --meta-in: #9aa5ae;
  --meta-out: #5fae5c;
  --tick: #4fae4e;
  --danger: #e53935;
  --link: #2481cc;
  --chat-a: #cfe3c6; --chat-b: #b3d5c7; --chat-c: #a6c6d9;
  --doodle: rgba(70, 110, 90, .11);
  --overlay: rgba(0, 0, 0, .45);
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  --fab: #3b9de3;
  --text-size: 15px;
  --bubble-radius: 14px;
  --green: #4fae4e;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --accent: #6ab3f3;
  --accent-soft: rgba(106, 179, 243, .16);
  --header: #212d3b;
  --header-text: #f4f7fa;
  --header-sub: #7f93a8;
  --bg: #17212b;
  --bg-alt: #0e1621;
  --card: #17212b;
  --text: #f5f7fa;
  --sub: #708499;
  --line: #0e1621;
  --hover: #1d2936;
  --active: #2b5278;
  --badge: #3a8fd6;
  --badge-muted: #4a5a6b;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --bubble-in-text: #f5f7fa;
  --bubble-out-text: #f5f7fa;
  --meta-in: #6d7f8f;
  --meta-out: #7da8d3;
  --tick: #7bc4ff;
  --danger: #ef5350;
  --link: #6ab3f3;
  --chat-a: #0e1621; --chat-b: #0c1520; --chat-c: #0a121b;
  --doodle: rgba(120, 160, 200, .06);
  --overlay: rgba(0, 0, 0, .6);
  --shadow: 0 2px 12px rgba(0, 0, 0, .5);
  --fab: #2b78b8;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.35; color: var(--text); background: var(--bg-alt);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
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.ic { flex: none; display: block; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(128, 140, 152, .35); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 140, 152, .6); }
::-webkit-scrollbar-track { background: transparent; }
.muted { color: var(--sub); }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; }

/* ===== Оболочка ===== */
.shell { display: flex; height: 100vh; height: 100dvh; background: var(--bg); }
.pane-left { width: 410px; flex: none; border-right: 1px solid var(--line); background: var(--bg); position: relative; min-width: 0; display: flex; flex-direction: column; }
.pane-right { flex: 1; min-width: 0; position: relative; background: var(--bg-alt); display: flex; flex-direction: column; }
.pane-right > .view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.shell.solo .pane-left { display: none; }
.right-empty { flex: 1; display: grid; place-items: center; background: linear-gradient(160deg, var(--chat-a), var(--chat-b) 55%, var(--chat-c)); }
.right-empty-badge { background: rgba(0, 0, 0, .28); color: #fff; padding: 6px 16px; border-radius: 18px; font-size: 14px; max-width: 80%; text-align: center; }
.right-empty-badge.error { background: rgba(200, 40, 40, .75); }
.icon-btn.back-narrow { display: none; }
@media (max-width: 860px) {
  .pane-left { width: 100%; border-right: 0; }
  .pane-right { display: none; }
  .shell.has-right .pane-left { display: none; }
  .shell.has-right .pane-right, .shell.solo .pane-right { display: flex; width: 100%; }
  .icon-btn.back-narrow { display: inline-grid; }
}

/* ===== Базовые элементы ===== */
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.small { width: 22px; height: 22px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: inline-grid; place-items: center; color: inherit; flex: none; transition: background .15s; }
.icon-btn:hover { background: rgba(128, 140, 152, .18); }
.icon-btn.light { color: #fff; }
.bar .icon-btn { color: var(--header-text); }
.bar .icon-btn:hover { background: rgba(255, 255, 255, .16); }
.btn-primary { background: var(--accent); color: #fff; border-radius: 10px; padding: 12px 22px; font-weight: 500; font-size: 15px; letter-spacing: .2px; transition: filter .15s, transform .05s; }
:root[data-theme="dark"] .btn-primary { color: #0b1620; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: scale(.985); }
.btn-primary[disabled] { opacity: .55; cursor: default; }
.btn-primary.wide { width: 100%; margin-top: 10px; }
.btn-text { color: var(--accent); font-weight: 500; padding: 9px 14px; border-radius: 8px; text-transform: uppercase; font-size: 13.5px; letter-spacing: .4px; }
.btn-text:hover { background: var(--accent-soft); }
.btn-text.danger { color: var(--danger); }
.btn-text.danger:hover { background: rgba(229, 57, 53, .12); }
.btn-chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 16px; background: var(--hover); color: var(--text); font-size: 13.5px; }
.btn-chip.on { background: var(--accent); color: #fff; }
.input { width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); outline: none; transition: border-color .15s; }
:root[data-theme="dark"] .input { border-color: #2a3a4b; background: #0e1621; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; }
.field { display: block; margin: 14px 0 0; text-align: left; }
.field > span { display: block; font-size: 12.5px; color: var(--sub); margin: 0 2px 5px; }
.hint { font-size: 12.5px; color: var(--sub); margin: 6px 2px; }
.pill { background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--badge); color: #fff; font-size: 12.5px; font-weight: 600; display: inline-grid; place-items: center; flex: none; }
.badge.muted { background: var(--badge-muted); }

.switch { position: relative; width: 44px; height: 24px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: #b7c0c8; border-radius: 12px; transition: background .2s; cursor: pointer; }
.switch .slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:disabled + .slider { opacity: .5; }

.seg { display: flex; background: var(--hover); border-radius: 10px; padding: 3px; gap: 2px; width: 100%; }
.seg button { flex: 1; padding: 8px 10px; border-radius: 8px; color: var(--sub); font-size: 14px; }
.seg button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); font-weight: 500; }
:root[data-theme="dark"] .seg button.on { background: #2b5278; color: #fff; }

.range-row { display: flex; align-items: center; gap: 12px; width: 100%; }
.range { flex: 1; accent-color: var(--accent); }
.range-val { width: 30px; text-align: right; color: var(--sub); font-variant-numeric: tabular-nums; }

/* ===== Аватар ===== */
.avatar { border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 500; position: relative; overflow: hidden; flex: none; user-select: none; }
.avatar > span { position: relative; z-index: 0; }
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.avatar.saved { background: linear-gradient(180deg, #5fb1ec, #3a8fd6); }

/* ===== Верхние панели ===== */
.bar { display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 6px; background: var(--header); color: var(--header-text); flex: none; box-shadow: 0 1px 3px rgba(0, 0, 0, .18); position: relative; z-index: 3; }
.bar-title { flex: 1; min-width: 0; padding: 0 6px; cursor: pointer; }
.bar-title-main { font-size: 19px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title-sub { font-size: 13px; color: var(--header-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title-sub.warn { color: #ffe08a; }
.bar-title-sub:empty { display: none; }
.bar-ghost { color: var(--header-sub); display: inline-grid; place-items: center; width: 28px; }
.search-bar { display: none; }
.list-wrap.searching > .bar:not(.search-bar) { display: none; }
.list-wrap.searching > .search-bar { display: flex; }
.search-bar.always, .search-bar.in-chat { display: flex; }
.search-input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--header-text); font-size: 17px; padding: 8px 6px; }
.search-input::placeholder { color: var(--header-sub); }
.search-input::-webkit-search-cancel-button { display: none; }

/* ===== Список чатов ===== */
.list-wrap { display: flex; flex-direction: column; height: 100%; position: relative; min-height: 0; }
.dialogs { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.dlg { display: flex; align-items: center; gap: 12px; padding: 9px 14px 9px 12px; cursor: pointer; transition: background .12s; }
.dlg:hover { background: var(--hover); }
.dlg.active { background: var(--active); }
:root:not([data-theme="dark"]) .dlg.active { background: #e3effa; }
.dlg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.dlg-top, .dlg-bottom { display: flex; align-items: center; gap: 5px; min-width: 0; }
.dlg-title { font-size: 16.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.verified { color: var(--accent); flex: none; }
.mute-ic { color: var(--sub); flex: none; }
.dlg-meta { margin-left: auto; display: flex; align-items: center; gap: 3px; flex: none; color: var(--sub); font-size: 12.5px; }
.tick { color: var(--meta-in); }
.tick.read { color: var(--tick); }
.tick.pending { color: var(--sub); }
.tick.failed { color: var(--danger); }
.dlg-preview { flex: 1; min-width: 0; color: var(--sub); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg-sender { color: var(--text); opacity: .85; }
.dlg-preview.is-typing, .typing { color: var(--accent); }
.pin-ic { color: var(--sub); transform: rotate(40deg); flex: none; }
.section-title { padding: 10px 16px 6px; font-size: 13.5px; font-weight: 500; color: var(--accent); }
.fab { position: absolute; right: 18px; bottom: 18px; width: 56px; height: 56px; border-radius: 50%; background: var(--fab); color: #fff; display: grid; place-items: center; box-shadow: 0 3px 10px rgba(0, 0, 0, .3); transition: transform .12s, filter .12s; z-index: 4; }
.fab:hover { filter: brightness(1.08); }
.fab:active { transform: scale(.94); }
.state-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 28px; text-align: center; color: var(--sub); }
.state-title { color: var(--text); font-size: 18px; font-weight: 500; }
.state-text { font-size: 14.5px; max-width: 320px; }
.skeletons { padding: 4px 0; }
.dlg.skel { cursor: default; }
.dlg.skel:hover { background: none; }
.skel-ava { width: 54px; height: 54px; background: var(--hover); }
.skel-line { height: 12px; border-radius: 6px; background: var(--hover); animation: pulse 1.2s ease-in-out infinite; }
.skel-line.w40 { width: 40%; } .skel-line.w70 { width: 70%; }
@keyframes pulse { 50% { opacity: .5; } }

/* ===== Меню (drawer) ===== */
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); opacity: 0; transition: opacity .2s; z-index: 1000; }
.drawer-backdrop.show { opacity: 1; }
.drawer { position: absolute; left: 0; top: 0; bottom: 0; width: min(310px, 86vw); background: var(--bg); transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer.open { transform: none; }
.drawer-head { background: linear-gradient(135deg, #4d7aa3, #2f5d8a); color: #fff; padding: 16px 16px 10px; }
:root[data-theme="dark"] .drawer-head { background: linear-gradient(135deg, #263a50, #1a2735); }
.drawer-head-top { display: flex; justify-content: space-between; align-items: flex-start; }
.drawer-head-bottom { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
.drawer-name-wrap { flex: 1; min-width: 0; }
.drawer-name { font-weight: 500; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-phone { font-size: 13.5px; opacity: .78; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-acc, .drawer-item { display: flex; align-items: center; gap: 16px; padding: 11px 18px; cursor: pointer; }
.drawer-acc { gap: 14px; padding: 8px 16px; }
.drawer-acc:hover, .drawer-item:hover { background: var(--hover); }
.drawer-acc.current { background: var(--accent-soft); }
.drawer-acc-info { flex: 1; min-width: 0; }
.drawer-acc-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-acc-sub { font-size: 13px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-check { color: var(--accent); }
.drawer-item svg { color: var(--sub); }
.drawer-item .switch { margin-left: auto; }
.drawer-item span { flex: 1; }
.drawer-sep { height: 1px; background: var(--line); margin: 6px 0; }
:root[data-theme="dark"] .drawer-sep { background: #222f3d; }
.drawer-foot { margin-top: auto; padding: 14px 18px; font-size: 12.5px; color: var(--sub); }

/* ===== Меню / модалки / тосты ===== */
.menu { position: fixed; z-index: 1500; min-width: 210px; max-width: 320px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow), 0 0 0 1px rgba(0, 0, 0, .06); padding: 6px 0; animation: pop .12s ease-out; }
:root[data-theme="dark"] .menu { background: #212d3b; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 16px; text-align: left; font-size: 15px; }
.menu-item:hover { background: var(--hover); }
.menu-item svg { color: var(--sub); }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.menu-ic-gap { width: 20px; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 0; }
:root[data-theme="dark"] .menu-sep { background: #2a3a4b; }
.react-row { display: flex; gap: 2px; padding: 4px 8px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.react-btn { font-size: 22px; width: 38px; height: 38px; border-radius: 50%; transition: transform .1s, background .1s; }
.react-btn:hover { background: var(--hover); transform: scale(1.2); }

.backdrop { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 1100; opacity: 0; transition: opacity .18s; padding: 16px; }
.backdrop.show { opacity: 1; }
.modal { background: var(--card); border-radius: 16px; width: min(360px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow); padding: 18px 20px 10px; transform: scale(.96); transition: transform .18s; }
.backdrop.show .modal { transform: none; }
:root[data-theme="dark"] .modal { background: #212d3b; }
.modal.wide { width: min(480px, 100%); }
.modal-title { font-size: 19px; font-weight: 500; margin-bottom: 12px; }
.modal-text { color: var(--text); opacity: .85; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px; margin: 14px -8px 0; }
#toasts { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 3000; pointer-events: none; }
.toast { background: rgba(32, 40, 48, .94); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14.5px; opacity: 0; transform: translateY(10px); transition: all .22s; max-width: 86vw; text-align: center; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: rgba(190, 40, 40, .95); }

/* ===== Экран чата ===== */
.conv { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; background: var(--bg-alt); }
.chat-bar { padding-left: 6px; }
.chat-head-ava { cursor: pointer; margin: 0 4px 0 2px; }
.chat-head-body { flex: 1; min-width: 0; cursor: pointer; padding: 4px 6px; }
.chat-head-text { min-width: 0; }
.chat-title { font-size: 17.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.chat-sub { font-size: 13px; color: var(--header-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 17px; }
.chat-sub.typing { color: #fff; }
.chat-sub.online { color: #bfe3ff; }
.sel-bar .sel-count { flex: 1; font-size: 18px; font-weight: 500; padding: 0 8px; }
.msgs-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; background: linear-gradient(160deg, var(--chat-a), var(--chat-b) 55%, var(--chat-c)); }
:root[data-bg="plain"] .msgs-wrap { background: var(--chat-b); }
:root[data-bg="dots"] .msgs-wrap { background: radial-gradient(var(--doodle) 1.5px, transparent 1.6px) 0 0 / 22px 22px, linear-gradient(160deg, var(--chat-a), var(--chat-c)); }
:root[data-bg="default"] .msgs-wrap::before { content: ''; position: absolute; inset: 0; opacity: 1; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='.07' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='24' cy='26' r='9'/%3E%3Cpath d='M92 18l10 10M102 18L92 28'/%3E%3Cpath d='M130 52q10-14 20 0t-20 18'/%3E%3Cpath d='M30 84h22M41 73v22'/%3E%3Crect x='86' y='74' width='20' height='16' rx='4'/%3E%3Cpath d='M20 132q12-16 24 0'/%3E%3Ccircle cx='116' cy='128' r='6'/%3E%3Cpath d='M70 140l8-14 8 14z'/%3E%3C/g%3E%3C/svg%3E"); background-size: 160px; }
:root[data-theme="dark"][data-bg="default"] .msgs-wrap::before { filter: invert(1); opacity: .5; }
.msgs { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 8px 10px; position: relative; scroll-behavior: auto; }
.msgs-inner { display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; min-height: 100%; justify-content: flex-end; }
.top-spinner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3; background: var(--card); padding: 6px; border-radius: 20px; box-shadow: var(--shadow); }
.fab-down { width: 44px; height: 44px; right: 14px; bottom: 14px; background: var(--card); color: var(--sub); }
.fab-badge { position: absolute; top: -8px; left: 50%; transform: translateX(-50%); background: var(--badge); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 10px; font-weight: 600; }
.drop-hint { position: absolute; inset: 10px; border: 3px dashed var(--accent); border-radius: 18px; background: rgba(36, 129, 204, .15); backdrop-filter: blur(3px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--accent); font-size: 18px; z-index: 6; pointer-events: none; }
.empty-chat { margin: auto; }
.empty-chat-badge { background: rgba(0, 0, 0, .3); color: #fff; padding: 6px 16px; border-radius: 16px; font-size: 14px; text-align: center; }
.empty-chat-badge.error { background: rgba(190, 40, 40, .8); }

.search-results { position: absolute; inset: 0; background: var(--bg); z-index: 5; overflow-y: auto; }
.sr-item { padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.sr-item:hover { background: var(--hover); }
.sr-top { display: flex; justify-content: space-between; color: var(--accent); font-size: 14px; }
.sr-date { color: var(--sub); font-size: 12.5px; }
.sr-text { color: var(--text); opacity: .85; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ===== Сообщения ===== */
.row { display: flex; align-items: flex-end; gap: 6px; margin-top: 2px; padding: 0 2px; border-radius: 8px; position: relative; }
.row.first { margin-top: 8px; }
.row.out { justify-content: flex-end; }
.row.date, .row.service { justify-content: center; margin: 10px 0 6px; }
.date-pill, .service-pill { background: rgba(0, 0, 0, .28); color: #fff; padding: 3px 12px; border-radius: 14px; font-size: 13px; font-weight: 500; text-align: center; max-width: 80%; }
.row.selected { background: rgba(36, 129, 204, .22); }
.row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { background: rgba(255, 255, 255, .55); } 100% { background: transparent; } }
.row.pending .bubble { opacity: .8; }
.sel-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--sub); display: grid; place-items: center; color: transparent; flex: none; align-self: center; background: var(--card); }
.sel-check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.msg-ava { margin-bottom: 0; }
.msg-ava-gap { width: 36px; flex: none; }
.bubble-wrap { max-width: min(78%, 560px); min-width: 0; display: flex; }
.row.out .bubble-wrap { justify-content: flex-end; }
.bubble { position: relative; background: var(--bubble-in); color: var(--bubble-in-text); border-radius: var(--bubble-radius); padding: 6px 9px 6px; font-size: var(--text-size); line-height: 1.32; min-width: 64px; max-width: 100%; box-shadow: 0 1px 1.5px rgba(0, 0, 0, .13); word-break: break-word; overflow-wrap: anywhere; }
.bubble.out { background: var(--bubble-out); color: var(--bubble-out-text); }
.bubble.in.last { border-bottom-left-radius: 4px; }
.bubble.out.last { border-bottom-right-radius: 4px; }
.bubble.in.last::after, .bubble.out.last::after { content: ''; position: absolute; bottom: 0; width: 10px; height: 14px; }
.bubble.in.last::after { left: -7px; background: var(--bubble-in); clip-path: path('M10 0 L10 14 L0 14 C6 13 9 8 10 0 Z'); }
.bubble.out.last::after { right: -7px; background: var(--bubble-out); clip-path: path('M0 0 L0 14 L10 14 C4 13 1 8 0 0 Z'); }
.bubble.standalone, .bubble.emoji-only { background: transparent !important; box-shadow: none; padding: 0; }
.bubble.standalone::after, .bubble.emoji-only::after { display: none !important; }
.bubble.emoji-only .text { font-size: 44px; line-height: 1.15; padding-bottom: 14px; }
.sender { font-size: 13.5px; font-weight: 500; margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd { font-size: 13.5px; color: var(--accent); margin-bottom: 2px; }
.reply { display: flex; gap: 7px; border-left: 3px solid var(--accent); padding: 1px 6px 1px 8px; margin: 1px 0 4px; background: var(--accent-soft); border-radius: 4px; cursor: pointer; min-width: 120px; }
.bubble.out .reply { border-left-color: var(--meta-out); background: rgba(80, 160, 80, .12); }
:root[data-theme="dark"] .bubble.out .reply { border-left-color: #8ec3f3; background: rgba(140, 195, 243, .13); }
.reply-thumb { width: 34px; height: 34px; border-radius: 4px; object-fit: cover; align-self: center; }
.reply-body { min-width: 0; }
.reply-name { font-size: 13.5px; font-weight: 500; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble.out .reply-name { color: var(--meta-out); }
:root[data-theme="dark"] .bubble.out .reply-name { color: #8ec3f3; }
.reply-text { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.text { white-space: pre-wrap; }
.text a.link, .text .link { color: var(--link); }
.bubble.out .text a.link { color: var(--link); }
.text .mention { cursor: pointer; }
.text .mono { font-family: Consolas, "SFMono-Regular", monospace; background: rgba(128, 140, 152, .2); padding: 0 4px; border-radius: 4px; font-size: .92em; }
.text .mono.pre { display: block; padding: 6px 8px; margin: 3px 0; white-space: pre-wrap; }
.text .quote { display: block; border-left: 3px solid var(--accent); padding-left: 8px; opacity: .92; }
.spoiler { background: rgba(128, 140, 152, .8); color: transparent; border-radius: 4px; cursor: pointer; user-select: none; }
.spoiler.open { background: rgba(128, 140, 152, .18); color: inherit; user-select: auto; }
.meta { position: absolute; right: 8px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; color: var(--meta-in); user-select: none; white-space: nowrap; }
.bubble.out .meta { color: var(--meta-out); }
.meta .views, .meta .edited { margin-right: 2px; display: inline-flex; align-items: center; gap: 2px; }
.meta .tick { color: var(--meta-out); }
.meta .tick.read { color: var(--tick); }
.meta .pinned-ic { transform: rotate(40deg); }
.meta-gap { display: inline-block; width: 50px; height: 1px; }
.meta-gap.out { width: 76px; }
.meta-line { display: flex; justify-content: flex-end; margin-top: 2px; }
.meta-line .meta { position: static; }
.meta.overlay { background: rgba(0, 0, 0, .45); color: #fff !important; padding: 1px 7px; border-radius: 10px; right: 8px; bottom: 8px; }
.meta.overlay .tick, .meta.overlay .tick.read { color: #fff; }
.bubble.emoji-only .meta.overlay { display: flex; position: relative; right: auto; bottom: auto; width: fit-content; margin: -6px 0 0 auto; background: rgba(0, 0, 0, .3); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding-bottom: 14px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px 2px 6px; border-radius: 14px; background: rgba(128, 140, 152, .2); font-size: 14px; }
.reaction.chosen { background: var(--accent); color: #fff; }
.reaction .re-count { font-size: 13px; font-weight: 500; }

/* медиа в пузыре */
.media { position: relative; border-radius: calc(var(--bubble-radius) - 4px); overflow: hidden; }
.bubble.visual { padding: 3px; }
.bubble.visual .text { padding: 5px 6px 2px; }
.bubble.visual .reply, .bubble.visual .sender, .bubble.visual .fwd { margin-left: 6px; margin-right: 6px; margin-top: 3px; }
.bubble.visual .meta { right: 10px; bottom: 7px; }
.media.photo, .media.video { max-width: 100%; height: auto !important; cursor: zoom-in; background: rgba(128, 140, 152, .25); }
.media.photo img, .media.video img, .media.video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media.video { cursor: pointer; }
.play-overlay { position: absolute; inset: 0; display: grid; place-items: center; }
.play-overlay svg { background: rgba(0, 0, 0, .5); color: #fff; border-radius: 50%; padding: 12px; width: 56px; height: 56px; box-sizing: border-box; }
.dur-badge { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 9px; }
.gif-badge { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.video-ph { width: 100%; height: 100%; background: #2d3a4a; }
.ttl-badge { position: absolute; right: 8px; top: 8px; display: inline-flex; align-items: center; gap: 4px; background: rgba(0, 0, 0, .55); color: #ffd9a0; font-size: 11.5px; padding: 2px 8px; border-radius: 10px; z-index: 2; }
.ttl-badge.saved { color: #b7f0b4; }
.ttl-badge .saved-mark { opacity: .9; }
.media.voice-wrap .ttl-badge, .media.round .ttl-badge { position: static; display: inline-flex; margin-top: 4px; background: rgba(255, 160, 40, .16); color: #c27a12; }
.media.round .ttl-badge { position: absolute; top: auto; bottom: 6px; left: 50%; transform: translateX(-50%); }
:root[data-theme="dark"] .media.voice-wrap .ttl-badge { color: #ffd9a0; }
.media.voice-wrap { overflow: visible; min-width: 230px; }
.spoiler-media img { filter: blur(0); transition: filter .2s; }
.spoiler-media:not(.revealed) img { filter: blur(26px) saturate(1.2); transform: scale(1.1); }
.spoiler-cover { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 14px; }
.spoiler-media.revealed .spoiler-cover { display: none; }
.upload-ring { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .25); }
.upload-ring-in { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: conic-gradient(#fff var(--p), rgba(255, 255, 255, .25) 0); position: relative; }
.upload-ring-in::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: rgba(30, 40, 50, .85); }
.upload-ring-in svg { position: relative; }
.upload-line { height: 3px; background: rgba(128, 140, 152, .3); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.upload-line i { display: block; height: 100%; background: var(--accent); }

.media.round { width: 220px; height: 220px; border-radius: 50%; cursor: pointer; background: #1d2936; }
.media.round video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.round-ring { position: absolute; inset: 0; border-radius: 50%; --p: 0deg; background: conic-gradient(var(--accent) var(--p), transparent 0); -webkit-mask: radial-gradient(circle, transparent 66%, #000 67%); mask: radial-gradient(circle, transparent 66%, #000 67%); pointer-events: none; }
.media.round .play-overlay { transition: opacity .15s; }
.media.round.playing .play-overlay { opacity: 0; }
.round-time { left: 10px; top: 10px; }

.voice { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.voice-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
:root[data-theme="dark"] .voice-btn { color: #0b1620; }
.voice.out .voice-btn { background: #4fae4e; color: #fff; }
:root[data-theme="dark"] .voice.out .voice-btn { background: #8ec3f3; color: #0b2036; }
.voice-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.voice-wave { display: flex; align-items: center; height: 26px; gap: 2px; cursor: pointer; }
.voice-wave i { display: block; width: 3px; border-radius: 2px; background: rgba(128, 140, 152, .5); transition: background .1s; }
.voice-wave i.on { background: var(--accent); }
.voice.out .voice-wave i.on { background: #4fae4e; }
:root[data-theme="dark"] .voice.out .voice-wave i.on { background: #cfe5fa; }
.voice-time { font-size: 12px; color: var(--sub); }
.media.file, .media.card { display: flex; align-items: center; gap: 12px; padding: 4px 2px; min-width: 210px; overflow: visible; }
.file-ic { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; position: relative; }
:root[data-theme="dark"] .file-ic { color: #0b1620; }
.file-ic .ext { position: absolute; font-size: 9.5px; font-weight: 700; bottom: 5px; opacity: .0; }
.file-info { min-width: 0; flex: 1; }
.file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.file-sub { font-size: 12.5px; color: var(--sub); }
.file-sub.bad, .s-sub.bad { color: var(--danger); }
.media.card { text-decoration: none; color: inherit; flex-wrap: wrap; }
.card-ic { width: 46px; height: 46px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.media.poll { display: block; }
.poll-q { font-weight: 500; margin-bottom: 6px; }
.poll-a { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.poll-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--sub); flex: none; }
.media.web { display: block; border-left: 3px solid var(--accent); padding: 2px 8px; margin-top: 4px; min-width: 200px; max-width: 360px; }
.web-site { color: var(--accent); font-weight: 500; font-size: 13.5px; }
.web-title { font-weight: 500; }
.web-desc { font-size: 13.5px; opacity: .85; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.media.expired { opacity: .85; }
.media.expired svg { color: #e0902a; }
.media.sticker { background: transparent; overflow: visible; }
.sticker-img { width: 190px; height: 190px; object-fit: contain; display: block; }
.sticker-ph { width: 120px; height: 120px; font-size: 80px; display: grid; place-items: center; }
.tgs { overflow: hidden; }
.sticker-fallback { font-size: 60px; }

/* ===== Композер ===== */
.composer-holder { flex: none; background: var(--bg); box-shadow: 0 -1px 0 var(--line); position: relative; z-index: 4; }
:root[data-theme="dark"] .composer-holder { background: #17212b; box-shadow: 0 -1px 0 #0e1621; }
.composer { max-width: 100%; }
.composer-row { display: flex; align-items: flex-end; gap: 2px; padding: 6px 6px 6px 4px; max-width: 880px; margin: 0 auto; }
.composer-btn { color: var(--sub); height: 46px; width: 44px; }
.composer-btn:hover { color: var(--accent); }
.msg-input { flex: 1; min-width: 0; min-height: 46px; resize: none; border: 0; outline: none; background: transparent; padding: 11px 6px; font-size: 16px; line-height: 1.35; max-height: 180px; overflow-y: auto; }
.msg-input::placeholder { color: var(--sub); }
.send-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; transition: transform .1s; }
:root[data-theme="dark"] .send-btn { color: #0b1620; }
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(.92); }
.compose-ctx { display: flex; align-items: center; gap: 10px; padding: 6px 8px 0 14px; max-width: 880px; margin: 0 auto; border-left: 0; }
.ctx-ic { color: var(--accent); }
.ctx-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 10px; }
.ctx-name { font-size: 13.5px; font-weight: 500; color: var(--accent); }
.ctx-text { font-size: 13.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-bar { display: flex; align-items: center; gap: 12px; padding: 6px 8px; max-width: 880px; margin: 0 auto; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e53935; animation: blink 1s infinite; flex: none; }
@keyframes blink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 42px; }
.rec-level { flex: 1; height: 6px; border-radius: 3px; background: var(--hover); overflow: hidden; }
.rec-level i { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform .1s; }
.rec-cancel { color: var(--danger); }
.rec-ttl { color: var(--sub); }
.rec-ttl.on { color: #ef8b1c; background: rgba(239, 139, 28, .15); }
.panel-holder { display: none; }
.panel-holder.open { display: block; border-top: 1px solid var(--line); }
.picker { height: 300px; display: flex; flex-direction: column; max-width: 880px; margin: 0 auto; }
.picker-tabs { display: flex; justify-content: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.picker-tab { width: 56px; height: 38px; border-radius: 10px; color: var(--sub); display: grid; place-items: center; }
.picker-tab.on { color: var(--accent); background: var(--accent-soft); }
.picker-body { flex: 1; min-height: 0; position: relative; display: flex; }
.picker-loading, .picker-empty { margin: auto; color: var(--sub); text-align: center; padding: 20px; }
.emoji-grid { flex: 1; overflow-y: auto; padding: 6px 8px; }
.emoji-sec { display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.emo { width: 40px; height: 40px; font-size: 25px; border-radius: 8px; line-height: 1; }
.emo:hover { background: var(--hover); }
.emoji-cats { display: flex; flex-direction: column; border-left: 1px solid var(--line); padding: 4px; overflow-y: auto; }
.emo-cat { width: 34px; height: 34px; font-size: 18px; border-radius: 8px; flex: none; }
.emo-cat:hover { background: var(--hover); }
.sticker-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 4px; padding: 6px; align-content: start; }
.sticker-cell { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; padding: 4px; }
.sticker-cell:hover { background: var(--hover); }
.sticker-cell img { width: 100%; height: 100%; object-fit: contain; }
.set-bar { display: flex; flex-direction: column; border-left: 1px solid var(--line); padding: 4px; overflow-y: auto; gap: 2px; }
.set-btn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--sub); flex: none; font-size: 12px; overflow: hidden; }
.set-btn img { width: 30px; height: 30px; object-fit: contain; }
.set-btn.on { background: var(--accent-soft); color: var(--accent); }
.gif-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 4px; padding: 6px; align-content: start; }
.gif-cell { aspect-ratio: 4/3; border-radius: 8px; overflow: hidden; background: var(--hover); }
.gif-cell img, .gif-cell video { width: 100%; height: 100%; object-fit: cover; }

/* вложения */
.att-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.att-list:not(.multi) .att-item { width: 100%; }
.att-item { position: relative; border-radius: 10px; overflow: hidden; background: var(--hover); flex: none; }
.att-item img, .att-item video { display: block; max-width: 100%; max-height: 260px; margin: 0 auto; }
.att-list.multi .att-item { width: 120px; height: 120px; }
.att-list.multi .att-item img, .att-list.multi .att-item video { width: 100%; height: 100%; object-fit: cover; }
.att-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 8px 4px; font-size: 12px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-item.file { display: flex; align-items: center; gap: 12px; padding: 12px; width: 100%; color: var(--accent); }
.att-info { min-width: 0; color: var(--text); }
.att-fname { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-fsize { color: var(--sub); font-size: 13px; }
.att-caption { margin: 8px 0; }
.att-opt { display: flex; align-items: center; gap: 10px; padding: 8px 2px; cursor: pointer; flex-wrap: wrap; }
.att-opt .input { width: auto; padding: 6px 8px; margin-left: auto; }
.att-opt svg { color: #ef8b1c; }
.att-hint { flex-basis: 100%; font-size: 12.5px; color: var(--sub); margin-left: 28px; }
.fw { display: flex; flex-direction: column; gap: 8px; }
.fw-list { max-height: 50vh; overflow-y: auto; margin: 0 -8px; }
.fw-item { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; cursor: pointer; }
.fw-item:hover { background: var(--hover); }

.round-modal { width: auto; padding: 18px; background: #101820; color: #fff; text-align: center; }
.round-rec-preview { width: 320px; height: 320px; border-radius: 50%; overflow: hidden; position: relative; margin: 0 auto; background: #000; }
.round-rec-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.round-rec-ring { position: absolute; inset: 0; border-radius: 50%; --p: 0deg; background: conic-gradient(#e53935 var(--p), transparent 0); -webkit-mask: radial-gradient(circle, transparent 94%, #000 95%); mask: radial-gradient(circle, transparent 94%, #000 95%); }
.round-rec-time { margin: 12px 0 6px; font-size: 20px; font-variant-numeric: tabular-nums; }
.round-rec-actions { display: flex; align-items: center; justify-content: center; gap: 18px; }
.round-rec-actions .btn-text { color: #9ec7ee; }
.rec-main { width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.rec-main.recording { background: #e53935; }

/* ===== Просмотрщик ===== */
.viewer { position: fixed; inset: 0; background: rgba(8, 12, 16, .94); z-index: 1300; display: flex; flex-direction: column; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.viewer-top { display: flex; align-items: center; gap: 6px; padding: 8px 12px; color: #fff; z-index: 2; }
.viewer-meta { flex: 1; min-width: 0; }
.viewer-from { font-weight: 500; }
.viewer-date, .viewer-ttl { font-size: 13px; opacity: .75; }
.viewer-ttl { color: #ffd9a0; opacity: 1; display: flex; align-items: center; gap: 3px; }
.viewer-count { opacity: .8; font-size: 14px; padding: 0 8px; }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: auto; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; user-select: none; }
.viewer-img.zoom { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-video { max-width: 100%; max-height: 100%; outline: none; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff; display: grid; place-items: center; z-index: 2; }
.viewer-nav:hover { background: rgba(255, 255, 255, .25); }
.viewer-nav.prev { left: 14px; } .viewer-nav.next { right: 14px; }
.viewer-caption { color: #fff; text-align: center; padding: 10px 24px 18px; max-height: 20vh; overflow: auto; }

/* ===== Профиль чата / страницы ===== */
.info-panel { position: absolute; inset: 0; background: var(--bg-alt); z-index: 7; display: flex; flex-direction: column; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.profile { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.profile-body, .page-body { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.profile-head { background: var(--card); padding: 22px 16px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.profile-name { font-size: 22px; font-weight: 500; margin-top: 8px; text-align: center; }
.profile-sub { color: var(--sub); }
.info-card, .s-card { background: var(--card); margin-top: 8px; }
.info-row { display: flex; gap: 22px; align-items: center; padding: 11px 18px; }
.info-row.click { cursor: pointer; }
.info-row.click:hover { background: var(--hover); }
.info-ic { color: var(--sub); }
.info-val { word-break: break-word; }
.info-label { font-size: 13px; color: var(--sub); }
.act-row { display: flex; background: var(--card); margin-top: 8px; padding: 6px; gap: 4px; }
.act { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 10px; color: var(--accent); font-size: 13px; }
.act:hover { background: var(--hover); }
.act.danger { color: var(--danger); }
.tabs { display: flex; background: var(--card); margin-top: 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { flex: 1; padding: 13px 12px; color: var(--sub); font-weight: 500; font-size: 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { background: var(--card); min-height: 160px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.mg-cell { aspect-ratio: 1; position: relative; cursor: pointer; background: var(--hover); }
.mg-cell img { width: 100%; height: 100%; object-fit: cover; }
.mg-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: inherit; }
.file-row:hover { background: var(--hover); }
.file-row audio { height: 32px; max-width: 160px; }
.member { display: flex; align-items: center; gap: 12px; padding: 8px 16px; cursor: pointer; }
.member:hover { background: var(--hover); }
.member-main { flex: 1; min-width: 0; }
.member-name { font-weight: 500; }
.member-sub { font-size: 13px; color: var(--sub); }
.admin-tag { font-size: 12px; color: var(--accent); }

.page { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--bg-alt); }
.page-body.settings { padding-bottom: 28px; }
.note { display: flex; gap: 12px; padding: 14px 16px; background: var(--card); color: var(--sub); font-size: 14px; align-items: flex-start; }
.note svg { color: #e0902a; margin-top: 2px; }
.s-profile { display: flex; gap: 16px; align-items: center; padding: 18px 18px; background: var(--card); cursor: pointer; }
.s-profile-main { min-width: 0; }
.s-profile-name { font-size: 20px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-profile-sub { color: var(--sub); font-size: 14.5px; }
.s-profile-state { font-size: 13px; margin-top: 2px; }
.s-profile-state.ok { color: var(--green); } .s-profile-state.bad { color: #e0902a; }
.s-group { margin-top: 12px; }
.s-head { padding: 10px 18px 6px; color: var(--accent); font-weight: 500; font-size: 14px; }
.s-card { margin-top: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
:root[data-theme="dark"] .s-card { border-color: #0e1621; }
.s-foot { padding: 8px 18px 4px; color: var(--sub); font-size: 13px; line-height: 1.4; }
.s-row { display: flex; align-items: center; gap: 16px; padding: 11px 18px; min-height: 54px; }
.s-row + .s-row { border-top: 1px solid var(--line); }
:root[data-theme="dark"] .s-row + .s-row { border-color: #1d2936; }
.s-row.click { cursor: pointer; }
.s-row.click:hover { background: var(--hover); }
.s-row.danger .s-title { color: var(--danger); }
.s-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: #7e8b97; color: #fff; flex: none; }
.s-ic.c-blue { background: #3a8fd6; } .s-ic.c-green { background: #4fae4e; } .s-ic.c-red { background: #e5534b; } .s-ic.c-orange { background: #f0932b; }
.s-ic.c-violet { background: #8e6bd8; } .s-ic.c-cyan { background: #2aa9b8; } .s-ic.c-gray { background: #7e8b97; }
.s-main { flex: 1; min-width: 0; }
.s-title { font-size: 16px; }
.s-sub { font-size: 13.5px; color: var(--sub); word-break: break-word; }
.s-sub.long { font-size: 14px; line-height: 1.45; }
.s-sub.click { cursor: pointer; color: var(--accent); }
.s-select { width: auto; padding: 6px 8px; }
.chev { color: var(--sub); }
.sample-chat { padding: 16px; display: flex; flex-direction: column; gap: 8px; background: linear-gradient(160deg, var(--chat-a), var(--chat-b) 55%, var(--chat-c)); }
.sample-chat .bubble { max-width: 70%; }
.sample-chat .bubble.out { align-self: flex-end; }
.set-thumb { width: 38px; height: 38px; object-fit: contain; }
.form { padding: 4px 16px 20px; background: var(--card); margin-top: 8px; }
.pair { text-align: center; padding: 6px 0 2px; }
.pair-code { font-size: 38px; font-weight: 600; letter-spacing: 4px; font-family: Consolas, monospace; color: var(--accent); user-select: all; }
.pair-left { color: var(--sub); margin: 6px 0 10px; }

.contact { display: flex; align-items: center; gap: 14px; padding: 8px 16px; cursor: pointer; }
.contact:hover { background: var(--hover); }
.contact-main { min-width: 0; }
.contact-name { font-weight: 500; font-size: 16px; }
.contact-sub { font-size: 13.5px; color: var(--sub); }
.contact-sub.online { color: var(--accent); }
.contact-list { background: var(--bg); min-height: 100%; }
.letter { padding: 8px 18px 2px; font-weight: 600; color: var(--accent); background: var(--bg); }
.page .page-body .contact-list, .page .page-body .arch-grid { background: transparent; }

.arch-seg { margin: 10px 14px; width: auto; }
.arch-grid { align-items: start; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 4px 14px 24px; }
.arch-card { background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); display: flex; flex-direction: column; }
.arch-head { display: flex; gap: 8px; align-items: center; padding: 8px 12px; font-size: 13.5px; color: var(--sub); }
.arch-dir { font-weight: 600; color: var(--accent); } .arch-dir.out { color: var(--green); }
.arch-img, .arch-video { width: 100%; max-height: 300px; object-fit: cover; display: block; cursor: zoom-in; }
.arch-round { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; margin: 6px auto; }
.arch-card .voice { padding: 12px; }
.arch-foot { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 12px; gap: 6px; margin-top: auto; }
.arch-meta { display: flex; flex-direction: column; font-size: 12.5px; color: var(--sub); }
.arch-actions { display: flex; }
.arch-actions .icon-btn { color: var(--sub); width: 38px; height: 38px; }
.ttl-chip { color: #e0902a; display: inline-flex; align-items: center; }

/* ===== Вход ===== */
.auth-screen { flex: 1; min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; background: linear-gradient(160deg, #4d7aa3, #2a5d8f 60%, #1d4670); padding: 20px; overflow-y: auto; }
:root[data-theme="dark"] .auth-screen { background: linear-gradient(160deg, #1a2735, #0e1621); }
.auth-card { width: min(400px, 100%); background: var(--card); border-radius: 20px; padding: 26px 26px 22px; text-align: center; box-shadow: var(--shadow); position: relative; }
.auth-card h1 { font-size: 24px; margin: 10px 0 6px; font-weight: 600; }
.auth-card h2 { font-size: 19px; margin: 8px 0 4px; font-weight: 600; }
.auth-sub { color: var(--sub); font-size: 14.5px; margin: 6px 0 4px; line-height: 1.45; }
.auth-logo { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: linear-gradient(180deg, #5fb1ec, #2f7fc6); color: #fff; display: grid; place-items: center; }
.auth-top { position: absolute; left: 6px; top: 6px; }
.auth-back { color: var(--sub) !important; }
.auth-error { background: rgba(229, 57, 53, .12); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: 12px 0 4px; font-size: 14px; text-align: left; word-break: break-word; }
.auth-ok { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--green); margin: 16px 0 8px; }
.auth-body .seg { margin: 14px 0 6px; }
.qr-box { width: 240px; height: 240px; margin: 14px auto 6px; padding: 8px; background: #fff; border-radius: 14px; display: grid; place-items: center; }
.qr-svg { width: 100%; height: 100%; display: block; }
.qr-hint { color: var(--sub); font-size: 13px; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ===== пользовательский сайт / ключ регистрации ===== */
.reg-actions { display: flex; gap: 2px; flex: none; }
.code-input { text-transform: uppercase; letter-spacing: 4px; font-size: 21px; text-align: center; font-family: Consolas, "SFMono-Regular", monospace; }
.auth-card .field { margin-top: 12px; }

/* плашка непрочитанных и панель закрепа */
.row.unread-div { justify-content: center; margin: 10px -10px 6px; padding: 5px 0; background: rgba(0, 0, 0, .18); }
.unread-pill { color: #fff; font-size: 13.5px; font-weight: 500; }
.pin-bar { display: flex; align-items: center; gap: 12px; padding: 6px 14px; background: var(--card); border-bottom: 1px solid var(--line); cursor: pointer; flex: none; position: relative; z-index: 2; }
.pin-bar:hover { background: var(--hover); }
.pin-bar-ic { color: var(--accent); transform: rotate(40deg); }
.pin-bar-body { min-width: 0; border-left: 2px solid var(--accent); padding-left: 10px; }
.pin-bar-title { font-size: 13px; font-weight: 500; color: var(--accent); }
.pin-bar-text { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); opacity: .85; }
.auth-note { color: var(--sub); font-size: 12.5px; line-height: 1.4; margin: 14px 0 0; }
.auth-hello { font-size: 19px; font-weight: 600; color: var(--text); }
.s-row.col { align-items: flex-start; }
.s-row.col .seg { margin: 8px 0 6px; }

/* ---------- истории ---------- */
.avatar.ring { cursor: pointer; }
.avatar.ring-unread { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4.5px #35c46e; }
.avatar.ring-seen { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--badge-muted); }
.stories-strip { display: flex; gap: 12px; padding: 12px 14px 8px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--bg); }
.stories-strip::-webkit-scrollbar { display: none; }
.st-item { flex: none; width: 66px; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.st-ava { position: relative; padding: 5px; }
.st-name { font-size: 12px; max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.st-name.seen { color: var(--sub); }
.st-add { position: absolute; right: 2px; bottom: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; border: 2px solid var(--bg); z-index: 2; }
:root[data-theme="dark"] .st-add { color: #0b1620; }

.story-view { position: fixed; inset: 0; z-index: 1400; background: rgba(0, 0, 0, .92); display: grid; place-items: center; opacity: 0; transition: opacity .18s; }
.story-view.show { opacity: 1; }
.sv-frame { position: relative; height: min(100dvh, 940px); aspect-ratio: 9 / 16; max-width: 100vw; background: #111; overflow: hidden; border-radius: 14px; user-select: none; touch-action: none; }
@media (max-width: 560px) { .sv-frame { width: 100vw; height: 100dvh; aspect-ratio: auto; border-radius: 0; } }
.sv-stage { position: absolute; inset: 0; display: grid; place-items: center; }
.sv-media { width: 100%; height: 100%; object-fit: contain; background: #000; pointer-events: none; }
.sv-loading { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.sv-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(0, 0, 0, .55), transparent 22%, transparent 70%, rgba(0, 0, 0, .65)); }
.sv-top { position: absolute; left: 0; right: 0; top: 0; padding: 10px 10px 0; color: #fff; z-index: 3; }
.sv-bars { display: flex; gap: 4px; }
.sv-bar { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .35); overflow: hidden; }
.sv-bar i { display: block; height: 100%; width: 0; background: #fff; }
.sv-bar.done i { width: 100%; }
.sv-head { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.sv-who { flex: 1; min-width: 0; }
.sv-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.sv-time { font-size: 12.5px; opacity: .85; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.sv-actions { display: flex; align-items: center; gap: 4px; }
.sv-views { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 0 6px; }
.sv-head .icon-btn { color: #fff; }
.sv-head .icon-btn.off { opacity: .55; }
.sv-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 16px 22px; color: #fff; z-index: 3; text-align: center; pointer-events: none; }
.sv-cap-text { display: inline-block; max-width: 100%; max-height: 32vh; overflow: auto; font-size: 15.5px; line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere; pointer-events: auto; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.sv-cap-text a { color: #9fd0ff; }
.story-view.paused .sv-bar i { opacity: .8; }

.compose-story .cs-preview { display: block; width: 100%; max-height: 38vh; object-fit: contain; background: #000; border-radius: 10px; margin-bottom: 10px; }
.compose-story .cs-body textarea { width: 100%; resize: vertical; margin-bottom: 8px; }
.cs-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; margin: 6px 0; }
.cs-label .input { width: auto; min-width: 150px; }
.cs-progress { height: 4px; border-radius: 2px; background: var(--accent-soft); overflow: hidden; margin-top: 10px; }
.cs-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* профиль: многострочные значения, карточка личного канала */
.info-val { white-space: pre-line; overflow-wrap: anywhere; }
.pc-card { display: flex; gap: 12px; align-items: flex-start; padding: 8px 18px 14px; cursor: pointer; }
.pc-card:hover { background: var(--hover); }
.pc-main { flex: 1; min-width: 0; }
.pc-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { font-size: 13px; color: var(--sub); }
.pc-last { margin-top: 6px; padding: 7px 10px; border-radius: 10px; background: var(--bg-alt); display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.pc-last-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pc-last-date { flex: none; font-size: 12px; color: var(--sub); }

/* лента миниатюр в просмотрщике, ссылки в шапке истории */
.viewer-strip { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; justify-content: safe center; background: rgba(0, 0, 0, .35); scrollbar-width: thin; }
.vs-thumb { flex: none; width: 54px; height: 54px; border-radius: 8px; overflow: hidden; opacity: .55; border: 2px solid transparent; padding: 0; background: #222; transition: opacity .12s, border-color .12s; }
.vs-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vs-thumb:hover { opacity: .85; }
.vs-thumb.on { opacity: 1; border-color: #fff; }
.sv-ava.link, .sv-name { cursor: pointer; }
.sv-name:hover { text-decoration: underline; }
.avatar.ring-click { cursor: pointer; }

/* архив: сессия Telegram недоступна, показываем сохранённое */
.archive-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #fff3d6; color: #5c4400; border-bottom: 1px solid #f0d99a; }
:root[data-theme="dark"] .archive-bar { background: #3a3220; color: #f3dca0; border-bottom-color: #54482a; }
.archive-bar .ab-text { flex: 1; min-width: 0; }
.archive-bar .ab-title { font-weight: 600; font-size: 14.5px; }
.archive-bar .ab-sub { font-size: 12.5px; opacity: .85; }
.offline-bar { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px 16px; background: var(--card); color: var(--sub); border-top: 1px solid var(--line); font-size: 14px; }

/* файлы архива (админка) */
.f-info { background: var(--card); padding: 6px 4px 2px; margin-top: 8px; }
.f-total { padding: 8px 16px 0; font-weight: 500; }
.f-actions { display: flex; gap: 4px; padding: 0 8px; }
.f-chips { display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; background: var(--card); border-bottom: 1px solid var(--line); }
.f-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 3px; padding: 3px; background: var(--card); }
.f-cell { position: relative; aspect-ratio: 1; background: var(--bg-alt); overflow: hidden; cursor: pointer; border-radius: 4px; }
.f-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.f-cell .f-ico { width: 100%; height: 100%; display: grid; place-items: center; color: var(--sub); }
.f-cell .f-meta { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 4px; padding: 14px 6px 4px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); pointer-events: none; }
.f-cell.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.f-cell.picked img { opacity: .75; }
.f-check { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .25); display: grid; place-items: center; color: #fff; }
.f-check.on { background: var(--accent); border-color: var(--accent); }
.f-more { display: flex; justify-content: center; padding: 8px; background: var(--card); }
.f-bar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -2px 8px rgba(0, 0, 0, .12); }
.f-bar span { flex: 1; font-size: 14px; }
.f-bar .btn-text[disabled] { opacity: .4; pointer-events: none; }

/* одноразовое у пользователя: закрытая карточка и кружок в окне */
.media.card.ttl-card { cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-width: 230px; }
.media.card.ttl-card:hover { filter: brightness(.97); }
.ttl-round { width: min(70vw, 320px); aspect-ratio: 1; border-radius: 50%; object-fit: cover; background: #000; display: block; margin: 0 auto; }

/* кнопки ботов */
.bubble-col { display: flex; flex-direction: column; min-width: 0; max-width: 100%; gap: 3px; }
.kb { display: flex; flex-direction: column; gap: 3px; }
.kb-row { display: flex; gap: 3px; }
.kb-btn { flex: 1 1 0; min-width: 0; padding: 8px 10px; border-radius: 9px; border: 0; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500;
  background: rgba(40, 60, 80, .55); color: #fff; backdrop-filter: blur(4px); display: inline-flex; align-items: center; justify-content: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; }
.kb-btn:hover { background: rgba(40, 60, 80, .75); }
.kb-btn.off { opacity: .5; cursor: default; }
.kb-btn .kb-ic { font-size: 11px; opacity: .8; }
.kb-panel { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; background: var(--card, #17212b); border-top: 1px solid rgba(128, 140, 152, .2); max-height: 38vh; overflow: auto; }
.kb-panel .kb-btn { background: rgba(128, 140, 152, .22); color: var(--text); padding: 10px; }
.kb-panel .kb-btn:hover { background: rgba(128, 140, 152, .34); }
.kb-close { align-self: flex-end; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: 13px; padding: 2px 6px; }

/* кнопка скачивания приложения на экране входа сайта */
.dl-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(128, 140, 152, .25); text-align: center; }
.dl-box:empty { display: none; }
.dl-btn { display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; box-sizing: border-box; }
.dl-sub { margin-top: 8px; font-size: 13px; color: var(--hint, #7f8c98); }
.dl-sub a { color: var(--accent); text-decoration: none; }
