/* «Хрюкстер» — оформление по мотивам Telegram (светлая и тёмная тема). */

:root {
  --accent: #3390ec;
  --accent-hover: #2b84dc;
  --accent-soft: rgba(51, 144, 236, 0.1);
  --danger: #e53935;
  --green: #4fae4e;
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --bg-grouped: #f1f2f6;
  --hover: #f4f4f5;
  --line: #e4e4e7;
  --text: #0f0f0f;
  --text-2: #707579;
  --text-3: #a2acb4;
  --chat-active: #3390ec;
  --bubble-in: #ffffff;
  --bubble-out: #eeffde;
  --meta-in: #8a9299;
  --meta-out: #4fae4e;
  --link: #3390ec;
  --link-out: #3a8d2a;
  --reply-out: rgba(79, 174, 78, 0.12);
  --reply-out-bar: #4fae4e;
  --react-in: rgba(51, 144, 236, 0.1);
  --react-out: rgba(79, 174, 78, 0.16);
  --react-mine: #3390ec;
  --react-mine-out: #4fae4e;
  --shadow-bubble: 0 1px 2px rgba(16, 35, 47, 0.15);
  --shadow-pop: 0 6px 24px rgba(0, 0, 0, 0.18);
  --overlay: rgba(0, 0, 0, 0.4);
  --wallpaper: radial-gradient(circle at 0% 0%, #dbddbb 0%, transparent 55%),
    radial-gradient(circle at 100% 15%, #d5d88d 0%, transparent 50%),
    radial-gradient(circle at 10% 100%, #88b884 0%, transparent 55%),
    radial-gradient(circle at 95% 95%, #6ba587 0%, transparent 55%), #b6cc9c;
  --pattern-opacity: 0.14;
  --pattern-filter: none;
  --pill: rgba(0, 0, 0, 0.22);
  --msg-font: 16px;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme='dark'] {
  --accent: #8774e1;
  --accent-hover: #7a66d8;
  --accent-soft: rgba(135, 116, 225, 0.14);
  --bg: #212121;
  --bg-2: #2c2c2c;
  --bg-grouped: #181818;
  --hover: #2c2c2c;
  --line: #2f2f2f;
  --text: #ffffff;
  --text-2: #aaaaaa;
  --text-3: #707579;
  --chat-active: #766ac8;
  --bubble-in: #212121;
  --bubble-out: #766ac8;
  --meta-in: #8c8c8c;
  --meta-out: rgba(255, 255, 255, 0.65);
  --link: #8ab4f8;
  --link-out: #ffffff;
  --reply-out: rgba(255, 255, 255, 0.14);
  --reply-out-bar: #ffffff;
  --react-in: rgba(135, 116, 225, 0.18);
  --react-out: rgba(255, 255, 255, 0.16);
  --react-mine: #8774e1;
  --react-mine-out: #ffffff;
  --shadow-bubble: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 6px 24px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.55);
  --wallpaper: radial-gradient(circle at 0% 0%, #1d2a3a 0%, transparent 55%),
    radial-gradient(circle at 100% 20%, #2a1d3a 0%, transparent 50%),
    radial-gradient(circle at 10% 100%, #1a2f2a 0%, transparent 55%), #0f0f10;
  --pattern-opacity: 0.08;
  --pattern-filter: invert(1);
  --pill: rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

:root[data-size='s'] { --msg-font: 14.5px; }
:root[data-size='l'] { --msg-font: 18px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }
.ic { display: contents; }

/* тонкие полосы прокрутки на компьютере */
@media (pointer: fine) {
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); border-radius: 3px; }
  :root[data-theme='dark'] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); }
  ::-webkit-scrollbar-track { background: transparent; }
}

#app { height: 100vh; height: 100dvh; display: flex; overflow: hidden; position: relative; }
.boot { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-2); }
.boot img { width: 72px; height: 72px; }

/* ---------- кнопки, поля, переключатели ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: #fff;
  font-weight: 600; transition: background 0.15s, opacity 0.15s; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.wide { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 9px; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; color: var(--text-2); flex: none; transition: background 0.15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.accent { color: var(--accent); }
.field { display: block; margin: 0 0 14px; position: relative; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin: 0 0 6px 4px; }
.field input, .input {
  width: 100%; padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-size: 16px; outline: none; transition: border-color 0.15s;
}
.field input:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.error { color: var(--danger); font-size: 14px; margin: -4px 0 12px 4px; min-height: 1px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--text-3); border-radius: 12px; transition: background 0.2s; cursor: pointer; }
.switch span::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.spinner { width: 16px; height: 16px; border: 2px solid var(--text-3); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- экран входа ---------- */
.auth { margin: auto; width: min(380px, 100% - 32px); padding: 24px 0; }
.auth .logo { width: 96px; height: 96px; margin: 0 auto 16px; }
.auth .logo img { display: block; width: 96px; height: 96px; }
.auth h1 { text-align: center; font-size: 26px; margin: 0 0 8px; }
.auth p.lead { text-align: center; color: var(--text-2); margin: 0 0 28px; }

/* ---------- раскладка ---------- */
.sidebar {
  width: 380px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: var(--bg); min-width: 0; position: relative; overflow: hidden;
}
.chatpane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; background: var(--wallpaper); }
.chatpane::before {
  content: ''; position: absolute; inset: 0; background: url('../img/pattern.svg') repeat; background-size: 360px;
  opacity: var(--pattern-opacity); filter: var(--pattern-filter); pointer-events: none;
}
.chatpane > * { position: relative; }
.chatpane.empty { align-items: center; justify-content: center; }
.chatpane.empty .hint { background: var(--pill); color: #fff; padding: 5px 14px; border-radius: 16px; font-size: 14px; font-weight: 500; }
@media (max-width: 899px) {
  .sidebar { width: 100%; border-right: 0; }
  .chatpane { display: none; }
  body.in-chat .sidebar { display: none; }
  body.in-chat .chatpane { display: flex; }
}

.topbar {
  display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-top)) 10px 8px;
  min-height: 56px; background: var(--bg); flex: none; z-index: 3;
}
.topbar .title { flex: 1; min-width: 0; font-size: 19px; font-weight: 600; padding-left: 6px; display: flex; align-items: center; gap: 10px; }
.topbar .title .spinner { width: 15px; height: 15px; }

