:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --panel-2: #f5f7f8;
  --fg: #17212b;
  --muted: #6b7785;
  --line: #e2e7ea;
  --accent: #1f8a7d;
  --accent-fg: #ffffff;
  --accent-soft: #dff1ee;
  --danger: #d64545;
  --hover: #f0f3f5;
  --shadow: 0 8px 30px rgba(15, 30, 40, 0.14);
  --radius: 12px;
  --chat-bg: #dfe8e6;
  --bubble: #ffffff;
  --bubble-mine: #d4f1e7;
  --bubble-mine-meta: #3e8f6f;
  --online: #34c759;
  color-scheme: light;
}
/* Тёмная тема: по системе (если не выбрана светлая) или выбрана вручную */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1419;
    --panel: #17212b;
    --panel-2: #1d2a35;
    --fg: #e8eef2;
    --muted: #8d9ba8;
    --line: #26333f;
    --accent: #3bb3a3;
    --accent-fg: #0b1a17;
    --accent-soft: #1d3b37;
    --danger: #ef6b6b;
    --hover: #202e3a;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    --chat-bg: #0f1820;
    --bubble: #1d2a35;
    --bubble-mine: #1f4a42;
    --bubble-mine-meta: #8fd3c3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1419;
  --panel: #17212b;
  --panel-2: #1d2a35;
  --fg: #e8eef2;
  --muted: #8d9ba8;
  --line: #26333f;
  --accent: #3bb3a3;
  --accent-fg: #0b1a17;
  --accent-soft: #1d3b37;
  --danger: #ef6b6b;
  --hover: #202e3a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --chat-bg: #0f1820;
  --bubble: #1d2a35;
  --bubble-mine: #1f4a42;
  --bubble-mine-meta: #8fd3c3;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#root { height: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { height: 100%; display: grid; place-items: center; }
.boot img { width: 160px; height: auto; }

