/* =====================================================================
   Мини-Телеграм — оформление в духе современных приложений
   Главный цвет (--accent) выбирает пользователь в «Оформлении», остальные оттенки считаются из него.
   Тёмная тема по умолчанию, светлая — data-theme="light"; фон чата — data-wallpaper.
   ===================================================================== */
:root {
  --accent: #8774e1;
  --accent-hover: color-mix(in srgb, var(--accent) 86%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 62%, #fff);
  --app-bg:
    radial-gradient(at 0 0, color-mix(in srgb, var(--accent) 16%, transparent) 0, transparent 45%),
    radial-gradient(at 100% 100%, color-mix(in srgb, var(--accent) 10%, transparent) 0, transparent 40%),
    #0b0b0e;
  --surface: #16171b;          /* боковая панель, шапка, окна */
  --surface-2: #202228;        /* поля ввода, наведение */
  --surface-3: #2a2d35;        /* нажатие, разделители */
  --border: rgba(255, 255, 255, .06);
  --text: #f1f2f5;
  --muted: #8b909c;
  --danger: #ff5c5c;
  --success: #4fce5d;
  --bubble-in: #202228;
  --bubble-out: linear-gradient(140deg, color-mix(in srgb, var(--accent) 75%, #fff) 0%, var(--accent) 55%, color-mix(in srgb, var(--accent) 82%, #000) 100%);
  --bubble-out-solid: color-mix(in srgb, var(--accent) 82%, #000); /* цвет «хвостика» исходящего сообщения */
  --text-out: #fff;
  --meta-in: #858a96;
  --meta-out: rgba(255, 255, 255, .72);
  --link-out: #fff;
  --out-chip: rgba(255, 255, 255, .2);  /* реакции, цитаты внутри своих сообщений */
  --out-strong: #fff;
  --out-strong-text: var(--bubble-out-solid);
  --quote-bg: var(--accent-soft);
  --glass: rgba(22, 23, 27, .76);
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .22);
  --chip-bg: rgba(0, 0, 0, .3);
  --chat-bg:
    radial-gradient(at 12% 18%, #2a1f4d 0, transparent 55%),
    radial-gradient(at 88% 12%, #12324a 0, transparent 50%),
    radial-gradient(at 78% 88%, #3a1d3f 0, transparent 55%),
    radial-gradient(at 18% 92%, #102f2c 0, transparent 50%),
    #121218;
  --pattern-opacity: .05;
  --pattern-invert: 1;
  --radius: 20px;
  --fs: 15px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --accent-text: color-mix(in srgb, var(--accent) 90%, #000);
  --app-bg:
    radial-gradient(at 0 0, color-mix(in srgb, var(--accent) 14%, transparent) 0, transparent 45%),
    radial-gradient(at 100% 100%, color-mix(in srgb, var(--accent) 10%, transparent) 0, transparent 40%),
    #e9ebf0;
  --surface: #ffffff;
  --surface-2: #f1f2f6;
  --surface-3: #e5e7ed;
  --border: rgba(0, 0, 0, .07);
  --text: #0f1419;
  --muted: #6f7680;
  --danger: #e53935;
  --bubble-in: #ffffff;
  --bubble-out: color-mix(in srgb, var(--accent) 16%, #fff);
  --bubble-out-solid: color-mix(in srgb, var(--accent) 16%, #fff);
  --text-out: #0f1419;
  --meta-in: #8a96a3;
  --meta-out: color-mix(in srgb, var(--accent) 85%, #000);
  --link-out: color-mix(in srgb, var(--accent) 85%, #000);
  --out-chip: color-mix(in srgb, var(--accent) 14%, transparent);
  --out-strong: var(--accent);
  --out-strong-text: #fff;
  --glass: rgba(255, 255, 255, .8);
  --shadow: 0 12px 40px rgba(17, 24, 39, .14);
  --shadow-sm: 0 1px 6px rgba(17, 24, 39, .09);
  --chip-bg: rgba(40, 60, 40, .3);
  --chat-bg:
    radial-gradient(at 10% 20%, #dcebb4 0, transparent 55%),
    radial-gradient(at 90% 15%, #9fd3b5 0, transparent 50%),
    radial-gradient(at 80% 90%, #c6dfa0 0, transparent 55%),
    radial-gradient(at 15% 85%, #a6cfc7 0, transparent 50%),
    #c9dea6;
  --pattern-opacity: .09;
  --pattern-invert: 0;
  color-scheme: light;
}

/* ----- Фоны чата (выбираются в «Оформлении»). Атрибут стоит и на <html>, и на плитках-превью ----- */
[data-wallpaper="ocean"] {
  --chat-bg:
    radial-gradient(at 15% 15%, #0f3b57 0, transparent 55%),
    radial-gradient(at 85% 20%, #1a2b5c 0, transparent 50%),
    radial-gradient(at 70% 90%, #0c4a4a 0, transparent 55%),
    #0b1520;
}
[data-wallpaper="sunset"] {
  --chat-bg:
    radial-gradient(at 15% 15%, #5a2440 0, transparent 55%),
    radial-gradient(at 85% 25%, #5f3418 0, transparent 50%),
    radial-gradient(at 60% 90%, #2f2160 0, transparent 55%),
    #170f17;
  --chip-bg: rgba(0, 0, 0, .3);
}
[data-wallpaper="mono"] {
  --chat-bg: radial-gradient(at 50% 0, color-mix(in srgb, var(--accent) 18%, transparent) 0, transparent 60%), #111115;
  --pattern-opacity: .035;
}
[data-theme="light"][data-wallpaper="ocean"], [data-theme="light"] [data-wallpaper="ocean"] {
  --chat-bg:
    radial-gradient(at 15% 15%, #bfe3f2 0, transparent 55%),
    radial-gradient(at 85% 20%, #b6c9f2 0, transparent 50%),
    radial-gradient(at 70% 90%, #b3e5df 0, transparent 55%),
    #c7dcef;
  --chip-bg: rgba(30, 60, 90, .3);
}
[data-theme="light"][data-wallpaper="sunset"], [data-theme="light"] [data-wallpaper="sunset"] {
  --chat-bg:
    radial-gradient(at 15% 15%, #f8d3c0 0, transparent 55%),
    radial-gradient(at 85% 20%, #f2c1d6 0, transparent 50%),
    radial-gradient(at 60% 90%, #f9e4b5 0, transparent 55%),
    #f2d4c9;
  --chip-bg: rgba(120, 60, 40, .3);
}
[data-theme="light"][data-wallpaper="mono"], [data-theme="light"] [data-wallpaper="mono"] {
  --chat-bg: radial-gradient(at 50% 0, color-mix(in srgb, var(--accent) 14%, transparent) 0, transparent 60%), #eef0f4;
  --chip-bg: rgba(0, 0, 0, .28);
  --pattern-opacity: .05;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--app-bg);
  color: var(--text);
  font: var(--fs)/1.42 "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* ----- Иконки ----- */
.ico { width: 24px; height: 24px; display: inline-grid; place-items: center; flex-shrink: 0; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ico.filled svg { fill: currentColor; stroke: none; }

/* ----- Кнопки и поля ----- */
.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; background: var(--accent); color: #fff; font-weight: 600;
  transition: background .15s, transform .1s; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--accent-text); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.danger:hover { background: rgba(255, 92, 92, .1); }
.btn.with-icon { justify-content: flex-start; padding: 12px 14px; font-weight: 500; }
.btn.with-icon.btn:not(.ghost):not(.danger) { justify-content: center; }
.icon-btn {
  background: none; border: 0; color: var(--muted); border-radius: 50%; display: grid; place-items: center;
  width: 40px; height: 40px; flex-shrink: 0; transition: background .15s, color .15s; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }
.link-btn { background: none; border: 0; color: var(--accent-text); padding: 4px; font-size: 14px; }
input:not([type=checkbox]), textarea {
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 12px; padding: 12px 14px; outline: none; width: 100%;
  transition: border-color .15s, background .15s;
}
input:focus, textarea:focus { border-color: var(--accent); background: var(--surface); }

/* ----- Плашка связи и подсказки ----- */
.conn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100; text-align: center; padding: 7px;
  padding-top: calc(7px + env(safe-area-inset-top)); background: var(--danger); color: #fff; font-size: 14px; font-weight: 500;
}
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 95;
  background: rgba(20, 20, 24, .92); color: #fff; padding: 10px 18px; border-radius: 14px; font-size: 14px; max-width: 90vw;
  box-shadow: var(--shadow); backdrop-filter: blur(10px); animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ===================== Экран входа ===================== */
.auth {
  height: 100%; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: var(--chat-bg); position: relative;
}
.auth::before, .chat::before {
  /* узор поверх градиента, как обои в Telegram */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: var(--pattern-opacity);
  background-image: url("pattern.svg"); background-size: 360px; filter: invert(var(--pattern-invert));
}
.auth-card {
  position: relative; width: 100%; max-width: 380px; background: var(--glass); backdrop-filter: blur(24px);
  padding: 36px 28px 28px; border-radius: 28px; display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--border); animation: rise .4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.logo {
  width: 104px; height: 104px; margin: 0 auto 6px; border-radius: 50%; color: #fff; display: grid; place-items: center;
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 65%, #fff), var(--accent)); box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 45%, transparent);
}
.logo .ico { width: 52px; height: 52px; margin-left: -4px; }
.auth-card h1 { margin: 0; font-size: 26px; letter-spacing: -.3px; }
.auth-card p { margin: 0 0 8px; }
.error { color: var(--danger); min-height: 18px; font-size: 13px; }

/* ===================== Раскладка ===================== */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar {
  width: var(--sidebar-w, 380px); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: relative;
}
.chat { flex: 1; display: flex; min-width: 0; background: var(--chat-bg); position: relative; }
.chat > * { position: relative; }
.sidebar-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; padding-top: calc(10px + env(safe-area-inset-top)); }
.search-box { flex: 1; position: relative; }
.search-box .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
#search { border-radius: 22px; padding: 10px 16px 10px 42px; }

/* ----- Папки (вкладки над списком чатов) ----- */
.folders { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.folders::-webkit-scrollbar { display: none; }
.folder-tab {
  position: relative; background: none; border: 0; padding: 11px 12px 12px; color: var(--muted); font-weight: 500; font-size: 14px;
  white-space: nowrap; border-radius: 10px 10px 0 0; transition: color .15s, background .15s; display: flex; gap: 6px; align-items: center;
}
.folder-tab:hover { background: var(--surface-2); }
.folder-tab.active { color: var(--accent-text); }
.folder-tab.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent);
}
.folder-tab .count { background: var(--muted); color: var(--surface); border-radius: 10px; font-size: 11px; padding: 0 6px; font-weight: 700; line-height: 17px; }
.folder-tab.active .count { background: var(--accent); color: #fff; }

/* ===================== Аватары ===================== */
.avatar {
  flex-shrink: 0; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 21px; color: #fff; position: relative; user-select: none; text-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.avatar.sm { width: 42px; height: 42px; font-size: 17px; }
.avatar.xs { width: 34px; height: 34px; font-size: 14px; }
.avatar.lg { width: 66px; height: 66px; font-size: 26px; }
.avatar.xl { width: 120px; height: 120px; font-size: 46px; }
.avatar .ico { width: 55%; height: 55%; }
.avatar.online::after {
  content: ""; position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px;
  background: var(--success); border: 3px solid var(--surface); border-radius: 50%;
}
.avatar.sm.online::after, .avatar.xs.online::after { width: 11px; height: 11px; border-width: 2px; }

/* ===================== Список чатов ===================== */
.chat-list { list-style: none; margin: 0; padding: 6px 8px 96px; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; gap: 12px; padding: 9px 10px; border-radius: 14px; cursor: pointer; align-items: center; user-select: none;
  transition: background .12s; animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-item .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.chat-item .name .ico { width: 16px; height: 16px; }
.chat-item .time { color: var(--muted); font-size: 12.5px; flex-shrink: 0; display: flex; align-items: center; gap: 2px; }
.chat-item .time .ico { width: 17px; height: 17px; color: var(--accent-text); }
.chat-item .preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.chat-item .preview .typing { color: var(--accent-text); }
.chat-item .preview b { color: var(--text); font-weight: 500; }
.chat-item.active .preview, .chat-item.active .time, .chat-item.active .preview b,
.chat-item.active .preview .typing, .chat-item.active .time .ico, .chat-item.active .ic { color: rgba(255, 255, 255, .85); }
.badge {
  background: var(--success); color: #fff; border-radius: 12px; font-size: 12px; padding: 0 7px; font-weight: 700;
  flex-shrink: 0; min-width: 22px; height: 22px; line-height: 22px; text-align: center;
}
.badge.muted { background: var(--muted); }
.badge.at { background: var(--accent); }
.chat-item.active .badge { background: #fff; color: var(--accent); }
.ic { color: var(--muted); display: inline-flex; }
.ic .ico { width: 17px; height: 17px; }
.section-title { color: var(--muted); font-size: 13px; font-weight: 600; padding: 14px 12px 6px; list-style: none; }
.fab {
  position: absolute; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 18px;
  border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .15s, background .15s;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.05); }

/* ===================== Окно чата ===================== */
.empty { margin: auto; }
.empty > span { background: rgba(0, 0, 0, .28); padding: 6px 14px; border-radius: 16px; color: #fff; font-size: 14px; backdrop-filter: blur(8px); }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-header {
  display: flex; align-items: center; gap: 4px; padding: 8px 12px 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.4); border-bottom: 1px solid var(--border); min-height: 60px; z-index: 3;
}
.chat-head-info { display: flex; align-items: center; gap: 12px; cursor: pointer; min-width: 0; flex: 1; padding: 2px 0; }
.chat-head-text { min-width: 0; }
.chat-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 4px; align-items: center; }
.chat-title .ico { width: 16px; height: 16px; color: var(--muted); }
.chat-status { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.online, .chat-status.typing { color: var(--accent-text); }
.back { display: none; }

.pinned-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 16px; background: var(--glass); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border); cursor: pointer; z-index: 2;
}
.pinned-text { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 10px; border-radius: 2px; }
.pinned-title { color: var(--accent-text); font-size: 13px; font-weight: 600; }
.pinned-body { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px max(14px, calc((100% - 740px) / 2)) 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.date-sep, .unread-sep {
  align-self: center; background: rgba(0, 0, 0, .28); color: #fff; padding: 4px 12px; border-radius: 14px;
  font-size: 13px; font-weight: 500; margin: 12px 0 8px; backdrop-filter: blur(10px);
}
.date-sep { position: sticky; top: 6px; z-index: 1; }
.unread-sep { background: var(--accent); }

/* ----- Сообщения ----- */
.msg-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 8px; }
.msg-row.cont { margin-top: 0; }
.msg-row.out { justify-content: flex-end; }
.msg-row.new { animation: msg-in .22s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes msg-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.msg-row .avatar { margin-bottom: 1px; cursor: pointer; }
.msg-row .avatar-spacer { width: 34px; flex-shrink: 0; }
.msg {
  max-width: min(500px, 78%); padding: 7px 11px 7px 12px; border-radius: var(--radius); background: var(--bubble-in);
  white-space: pre-wrap; overflow-wrap: anywhere; position: relative; box-shadow: var(--shadow-sm); user-select: text;
}
.msg-row.out .msg { background: var(--bubble-out); color: var(--text-out); }
/* «хвостик» у последнего сообщения в пачке, как в Telegram */
.msg.tail::before {
  /* прямоугольник у нижнего угла, из которого вырезан эллипс — получается изогнутый хвостик */
  content: ""; position: absolute; bottom: 0; width: 10px; height: 17px; background: var(--bubble-in);
  -webkit-mask: radial-gradient(10px 15px at var(--tail-x) 0, transparent 98%, #000 100%);
  mask: radial-gradient(10px 15px at var(--tail-x) 0, transparent 98%, #000 100%);
}
.msg-row:not(.out) .msg.tail { border-bottom-left-radius: 0; }
.msg-row:not(.out) .msg.tail::before { left: -9px; --tail-x: 0; }
.msg-row.out .msg.tail { border-bottom-right-radius: 0; }
.msg-row.out .msg.tail::before { right: -9px; --tail-x: 100%; background: var(--bubble-out-solid); }
.msg-row:not(.out) .msg.grouped { border-bottom-left-radius: 6px; }
.msg-row:not(.out).cont .msg { border-top-left-radius: 6px; }
.msg-row.out .msg.grouped { border-bottom-right-radius: 6px; }
.msg-row.out.cont .msg { border-top-right-radius: 6px; }
.msg.has-image { padding: 4px; }
.msg.has-image .text { padding: 5px 7px 2px; display: block; }
.msg.has-image .meta { padding-right: 8px; }
.msg.highlight { animation: flash 1.4s; }
@keyframes flash { 0%, 50% { filter: brightness(1.45); transform: scale(1.02); } }
.msg .author { font-weight: 600; font-size: 14px; margin-bottom: 2px; cursor: pointer; }
.msg .meta {
  float: right; font-size: 12px; color: var(--meta-in); margin: 8px -3px -5px 12px; white-space: nowrap; user-select: none;
  display: inline-flex; align-items: center; gap: 2px; line-height: 1;
}
.msg-row.out .msg .meta { color: var(--meta-out); }
.ticks { display: inline-flex; }
.ticks .ico { width: 17px; height: 17px; }
.msg .img {
  display: block; max-width: 100%; max-height: 380px; border-radius: 14px; cursor: zoom-in; min-width: 140px; object-fit: cover;
}
.quote {
  border-left: 3px solid var(--accent-text); padding: 4px 9px; margin: 2px 0 5px; border-radius: 6px;
  background: var(--quote-bg); cursor: pointer; font-size: 14px; overflow: hidden; transition: filter .15s;
}
.quote:hover { filter: brightness(1.1); }
.msg-row.out .quote { border-color: var(--meta-out); background: rgba(255, 255, 255, .14); }
.quote-author { font-weight: 600; color: var(--accent-text); font-size: 13px; }
.msg-row.out .quote-author { color: inherit; }
.quote-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg code { font-family: "JetBrains Mono", Consolas, "SF Mono", Menlo, monospace; font-size: 13.5px; background: rgba(127, 127, 127, .18); padding: 1px 5px; border-radius: 5px; }
.msg pre {
  font-family: "JetBrains Mono", Consolas, "SF Mono", Menlo, monospace; font-size: 13px; background: rgba(0, 0, 0, .25); padding: 10px 12px;
  border-radius: 10px; margin: 4px 0; overflow-x: auto; white-space: pre; border-left: 3px solid var(--accent-text);
}
:root[data-theme="light"] .msg pre { background: rgba(0, 0, 0, .05); }
.msg a { color: var(--accent-text); }
.msg-row.out .msg a { color: var(--link-out); text-decoration: underline; }
.spoiler { background: var(--muted); color: transparent; border-radius: 5px; cursor: pointer; transition: .25s; user-select: none; filter: blur(.3px); }
.spoiler.revealed { background: rgba(127, 127, 127, .2); color: inherit; filter: none; }
.mention { color: var(--accent-text); cursor: pointer; font-weight: 500; }
.msg-row.out .mention { color: inherit; text-decoration: underline; }
.mention.me { background: var(--accent-soft); border-radius: 5px; padding: 0 3px; }
.msg.mentions-me { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.forwarded { color: var(--accent-text); font-size: 13px; margin-bottom: 3px; font-weight: 500; }
.msg-row.out .forwarded { color: inherit; opacity: .85; }
.forwarded b { cursor: pointer; }
.to-bottom {
  position: absolute; right: 18px; bottom: 90px; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--surface); color: var(--muted); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 3;
  animation: pop .15s ease;
}
.to-bottom:hover { color: var(--text); }
.empty-chat {
  margin: auto; text-align: center; background: rgba(0, 0, 0, .28); color: #fff; padding: 18px 22px; border-radius: 20px;
  font-size: 14.5px; max-width: 320px; backdrop-filter: blur(10px);
}

/* ----- Вложения ----- */
.msg .video { display: block; max-width: 100%; max-height: 380px; border-radius: 14px; background: #000; }
.file-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; padding: 3px 0; min-width: 210px; }
.file-icon {
  width: 46px; height: 46px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; flex-shrink: 0;
}
.msg-row.out .file-icon { background: rgba(255, 255, 255, .22); }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-size { color: var(--meta-in); font-size: 13px; }
.msg-row.out .file-size { color: var(--meta-out); }
.voice { display: flex; align-items: center; gap: 12px; min-width: 230px; padding: 3px 0; }
.voice-play {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex-shrink: 0; transition: transform .1s;
}
.voice-play:active { transform: scale(.93); }
.voice-play .ico { width: 20px; height: 20px; }
.msg-row.out .voice-play { background: #fff; color: var(--bubble-out-solid); }
.voice-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.voice-track { height: 4px; border-radius: 2px; background: rgba(127, 127, 127, .35); cursor: pointer; position: relative; }
.voice-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-text); border-radius: 2px; }
.msg-row.out .voice-fill { background: currentColor; }
.voice-time { font-size: 12px; color: var(--meta-in); }
.msg-row.out .voice-time { color: var(--meta-out); }
.call-msg { display: flex; align-items: center; gap: 12px; cursor: pointer; min-width: 190px; padding: 2px 0; }
.call-msg .call-icon { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; }
.msg-row.out .call-msg .call-icon { background: rgba(255, 255, 255, .2); color: inherit; }
.call-msg .missed { color: var(--danger); }
.call-msg .sub { font-size: 13px; color: var(--meta-in); }
.msg-row.out .call-msg .sub { color: var(--meta-out); }

/* ----- Опрос ----- */
.poll { min-width: 250px; display: flex; flex-direction: column; gap: 7px; padding: 2px 0; }
.poll-q { font-weight: 700; font-size: 15.5px; }
.poll-kind { font-size: 13px; color: var(--meta-in); margin-top: -5px; }
.msg-row.out .poll-kind, .msg-row.out .poll-total { color: var(--meta-out); }
.poll-opt {
  position: relative; text-align: left; border: 0; background: rgba(127, 127, 127, .13); border-radius: 10px; padding: 9px 12px;
  overflow: hidden; display: flex; gap: 8px; align-items: center; transition: background .15s;
}
.poll-opt:hover { background: rgba(127, 127, 127, .2); }
.poll-opt .bar { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: .3; transition: width .35s ease; }
.msg-row.out .poll-opt .bar { background: #fff; }
.poll-opt span { position: relative; }
.poll-opt .pct { margin-left: auto; font-weight: 700; font-size: 13px; }
.poll-opt.mine { box-shadow: inset 0 0 0 2px var(--accent-text); }
.msg-row.out .poll-opt.mine { box-shadow: inset 0 0 0 2px currentColor; }
.poll-total { font-size: 13px; color: var(--meta-in); }
.poll-options-edit { display: flex; flex-direction: column; gap: 8px; }
.poll-options-edit .opt-row { display: flex; gap: 6px; align-items: center; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14.5px; cursor: pointer; }
.check input { width: 19px; height: 19px; accent-color: var(--accent); }

/* ----- Реакции ----- */
.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; clear: both; }
.reaction {
  border: 0; border-radius: 16px; padding: 3px 9px 3px 7px; font-size: 14px; background: var(--accent-soft); color: var(--accent-text);
  display: flex; gap: 5px; align-items: center; font-weight: 600; transition: transform .1s; animation: pop .2s ease;
}
.reaction:active { transform: scale(.92); }
.reaction.mine { background: var(--accent); color: #fff; }
.msg-row.out .reaction { background: rgba(255, 255, 255, .2); color: inherit; }
.msg-row.out .reaction.mine { background: #fff; color: var(--bubble-out-solid); }

/* ===================== Поле ввода ===================== */
.composer-wrap {
  padding: 6px max(14px, calc((100% - 740px) / 2)) 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 2;
}
.composer { display: flex; align-items: flex-end; gap: 8px; }
.input-box {
  flex: 1; min-width: 0; background: var(--surface); border-radius: 18px 18px 0 18px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; position: relative;
}
.input-box::after {
  /* хвостик у поля ввода */
  content: ""; position: absolute; right: -9px; bottom: 0; width: 10px; height: 17px; background: var(--surface);
  -webkit-mask: radial-gradient(10px 15px at 100% 0, transparent 98%, #000 100%);
  mask: radial-gradient(10px 15px at 100% 0, transparent 98%, #000 100%);
}
.input-row { display: flex; align-items: flex-end; gap: 2px; padding: 4px 6px; }
.input-row .icon-btn { width: 42px; height: 42px; }
.composer textarea {
  flex: 1; resize: none; border: 0; background: none; padding: 11px 4px; max-height: 180px; line-height: 1.38; border-radius: 0;
}
.composer textarea:focus { border: 0; background: none; }
.round-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--surface); color: var(--muted);
  display: grid; place-items: center; flex-shrink: 0; box-shadow: var(--shadow-sm); transition: background .15s, color .15s, transform .1s;
}
.round-btn:hover { color: var(--accent-text); }
.round-btn:active { transform: scale(.94); }
.round-btn.primary { background: var(--accent); color: #fff; }
.round-btn.primary:hover { background: var(--accent-hover); color: #fff; }
.round-btn .ico { width: 26px; height: 26px; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 6px 2px 14px; animation: fade-in .15s; }
.reply-bar-icon { color: var(--accent-text); display: grid; }
.reply-bar-text { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding: 1px 0 1px 9px; border-radius: 2px; }
.reply-bar-title { color: var(--accent-text); font-weight: 600; font-size: 14px; }
.reply-bar-body { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emoji-panel, .suggest-box, .upload-bar {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); margin-bottom: 8px; animation: pop .15s ease;
}
.emoji-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 2px; max-height: 240px; overflow-y: auto; padding: 10px; }
.emoji-panel button { background: none; border: 0; font-size: 26px; padding: 4px; border-radius: 10px; transition: transform .1s; }
.emoji-panel button:hover { background: var(--surface-2); transform: scale(1.15); }
.suggest-box { list-style: none; padding: 6px; max-height: 280px; overflow-y: auto; margin-top: 0; }
.suggest-box li { display: flex; align-items: center; gap: 12px; padding: 7px 10px; border-radius: 12px; cursor: pointer; }
.suggest-box li.selected, .suggest-box li:hover { background: var(--surface-2); }
.suggest-box .sub { color: var(--muted); font-size: 13px; }
.suggest-box .cmd { font-weight: 700; color: var(--accent-text); min-width: 78px; }
.upload-bar { position: relative; padding: 10px 16px; font-size: 14px; overflow: hidden; }
.upload-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: .22; width: 0; transition: width .2s; }
.upload-bar span { position: relative; }
.record-bar { align-items: center; }
.record-bar .input-box { flex-direction: row; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; min-height: 52px; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 42px; font-weight: 600; }
.rec-hint { flex: 1; font-size: 14px; }
.channel-bar { display: flex; justify-content: center; }
.channel-bar .btn { width: 100%; max-width: 420px; background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.channel-bar .btn:hover { background: var(--surface-2); }

/* ===================== Боковое меню ===================== */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 40; animation: fade-in .2s; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 300px; max-width: 85vw; background: var(--surface); z-index: 41;
  transform: translateX(-102%); transition: transform .25s cubic-bezier(.2, .8, .2, 1); display: flex; flex-direction: column;
  box-shadow: var(--shadow); padding: env(safe-area-inset-top) 8px 8px;
}
.drawer.open { transform: none; }
.drawer-head { padding: 22px 14px 16px; display: flex; flex-direction: column; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.drawer-head .avatar { margin-bottom: 10px; }
.drawer-name { font-weight: 700; font-size: 17px; }
.drawer-item {
  background: none; border: 0; text-align: left; padding: 12px 14px; font-size: 15px; display: flex; gap: 18px; align-items: center;
  border-radius: 12px; font-weight: 500; transition: background .12s;
}
.drawer-item .ico { color: var(--muted); }
.drawer-item:hover { background: var(--surface-2); }
.drawer-item.danger, .drawer-item.danger .ico { color: var(--danger); }
.drawer-foot { margin-top: auto; padding: 12px 14px; color: var(--muted); font-size: 12px; }

/* ===================== Окна ===================== */
.modal-overlay { display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal {
  width: 100%; max-width: 420px; max-height: 90dvh; overflow-y: auto; background: var(--surface); border-radius: 24px;
  padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); animation: modal-in .22s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes modal-in { from { opacity: 0; transform: scale(.94) translateY(10px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field textarea { color: var(--text); font-size: 15px; resize: none; font-weight: 400; }
.avatar-edit { align-self: center; position: relative; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar-edit .avatar::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: rgba(0, 0, 0, .35) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z'/%3E%3Ccircle cx='12' cy='13' r='4'/%3E%3C/svg%3E") center/40px no-repeat;
  opacity: 0; transition: opacity .15s;
}
.avatar-edit:hover .avatar::before { opacity: 1; }
.avatar-edit-hint { color: var(--accent-text); font-size: 14px; font-weight: 500; }
#avatarRemove, #groupAvatarRemove { align-self: center; margin-top: -10px; color: var(--muted); }
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.color-picker button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s; }
.color-picker button.selected { box-shadow: 0 0 0 2px var(--text); }
.pick-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.pick-list label { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; cursor: pointer; }
.pick-list label:hover { background: var(--surface-2); }
.pick-list .pick-name { flex: 1; }
.pick-list input { width: 21px; height: 21px; accent-color: var(--accent); }
.info-top { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 4px 0 6px; }
.info-top .avatar { margin-bottom: 10px; cursor: zoom-in; box-shadow: var(--shadow-sm); }
.info-name { font-size: 21px; font-weight: 700; }
.info-rows { display: flex; flex-direction: column; gap: 2px; }
.info-row { padding: 9px 10px; border-radius: 12px; }
.info-row:hover { background: var(--surface-2); }
.info-row .label { font-size: 13px; color: var(--muted); }
.info-row .value { white-space: pre-wrap; overflow-wrap: anywhere; }
.info-member { display: flex; align-items: center; gap: 12px; padding: 7px 8px; border-radius: 12px; cursor: pointer; }
.info-member:hover { background: var(--surface-2); }
.info-member .who { flex: 1; min-width: 0; }
.info-member .tag { font-size: 12px; color: var(--accent-text); font-weight: 600; }
.info-member .remove { color: var(--danger); }
.info-actions { display: flex; flex-direction: column; gap: 2px; }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.segmented button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; display: flex; gap: 8px; justify-content: center; align-items: center; color: var(--muted); transition: .15s; }
.segmented button .ico { width: 20px; height: 20px; }
.segmented button.selected { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.help h3 { margin: 16px 0 4px; font-size: 15px; }
.help h3:first-child { margin-top: 0; }
.help p { margin: 4px 0; font-size: 14px; line-height: 1.55; }
.help code, kbd { font-family: "JetBrains Mono", Consolas, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* ===================== Меню ===================== */
.ctx-menu {
  position: fixed; z-index: 60; background: var(--glass); backdrop-filter: blur(24px) saturate(1.6); border-radius: 16px;
  padding: 6px; min-width: 210px; max-width: calc(100vw - 16px); box-shadow: var(--shadow); border: 1px solid var(--border);
  animation: pop .14s ease; transform-origin: top left;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.ctx-menu > button {
  display: flex; gap: 14px; align-items: center; width: 100%; background: none; border: 0; text-align: left; padding: 9px 12px;
  font-size: 14.5px; border-radius: 10px; font-weight: 500;
}
.ctx-menu > button .ico { width: 21px; height: 21px; color: var(--muted); }
.ctx-menu > button:hover { background: var(--surface-2); }
.ctx-menu > button.danger, .ctx-menu > button.danger .ico { color: var(--danger); }
.ctx-reactions { display: flex; gap: 0; padding: 2px 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.ctx-reactions button {
  font-size: 22px; border: 0; background: none; border-radius: 50%; width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center; transition: transform .12s, background .12s;
}
.ctx-reactions button:hover { transform: scale(1.25); background: var(--surface-2); }

/* ===================== Просмотр фото ===================== */
.viewer {
  position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .88); display: grid; place-items: center; cursor: zoom-out;
  animation: fade-in .2s; backdrop-filter: blur(6px);
}
.viewer img { max-width: 96vw; max-height: 92dvh; border-radius: 10px; animation: modal-in .25s ease; }

/* ===================== Звонок ===================== */
.call-screen {
  position: fixed; inset: 0; z-index: 80; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  background: radial-gradient(at 30% 20%, #4b3a9e 0, transparent 60%), radial-gradient(at 70% 80%, #1d4f7a 0, transparent 60%), #14141c;
  animation: fade-in .25s;
}
.remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.remote-video.no-video { opacity: 0; }
.local-video {
  position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top)); width: 28vw; max-width: 220px; border-radius: 16px;
  background: #222; transform: scaleX(-1); box-shadow: var(--shadow); z-index: 2;
}
.call-info { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.call-info.over-video { position: absolute; top: calc(20px + env(safe-area-inset-top)); left: 20px; align-items: flex-start; text-shadow: 0 1px 4px #000; }
.call-info.over-video .avatar { display: none; }
.call-name { font-size: 28px; font-weight: 700; }
.call-status { color: rgba(255, 255, 255, .7); font-variant-numeric: tabular-nums; }
.call-actions {
  position: absolute; bottom: calc(44px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; justify-content: center; gap: 26px; z-index: 2;
}
.call-btn { display: flex; flex-direction: column; align-items: center; gap: 8px; background: none; border: 0; color: #fff; font-size: 13px; }
.call-btn .circle {
  width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(10px); transition: transform .1s, background .15s;
}
.call-btn .circle .ico { width: 28px; height: 28px; }
.call-btn:hover .circle { background: rgba(255, 255, 255, .26); }
.call-btn:active .circle { transform: scale(.92); }
.call-btn.off .circle { background: #fff; color: #111; }
.call-btn.red .circle { background: #f04848; }
.call-btn.green .circle { background: #3fbf5a; }
.call-screen .avatar.ringing { animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(135, 116, 225, .7); } 70% { box-shadow: 0 0 0 30px rgba(135, 116, 225, 0); } }

/* ===================== Телефон ===================== */
@media (max-width: 760px) {
  .sidebar { width: 100%; border: 0; }
  .chat { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .chat { display: flex; }
  .back { display: grid; }
  .chat-header { padding-left: 4px; gap: 0; }
  .chat-header .icon-btn { width: 38px; }
  .msg { max-width: 86%; }
  .to-bottom { right: 12px; }
  .composer-wrap { padding-left: 8px; padding-right: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .round-btn { width: 50px; height: 50px; }
  /* 16px в полях — иначе iPhone приближает страницу при вводе */
  input:not([type=checkbox]), textarea, .composer textarea { font-size: 16px; }
  /* окна выезжают снизу, как на телефоне */
  .modal-overlay { place-items: end center; padding: 0; }
  .modal {
    max-width: none; border-radius: 24px 24px 0 0; max-height: 92dvh;
    padding-bottom: calc(22px + env(safe-area-inset-bottom)); animation: slide-up .25s cubic-bezier(.2, .9, .3, 1);
  }
  @keyframes slide-up { from { transform: translateY(60%); opacity: .4; } }
  .poll, .voice, .file-card { min-width: 0; }
  .folder-tab { padding: 10px 10px 11px; }
}
@media (hover: none) {
  .icon-btn:hover, .chat-item:hover, .drawer-item:hover, .emoji-panel button:hover { background: none; transform: none; }
  /* долгое нажатие открывает наше меню, а не системное выделение текста */
  .msg { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* =====================================================================
   Версия 2: «плавающие» панели, оформление, приветствие, быстрые действия
   ===================================================================== */

/* ----- Плавающие панели на широком экране ----- */
@media (min-width: 900px) {
  .app { padding: 10px; gap: 10px; }
  .sidebar, .chat { border-radius: 24px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
  .sidebar { width: var(--sidebar-w, 370px); }
}

/* ----- Активный чат: мягкая подсветка вместо сплошной заливки ----- */
.chat-item.active { background: var(--accent-soft); color: var(--text); position: relative; }
.chat-item.active::before {
  content: ""; position: absolute; left: -8px; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent);
}
.chat-item.active .preview, .chat-item.active .time, .chat-item.active .ic { color: var(--muted); }
.chat-item.active .preview b { color: var(--text); }
.chat-item.active .preview .typing, .chat-item.active .time .ico { color: var(--accent-text); }
.chat-item.active .badge { background: var(--success); color: #fff; }
.chat-item.active .badge.muted { background: var(--muted); }
.chat-item.active .badge.at { background: var(--accent); }
.chat-item .name { font-size: 15.5px; }

/* ----- Свои сообщения: элементы внутри пузыря ----- */
.msg-row.out .quote, .msg-row.out .reaction, .msg-row.out .call-msg .call-icon, .msg-row.out .file-icon { background: var(--out-chip); }
.msg-row.out .reaction { color: inherit; }
.msg-row.out .reaction.mine, .msg-row.out .voice-play { background: var(--out-strong); color: var(--out-strong-text); }
.msg-row.out .poll-opt .bar { background: var(--out-strong); }
.date-sep, .unread-sep, .empty > span, .empty-chat { background: var(--chip-bg); }
.unread-sep { background: var(--accent); }
.msg { font-size: var(--fs); }
.ticks .ico { color: inherit; }

/* ----- Анимированные точки «печатает…» ----- */
.dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ----- «Скелетон» пока грузится переписка ----- */
.skeleton { display: flex; flex-direction: column; gap: 10px; padding-top: 20px; }
.skeleton div {
  height: 42px; border-radius: 18px; background: var(--bubble-in); opacity: .55; position: relative; overflow: hidden;
}
.skeleton div::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .08), transparent); animation: shimmer 1.2s infinite;
}
.skeleton .r { align-self: flex-end; background: var(--bubble-out-solid); }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ----- Быстрые действия при наведении на сообщение ----- */
.msg-actions {
  display: flex; gap: 2px; align-self: center; opacity: 0; transform: scale(.9); transition: opacity .12s, transform .12s;
  background: var(--glass); backdrop-filter: blur(16px); border-radius: 14px; padding: 3px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--border); pointer-events: none;
}
.msg-actions button {
  width: 32px; height: 32px; border: 0; background: none; border-radius: 10px; color: var(--muted); display: grid; place-items: center; font-size: 17px;
}
.msg-actions button:hover { background: var(--surface-2); color: var(--text); }
.msg-actions .ico { width: 19px; height: 19px; }
.msg-row:hover .msg-actions { opacity: 1; transform: none; pointer-events: auto; }
.msg-row.out .msg-actions { order: -1; }

/* ----- Экран приветствия ----- */
.welcome {
  margin: auto; text-align: center; max-width: 440px; padding: 34px 28px 28px; border-radius: 28px;
  background: var(--glass); backdrop-filter: blur(24px); box-shadow: var(--shadow); border: 1px solid var(--border); animation: rise .35s ease;
}
.welcome .logo { width: 88px; height: 88px; margin-bottom: 14px; background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent)); box-shadow: 0 12px 30px var(--accent-soft); }
.welcome .logo .ico { width: 44px; height: 44px; }
.welcome h2 { margin: 0 0 6px; font-size: 23px; letter-spacing: -.3px; }
.welcome p { margin: 0 0 22px; color: var(--muted); }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-actions button {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 10px; border-radius: 18px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; font-size: 14px; transition: transform .12s, background .12s;
}
.quick-actions button:hover { background: var(--accent-soft); transform: translateY(-2px); }
.quick-actions .ico { width: 26px; height: 26px; color: var(--accent-text); }
.empty { display: flex; width: 100%; padding: 16px; }

/* ----- Шапка бокового меню: кнопка ночного режима ----- */
.drawer-head { position: relative; }
.drawer-head .theme-toggle { position: absolute; right: 8px; top: 18px; }

/* ----- Окно «Оформление» ----- */
.accent-picker { display: flex; gap: 12px; flex-wrap: wrap; }
.accent-picker button {
  width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 2px transparent; transition: transform .12s, box-shadow .15s;
  display: grid; place-items: center; color: #fff;
}
.accent-picker button:hover { transform: scale(1.08); }
.accent-picker button.selected { box-shadow: 0 0 0 2px var(--text); }
.accent-picker .ico { width: 20px; height: 20px; opacity: 0; }
.accent-picker button.selected .ico { opacity: 1; }
.wallpaper-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.wp-tile {
  position: relative; width: 100%; height: 92px; border-radius: 16px; border: 0; background: var(--chat-bg); overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border); padding: 10px 8px; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px;
}
.wp-tile.selected { box-shadow: 0 0 0 2px var(--accent), inset 0 0 0 1px var(--border); }
.wp-tile .b { height: 12px; border-radius: 7px; background: var(--bubble-in); width: 70%; }
.wp-tile .b.o { align-self: flex-end; background: var(--bubble-out); width: 55%; }
.wp-label { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: 4px; }
.segmented.three button { font-size: 14px; }
.preview-chat { border-radius: 18px; padding: 14px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 6px; box-shadow: inset 0 0 0 1px var(--border); }
.preview-chat .msg { max-width: 85%; font-size: var(--fs); }
.preview-chat .msg-row { margin: 0; }

/* ----- Телефон: плавные переходы между списком и чатом ----- */
@media (max-width: 760px) {
  .app.in-chat .chat { animation: slide-in .26s cubic-bezier(.2, .8, .2, 1); }
  .app:not(.in-chat) .sidebar { animation: slide-back .26s cubic-bezier(.2, .8, .2, 1); }
  @keyframes slide-in { from { transform: translateX(40%); opacity: .3; } }
  @keyframes slide-back { from { transform: translateX(-20%); opacity: .5; } }
  .msg-actions { display: none; }
  .quick-actions button { padding: 14px 8px; }
  .chat-item.active { background: none; }
  .chat-item.active::before { display: none; }
  .wallpaper-picker { grid-template-columns: repeat(2, 1fr); }
}

/* =====================================================================
   Версия 3: инструменты для компьютера
   ===================================================================== */

/* ----- Поиск внутри чата ----- */
.chat-search {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px 6px 16px; background: var(--glass); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border); z-index: 3; animation: fade-in .15s;
}
.chat-search > .ico { color: var(--muted); width: 20px; height: 20px; }
.chat-search input { flex: 1; background: none; border: 0; padding: 8px 4px; }
.chat-search input:focus { background: none; border: 0; }
.chat-search-count { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg.found { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }

/* ----- Выделение нескольких сообщений ----- */
.select-bar {
  display: flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--glass); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border); z-index: 3; animation: fade-in .15s;
}
.select-count { flex: 1; font-weight: 600; padding-left: 4px; }
.select-bar .btn { padding: 8px 12px; }
.select-bar .btn .ico { width: 20px; height: 20px; }
.selecting .msg-row { cursor: pointer; padding-left: 34px; position: relative; }
.selecting .msg-row::before {
  content: ""; position: absolute; left: 4px; bottom: 6px; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--muted); background: var(--surface); transition: .12s;
}
.selecting .msg-row.selected::before {
  border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E") center/14px no-repeat;
}
.selecting .msg-row.selected .msg { filter: brightness(1.12); }
.selecting .msg-actions { display: none; }

/* ----- Отложенные сообщения ----- */
.scheduled-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--glass); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border); cursor: pointer; color: var(--accent-text); font-weight: 500; font-size: 14px; z-index: 2;
}
.scheduled-bar .ico { width: 19px; height: 19px; }
.schedule-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.schedule-quick button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 12px; text-align: left; font-weight: 500;
  display: flex; flex-direction: column; gap: 2px; transition: background .12s;
}
.schedule-quick button:hover { background: var(--accent-soft); }
.schedule-quick small { color: var(--muted); font-weight: 400; }
.scheduled-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scheduled-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2); }
.scheduled-list .when { font-size: 13px; color: var(--accent-text); font-weight: 600; }
.scheduled-list .what { flex: 1; min-width: 0; }
.scheduled-list .what div:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ----- Кнопка «вниз» со счётчиком новых сообщений ----- */
.to-bottom { overflow: visible; }
.new-below {
  position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 6px;
}
.history-loader { align-self: center; color: var(--muted); font-size: 13px; padding: 8px; display: flex; gap: 8px; align-items: center; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Перетаскиваемая граница панели чатов ----- */
.resizer { position: absolute; top: 0; right: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 5; }
.resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background .15s; }
.resizer:hover::after, body.resizing .resizer::after { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
@media (max-width: 760px) { .resizer { display: none; } }

/* ----- Черновик в списке чатов ----- */
.chat-item .draft { color: var(--danger); font-weight: 500; }

/* ----- Медиа в профиле ----- */
.media-section { border-top: 1px solid var(--border); padding-top: 6px; }
.media-tabs { display: flex; gap: 2px; }
.media-tabs button {
  flex: 1; border: 0; background: none; padding: 10px 4px 12px; color: var(--muted); font-weight: 600; font-size: 14px; position: relative;
  border-radius: 10px 10px 0 0;
}
.media-tabs button:hover { background: var(--surface-2); }
.media-tabs button.active { color: var(--accent-text); }
.media-tabs button.active::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.media-body { min-height: 120px; padding-top: 10px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-grid .cell { aspect-ratio: 1; border-radius: 8px; overflow: hidden; cursor: zoom-in; background: var(--surface-2); position: relative; }
.media-grid img, .media-grid video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .cell .ico { position: absolute; inset: 0; margin: auto; width: 32px; height: 32px; color: #fff; filter: drop-shadow(0 1px 3px #000); }
.media-list { display: flex; flex-direction: column; gap: 4px; }
.media-list .item { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; cursor: pointer; text-decoration: none; color: inherit; }
.media-list .item:hover { background: var(--surface-2); }
.media-list .item .sub { color: var(--muted); font-size: 13px; }
.media-list .item .main { flex: 1; min-width: 0; }
.media-list .item .main > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.media-list .file-icon { width: 42px; height: 42px; }
.media-list a.url { color: var(--accent-text); overflow-wrap: anywhere; }
.media-empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

/* ----- Участники: роли и ссылка-приглашение ----- */
.info-member .tag.admin { color: var(--success); }
.invite-box {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2); margin: 4px 0;
}
.invite-box .ico { color: var(--accent-text); }
.invite-box .link { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

/* =====================================================================
   Версия 4: удобства
   ===================================================================== */

/* ----- Плашка с кнопкой «Отменить» ----- */
.toast { display: flex; align-items: center; gap: 14px; }
.toast-action { background: none; border: 0; color: var(--accent-text); font-weight: 700; padding: 2px 4px; text-transform: uppercase; font-size: 13px; letter-spacing: .3px; }
:root[data-theme="light"] .toast-action { color: color-mix(in srgb, var(--accent) 60%, #fff); }

/* ----- Предпросмотр перед отправкой ----- */
.send-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; max-height: 340px; overflow-y: auto; }
.send-items.single { grid-template-columns: 1fr; }
.send-item { position: relative; border-radius: 14px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1; display: grid; place-items: center; }
.send-items.single .send-item { aspect-ratio: auto; max-height: 340px; }
.send-item img, .send-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.send-items.single .send-item img { object-fit: contain; max-height: 340px; }
.send-item .file-info { padding: 10px; text-align: center; font-size: 13px; display: flex; flex-direction: column; gap: 6px; align-items: center; overflow-wrap: anywhere; }
.send-item .file-info .ico { width: 34px; height: 34px; color: var(--accent-text); }
.send-item .remove {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff;
  display: grid; place-items: center;
}
.send-item .remove .ico { width: 16px; height: 16px; }
.send-actions { display: flex; gap: 8px; justify-content: space-between; }
.send-actions .btn:last-child { flex: 1; }

/* ----- Альбом в сообщении ----- */
.album { display: grid; gap: 3px; border-radius: 14px; overflow: hidden; min-width: 240px; }
.album.n2 { grid-template-columns: 1fr 1fr; }
.album.n3 { grid-template-columns: 1fr 1fr; }
.album.n3 > :first-child { grid-column: span 2; }
.album.n4 { grid-template-columns: 1fr 1fr; }
.album.many { grid-template-columns: repeat(3, 1fr); }
.album img { width: 100%; height: 100%; aspect-ratio: 1; object-fit: cover; display: block; cursor: zoom-in; }
.album.n3 > :first-child { aspect-ratio: 2 / 1; }

/* ----- Полноэкранный просмотр фото ----- */
.viewer { display: block; cursor: default; }
.viewer-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: #fff; z-index: 2;
  background: linear-gradient(rgba(0, 0, 0, .55), transparent);
}
.viewer-top .icon-btn { color: #fff; }
.viewer-top .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.viewer-caption { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.viewer-stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
.viewer-stage img { max-width: 92vw; max-height: 86dvh; border-radius: 8px; transition: transform .12s; cursor: grab; user-select: none; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 52px; border-radius: 50%; border: 0; z-index: 2;
  background: rgba(255, 255, 255, .12); color: #fff; display: grid; place-items: center; backdrop-filter: blur(8px);
}
.viewer-nav:hover { background: rgba(255, 255, 255, .25); }
.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }
.viewer-hint { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: rgba(255, 255, 255, .5); font-size: 12.5px; }

/* ----- Панель форматирования ----- */
.fmt-bar { display: flex; gap: 2px; padding: 6px 8px 0; animation: fade-in .12s; }
.fmt-bar button {
  min-width: 34px; height: 30px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text); display: grid; place-items: center; font-size: 14px;
}
.fmt-bar button:hover { background: var(--accent-soft); color: var(--accent-text); }
.fmt-bar .ico { width: 17px; height: 17px; }
.fmt-bar code { font-size: 12px; }

/* ----- Цитата выделенного фрагмента ----- */
.quote.partial .quote-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; font-style: italic; }

/* ----- Подсветка кода ----- */
.code-block { margin: 4px 0; border-radius: 10px; overflow: hidden; background: rgba(0, 0, 0, .28); border-left: 3px solid var(--accent-text); white-space: normal; }
:root[data-theme="light"] .code-block { background: rgba(0, 0, 0, .05); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--accent-text); background: rgba(127, 127, 127, .1); }
.msg-row.out .code-head { color: inherit; }
.code-copy { background: none; border: 0; color: inherit; font-size: 12px; opacity: .8; padding: 0; }
.code-copy:hover { opacity: 1; text-decoration: underline; }
.code-block pre { margin: 0; border: 0; border-radius: 0; background: none; padding: 9px 12px; }
.tok-keyword { color: #c792ea; }
.tok-string { color: #c3e88d; }
.tok-number { color: #f78c6c; }
.tok-comment { color: #7f8b97; font-style: italic; }
.tok-func { color: #82aaff; }
:root[data-theme="light"] .tok-keyword { color: #8e24aa; }
:root[data-theme="light"] .tok-string { color: #2e7d32; }
:root[data-theme="light"] .tok-number { color: #d84315; }
:root[data-theme="light"] .tok-func { color: #1565c0; }
.msg-row.out .tok-keyword, .msg-row.out .tok-string, .msg-row.out .tok-number, .msg-row.out .tok-func { filter: brightness(1.35); }
:root[data-theme="light"] .msg-row.out .tok-keyword, :root[data-theme="light"] .msg-row.out .tok-string,
:root[data-theme="light"] .msg-row.out .tok-number, :root[data-theme="light"] .msg-row.out .tok-func { filter: none; }

/* ----- Голосовые: волна и скорость ----- */
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.voice-wave i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: rgba(127, 127, 127, .45); transition: background .1s; }
.voice-wave i.played { background: var(--accent-text); }
.msg-row.out .voice-wave i { background: color-mix(in srgb, currentColor 35%, transparent); }
.msg-row.out .voice-wave i.played { background: currentColor; }
.voice-meta { display: flex; align-items: center; gap: 8px; }
.voice-speed {
  border: 0; border-radius: 8px; padding: 1px 6px; font-size: 11.5px; font-weight: 700; background: var(--accent-soft); color: var(--accent-text);
}
.msg-row.out .voice-speed { background: var(--out-chip); color: inherit; }

/* ----- Реакция из всех эмодзи ----- */
.ctx-reactions .more { font-size: 18px !important; color: var(--muted); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 36px); gap: 2px; padding: 2px; max-height: 260px; overflow-y: auto; }
.emoji-grid button { font-size: 22px; border: 0; background: none; border-radius: 8px; height: 36px; }
.emoji-grid button:hover { background: var(--surface-2); }

/* ----- Архив, папки, «непрочитано» вручную ----- */
.chat-item.archive-row .avatar { background: var(--surface-3) !important; color: var(--muted); }
.badge.dot { min-width: 12px; width: 12px; height: 12px; padding: 0; }
.folder-tab.add { color: var(--muted); padding: 11px 8px 12px; }
.folder-tab.add .ico { width: 18px; height: 18px; }
.archive-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.archive-head .icon-btn { width: 34px; height: 34px; }

/* ----- Аккаунты, «не беспокоить» ----- */
.accounts-list { display: flex; flex-direction: column; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
.accounts-list .drawer-item .avatar { width: 28px; height: 28px; font-size: 12px; }
.accounts-list .drawer-item .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.dnd-badge { color: var(--accent-text) !important; }

/* ----- История правок, горячие клавиши ----- */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-list li { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.history-list .when { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.history-list li.current { box-shadow: inset 0 0 0 2px var(--accent); }
.shortcuts { width: 100%; border-collapse: collapse; font-size: 14px; }
.shortcuts td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
.shortcuts td:first-child { white-space: nowrap; width: 45%; }
.shortcuts kbd { font-size: 12px; }