/* ---------- список чатов ---------- */
.searchbox { flex: 1; position: relative; min-width: 0; }
.searchbox input {
  width: 100%; height: 42px; border-radius: 21px; border: 2px solid transparent; background: var(--bg-2);
  padding: 0 38px 0 42px; outline: none; font-size: 15.5px; transition: border-color 0.15s, background 0.15s;
}
.searchbox input:focus { border-color: var(--accent); background: var(--bg); }
.searchbox .s-ic { position: absolute; left: 12px; top: 10px; width: 22px; height: 22px; color: var(--text-3); pointer-events: none; }
.searchbox .s-ic svg { width: 22px; height: 22px; }
.searchbox .clear { position: absolute; right: 2px; top: 1px; width: 40px; height: 40px; }
.conn-state { padding: 0 18px 6px; font-size: 14px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }
.chatlist { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 90px; }
.chatitem {
  display: flex; gap: 12px; align-items: center; padding: 8px 10px; cursor: pointer; user-select: none; border-radius: 12px;
  height: 72px;
}
.chatitem:hover { background: var(--hover); }
.chatitem.active { background: var(--chat-active); color: #fff; }
.chatitem .body { flex: 1; min-width: 0; }
.chatitem .row { display: flex; align-items: center; gap: 6px; }
.chatitem .row + .row { margin-top: 3px; }
.chatitem .name { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.chatitem .name .mute-ic svg { width: 15px; height: 15px; color: var(--text-3); }
.chatitem .time { font-size: 12.5px; color: var(--text-2); flex: none; display: flex; align-items: center; gap: 3px; }
.chatitem .time svg { width: 17px; height: 17px; color: var(--green); }
.chatitem .preview { flex: 1; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chatitem .preview .who { color: var(--text); }
.chatitem .preview .draft { color: var(--danger); }
.chatitem .preview .typing { color: var(--accent); }
.chatitem.active .preview, .chatitem.active .time, .chatitem.active .preview .who, .chatitem.active .preview .typing,
.chatitem.active .preview .draft, .chatitem.active .time svg, .chatitem.active .name .mute-ic svg { color: #fff; }
.badge {
  min-width: 22px; height: 22px; border-radius: 11px; padding: 0 7px; background: var(--accent); color: #fff;
  font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.badge.muted { background: var(--text-3); }
.chatitem.active .badge { background: #fff; color: var(--chat-active); }
.empty-list { padding: 40px 24px; text-align: center; color: var(--text-2); }
.list-section { padding: 10px 12px 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.found-text mark { background: transparent; color: var(--accent); font-weight: 600; }

.fab {
  position: absolute; right: 20px; bottom: calc(20px + var(--safe-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); z-index: 4; transition: transform 0.2s, background 0.15s;
}
.fab:hover { background: var(--accent-hover); }
.fab svg { width: 26px; height: 26px; }

.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 20px; position: relative; letter-spacing: 0.3px; overflow: visible;
  background-image: linear-gradient(rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.06));
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.xl { width: 120px; height: 120px; font-size: 42px; }
.avatar.lg { width: 80px; height: 80px; font-size: 30px; }
.avatar.md { width: 42px; height: 42px; font-size: 16px; }
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.xs { width: 34px; height: 34px; font-size: 13px; }
.avatar svg { width: 52%; height: 52%; }
.avatar .dot {
  position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px; border-radius: 50%; background: #0ac630;
  border: 2.5px solid var(--bg);
}
.chatitem.active .avatar .dot { border-color: var(--chat-active); }
.avatar.pig { background: #ffd6d6; }
.avatar.pig img { border-radius: 0; width: 70%; height: auto; }

.https-banner {
  display: flex; align-items: center; gap: 8px; margin: 0 10px 8px; padding: 9px 6px 9px 14px; background: var(--accent-soft);
  border-radius: 12px; font-size: 13.5px; flex: none;
}
.https-banner .grow { flex: 1; min-width: 0; }
.https-banner .icon-btn { width: 30px; height: 30px; }
.https-banner .icon-btn svg { width: 18px; height: 18px; }

/* ---------- боковые панели (настройки, новый чат) ---------- */
.panel {
  position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 10;
  animation: slide-in 0.2s ease-out;
}
.panel.grouped { background: var(--bg-grouped); }
.panel.grouped .topbar { background: var(--bg-grouped); }
.panel .p-body { flex: 1; overflow-y: auto; padding: 0 0 calc(24px + var(--safe-bottom)); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
.rpanel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(400px, 100%); background: var(--bg); z-index: 12;
  display: flex; flex-direction: column; box-shadow: -2px 0 12px rgba(0, 0, 0, 0.12); animation: slide-left 0.2s ease-out;
}
.rpanel.grouped, .rpanel.grouped .topbar { background: var(--bg-grouped); }
.rpanel .p-body { flex: 1; overflow-y: auto; padding-bottom: calc(24px + var(--safe-bottom)); }
@keyframes slide-left { from { transform: translateX(40px); opacity: 0; } }

.profile-head { display: flex; flex-direction: column; align-items: center; padding: 8px 16px 18px; text-align: center; }
.profile-head .avatar { margin-bottom: 12px; cursor: pointer; }
.profile-head .p-name { font-size: 22px; font-weight: 600; }
.profile-head .p-sub { color: var(--text-2); font-size: 14.5px; margin-top: 3px; }
.profile-head .p-sub.on { color: var(--accent); }
.avatar .cam {
  position: absolute; right: -2px; bottom: -2px; width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--bg-grouped); display: flex; align-items: center; justify-content: center;
}
.avatar .cam svg { width: 17px; height: 17px; color: #fff; }

.group { background: var(--bg); border-radius: 14px; margin: 0 14px 18px; overflow: hidden; }
.group-title { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.3px; margin: 0 30px 7px; }
.group-note { font-size: 13px; color: var(--text-2); margin: -10px 30px 18px; line-height: 1.4; }
.cell {
  display: flex; align-items: center; gap: 14px; padding: 11px 16px; min-height: 48px; position: relative; width: 100%;
  border: 0; background: transparent; text-align: left; color: var(--text); font-size: 16px;
}
button.cell:hover, a.cell:hover, label.cell:hover { background: var(--hover); text-decoration: none; }
.cell + .cell::before { content: ''; position: absolute; top: 0; left: 62px; right: 0; border-top: 1px solid var(--line); }
.cell.plain + .cell::before, .cell.plain::before { left: 16px; }
.cell .c-ic { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; flex: none; }
.cell .c-ic svg { width: 19px; height: 19px; }
.cell .c-main { flex: 1; min-width: 0; }
.cell .c-sub { font-size: 13.5px; color: var(--text-2); margin-top: 1px; }
.cell .c-val { color: var(--text-2); font-size: 15px; }
.cell .chev svg { width: 18px; height: 18px; color: var(--text-3); }
.cell.danger { color: var(--danger); }
.cell.accent { color: var(--accent); }
.cell .avatar { margin: -2px 0; }
.cell input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.cell.input-cell { padding: 4px 16px; }
.cell.input-cell input { border: 0; outline: none; background: transparent; padding: 10px 0; flex: 1; font-size: 16px; min-width: 0; }
.seg { display: flex; gap: 6px; padding: 12px 16px; }
.seg button { flex: 1; border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 6px; font-size: 14px; }
.seg button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.qr { display: flex; justify-content: center; padding: 16px; }
.qr img { width: 220px; height: 220px; border-radius: 12px; background: #fff; padding: 6px; }
.linkbox { display: flex; gap: 8px; align-items: center; padding: 4px 6px 4px 16px; font-size: 14px; word-break: break-all; }
.linkbox code { flex: 1; font-family: inherit; color: var(--text-2); }
.version { text-align: center; color: var(--text-3); font-size: 13px; padding: 4px 16px 12px; }

.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; background: var(--bg); position: sticky; top: 0; z-index: 2; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 13px 4px 11px; font-weight: 600; color: var(--text-2); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.media-grid .mg { aspect-ratio: 1; background: var(--bg-2) center/cover no-repeat; cursor: pointer; position: relative; border: 0; padding: 0; }
.media-grid .mg .duration { position: absolute; left: 4px; bottom: 4px; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 6px; }

/* ---------- чат ---------- */
.chathead { cursor: pointer; border-bottom: 1px solid var(--line); }
.chathead .who { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.chathead .info { flex: 1; min-width: 0; }
.chathead .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chathead .sub { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chathead .sub.on { color: var(--accent); }
.back-btn { display: none; }
@media (max-width: 899px) { .back-btn { display: inline-flex; } }
.dots::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.pinbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; background: var(--bg); border-bottom: 1px solid var(--line);
  cursor: pointer; flex: none; z-index: 2;
}
.pinbar .pin-line { width: 2px; align-self: stretch; background: var(--accent); border-radius: 1px; }
.pinbar .pin-body { flex: 1; min-width: 0; }
.pinbar .pin-title { color: var(--accent); font-size: 14px; font-weight: 600; }
.pinbar .pin-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 10px max(12px, calc((100% - 760px) / 2)) 8px;
  display: flex; flex-direction: column; overscroll-behavior: contain;
}
.messages .spacer { flex: 1; }
.day { display: flex; flex-direction: column; }
.dateline { align-self: center; margin: 10px 0 8px; position: sticky; top: 6px; z-index: 1; }
.dateline span { background: var(--pill); color: #fff; font-size: 13.5px; font-weight: 500; padding: 4px 11px; border-radius: 14px; }
.unread-line { align-self: stretch; text-align: center; margin: 10px -14px; padding: 4px; background: rgba(255, 255, 255, 0.55); color: var(--text-2); font-size: 14px; font-weight: 500; }
:root[data-theme='dark'] .unread-line { background: rgba(0, 0, 0, 0.35); color: #ddd; }
.empty-chat {
  margin: auto; background: var(--pill); color: #fff; border-radius: 18px; padding: 16px 22px; text-align: center; max-width: 260px;
}
.empty-chat b { display: block; font-size: 15px; margin-bottom: 4px; }
.empty-chat span { font-size: 14px; opacity: 0.9; }

.msg { display: flex; align-items: flex-end; gap: 8px; margin-top: 3px; max-width: 100%; transition: transform 0.15s; }
.msg.first { margin-top: 10px; }
.msg.out { justify-content: flex-end; }
.msg .side { width: 34px; flex: none; align-self: flex-end; }
.msg .side .avatar { cursor: pointer; }
.bubble {
  position: relative; background: var(--bubble-in); border-radius: var(--radius); padding: 6px 10px 7px 11px;
  box-shadow: var(--shadow-bubble); min-width: 70px; max-width: min(520px, calc(100% - 50px)); overflow-wrap: anywhere;
  font-size: var(--msg-font); line-height: 1.33;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.first .bubble { border-top-left-radius: var(--radius); }
.msg.in:not(.first) .bubble { border-top-left-radius: 6px; }
.msg.in:not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.out:not(.first) .bubble { border-top-right-radius: 6px; }
.msg.out:not(.last) .bubble { border-bottom-right-radius: 6px; }
/* хвостик у последнего сообщения в серии */
.msg.last:not(.media-only) .bubble::before {
  content: ''; position: absolute; bottom: 0; width: 11px; height: 17px; background: inherit;
  -webkit-mask: var(--tail) no-repeat; mask: var(--tail) no-repeat;
}
.msg.in.last:not(.media-only) .bubble { border-bottom-left-radius: 0; }
.msg.out.last:not(.media-only) .bubble { border-bottom-right-radius: 0; }
.msg.in.last .bubble::before { left: -9px; --tail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='17'%3E%3Cpath d='M11 0v17H0c3-1 6-3 8-6 2-4 3-8 3-11z'/%3E%3C/svg%3E"); }
.msg.out.last .bubble::before { right: -9px; --tail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='17'%3E%3Cpath d='M0 0v17h11C8 16 5 14 3 11 1 7 0 3 0 0z'/%3E%3C/svg%3E"); }
.msg.flash .bubble { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow-bubble); } }
.msg.selected .bubble { box-shadow: 0 0 0 2px var(--accent); }

.bubble .sender { font-size: 14.5px; font-weight: 600; margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble .fwd { font-size: 14px; color: var(--accent); margin-bottom: 2px; }
.msg.out .bubble .fwd { color: var(--link-out); }
.bubble .fwd b { font-weight: 600; }
.bubble .text { white-space: pre-wrap; }
.bubble .text a { color: var(--link); }
.msg.out .bubble .text a { color: var(--link-out); text-decoration: underline; }
.bubble .text.big-emoji { font-size: 44px; line-height: 1.15; }
.bubble.emoji-only { background: transparent !important; box-shadow: none; padding: 0 2px 22px; }
.bubble.emoji-only .meta-spacer { display: none; }
.bubble.emoji-only .meta { background: var(--pill); color: #fff !important; border-radius: 10px; padding: 3px 7px; right: 0; bottom: 0; }
.bubble .meta {
  position: absolute; right: 9px; bottom: 5px; font-size: 12px; color: var(--meta-in); display: inline-flex; gap: 3px;
  align-items: center; user-select: none; white-space: nowrap; line-height: 1;
}
.msg.out .bubble .meta { color: var(--meta-out); }
.meta svg { width: 17px; height: 17px; }
.meta .failed { color: var(--danger); }
.meta-spacer { display: inline-block; width: 46px; height: 12px; vertical-align: bottom; }
.msg.out .meta-spacer { width: 64px; }
.meta-spacer.edited { width: 82px; }
.msg.out .meta-spacer.edited { width: 100px; }

.reply-quote {
  display: block; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 3px 8px 4px;
  margin: 2px 0 5px; cursor: pointer; min-width: 120px; max-width: 100%; overflow: hidden;
}
.msg.out .reply-quote { border-left-color: var(--reply-out-bar); background: var(--reply-out); }
.msg.out .reply-quote .rq-name { color: var(--reply-out-bar); }
.reply-quote .rq-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-quote .rq-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.85; }

.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 2px; }
.reaction {
  border: 0; border-radius: 15px; padding: 3px 9px 3px 7px; background: var(--react-in); display: inline-flex; align-items: center;
  gap: 5px; font-size: 14px; color: var(--accent); font-weight: 600; height: 30px;
}
.msg.out .reaction { background: var(--react-out); color: var(--link-out); }
.reaction .r-e { font-size: 17px; line-height: 1; }
.reaction.mine { background: var(--react-mine); color: #fff; }
.msg.out .reaction.mine { background: var(--react-mine-out); color: var(--bubble-out); }
.reaction .r-av { display: flex; }
.reaction .r-av .avatar { width: 20px; height: 20px; font-size: 9px; border: 1.5px solid transparent; margin-left: -5px; }
.reaction .r-av .avatar:first-child { margin-left: 0; }

.bubble.media { padding: 3px; }
.bubble.media.bare { padding: 0; background: transparent !important; box-shadow: none; }
.bubble.media.bare .thumb { border-radius: var(--radius); box-shadow: var(--shadow-bubble); }
.bubble.media .sender, .bubble.media .fwd { padding: 3px 7px 1px; }
.bubble.media .reply-quote { margin: 3px 3px 5px; }
.bubble.media .reactions { padding: 0 6px 4px; }
.bubble.media .meta { right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.45); color: #fff !important; border-radius: 10px; padding: 3px 7px; }
.bubble.media.with-reactions .meta { position: static; float: right; margin: -26px 6px 6px 0; }
.thumb {
  position: relative; display: block; border-radius: calc(var(--radius) - 3px); overflow: hidden; background: rgba(0, 0, 0, 0.08);
  max-width: min(400px, 72vw); cursor: pointer;
}
.thumb img, .thumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb .play {
  position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.thumb .play svg { width: 26px; height: 26px; margin-left: 3px; }
.thumb .duration { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 10px; }
.thumb .progress {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: #fff; font-size: 13px;
}
.ring { width: 48px; height: 48px; }
.ring circle { fill: none; stroke-width: 3.5; }
.ring .track { stroke: rgba(255, 255, 255, 0.3); }
.ring .bar { stroke: #fff; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 0.2s; }

.filebox { display: flex; gap: 12px; align-items: center; padding: 3px 4px 2px 0; min-width: 220px; color: inherit; text-decoration: none !important; }
.filebox .ficon { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.msg.out .filebox .ficon { background: var(--green); }
:root[data-theme='dark'] .msg.out .filebox .ficon { background: rgba(255, 255, 255, 0.25); }
.filebox .ficon svg { width: 24px; height: 24px; }
.filebox .fname { font-weight: 600; overflow-wrap: anywhere; font-size: 15px; }
.filebox .fsize { font-size: 13.5px; color: var(--meta-in); margin-top: 2px; }
.msg.out .filebox .fsize { color: var(--meta-out); }
.bubble.filebub { padding-bottom: 22px; }
.retry { border: 0; background: var(--danger); color: #fff; border-radius: 8px; padding: 5px 11px; font-size: 13px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.swipe-reply {
  position: absolute; right: -44px; top: 50%; width: 32px; height: 32px; margin-top: -16px; border-radius: 50%; background: var(--pill);
  color: #fff; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.1s;
}
.swipe-reply svg { width: 18px; height: 18px; }

.to-bottom {
  position: absolute; right: 16px; bottom: calc(84px + var(--safe-bottom)); width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg); color: var(--text-2); border: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25); display: flex;
  align-items: center; justify-content: center; z-index: 3;
}
.to-bottom svg { width: 26px; height: 26px; }
.to-bottom .badge { position: absolute; top: -8px; left: 50%; transform: translateX(-50%); }

/* ---------- поле ввода ---------- */
.composer-wrap { flex: none; padding: 6px max(10px, calc((100% - 776px) / 2)) calc(10px + var(--safe-bottom)); z-index: 2; position: relative; }
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer .box {
  flex: 1; min-width: 0; background: var(--bg); border-radius: 18px; box-shadow: var(--shadow-bubble); display: flex;
  flex-direction: column; overflow: hidden;
}
.composer .inrow { display: flex; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; font-size: var(--msg-font); line-height: 1.35;
  padding: 13px 6px 13px 14px; max-height: 180px; min-height: 48px; min-width: 0;
}
.composer .icon-btn { width: 46px; height: 48px; border-radius: 0; color: var(--text-3); }
.composer .icon-btn:hover { background: transparent; color: var(--accent); }
.send-btn {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center;
  justify-content: center; flex: none; box-shadow: var(--shadow-bubble); transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn svg { width: 25px; height: 25px; }
.send-btn.idle { background: var(--bg); color: var(--text-3); }
.compose-bar { display: flex; align-items: center; gap: 10px; padding: 8px 6px 2px 12px; }
.compose-bar .cb-ic { color: var(--accent); }
.compose-bar .cb-ic svg { width: 22px; height: 22px; }
.compose-bar .cb-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; }
.compose-bar .cb-title { color: var(--accent); font-size: 14px; font-weight: 600; }
.compose-bar .cb-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.compose-bar .icon-btn { width: 34px; height: 34px; border-radius: 50%; }
.compose-bar .icon-btn svg { width: 20px; height: 20px; }
.dropzone {
  position: absolute; inset: 10px; background: rgba(51, 144, 236, 0.16); border: 3px dashed var(--accent); border-radius: 18px; z-index: 5;
  display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; color: var(--accent); pointer-events: none;
}

/* ---------- окна ---------- */
.modal-wrap {
  position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 20;
  animation: fade 0.15s; padding: 16px;
}
.modal {
  background: var(--bg); width: min(420px, 100%); max-height: min(720px, 100%); border-radius: 16px; display: flex;
  flex-direction: column; overflow: hidden; box-shadow: var(--shadow-pop);
}
.modal .mhead { display: flex; align-items: center; gap: 6px; padding: 12px 8px 8px 20px; font-size: 19px; font-weight: 600; }
.modal .mhead .grow { flex: 1; }
.modal .mbody { overflow-y: auto; padding: 0 0 12px; }
.modal .mtext { padding: 0 20px 8px; font-size: 15.5px; line-height: 1.45; }
.modal .mactions { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 12px 4px; }
.modal .mactions button { border: 0; background: transparent; color: var(--accent); font-weight: 600; padding: 10px 14px; border-radius: 10px; text-transform: uppercase; font-size: 14px; }
.modal .mactions button:hover { background: var(--accent-soft); }
.modal .mactions button.danger { color: var(--danger); }
.modal .mactions button.danger:hover { background: rgba(229, 57, 53, 0.1); }
@keyframes fade { from { opacity: 0; } }

/* ---------- просмотр фото/видео ---------- */
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.94); z-index: 30; display: flex; align-items: center; justify-content: center; animation: fade 0.15s; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .vbar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 4px; padding: calc(8px + var(--safe-top)) 8px 8px 16px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent); z-index: 1; color: #fff;
}
.viewer .vbar .v-info { flex: 1; min-width: 0; font-size: 14px; }
.viewer .vbar .v-info b { display: block; font-size: 15px; }
.viewer .icon-btn { color: #fff; }
.viewer .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- меню сообщения ---------- */
.menu-wrap { position: fixed; inset: 0; z-index: 25; }
.menu {
  position: fixed; z-index: 26; background: var(--bg); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 6px 0; min-width: 210px;
  animation: pop 0.12s ease-out; transform-origin: top left;
}
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }
.menu button {
  display: flex; gap: 16px; align-items: center; width: 100%; border: 0; background: transparent; padding: 9px 18px; text-align: left; font-size: 15px;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu svg { width: 21px; height: 21px; color: var(--text-2); }
.menu button.danger svg { color: var(--danger); }
.react-bar {
  position: fixed; z-index: 26; background: var(--bg); border-radius: 28px; box-shadow: var(--shadow-pop); display: flex; padding: 5px 6px; gap: 2px;
  animation: pop 0.12s ease-out;
}
.react-bar button { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; font-size: 25px; line-height: 1; transition: transform 0.12s; }
.react-bar button:hover { transform: scale(1.25); }
.react-bar button.on { background: var(--accent-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); background: rgba(30, 30, 30, 0.9); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-size: 14.5px; z-index: 40; max-width: calc(100% - 32px); animation: fade 0.2s;
}

@media (pointer: coarse) {
  .msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

/* ---------- «Избранное» ---------- */
.avatar.saved { background: linear-gradient(180deg, #72d5fd, #2a9ef1); color: #fff; }
.avatar.saved svg { width: 46%; height: 46%; }
.saved-empty { max-width: 300px; text-align: left; }
.saved-empty .se-ic { display: flex; justify-content: center; margin-bottom: 6px; }
.saved-empty .se-ic svg { width: 46px; height: 46px; }
.saved-empty b { text-align: center; }
.saved-empty ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.5; opacity: 0.92; }
.cell .c-ic.round { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); }
.cell .c-ic.round svg { width: 21px; height: 21px; }

/* ---------- голосовые ---------- */
.bubble.voicebub { padding: 7px 10px 6px 7px; min-width: 252px; }
.voice { display: flex; align-items: center; gap: 10px; --wave: var(--accent); }
.msg.out .voice { --wave: var(--green); }
:root[data-theme='dark'] .msg.out .voice { --wave: #fff; }
.vbtn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--wave); color: #fff; display: flex;
  align-items: center; justify-content: center; flex: none; padding: 0;
}
:root[data-theme='dark'] .msg.out .vbtn { color: var(--bubble-out); }
.vbtn svg { width: 22px; height: 22px; }
.voice:not(.playing) .vbtn:not(.pending) svg { margin-left: 2px; }
.vbtn .ring { width: 44px; height: 44px; }
.vbtn.failed { background: var(--danger); }
.vmain { flex: 1; min-width: 0; }
.wave { position: relative; height: 28px; width: 190px; max-width: 100%; cursor: pointer; color: var(--wave); touch-action: pan-y; }
.w-bars { display: flex; align-items: center; gap: 2px; height: 100%; width: 190px; }
.wave > .w-bars { opacity: 0.35; }
:root[data-theme='dark'] .wave > .w-bars { opacity: 0.5; }
.w-bars i { flex: none; width: 2.75px; min-height: 2px; border-radius: 2px; background: currentColor; }
.w-fg { position: absolute; left: 0; top: 0; bottom: 0; width: 0; overflow: hidden; }
.vinfo { display: flex; align-items: center; gap: 6px; height: 16px; margin-top: 2px; font-size: 13px; color: var(--meta-in); font-variant-numeric: tabular-nums; }
.msg.out .vinfo { color: var(--meta-out); }
.vdot { display: none; width: 6px; height: 6px; border-radius: 50%; background: var(--wave); }
.voice.unplayed .vdot { display: inline-block; }
.vspeed {
  border: 0; border-radius: 8px; padding: 1px 6px; font-size: 11.5px; font-weight: 700; line-height: 1.4;
  background: color-mix(in srgb, var(--wave) 15%, transparent); color: var(--wave);
}

/* ---------- поле ввода: эмодзи и запись ---------- */
.composer .inrow .emoji-btn { width: 44px; }
.composer .inrow .emoji-btn + textarea { padding-left: 0; }
.composer .emoji-btn.on { color: var(--accent); }
.send-wrap { position: relative; flex: none; }
.send-btn { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.send-btn.idle { color: var(--text-2); }
.send-btn.rec {
  background: var(--accent); color: #fff; transform: scale(1.45); position: relative; z-index: 6; transition: box-shadow 0.08s;
  box-shadow: 0 0 0 calc(var(--level, 0) * 20px) color-mix(in srgb, var(--accent) 22%, transparent);
}
.rec-row { display: none; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; overflow: hidden; user-select: none; }
.composer-wrap.recording .inrow { display: none; }
.composer-wrap.recording .rec-row { display: flex; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e53935; flex: none; animation: rec-blink 1s ease-in-out infinite; }
@keyframes rec-blink { 50% { opacity: 0.25; } }
.rec-time { min-width: 56px; font-variant-numeric: tabular-nums; }
.rec-mid { flex: 1; min-width: 0; display: flex; justify-content: center; overflow: hidden; }
.rec-hint { display: inline-flex; align-items: center; justify-content: center; gap: 4px; color: var(--text-2); white-space: nowrap; }
.rec-hint svg { width: 18px; height: 18px; animation: rec-nudge 1.4s ease-in-out infinite; }
@keyframes rec-nudge { 50% { transform: translateX(-4px); } }
.rec-cancel {
  display: none; border: 0; background: transparent; color: var(--accent); font-weight: 600; text-transform: uppercase;
  font-size: 14px; padding: 10px;
}
.composer-wrap.locked .rec-hint { display: none; }
.composer-wrap.locked .rec-cancel { display: block; }
.rec-lock {
  display: none; position: absolute; left: 50%; bottom: calc(100% + 26px); width: 40px; margin-left: -20px; padding: 9px 0 6px;
  border-radius: 20px; background: var(--bg); color: var(--text-2); box-shadow: var(--shadow-pop); flex-direction: column;
  align-items: center; gap: 2px; z-index: 5; pointer-events: none;
}
.rec-lock svg { width: 20px; height: 20px; }
.rec-lock .ic:last-child svg { width: 16px; height: 16px; animation: rec-up 1.4s ease-in-out infinite; }
@keyframes rec-up { 50% { transform: translateY(-3px); } }
.composer-wrap.recording:not(.locked) .rec-lock { display: flex; }

/* ---------- панель эмодзи ---------- */
.emoji-panel { display: none; flex-direction: column; background: var(--bg); min-height: 0; }
.composer-wrap.emoji-open .emoji-panel { display: flex; }
.composer-wrap .emoji-panel {
  height: 300px; margin: 8px -10px calc(-10px - var(--safe-bottom)); border-top: 1px solid var(--line);
}
@media (pointer: fine) {
  .composer-wrap .emoji-panel {
    position: absolute; bottom: calc(100% - 2px); left: max(10px, calc((100% - 776px) / 2)); width: 352px; height: 400px; margin: 0;
    border: 0; border-radius: 16px; box-shadow: var(--shadow-pop); overflow: hidden; z-index: 8; animation: pop 0.12s ease-out;
    transform-origin: bottom left;
  }
}
.emoji-pop {
  position: fixed; z-index: 26; width: min(352px, calc(100vw - 16px)); height: min(400px, calc(100vh - 16px)); background: var(--bg);
  border-radius: 16px; box-shadow: var(--shadow-pop); overflow: hidden; display: flex; animation: pop 0.12s ease-out;
}
.emoji-pop .emoji-panel { display: flex; flex: 1; }
.ep-head { padding: 8px 10px 2px; }
.ep-search {
  width: 100%; height: 36px; border-radius: 18px; border: 0; background: var(--bg-2); padding: 0 14px; outline: none; font-size: 15px;
}
.ep-scroll { flex: 1; min-height: 0; overflow-y: auto; position: relative; padding: 0 6px 6px; overscroll-behavior: contain; }
.ep-title { font-size: 13px; color: var(--text-2); font-weight: 600; padding: 10px 6px 4px; }
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
.ep-grid button {
  border: 0; background: transparent; height: 42px; padding: 0; border-radius: 10px; font-size: 27px; line-height: 1;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.ep-grid button:hover { background: var(--hover); }
.ep-results { padding-top: 6px; }
.ep-none { grid-column: 1 / -1; text-align: center; color: var(--text-2); padding: 30px 0; font-size: 14px; }
.ep-tabs { display: flex; justify-content: space-around; border-top: 1px solid var(--line); padding: 4px; flex: none; }
.composer-wrap .emoji-panel .ep-tabs { padding-bottom: calc(4px + var(--safe-bottom)); }
@media (pointer: fine) {
  .composer-wrap .emoji-panel .ep-tabs { padding-bottom: 4px; }
}
.ep-tabs button { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 10px; color: var(--text-3); display: flex; align-items: center; justify-content: center; padding: 0; }
.ep-tabs button svg { width: 21px; height: 21px; }
.ep-tabs button.on { color: var(--accent); background: var(--accent-soft); }
.ep-tabs .ep-del { color: var(--text-2); }
.react-bar button.more { font-size: 0; color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.react-bar button.more svg { width: 22px; height: 22px; }
.react-bar button.more:hover { transform: none; background: var(--hover); }

/* ---------- выбор нескольких сообщений ---------- */
.selbar .title { font-size: 17px; }
.icon-btn.danger { color: var(--danger); }
.selmark { display: none; }
.chatpane.selecting .msg { cursor: pointer; margin-left: -12px; margin-right: -12px; padding: 2px 12px; max-width: none; }
.chatpane.selecting .selmark {
  display: flex; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, 0.14); flex: none;
  align-self: center; align-items: center; justify-content: center; color: #fff;
}
.chatpane.selecting .msg.out .selmark { margin-right: auto; }
.selmark svg { width: 15px; height: 15px; opacity: 0; stroke-width: 3; }
.msg.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.msg.sel .selmark { background: var(--accent) !important; border-color: var(--accent) !important; }
.msg.sel .selmark svg { opacity: 1; }