/* --- Кнопки и поля --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-fg); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn svg, .menu-item svg { width: 22px; height: 22px; }

.field { display: block; margin: 0 0 14px; }
.field > span { display: block; margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); outline: none;
}
.input:focus { border-color: var(--accent); background: var(--panel); }
textarea.input { resize: vertical; min-height: 70px; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.error { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-size: 14px; }

/* --- Экраны входа --- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px 24px; border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.auth-logo { margin: 0 0 6px; text-align: center; line-height: 0; }
.auth-logo img { width: 200px; max-width: 70%; height: auto; }
.auth-sub { margin: 0 0 22px; text-align: center; color: var(--muted); }

/* --- Оболочка приложения --- */
.app { height: 100%; height: 100dvh; display: grid; grid-template-columns: 340px 1fr; }
.side { display: flex; flex-direction: column; min-width: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; }
.search { flex: 1; min-height: 40px; padding: 8px 14px; border: 0; border-radius: 20px; background: var(--panel-2); outline: none; }
.side-title { padding: 10px 18px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.list { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px;
  background: transparent; text-align: left; cursor: pointer;
}
.row:hover { background: var(--hover); }
.row.active { background: var(--accent); color: var(--accent-fg); }
.row.active .row-sub { color: inherit; opacity: .8; }
.row-body { flex: 1; min-width: 0; }
.row-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.main-head { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.main-head h2 { margin: 0; font-size: 17px; }
.main-body { flex: 1; overflow-y: auto; padding: 20px 16px 40px; }
.narrow { max-width: 560px; margin: 0 auto; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 16px; }
.empty-pill { padding: 6px 14px; border-radius: 16px; background: color-mix(in srgb, var(--fg) 8%, transparent); }
.back { display: none; }

.card { margin: 0 0 16px; padding: 18px; border-radius: var(--radius); background: var(--panel); }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.profile-top { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.profile-top .name { margin: 8px 0 0; font-size: 21px; font-weight: 700; }
.profile-top .sub { color: var(--muted); }
.avatar-edit { position: relative; border: 0; padding: 0; border-radius: 50%; background: none; cursor: pointer; }
.avatar-edit::after {
  content: "Изменить"; position: absolute; inset: 0; display: grid; place-items: center; border-radius: 50%;
  background: rgba(0, 0, 0, .45); color: #fff; font-size: 13px; font-weight: 600; opacity: 0; transition: opacity .15s;
}
.avatar-edit:hover::after { opacity: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- Аватар --- */
.av {
  flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 50%;
  color: #fff; font-weight: 700; user-select: none;
}
.av img { width: 100%; height: 100%; object-fit: cover; }

/* --- Меню, диалоги, тосты --- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4); animation: fade .15s; }
.drawer {
  position: fixed; z-index: 51; top: 0; bottom: 0; left: 0; width: min(300px, 85vw);
  background: var(--panel); box-shadow: var(--shadow); animation: slide .18s ease-out; display: flex; flex-direction: column;
}
/* Шапка шторки: фото на всю ширину, имя поверх (как в Telegram) */
.drawer-head { position: relative; }
.drawer-photo { display: block; width: 100%; aspect-ratio: 1; max-height: 52vh; padding: 0; border: 0; background: var(--accent-soft); cursor: pointer; overflow: hidden; }
.drawer-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.drawer-letters { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; font-size: 96px; font-weight: 700; }
.drawer-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 18px 12px; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); color: #fff; pointer-events: none; }
.drawer-cap .name { font-size: 19px; font-weight: 700; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.drawer-cap .sub { font-size: 14px; opacity: .85; }
.emoji-link { pointer-events: auto; margin-top: 2px; padding: 0; border: 0; background: none; color: #8fe3d6; font-size: 14px; cursor: pointer; }
.emoji-link:hover { text-decoration: underline; }
.menu-item {
  display: flex; align-items: center; gap: 18px; width: 100%; padding: 12px 20px; border: 0;
  background: transparent; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--hover); }
.menu-item svg { color: var(--muted); }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.drawer-foot { margin-top: auto; padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.foot-logo { width: 96px; height: auto; }
.version { font-size: 12px; color: var(--muted); }

.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
/* подложка внутри окна - под ним (иначе перекрывает и «съедает» клики) */
.modal-wrap > .scrim { z-index: 0; }
.modal { position: relative; z-index: 1; width: 100%; max-width: 400px; padding: 22px; border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); animation: pop .15s ease-out; }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal .actions { justify-content: flex-end; margin-top: 8px; }
.linkbox { display: flex; gap: 8px; margin: 0 0 12px; }
.linkbox .input { font-size: 13px; }

.toasts { position: fixed; z-index: 70; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 10px 16px; border-radius: 10px; background: #1d2a35; color: #fff; box-shadow: var(--shadow); animation: pop .15s ease-out; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(-100%); } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }

/* --- Список чатов --- */
.row-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.row-line .row-name, .row-line .row-sub { flex: 1; min-width: 0; }
.row-time { flex: none; font-size: 12px; color: var(--muted); }
.row.active .row-time { color: inherit; opacity: .8; }
.row-time .ticks { margin-right: 4px; color: var(--accent); }
.row.active .row-time .ticks { color: inherit; }
.unread { flex: none; min-width: 22px; padding: 1px 7px; border-radius: 11px; background: var(--accent); color: var(--accent-fg); font-size: 12px; font-weight: 700; text-align: center; }
.row.active .unread { background: var(--accent-fg); color: var(--accent); }
.typing { color: var(--accent); }
.row.active .typing { color: inherit; }
.av-wrap { position: relative; flex: none; }
.dot { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--online); border: 2px solid var(--panel); }
.row.active .dot { border-color: var(--accent); }
.av-family { background: var(--accent-soft); }
.av .av-family-img, .av-family img { width: 78%; height: 78%; object-fit: contain; }
.av-icon { background: var(--accent-soft); color: var(--accent); }
.av-icon svg { width: 55%; height: 55%; }
.row.pick { cursor: pointer; }
.row.pick input { width: 18px; height: 18px; accent-color: var(--accent); }

/* --- Переписка --- */
.chat-head { padding: 6px 8px; }
.head-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 4px 6px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer; }
.head-info:hover { background: var(--hover); }
.head-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-body { position: relative; flex: 1; min-height: 0; background: var(--chat-bg); }
.msgs { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; }
.msgs-inner { padding: 12px 12px 8px; display: flex; flex-direction: column; min-height: 100%; justify-content: flex-end; }
.day, .sys, .unread-line { display: flex; justify-content: center; margin: 10px 0; }
.day span, .sys span { padding: 3px 12px; border-radius: 12px; background: color-mix(in srgb, var(--fg) 12%, transparent); color: var(--fg); font-size: 13px; text-align: center; }
.unread-line { margin: 12px -12px; padding: 4px 0; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 13px; font-weight: 600; }
.msg { display: flex; align-items: flex-start; gap: 8px; margin-top: 2px; }
.msg.first { margin-top: 8px; }
.msg.right { justify-content: flex-end; }
.msg-av { flex: none; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%; }
.av-gap { flex: none; width: 34px; }
.bubble { max-width: min(560px, 80%); padding: 6px 10px 6px; border-radius: 14px; background: var(--bubble); box-shadow: 0 1px 1px rgba(0, 0, 0, .08); overflow-wrap: anywhere; }
.msg.first .bubble { border-top-left-radius: 4px; }
.msg.first.right .bubble { border-top-right-radius: 4px; border-top-left-radius: 14px; }
.mine .bubble { background: var(--bubble-mine); }
.author { margin-bottom: 2px; font-size: 14px; font-weight: 600; }
.text { white-space: pre-wrap; }
.text.deleted { font-style: italic; color: var(--muted); }
.meta { float: right; margin: 6px 0 -4px 12px; font-size: 12px; color: var(--muted); white-space: nowrap; user-select: none; }
.mine .meta { color: var(--bubble-mine-meta); }
.ticks { margin-left: 3px; letter-spacing: -3px; }
.ticks.read { color: var(--accent); }
.quote { margin: 2px 0 4px; padding: 3px 8px; border-left: 3px solid var(--q, var(--accent)); border-radius: 6px; background: color-mix(in srgb, var(--q, var(--accent)) 12%, transparent); cursor: pointer; }
.quote-name { font-size: 13px; font-weight: 600; color: var(--q, var(--accent)); }
.quote-text { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.msg.flash .bubble { animation: flash 1.4s; }
@keyframes flash { 30% { box-shadow: 0 0 0 3px var(--accent); } }
.down-btn {
  position: absolute; right: 16px; bottom: 16px; width: 46px; height: 46px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); cursor: pointer;
}
.down-btn svg { width: 24px; height: 24px; }
.down-count:not(:empty) { position: absolute; top: -6px; right: -2px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-size: 12px; font-weight: 700; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); }
.compose-row { display: flex; align-items: flex-end; gap: 6px; }
.compose-input { flex: 1; min-height: 42px; max-height: 180px; padding: 10px 14px; border: 0; border-radius: 21px; background: var(--panel-2); outline: none; resize: none; line-height: 1.4; }
.send-btn { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
.send-btn svg { width: 22px; height: 22px; }
.compose-bar { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 2px 0 6px; border-bottom: 1px solid var(--line); }
.compose-bar[hidden] { display: none; }
.bar-icon { color: var(--accent); display: grid; }
.bar-icon svg { width: 22px; height: 22px; }
.bar-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; }

.ctx-scrim { position: fixed; inset: 0; z-index: 55; }
.ctx { position: fixed; z-index: 56; min-width: 190px; padding: 6px 0; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); animation: pop .12s ease-out; }
.ctx .menu-item { padding: 9px 16px; gap: 14px; }
.ctx .menu-item svg { width: 20px; height: 20px; }

/* --- Профиль: плитки действий --- */
.avatar-open { padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; max-width: 420px; margin-top: 16px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; border: 0; border-radius: 12px;
  background: var(--panel-2); color: var(--fg); font-size: 13px; cursor: pointer;
}
.tile:hover { background: var(--hover); }
.tile svg { width: 24px; height: 24px; color: var(--accent); }
.tile.off svg { color: var(--muted); }
.muted-ic { flex: none; display: grid; color: var(--muted); }
.muted-ic svg { width: 15px; height: 15px; }
.row.active .muted-ic { color: inherit; }
.unread.quiet { background: color-mix(in srgb, var(--muted) 55%, transparent); color: #fff; }

/* --- Просмотрщик фото/видео --- */
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .92); display: flex; flex-direction: column; animation: fade .15s; color: #fff; }
.lb-top { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
.lb-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; }
.lb-name { font-weight: 600; }
.lb-sub, .lb-count { font-size: 13px; color: rgba(255, 255, 255, .65); }
.lb-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.lb-btn { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border: 0; border-radius: 18px; background: rgba(255, 255, 255, .1); color: #fff; font-size: 14px; text-decoration: none; cursor: pointer; }
.lb-btn:hover { background: rgba(255, 255, 255, .2); }
.lb-btn.danger { color: #ff8a8a; }
.lb-x { width: 40px; padding: 0; justify-content: center; }
.lb-x svg { width: 22px; height: 22px; }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px 16px; touch-action: pan-y pinch-zoom; }
.lb-media { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; user-select: none; }
.lb-nav { position: absolute; top: 50%; width: 48px; height: 48px; margin-top: -24px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; }
.lb-nav:hover { background: rgba(255, 255, 255, .22); }
.lb-nav svg { width: 26px; height: 26px; }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

/* --- Вложения в сообщениях --- */
.bubble.has-media { padding: 3px; }
.bubble.has-media > .author, .bubble.has-media > .quote, .bubble.has-media > .text, .bubble.has-media > .voice, .bubble.has-media > .file-row { margin-left: 7px; margin-right: 7px; }
.bubble.has-media > .text { padding: 4px 0 3px; }
.bubble.media-only { background: transparent; box-shadow: none; padding: 0; }
.media { overflow: hidden; border-radius: 11px; }
.media.single { width: min(340px, 70vw); }
.media.single .media-cell { width: 100%; aspect-ratio: 4 / 3; max-height: 420px; }
.media.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: min(340px, 70vw); }
.media.grid.n3 > :first-child { grid-column: span 2; aspect-ratio: 2 / 1; }
.media-cell { position: relative; display: block; width: 100%; padding: 0; border: 0; aspect-ratio: 1; background: color-mix(in srgb, var(--fg) 8%, transparent); cursor: zoom-in; overflow: hidden; }
.media-cell img, .media-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.play-badge { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff; }
.play-badge svg { width: 24px; height: 24px; margin-left: 3px; }
.dur-badge { position: absolute; left: 6px; top: 6px; padding: 1px 7px; border-radius: 9px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 12px; }
.media-meta { position: relative; height: 0; }
.media-meta .meta { position: absolute; right: 6px; bottom: 6px; float: none; margin: 0; padding: 1px 7px; border-radius: 9px; background: rgba(0, 0, 0, .45); color: #fff; }
.media-meta .ticks.read { color: #fff; }

.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 4px 0 2px; }
.voice-btn { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
.voice-btn svg { width: 22px; height: 22px; }
.voice-body { flex: 1; min-width: 0; }
.wave { display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; }
.wave i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 35%, transparent); }
.wave i.on { background: var(--accent); }
.voice-time { font-size: 12px; color: var(--muted); }
.mine .voice-time { color: var(--bubble-mine-meta); }

.file-row { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 4px 0; color: inherit; text-decoration: none; }
.file-ic { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-fg); }
.file-ic svg { width: 22px; height: 22px; }
.file-body { flex: 1; min-width: 0; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 13px; color: var(--muted); }
.file-audio { width: 100%; height: 34px; margin-top: 4px; }
.quote { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; }
.quote > :not(.quote-thumb) { grid-column: 2; }
.quote-thumb { grid-row: span 2; width: 36px; height: 36px; border-radius: 4px; object-fit: cover; }

/* --- Поле ввода: вложения и запись --- */
.attach-btn { width: 42px; height: 42px; }
.tray { display: flex; gap: 8px; margin: 0 0 8px; overflow-x: auto; padding-bottom: 2px; }
.tray-item { position: relative; flex: none; width: 76px; }
.tray-item img, .tray-ic { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); }
.tray-ic svg { width: 28px; height: 28px; }
.tray-name { margin-top: 2px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-item.err .tray-name { color: var(--danger); }
.tray-prog { position: absolute; left: 6px; right: 6px; top: 64px; height: 4px; border-radius: 2px; background: rgba(0, 0, 0, .3); overflow: hidden; }
.tray-prog i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.tray-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; }
.tray-x svg { width: 14px; height: 14px; }
.rec { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 14px; border-radius: 21px; background: var(--panel-2); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; }
.rec-wave { width: 40px; height: 6px; border-radius: 3px; background: var(--accent); transform: scaleX(calc(.2 + var(--lvl, 0) * .8)); transform-origin: left; transition: transform .1s; }
.rec-hint { color: var(--muted); font-size: 14px; }
@keyframes blink { 50% { opacity: .3; } }
.drop-hint { position: absolute; inset: 10px; display: none; place-items: center; border: 2px dashed var(--accent); border-radius: 16px; background: color-mix(in srgb, var(--accent) 12%, var(--chat-bg)); color: var(--accent); font-weight: 600; pointer-events: none; }
.chat-body.drag .drop-hint { display: grid; }

/* --- Эмодзи-статус --- */
.emoji-st { margin-left: 5px; font-size: .95em; font-weight: 400; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; max-height: 50vh; overflow-y: auto; margin: 0 0 12px; }
.emoji-cell { height: 42px; border: 0; border-radius: 10px; background: transparent; font-size: 24px; cursor: pointer; }
.emoji-cell:hover { background: var(--hover); }
.emoji-cell.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

/* --- Настройки --- */
.set-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.set-row + .set-row, div + .set-row { border-top: 1px solid var(--line); }
.set-body { flex: 1; min-width: 0; }
.set-label { font-weight: 500; }
.set-hint { font-size: 13px; color: var(--muted); }
.switch { appearance: none; flex: none; width: 46px; height: 28px; margin: 0; border-radius: 14px; background: color-mix(in srgb, var(--muted) 45%, transparent); position: relative; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: .6; }
.steps { margin: 0 0 14px; padding-left: 20px; line-height: 1.7; }

/* --- Телефон: одна колонка, как в Telegram --- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app .main { display: none; }
  .app.open .side { display: none; }
  .app.open .main { display: flex; }
  .back { display: grid; }
  .side { border-right: 0; }
  .main-body { padding: 16px 16px 40px; }
  .bubble { max-width: 86%; }
  .lb-nav { display: none; }
  .lb-sub { display: none; }
  .msgs-inner { padding: 10px 8px 6px; }
}

/* --- Выбор темы --- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 10px; background: var(--panel-2); }
.seg-btn { min-height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; }
.seg-btn.on { background: var(--accent); color: var(--accent-fg); }

/* --- Звонки --- */
.head-calls { display: flex; align-items: center; gap: 2px; flex: none; }
.join-btn { min-height: 34px; padding: 0 12px; gap: 6px; font-size: 14px; }
.join-btn svg { width: 18px; height: 18px; }
.call-dot { position: absolute; left: -2px; bottom: -2px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: var(--online); color: #fff; border: 2px solid var(--panel); }
.call-dot svg { width: 11px; height: 11px; }

.call { position: fixed; inset: 0; z-index: 75; display: flex; flex-direction: column; background: #0b1116; color: #fff; }
.call[hidden] { display: none; }
.call-top { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.call-min { color: #fff; }
.call-min:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.call-head { flex: 1; min-width: 0; text-align: center; margin-right: 40px; }
.call-title { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-status { font-size: 14px; color: rgba(255, 255, 255, .65); font-variant-numeric: tabular-nums; }
.call-grid { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px 12px; grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.call-grid[data-n="2"] { grid-template-columns: 1fr 1fr; }
.call-grid[data-n="3"], .call-grid[data-n="4"] { grid-template-columns: 1fr 1fr; }
.call-grid[data-n="5"], .call-grid[data-n="6"] { grid-template-columns: repeat(3, 1fr); }
.tile-v { position: relative; min-height: 0; overflow: hidden; border-radius: 16px; background: #1b2731; }
.tile-v video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-v.local video { transform: scaleX(-1); }
.tile-v.no-video video { opacity: 0; }
.tile-av { position: absolute; inset: 0; display: none; place-items: center; }
.tile-v.no-video .tile-av { display: grid; }
.tile-v.speaking { box-shadow: inset 0 0 0 3px var(--online); }
.tile-name { position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 4px; max-width: calc(100% - 16px); padding: 3px 10px; border-radius: 12px; background: rgba(0, 0, 0, .5); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-mute { display: grid; color: #ff8a8a; }
.tile-mute svg { width: 16px; height: 16px; }
.tile-st { margin-left: 4px; color: rgba(255, 255, 255, .6); font-size: 12px; }
.call-controls { display: flex; justify-content: center; gap: 18px; padding: 14px 12px calc(20px + env(safe-area-inset-bottom)); }
.call-btn { width: 60px; height: 60px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer; }
.call-btn:hover { background: rgba(255, 255, 255, .24); }
.call-btn svg { width: 28px; height: 28px; }
.call-btn.off { background: #fff; color: #0b1116; }
.call-btn.end { background: #e5484d; }
.call-btn.end:hover { background: #f05a5f; }
.call-btn.ok { background: #2fb36b; }
.call-btn.ok:hover { background: #38c477; }

.call-pill {
  position: fixed; z-index: 74; left: 50%; top: calc(8px + env(safe-area-inset-top)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border: 0; border-radius: 20px; background: #2fb36b; color: #fff; font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
}
.call-pill svg { width: 18px; height: 18px; }
.call-pill-back { font-weight: 400; opacity: .85; }

.ring { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: 16px; background: rgba(5, 10, 14, .82); animation: fade .2s; }
.ring-card { width: 100%; max-width: 340px; padding: 28px 20px 24px; border-radius: 22px; background: #16212b; color: #fff; text-align: center; box-shadow: var(--shadow); }
.ring-av { display: flex; justify-content: center; margin-bottom: 14px; }
.ring-av .av { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47, 179, 107, .6); } 70% { box-shadow: 0 0 0 18px rgba(47, 179, 107, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 179, 107, 0); } }
.ring-name { font-size: 21px; font-weight: 700; }
.ring-sub { margin-top: 4px; color: rgba(255, 255, 255, .65); }
.ring-btns { display: flex; justify-content: center; gap: 28px; margin-top: 26px; }

@media (max-width: 760px) {
  .call-grid[data-n="2"] { grid-template-columns: 1fr; }
  .call-grid[data-n="5"], .call-grid[data-n="6"] { grid-template-columns: 1fr 1fr; }
  .head-calls .join-btn { padding: 0 10px; }
}

/* --- Реакции --- */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.bubble.has-media > .reacts { margin: 4px 7px 4px; }
.react { display: inline-flex; align-items: center; gap: 4px; min-height: 26px; padding: 0 8px; border: 0; border-radius: 13px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--fg); font-size: 14px; cursor: pointer; }
.react span { font-size: 13px; font-weight: 600; color: var(--accent); }
.react.on { background: var(--accent); }
.react.on span { color: var(--accent-fg); }
.ctx-reacts { display: flex; gap: 2px; padding: 4px 8px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctx-react { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; font-size: 21px; cursor: pointer; transition: transform .1s; }
.ctx-react:hover { background: var(--hover); transform: scale(1.15); }
.ctx-react.on { background: var(--accent-soft); }

/* --- Закреплённые --- */
.pin-bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px 4px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.pin-main { flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 10px; padding: 4px 0; border: 0; background: none; text-align: left; cursor: pointer; }
.pin-lines { display: flex; flex-direction: column; gap: 2px; width: 3px; }
.pin-lines i { flex: 1; min-height: 6px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 35%, transparent); }
.pin-lines i.on { background: var(--accent); }
.pin-body { min-width: 0; }
.pin-title { font-size: 13px; font-weight: 600; color: var(--accent); }
.pin-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Поиск --- */
mark { background: #ffd54a; color: #1d1d1d; border-radius: 3px; padding: 0 1px; }
.find-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.find-bar .search { flex: 1; }
.find-count { flex: none; min-width: 60px; text-align: center; font-size: 13px; color: var(--muted); }

/* --- Новая версия --- */
.update-bar { position: fixed; z-index: 72; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 8px 8px 8px 16px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); animation: pop .2s ease-out; }
.update-bar .btn { min-height: 34px; }

/* --- Пересылка --- */
.fwd { display: flex; align-items: center; gap: 4px; margin: 0 0 3px; font-size: 13px; color: var(--accent); }
.fwd svg { width: 14px; height: 14px; flex: none; }
.fwd b { font-weight: 600; cursor: pointer; }
.bubble.has-media > .fwd { margin: 4px 7px 3px; }
.fwd-modal { max-width: 440px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100dvh - 32px); }
.fwd-modal h3 { margin: 0; }
.fwd-preview { padding: 6px 10px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--accent-soft); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd-list { flex: 1; min-height: 120px; max-height: 45vh; overflow-y: auto; margin: 0 -8px; }
.fwd-modal .actions { margin-top: 0; }

/* --- Демонстрация экрана --- */
.call-btn.on { background: #2fb36b; }
.tile-v { cursor: pointer; }
.tile-v.screen video { object-fit: contain; background: #000; transform: none; }
.call-grid.has-focus { grid-template-columns: 1fr !important; }
.call-grid.has-focus .tile-v:not(.focus) { display: none; }
