/* G-Chat — оформление в духе Telegram для Android. Светлая и тёмная темы. */

:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f1f3f5;
  --border: #e7e9ec;
  --text: #000000;
  --muted: #8a959e;
  --accent: #3390ec;
  --accent-2: #4ea4f6;
  --header: #517da2;
  --header-text: #ffffff;
  --header-muted: #d6e5f2;
  --hover: #f2f4f6;
  --active: #e9f2fd;
  --bubble-in: #ffffff;
  --bubble-out: #effedd;
  --meta-in: #a0acb6;
  --meta-out: #5ea94f;
  --tick: #4fae4e;
  --quote-out: #4fae4e;
  --online: #4fae4e;
  --danger: #e53935;
  --badge: #4fae4e;
  --chat-bg: linear-gradient(160deg, #d7e5b8 0%, #b5d3a5 45%, #8fbfa6 100%);
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='.07' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='22' cy='24' r='8'/%3E%3Cpath d='M62 14l7 13 7-13'/%3E%3Cpath d='M112 22h18M121 13v18'/%3E%3Crect x='14' y='76' width='18' height='13' rx='3'/%3E%3Cpath d='M70 82c5-7 13-7 18 0s13 7 18 0'/%3E%3Ccircle cx='136' cy='86' r='5'/%3E%3Cpath d='M22 136l9-9 9 9'/%3E%3Cpath d='M88 140a9 9 0 1 0-18 0'/%3E%3Cpath d='M118 128l12 12M130 128l-12 12'/%3E%3Cpath d='M48 48l6 6M54 48l-6 6'/%3E%3Cpath d='M98 52c0-6 9-6 9 0s-9 9-9 9-9-3-9-9 9-6 9 0z'/%3E%3C/g%3E%3C/svg%3E");
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  --bubble-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  color-scheme: light;
}

/* Тёмная тема: вручную или по системе, если не выбрана светлая. */
:root[data-theme='dark'] {
  --bg: #17212b;
  --panel: #17212b;
  --panel-2: #242f3d;
  --border: #0e1621;
  --text: #f5f5f5;
  --muted: #708499;
  --accent: #5eb5f7;
  --accent-2: #6fc0ff;
  --header: #232e3c;
  --header-text: #ffffff;
  --header-muted: #8b9bab;
  --hover: #202b36;
  --active: #2b5278;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --meta-in: #6d7f8f;
  --meta-out: #7da8d3;
  --tick: #6ab3f3;
  --quote-out: #8dc6f7;
  --online: #5eb5f7;
  --danger: #ef5350;
  --badge: #5eb5f7;
  --chat-bg: #0e1621;
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.035' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='22' cy='24' r='8'/%3E%3Cpath d='M62 14l7 13 7-13'/%3E%3Cpath d='M112 22h18M121 13v18'/%3E%3Crect x='14' y='76' width='18' height='13' rx='3'/%3E%3Cpath d='M70 82c5-7 13-7 18 0s13 7 18 0'/%3E%3Ccircle cx='136' cy='86' r='5'/%3E%3Cpath d='M22 136l9-9 9 9'/%3E%3Cpath d='M88 140a9 9 0 1 0-18 0'/%3E%3Cpath d='M118 128l12 12M130 128l-12 12'/%3E%3Cpath d='M48 48l6 6M54 48l-6 6'/%3E%3Cpath d='M98 52c0-6 9-6 9 0s-9 9-9 9-9-3-9-9 9-6 9 0z'/%3E%3C/g%3E%3C/svg%3E");
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  --bubble-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme='system'] {
    --bg: #17212b;
    --panel: #17212b;
    --panel-2: #242f3d;
    --border: #0e1621;
    --text: #f5f5f5;
    --muted: #708499;
    --accent: #5eb5f7;
    --accent-2: #6fc0ff;
    --header: #232e3c;
    --header-text: #ffffff;
    --header-muted: #8b9bab;
    --hover: #202b36;
    --active: #2b5278;
    --bubble-in: #182533;
    --bubble-out: #2b5278;
    --meta-in: #6d7f8f;
    --meta-out: #7da8d3;
    --tick: #6ab3f3;
    --quote-out: #8dc6f7;
    --online: #5eb5f7;
    --danger: #ef5350;
    --badge: #5eb5f7;
    --chat-bg: #0e1621;
    --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.035' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='22' cy='24' r='8'/%3E%3Cpath d='M62 14l7 13 7-13'/%3E%3Cpath d='M112 22h18M121 13v18'/%3E%3Crect x='14' y='76' width='18' height='13' rx='3'/%3E%3Cpath d='M70 82c5-7 13-7 18 0s13 7 18 0'/%3E%3Ccircle cx='136' cy='86' r='5'/%3E%3Cpath d='M22 136l9-9 9 9'/%3E%3Cpath d='M88 140a9 9 0 1 0-18 0'/%3E%3Cpath d='M118 128l12 12M130 128l-12 12'/%3E%3Cpath d='M48 48l6 6M54 48l-6 6'/%3E%3Cpath d='M98 52c0-6 9-6 9 0s-9 9-9 9-9-3-9-9 9-6 9 0z'/%3E%3C/g%3E%3C/svg%3E");
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
    --bubble-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Общие кривые и длительности анимаций — все переходы в одном ритме. */
:root {
  --ease: cubic-bezier(0.2, 0.85, 0.25, 1);
  --t-slide: 0.32s;
  --t-fast: 0.18s;
  /* Подъём вместе с клавиатурой — в такт системной анимации Android. */
  --t-kb: 0.28s;
  --ease-kb: cubic-bezier(0.2, 0.8, 0.2, 1);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 Roboto, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.online-text { color: var(--accent); }
[hidden] { display: none !important; }

.boot, .fatal {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

/* ---------- кнопки и поля ---------- */

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; text-align: left; }
.btn:disabled { opacity: 0.6; cursor: default; }

.icon-btn {
  border: 0;
  background: transparent;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 22px;
  color: var(--muted);
  flex: none;
  text-decoration: none;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--active); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255, 255, 255, 0.12); }

/* Контурные иконки одного стиля. */
.icon {
  width: 24px;
  height: 24px;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon .dots { stroke-width: 3.4; }
.icon .filled { fill: currentColor; stroke: none; }
.icon.flip { transform: scaleX(-1); }
.avatar-icon { width: 54%; height: 54%; stroke-width: 1.7; }

/* Смайлики Twemoji внутри текста. */
.emoji-img {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  margin: 0 0.04em;
  vertical-align: -0.28em;
}
.big-emoji .emoji-img { width: 1.1em; height: 1.1em; vertical-align: -0.15em; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--panel-2);
  outline: none;
}
.field input:focus, .input:focus { border-color: var(--accent); }

/* ---------- вход ---------- */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--kb, 0px));
  transition: padding-bottom var(--t-kb) var(--ease-kb);
  background: var(--chat-bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 12px 0 4px; font-size: 22px; text-align: center; }
.auth-card > p { text-align: center; margin: 0 0 8px; }
.auth-card .btn { width: 100%; margin-top: 8px; padding: 13px; }
.auth-logo { display: grid; place-items: center; }
.auth-logo img { width: 80px; height: 80px; }
.auth-error { color: var(--danger); min-height: 20px; font-size: 14px; }

/* ---------- каркас ---------- */

.layout { display: flex; height: 100%; overflow: hidden; position: relative; }

.sidebar {
  width: 380px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
/* Затемнение списка, когда поверх него выезжает чат (на телефоне). */
.sidebar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  transition: opacity var(--t-slide) var(--ease);
}
.sidebar.dragging::after { transition: none; }

/* Контакты: выезжают справа поверх списка чатов. */
.people-panel {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--t-slide) var(--ease);
  box-shadow: -6px 0 18px rgba(0, 0, 0, 0.12);
}
.people-panel.open { transform: none; }
.people-panel.dragging { transition: none; }
.people-list { flex: 1; overflow-y: auto; min-height: 0; padding: 4px 0 calc(16px + env(safe-area-inset-bottom)); }
.people-list .user-item { padding: 8px 14px; border-radius: 0; }
.people-list .profile-action { padding: 12px 18px; }
.side-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--header);
  color: var(--header-text);
  min-height: 56px;
}
.side-head .icon-btn { color: var(--header-text); }
.side-head .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.side-title { flex: 1; font-weight: 500; font-size: 20px; padding-left: 6px; }
.side-title .conn { font-weight: 400; font-size: 14px; color: var(--header-muted); margin-left: 8px; }

.search-box { padding: 8px 10px; background: var(--panel); }
.search-input {
  width: 100%;
  border: 0;
  border-radius: 22px;
  padding: 9px 16px 9px 38px;
  background: var(--panel-2) no-repeat 13px 50% / 16px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a959e' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5l5 5'/%3E%3C/svg%3E");
  outline: none;
}
.search-input:focus { box-shadow: 0 0 0 2px var(--accent); }
.search-head { padding: 4px 16px 6px; }
mark { background: rgba(255, 200, 0, 0.45); color: inherit; border-radius: 3px; padding: 0 1px; }

.notif-banner {
  margin: 0 10px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.notif-banner span { flex: 1; }
.notif-banner .btn { padding: 6px 10px; }

.chat-list { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.chat-item {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item:active { background: var(--active); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .chat-item-time, .chat-item.active .chat-item-preview { color: rgba(255, 255, 255, 0.85); }
.chat-item-body {
  flex: 1;
  min-width: 0;
  padding: 2px 0 10px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 8px; }
.chat-item-top { margin-bottom: 3px; }
.chat-item-title { flex: 1; font-weight: 500; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 13px; color: var(--muted); flex: none; }
.chat-item-preview { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chat-item-preview.typing { color: var(--accent); }
.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--badge);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  display: inline-grid;
  place-items: center;
  flex: none;
}
.chat-item.active .badge { background: #fff; color: var(--accent); }
.badge.muted { background: #b3bac1; }
:root[data-theme='dark'] .badge.muted { background: #4f5d6b; }
.chat-item-muted { color: var(--muted); display: grid; place-items: center; margin-left: -4px; }
.chat-item-muted .icon { width: 15px; height: 15px; stroke-width: 2; }
.chat-item.active .chat-item-muted { color: rgba(255, 255, 255, 0.85); }

.fab {
  position: absolute;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  z-index: 2;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab .icon { width: 26px; height: 26px; margin: auto; }

.empty { padding: 24px 16px; text-align: center; }

/* ---------- аватарки ---------- */

.avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 500;
  font-size: 19px;
  flex: none;
  position: relative;
  user-select: none;
  background: linear-gradient(180deg, var(--a1, #72d5fd), var(--a2, #2a9ef1));
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }
.avatar.xl { width: 112px; height: 112px; font-size: 42px; }
.avatar.c0 { --a1: #ff885e; --a2: #ff516a; } .avatar.c1 { --a1: #a0de7e; --a2: #54cb68; }
.avatar.c2 { --a1: #ffcd6a; --a2: #ffa85c; } .avatar.c3 { --a1: #72d5fd; --a2: #2a9ef1; }
.avatar.c4 { --a1: #e0a2f3; --a2: #d669ed; } .avatar.c5 { --a1: #ff8aac; --a2: #e95d86; }
.avatar.c6 { --a1: #53edd6; --a2: #28c9b7; } .avatar.c7 { --a1: #82b1ff; --a2: #665fff; }
.avatar.saved { --a1: #72d5fd; --a2: #2a9ef1; font-size: 24px; }
.avatar.sm.saved, .avatar.sm.family { font-size: 18px; }
.avatar.lg.saved, .avatar.lg.family { font-size: 34px; }
.avatar.xl.saved, .avatar.xl.family { font-size: 54px; }
.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-2);
}
.online-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--online);
  border: 2.5px solid var(--panel);
  z-index: 1;
}
.avatar.sm .online-dot { width: 12px; height: 12px; }

.author.c0 { color: #e65d4b; } .author.c1 { color: #3fa94b; }
.author.c2 { color: #d9932c; } .author.c3 { color: #2a9ef1; }
.author.c4 { color: #a65ad3; } .author.c5 { color: #d6517b; }
.author.c6 { color: #1fae9b; } .author.c7 { color: #5d6ae6; }

/* ---------- боковое меню ---------- */

.drawer-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0);
  transition: background 0.25s;
}
.drawer-root.open { background: rgba(0, 0, 0, 0.45); }
.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(310px, 84vw);
  background: var(--panel);
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.drawer-root.open .drawer { transform: translateX(0); }
.drawer-head {
  background: var(--header);
  color: #fff;
  padding: 20px 20px 14px;
  padding-top: max(20px, calc(env(safe-area-inset-top) + 12px));
}
.drawer-head .online-dot { display: none; }
.drawer-name { font-weight: 500; font-size: 17px; margin-top: 14px; }
.drawer-user { font-size: 14px; color: var(--header-muted); }
.drawer-list { padding: 6px 0; flex: 1; }
.drawer-item {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 13px 22px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.drawer-item:hover { background: var(--hover); }
.drawer-item { gap: 28px; padding: 12px 22px; }
.drawer-icon { width: 24px; color: var(--muted); }
.drawer-label { flex: 1; }
.drawer-sep { height: 1px; background: var(--border); margin: 6px 0; }
:root[data-theme='dark'] .drawer-sep { background: #0b131c; }

/* Переключатель как в Android. */
.switch {
  flex: none;
  width: 34px;
  height: 14px;
  border-radius: 7px;
  background: #b3bac1;
  position: relative;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s, background 0.2s;
}
.switch.on { background: rgba(51, 144, 236, 0.5); }
.switch.on::after { transform: translateX(18px); background: var(--accent); }
.drawer-foot { padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); font-size: 13px; color: var(--muted); }

/* ---------- окно чата ---------- */

.chat-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--pattern), var(--chat-bg);
  background-attachment: fixed;
}
.pane-empty {
  flex: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
}
.pane-empty p {
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 14px;
}
.pane-empty img { width: 96px; height: 96px; opacity: 0.9; }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  /* Клавиатура открылась — поле ввода и лента плавно поднимаются над ней. */
  padding-bottom: var(--kb, 0px);
  transition: padding-bottom var(--t-kb) var(--ease-kb);
}
body.kb-open .composer { padding-bottom: 6px; }
.chat.dragging::after {
  content: 'Отпустите, чтобы отправить файлы';
  position: absolute;
  inset: 12px;
  border: 3px dashed var(--accent);
  border-radius: 16px;
  background: rgba(51, 144, 236, 0.12);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  z-index: 5;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 6px;
  padding-top: max(4px, env(safe-area-inset-top));
  background: var(--header);
  color: var(--header-text);
  min-height: 56px;
  z-index: 3;
}
.chat-head .icon-btn { color: var(--header-text); }
.chat-head .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.chat-head .back { display: none; }
.chat-head-info {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 10px;
}
.chat-head-info > div { min-width: 0; }
.chat-head .online-dot { display: none; }
.chat-head-title { font-weight: 500; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { font-size: 14px; color: var(--header-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub.typing { color: var(--header-text); }

/* Анимированное многоточие у «печатает». */
.typing::after {
  content: '';
  display: inline-block;
  width: 1.1em;
  text-align: left;
  animation: dots 1.2s steps(1, end) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.pinned-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 4px 0;
}
.pinned-icon { font-size: 16px; }
.pinned-text { min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; }
.pinned-label { color: var(--accent); font-weight: 500; font-size: 14px; }
.pinned-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 6px 10px 10px;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}
.messages > :first-child { margin-top: auto; }
.load-more { text-align: center; padding: 8px; font-size: 13px; }
.load-more, .messages > .empty {
  align-self: center;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  border-radius: 14px;
  padding: 4px 12px;
  margin: 8px 0;
  font-size: 14px;
  max-width: 320px;
}

.day-sep { display: flex; justify-content: center; margin: 10px 0 6px; position: sticky; top: 4px; z-index: 1; }
.day-sep span {
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 3px 11px;
  border-radius: 14px;
}

/* ---------- сообщения ---------- */

/* Строка сообщения во всю ширину ленты (с отступами по краям): выделить можно нажатием в любом месте строки. */
.msg {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin: 0 -10px;
  padding: 6px 10px 0;
  max-width: none;
  transition: transform 0.18s ease;
  position: relative;
}
.msg.grouped { padding-top: 2px; }
.msg.mine { flex-direction: row-reverse; }
.msg.appear { animation: appear 0.26s var(--ease); transform-origin: 0 100%; }
.msg.appear-mine { animation: appear 0.26s var(--ease); transform-origin: 100% 100%; }
@keyframes appear {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to { opacity: 1; transform: none; }
}
.msg.sending { transform-origin: 100% 100%; }
.tick.sending { display: inline-grid; vertical-align: -2px; letter-spacing: 0; }
.tick.sending .icon { width: 13px; height: 13px; stroke-width: 2.2; }
.msg.closing { opacity: 0; transform: scale(0.9); transition: opacity 0.2s, transform 0.2s; }

/* Смена чата на ПК: лента мягко проявляется. */
.chat.chat-enter .messages, .chat.chat-enter .chat-head-info { animation: chat-enter 0.24s var(--ease); }
@keyframes chat-enter {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- выделение сообщений ---------- */

.select-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 4px 6px;
  padding-top: max(4px, env(safe-area-inset-top));
  background: var(--header);
  color: var(--header-text);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity var(--t-fast) ease, transform var(--t-fast) var(--ease);
}
.chat.selecting .select-bar { opacity: 1; transform: none; pointer-events: auto; }
.select-bar .icon-btn { color: var(--header-text); }
.select-bar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.select-count { flex: 1; font-weight: 500; font-size: 18px; padding-left: 8px; }

/* Кружок-галочка слева у каждой строки; строки чуть сдвигаются, освобождая для него место. */
.msg { transition: transform 0.18s ease, padding-left var(--t-fast) var(--ease), background-color var(--t-fast); }
.chat.selecting .msg:not(.pending):not(.sending) { padding-left: 48px; cursor: pointer; }
.chat.selecting .msg:not(.pending):not(.sending)::before {
  content: '';
  position: absolute;
  left: 14px;
  bottom: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
  background: rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  animation: pop var(--t-fast) var(--ease);
}
.chat.selecting .msg.selected:not(.pending):not(.sending)::before {
  border-color: var(--accent);
  background: var(--accent) no-repeat center / 14px
    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.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
.msg.selected { background-color: rgba(51, 144, 236, 0.18); }
.chat.selecting .msg-actions { display: none; }

/* @упоминания в тексте. */
.mention { color: var(--accent); cursor: pointer; font-weight: 500; }
.msg.mine .mention { color: var(--quote-out); }
.mention.me { background: rgba(51, 144, 236, 0.14); border-radius: 4px; padding: 0 2px; }
.msg.flash .bubble { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%, 50% { box-shadow: 0 0 0 4px rgba(51, 144, 236, 0.45); }
  100% { box-shadow: var(--bubble-shadow); }
}
.msg.ctx-target .bubble { filter: brightness(0.94); }
/* Свайп влево — значок «ответить» появляется справа. */
.msg::after {
  content: '↩';
  position: absolute;
  right: -34px;
  bottom: 6px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg.reply-ready::after { opacity: 1; }

.msg-avatar { width: 40px; flex: none; align-self: flex-end; }
.msg-avatar .online-dot { display: none; }

.bubble {
  position: relative;
  background: var(--bubble-in);
  border-radius: 16px;
  padding: 6px 10px 6px;
  max-width: min(520px, 80%);
  box-shadow: var(--bubble-shadow);
  overflow-wrap: anywhere;
  min-width: 0;
}
.msg.mine .bubble { background: var(--bubble-out); }
/* Хвостик у последнего сообщения серии. */
.msg.tail:not(.mine) .bubble { border-bottom-left-radius: 4px; }
.msg.tail.mine .bubble { border-bottom-right-radius: 4px; }
.msg.tail .bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  width: 11px;
  height: 17px;
  background: inherit;
}
.msg.tail:not(.mine) .bubble::before { left: -8px; clip-path: path('M11 0V17H0C5 15.5 9 12 11 0Z'); }
.msg.tail.mine .bubble::before { right: -8px; clip-path: path('M0 0V17H11C6 15.5 2 12 0 0Z'); }
.bubble.emoji-only, .msg.mine .bubble.emoji-only { background: transparent; box-shadow: none; padding: 0 4px; }
.bubble.emoji-only::before { display: none; }
.bubble.media-only { padding: 0; overflow: hidden; }
.bubble.media-only::before { display: none; }
.bubble.media-only .att-image, .bubble.media-only .album { margin: 0; border-radius: 0; }
.bubble.media-only .meta {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  margin: 0;
}
.bubble.media-only .tick { color: #fff; }

/* Пересланные сообщения — с градиентным фоном (хвостик берёт нижний цвет градиента).
   Градиент привязан к экрану, поэтому несколько пересланных подряд выглядят одной цветной полосой. */
.bubble.fwd { background-attachment: fixed !important; }
.msg.grouped:has(> .bubble.fwd-cont) { padding-top: 1px; }
.bubble.fwd { background: linear-gradient(135deg, #e3f1ff 0%, #f4e6ff 100%); }
.msg.mine .bubble.fwd { background: linear-gradient(135deg, #d9f7c8 0%, #c9ecf7 100%); }
.msg.tail:not(.mine) .bubble.fwd::before { background: #e3f1ff; }
.msg.tail.mine .bubble.fwd::before { background: #c9ecf7; }
:root[data-theme='dark'] .bubble.fwd { background: linear-gradient(135deg, #1f3550 0%, #3a2a55 100%); }
:root[data-theme='dark'] .msg.mine .bubble.fwd { background: linear-gradient(135deg, #2b5278 0%, #5b3f8f 100%); }
:root[data-theme='dark'] .msg.tail:not(.mine) .bubble.fwd::before { background: #1f3550; }
:root[data-theme='dark'] .msg.tail.mine .bubble.fwd::before { background: #5b3f8f; }
@media (prefers-color-scheme: dark) {
  :root[data-theme='system'] .bubble.fwd { background: linear-gradient(135deg, #1f3550 0%, #3a2a55 100%); }
  :root[data-theme='system'] .msg.mine .bubble.fwd { background: linear-gradient(135deg, #2b5278 0%, #5b3f8f 100%); }
  :root[data-theme='system'] .msg.tail:not(.mine) .bubble.fwd::before { background: #1f3550; }
  :root[data-theme='system'] .msg.tail.mine .bubble.fwd::before { background: #5b3f8f; }
}

.author { font-weight: 500; font-size: 15px; margin-bottom: 1px; }
.forwarded { color: var(--accent); font-size: 14px; margin-bottom: 2px; }
.msg.mine .forwarded { color: var(--quote-out); }
.text { white-space: pre-wrap; }
.big-emoji { font-size: 48px; line-height: 1.15; }
.deleted { font-style: italic; }
.meta {
  display: block;
  text-align: right;
  font-size: 12px;
  color: var(--meta-in);
  margin-top: 2px;
  user-select: none;
  white-space: nowrap;
}
/* Время в конце текста: под него в тексте оставлено место, а сама подпись прижата к углу. */
.bubble:has(> .text):not(:has(> .reactions)):not(.emoji-only) > .meta { position: absolute; right: 10px; bottom: 5px; margin: 0; }
.bubble:not(:has(> .reactions)):not(.emoji-only) > .text::after { content: ''; display: inline-block; width: 44px; }
.msg.mine .bubble:not(:has(> .reactions)):not(.emoji-only) > .text::after { width: 62px; }
.bubble.is-edited:not(:has(> .reactions)):not(.emoji-only) > .text::after { width: 108px; }
.msg.mine .bubble.is-edited:not(:has(> .reactions)):not(.emoji-only) > .text::after { width: 126px; }
.msg .bubble.emoji-only > .meta {
  display: inline-block;
  float: right;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
}
.bubble.emoji-only .tick { color: #fff; }
.msg.mine .meta { color: var(--meta-out); }
.edited { font-style: italic; }
.tick { margin-left: 3px; letter-spacing: -4px; padding-right: 4px; color: var(--tick); }
.msg.pending .bubble { opacity: 0.8; }

.msg-actions {
  display: flex;
  gap: 4px;
  align-self: center;
  opacity: 0;
  transition: opacity 0.12s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  border: 0;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
}
.msg-actions button:hover { background: rgba(0, 0, 0, 0.4); }

.reply-quote {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 3px solid var(--accent);
  background: rgba(51, 144, 236, 0.1);
  border-radius: 6px;
  padding: 3px 8px;
  margin: 2px 0 4px;
  cursor: pointer;
  font-size: 15px;
  min-width: 0;
}
.msg.mine .reply-quote { border-left-color: var(--quote-out); background: rgba(79, 174, 78, 0.12); }
.reply-author { font-weight: 500; font-size: 14px; margin: 0; }
.msg.mine .reply-author { color: var(--quote-out); }
.reply-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction {
  border: 0;
  background: rgba(51, 144, 236, 0.14);
  border-radius: 14px;
  padding: 2px 9px 2px 6px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.reaction span { font-size: 13px; font-weight: 500; color: var(--accent); }
.reaction.mine { background: var(--accent); }
.reaction.mine span { color: #fff; }
.msg.mine .reaction:not(.mine) { background: rgba(79, 174, 78, 0.18); }
.msg.mine .reaction:not(.mine) span { color: var(--quote-out); }

.att-image { display: block; position: relative; margin: 2px -6px 4px; border-radius: 12px; overflow: hidden; }
.att-image img, .att-image video {
  display: block;
  max-width: 100%;
  width: auto;
  max-height: 360px;
  min-width: 160px;
  min-height: 90px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.08);
}
.att-video-thumb video { width: 100%; }
.play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  pointer-events: none;
}
.play .icon {
  width: 44px;
  height: 44px;
  padding: 11px 9px 11px 13px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
}
.att-audio { display: block; max-width: 100%; margin: 4px 0; }
.att-file { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; padding: 4px 0; }
.att-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex: none;
}
.msg.mine .att-icon { background: var(--meta-out); }
.att-info { display: flex; flex-direction: column; min-width: 0; }
.att-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }

.album { display: grid; gap: 2px; margin: 2px -6px 4px; border-radius: 12px; overflow: hidden; }
.bubble:has(.album) { width: min(380px, 80%); }
.album.n2, .album.n3, .album.n4 { grid-template-columns: 1fr 1fr; }
.album.n3 .album-cell:first-child { grid-column: span 2; aspect-ratio: 2 / 1; }
.album-cell { position: relative; display: block; aspect-ratio: 1; background: rgba(0, 0, 0, 0.15); }
.album-cell img, .album-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Кнопка «вниз» со счётчиком новых сообщений. */
.scroll-fab {
  position: absolute;
  right: 12px;
  bottom: 74px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 3;
  animation: pop 0.18s ease-out;
}
.scroll-fab .icon { width: 26px; height: 26px; margin: auto; }
.fab-badge {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  display: grid;
  place-items: center;
  padding: 0 6px;
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- поле ввода ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 2;
}
.composer-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  background: var(--panel);
  border-radius: 24px;
  box-shadow: var(--bubble-shadow);
  padding: 2px 2px;
}
.composer-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  padding: 10px 4px;
  max-height: 160px;
  line-height: 1.35;
}
.send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  flex: none;
  cursor: pointer;
  box-shadow: var(--bubble-shadow);
  transition: transform 0.12s;
  display: grid;
  place-items: center;
}
.send:active { transform: scale(0.9); }
.send .icon { width: 25px; height: 25px; stroke-width: 2; animation: pop 0.15s ease-out; }
.composer-field .icon-btn { color: var(--muted); }
.composer-field .icon { width: 26px; height: 26px; }

.context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 2;
  animation: slide-up var(--t-fast) var(--ease);
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* Подсказка участников после «@». */
.mention-box {
  background: var(--panel);
  border-top: 1px solid var(--border);
  max-height: 230px;
  overflow-y: auto;
  z-index: 2;
  animation: slide-up var(--t-fast) var(--ease);
}
.mention-item {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  text-align: left;
  cursor: pointer;
}
.mention-item:hover, .mention-item.on { background: var(--hover); }
.mention-item .avatar { width: 36px; height: 36px; font-size: 14px; }
.mention-text { min-width: 0; }
.mention-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context-text { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; }
.context-label { color: var(--accent); font-weight: 500; font-size: 14px; }
.context-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }

/* ---------- смайлики ---------- */

.emoji-panel {
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 280px;
  flex: none;
  z-index: 2;
  animation: slide-up var(--t-fast) var(--ease);
}
.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex: none;
}
.emoji-tabs button {
  border: 0;
  background: transparent;
  font-size: 20px;
  width: 40px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  flex: none;
  opacity: 0.55;
}
.emoji-tabs button.on { opacity: 1; background: var(--hover); }
.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  align-content: start;
}
.emoji-cat { grid-column: 1 / -1; padding: 6px 2px 4px; }
.emoji { border: 0; background: transparent; font-size: 28px; height: 44px; border-radius: 8px; cursor: pointer; line-height: 1; }
.emoji:hover { background: var(--hover); }
.emoji:active { transform: scale(0.85); }

/* ---------- меню сообщения ---------- */

.ctx-overlay { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.12); animation: fade 0.15s; }
.ctx-overlay.closing { opacity: 0; transition: opacity 0.12s; }
.ctx-overlay.closing .ctx-menu { transform: scale(0.92); transition: transform 0.12s; }
.ctx-menu {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  animation: pop 0.16s ease-out;
  transform-origin: top center;
}
.ctx-reactions {
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  background: var(--panel);
  border-radius: 26px;
  box-shadow: var(--shadow);
}
.ctx-reactions button {
  border: 0;
  background: transparent;
  font-size: 26px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.12s;
}
.ctx-reactions button:hover { transform: scale(1.2); }
.ctx-reactions button.on { background: var(--active); }
.ctx-list {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
  padding: 6px 0;
}
.ctx-item {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 18px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-icon { width: 22px; text-align: center; color: var(--muted); font-size: 18px; }
.ctx-item.danger .ctx-icon { color: var(--danger); }
.clipboard-helper { position: fixed; left: -9999px; }

/* ---------- просмотр фото ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, var(--fade, 0.96));
  display: flex;
  flex-direction: column;
  animation: fade 0.2s;
  color: #fff;
}
.viewer.closing { opacity: 0; transition: opacity 0.2s; }
.viewer-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
  position: relative;
  z-index: 2;
}
.viewer-info { flex: 1; min-width: 0; }
.viewer-name { font-weight: 500; }
.viewer-date { font-size: 13px; opacity: 0.75; }
.viewer-count { font-size: 14px; opacity: 0.8; padding: 0 6px; }
.viewer-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
  margin-top: -56px;
}
.viewer-media { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
img.viewer-media { cursor: zoom-in; }
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 34px;
  cursor: pointer;
  z-index: 2;
}
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }
@media (pointer: coarse) { .viewer-nav { display: none; } }

/* ---------- информация о чате ---------- */

.profile-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  z-index: 50;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  /* Профиль опускается сверху вниз и уезжает обратно вверх. */
  transform: translateY(-100%);
  transition: transform var(--t-slide) var(--ease);
  display: flex;
  flex-direction: column;
}
.profile-panel.open { transform: none; }
.profile-panel .profile-hero > * { transition: opacity 0.3s 0.08s, transform 0.3s 0.08s var(--ease); }
.profile-panel:not(.open) .profile-hero > * { opacity: 0; transform: translateY(-12px); }
.profile-action.plain { color: inherit; }
.profile-action.plain .ctx-icon { color: var(--muted); }
.profile-action-label { flex: 1; display: flex; flex-direction: column; }
.profile-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  padding-top: max(4px, env(safe-area-inset-top));
  background: var(--header);
  color: var(--header-text);
  min-height: 56px;
}
.profile-head .icon-btn { color: var(--header-text); }
.profile-head-title { flex: 1; font-size: 19px; font-weight: 500; }
.profile-scroll { flex: 1; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px 18px;
  background: var(--panel);
  text-align: center;
}
.profile-hero .online-dot { display: none; }
.profile-title { font-size: 21px; font-weight: 500; margin-top: 10px; }
.profile-sub { color: var(--muted); }
.profile-photo-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.profile-section { background: var(--panel); margin-top: 10px; padding: 8px 0; }
.profile-section-title { color: var(--accent); font-weight: 500; font-size: 15px; padding: 8px 16px; }
.profile-row { padding: 8px 16px; }
.profile-row-label { font-size: 13px; color: var(--muted); }
.profile-action {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
}
.profile-action .ctx-icon { color: inherit; }
.profile-action.danger { color: var(--danger); }
.profile-action:hover { background: var(--hover); }
.profile-section .user-item { padding: 8px 16px; border-radius: 0; }
.profile-section .tabs { padding: 4px 12px 10px; margin: 0; }
.profile-files { padding: 0 2px; }
.profile-empty { text-align: center; padding: 18px; }
.profile-section .btn.wide { margin: 8px 12px 0; width: calc(100% - 24px); text-align: center; }

/* ---------- окна ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  z-index: 75;
  padding: 16px;
  padding-bottom: calc(16px + var(--kb, 0px));
  transition: padding-bottom var(--t-kb) var(--ease-kb);
  animation: fade 0.18s;
}
.overlay.closing { opacity: 0; transition: opacity 0.2s; }
.overlay.closing .modal { transform: scale(0.94); transition: transform 0.2s var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; padding: 12px 8px 4px 20px; }
.modal-head h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 500; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.modal-body > .btn.wide { margin-bottom: 8px; }

.user-list { display: flex; flex-direction: column; }
.user-item {
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.user-item:hover:not(:disabled) { background: var(--hover); }
.user-item:disabled { cursor: default; color: inherit; }
label.user-item input { width: 20px; height: 20px; accent-color: var(--accent); }

.invite-link { display: flex; gap: 8px; margin: 8px 0; }
.invite-link .input { font-size: 13px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 8px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 500;
}
.tabs button.on { background: var(--accent); color: #fff; }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.media-cell { position: relative; aspect-ratio: 1; overflow: hidden; background: rgba(0, 0, 0, 0.15); display: block; }
.media-cell img, .media-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  text-decoration: none;
  color: inherit;
}
.doc-row:hover { background: var(--hover); }
.doc-row .att-info { flex: 1; }

.avatar-edit { display: flex; align-items: center; gap: 16px; margin: 4px 0 12px; }
.avatar-edit-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.admin-user { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.admin-user.disabled { opacity: 0.6; }
.admin-user-info { flex: 1; min-width: 160px; }
.admin-user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-user-actions .btn { padding: 6px 10px; font-size: 13px; }
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--accent);
  color: #fff;
  vertical-align: 1px;
}
.tag.off { background: var(--danger); }
.temp-password {
  font: 500 26px/1.2 ui-monospace, Consolas, monospace;
  letter-spacing: 2px;
  text-align: center;
  padding: 14px;
  margin: 8px 0;
  border-radius: 12px;
  background: var(--panel-2);
  user-select: all;
}

.toast {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 100;
  max-width: calc(100% - 32px);
  box-shadow: var(--shadow);
  animation: slide-up 0.22s var(--ease);
}
.toast.closing { opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }

/* ---------- размеры иконок и смайликов в разных местах ---------- */

.ctx-icon { display: grid; place-items: center; width: 24px; }
.ctx-icon .icon { width: 23px; height: 23px; }
.ctx-reactions .emoji-img { width: 30px; height: 30px; margin: 0; vertical-align: middle; }
.reaction .emoji-img { width: 18px; height: 18px; margin: 0; vertical-align: middle; }
.emoji .emoji-img { width: 30px; height: 30px; margin: 0; vertical-align: middle; }
.emoji-tabs button { display: grid; place-items: center; color: var(--muted); }
.emoji-tabs .emoji-img, .emoji-tabs .icon { width: 22px; height: 22px; margin: 0; }
.context-icon { color: var(--accent); display: grid; place-items: center; }
.pinned-icon { color: var(--accent); display: grid; place-items: center; }
.pinned-icon .icon { width: 20px; height: 20px; }
.att-icon .icon { width: 24px; height: 24px; }
.msg-actions button { display: grid; place-items: center; }
.msg-actions .icon { width: 18px; height: 18px; }
.viewer-nav { display: grid; place-items: center; }
.viewer-nav .icon { width: 30px; height: 30px; }
.profile-action .ctx-icon .icon { color: inherit; }
.modal-body > .profile-action { margin: 0 -8px 6px; width: calc(100% + 16px); border-radius: 10px; }
.chat-item-title .emoji-img, .chat-item-preview .emoji-img { width: 1.15em; height: 1.15em; vertical-align: -0.22em; }

/* ---------- голосовые сообщения ---------- */

.bubble.voice-bubble { width: 280px; max-width: 86%; }
.voice { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.voice-play {
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.msg.mine .voice-play { background: var(--meta-out); }
.voice-play .icon { width: 22px; height: 22px; }
.voice-play .icon .filled { fill: currentColor; }
.voice-body { flex: 1; min-width: 0; }
/* Волна сжимается под ширину пузыря и никогда не вылезает за его край. */
.voice-wave { position: relative; height: 24px; cursor: pointer; overflow: hidden; }
.wave-bars { position: absolute; inset: 0; display: flex; align-items: center; gap: 1.5px; }
.wave-bars span { flex: 1 1 0; max-width: 3px; min-width: 1px; border-radius: 2px; background: var(--muted); opacity: 0.45; }
.msg.mine .wave-bars span { background: var(--meta-out); }
.wave-bars.fill span { background: var(--accent); opacity: 1; }
.msg.mine .wave-bars.fill span { background: var(--meta-out); }
.voice-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 13px; color: var(--meta-in); }
.msg.mine .voice-meta { color: var(--meta-out); }
.voice-speed {
  border: 0;
  border-radius: 8px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(51, 144, 236, 0.15);
  color: var(--accent);
  cursor: pointer;
}
.msg.mine .voice-speed { background: rgba(79, 174, 78, 0.18); color: var(--meta-out); }
.voice-bubble > .meta { margin-top: -16px; }

/* ---------- кружки ---------- */

.bubble.round-only, .msg.mine .bubble.round-only { background: transparent; box-shadow: none; padding: 0; }
.bubble.round-only::before { display: none; }
.round {
  position: relative;
  width: min(240px, 62vw);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  transition: width 0.2s ease;
}
.round.playing { width: min(300px, 78vw); }
.round-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.round-progress { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.round-ring { fill: none; stroke: rgba(255, 255, 255, 0.85); stroke-width: 2.5; transition: stroke-dashoffset 0.25s linear; }
.round-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  pointer-events: none;
}
.round-play .icon { width: 44px; height: 44px; padding: 11px 9px 11px 13px; border-radius: 50%; background: rgba(0, 0, 0, 0.4); }
.round.playing .round-play { display: none; }
.round-time {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
}
.bubble.round-only > .meta {
  display: inline-block;
  float: right;
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
}
.bubble.round-only .tick { color: #fff; }

/* ---------- записи о звонках ---------- */

.bubble.call-bubble { min-width: 220px; }
.call-msg { display: flex; align-items: center; gap: 12px; }
.call-msg-text { flex: 1; min-width: 0; }
.call-msg-title { font-weight: 500; }
.call-msg-sub { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--online); }
.call-msg-sub.missed { color: var(--danger); }
.call-msg-sub .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.call-msg-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.msg.mine .call-msg-btn { color: var(--meta-out); }
.call-msg-btn:hover { background: var(--hover); }
.call-msg-btn .icon { width: 24px; height: 24px; }

/* ---------- запись голосового и кружка ---------- */

.send { touch-action: none; -webkit-touch-callout: none; position: relative; }
.composer { position: relative; }
.composer.recording .composer-field { visibility: hidden; }
.rec-root { position: absolute; inset: 0; pointer-events: none; }
.rec-bar {
  position: absolute;
  left: 8px;
  right: 64px;
  top: 6px;
  bottom: max(6px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--bubble-shadow);
  pointer-events: auto;
  overflow: hidden;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; opacity: 0.4; }
.rec-root.live .rec-dot { opacity: 1; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.rec-timer { font-variant-numeric: tabular-nums; min-width: 58px; }
.rec-hint { flex: 1; text-align: center; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap; }
.rec-hint .icon { width: 18px; height: 18px; }
.rec-cancel {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
  cursor: pointer;
}
.rec-lock {
  position: absolute;
  right: 12px;
  bottom: calc(100% + 34px);
  width: 40px;
  padding: 8px 0 4px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: pop 0.2s ease-out;
}
.rec-lock .icon { width: 20px; height: 20px; }
/* Кнопка записи увеличивается и «дышит» в такт голосу. */
.send.rec-active {
  z-index: 3;
  transform-origin: center;
  transition: none;
  box-shadow: 0 0 0 calc(var(--level, 0) * 26px) rgba(51, 144, 236, 0.22), var(--shadow);
  scale: 1.35;
}

.round-rec {
  position: fixed;
  inset: 0 0 calc(62px + env(safe-area-inset-bottom));
  z-index: 65;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  animation: fade 0.15s;
  pointer-events: none;
}
.round-rec-circle { position: relative; width: min(78vw, 340px); aspect-ratio: 1; margin-bottom: 30px; }
.round-canvas { width: 100%; height: 100%; border-radius: 50%; display: block; background: #000; }
.round-rec-progress { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); }
.round-rec-ring { fill: none; stroke: var(--accent); stroke-width: 1.6; transition: stroke-dashoffset 0.1s linear; }
.round-rec-flip {
  position: absolute;
  left: calc(50% - min(39vw, 170px));
  bottom: calc(50% - min(39vw, 170px) + 40px);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: pointer;
}
.round-rec-flip .icon { width: 24px; height: 24px; }

/* ---------- экран звонка ---------- */

.call-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #1d2733;
  color: #fff;
  overflow: clip;
  animation: fade 0.2s;
}
.call-screen.closing { opacity: 0; transition: opacity 0.25s; }
/* Размытая аватарка на фоне; увеличена, чтобы не было видно светлых краёв размытия. */
.call-backdrop { position: absolute; inset: 0; transform: scale(1.25); filter: blur(40px) brightness(0.55); }
.call-backdrop .avatar { width: 100%; height: 100%; border-radius: 0; font-size: 0; }
.call-backdrop .online-dot { display: none; }
.call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.3s;
}
.call-screen.remote-video .call-remote { opacity: 1; }
.call-screen.remote-screen .call-remote { object-fit: contain; }
.call-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 8px 8px;
  z-index: 2;
}
.call-top-title { opacity: 0.7; font-size: 15px; }
.call-info {
  position: absolute;
  top: 16%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 0 16px;
  z-index: 1;
  transition: top 0.3s, transform 0.3s;
}
.call-info .online-dot { display: none; }
.call-name { font-size: 26px; font-weight: 500; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.call-status { font-size: 16px; opacity: 0.85; font-variant-numeric: tabular-nums; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
/* Когда видно собеседника, имя уезжает наверх и уменьшается. */
.call-screen.remote-video .call-info { top: max(48px, calc(env(safe-area-inset-top) + 40px)); }
.call-screen.remote-video .call-info .avatar { display: none; }
.call-screen.remote-video .call-name { font-size: 18px; }
.call-peer-muted {
  position: absolute;
  left: 50%;
  bottom: 170px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 14px;
  z-index: 2;
  white-space: nowrap;
}
.call-peer-muted .icon { width: 18px; height: 18px; }
.call-local {
  position: absolute;
  right: 12px;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  width: 110px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 3;
  touch-action: none;
  cursor: grab;
}
.call-local.mirror { transform: scaleX(-1); }
.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 24px 12px max(28px, calc(env(safe-area-inset-bottom) + 16px));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.45));
  z-index: 2;
  flex-wrap: wrap;
}
.call-btn {
  border: 0;
  background: transparent;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  width: 72px;
  font-size: 13px;
}
.call-btn-circle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.15s, transform 0.1s;
}
.call-btn:active .call-btn-circle { transform: scale(0.92); }
.call-btn.on .call-btn-circle { background: #fff; color: #1d2733; }
.call-btn.off .call-btn-circle { background: rgba(255, 255, 255, 0.18); }
.call-btn.danger .call-btn-circle { background: #e53935; color: #fff; }
.call-btn.accept .call-btn-circle { background: #4fae4e; color: #fff; }
.call-btn.accept .call-btn-circle { animation: ring-pulse 1.4s infinite; }
@keyframes ring-pulse { 0% { box-shadow: 0 0 0 0 rgba(79, 174, 78, 0.6); } 100% { box-shadow: 0 0 0 18px rgba(79, 174, 78, 0); } }
.call-btn-circle .icon { width: 27px; height: 27px; }
.call-btn.hangup .icon { transform: rotate(135deg); }
.call-btn-label { opacity: 0.9; white-space: nowrap; }

.call-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(36px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  z-index: 85;
  border: 0;
  background: #4fae4e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.call-bar .icon { width: 18px; height: 18px; }
body.has-call-bar #app { padding-top: calc(36px + env(safe-area-inset-top)); }

.profile-call-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: center; flex-wrap: wrap; }
.profile-call-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.profile-call-actions .icon { width: 20px; height: 20px; }
button.doc-row { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; }

/* ---------- телефоны ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    border-right: 0;
    transition: transform var(--t-slide) var(--ease);
  }
  .chat-pane {
    position: absolute;
    inset: 0;
    z-index: 5;
    transform: translateX(100%);
    transition: transform var(--t-slide) var(--ease);
    box-shadow: -6px 0 18px rgba(0, 0, 0, 0.18);
  }
  body.show-chat .chat-pane { transform: translateX(0); }
  body.show-chat .sidebar { transform: translateX(-25%); }
  body.show-chat .sidebar::after { opacity: var(--dim, 0.3); }
  .chat-pane.dragging, .sidebar.dragging { transition: none; }
  .chat-head .back { display: inline-grid; }
  .bubble { max-width: 86%; }
  .bubble:has(.album) { width: 86%; }
  .msg-actions { display: none; }

  /* Окна на телефоне выезжают снизу. */
  .overlay { padding: 0 0 var(--kb, 0px); align-items: end; }
  .modal, .modal.wide {
    max-width: none;
    max-height: 92%;
    border-radius: 16px 16px 0 0;
    animation: sheet var(--t-slide) var(--ease);
  }
  .overlay.closing .modal { transform: translateY(100%); transition: transform 0.22s ease-in; }
}
@keyframes sheet {
  from { transform: translateY(100%); }
  to { transform: none; }
}

/* ---------- меню вложений ---------- */

.attach-overlay {
  position: fixed;
  inset: 0;
  z-index: 72;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  transition: background var(--t-slide) var(--ease);
}
.attach-overlay.open { background: rgba(0, 0, 0, 0.4); }
.attach-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: min(78vh, 640px);
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--t-slide) var(--ease);
  overflow: hidden;
}
.attach-overlay.open .attach-sheet { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--muted); opacity: 0.5; margin: 8px auto 6px; flex: none; }
.attach-body { flex: 1; overflow-y: auto; min-height: 0; padding: 0 4px; }
.attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.attach-tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 6px;
}
.attach-tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.18s var(--ease); }
.attach-tile.picked img { transform: scale(0.86); border-radius: 8px; }
.attach-tile.camera, .attach-tile.all { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; font-size: 13px; }
.attach-tile.camera .icon, .attach-tile.all .icon { width: 30px; height: 30px; }
.attach-tile.camera { background: #222; color: #fff; }
.attach-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.attach-tile.picked .attach-check { background: var(--accent); border-color: var(--accent); animation: pop 0.16s var(--ease); }
.attach-dur { position: absolute; left: 6px; bottom: 6px; font-size: 12px; color: #fff; background: rgba(0, 0, 0, 0.45); border-radius: 8px; padding: 1px 6px; }
.attach-note { grid-column: 1 / -1; padding: 16px; text-align: center; }
.attach-list { padding: 4px 4px 12px; }
.attach-list .user-item { padding: 8px 12px; }
.attach-tabs {
  flex: none;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.attach-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
}
.attach-tab-icon { width: 52px; height: 30px; border-radius: 15px; display: grid; place-items: center; transition: background 0.18s; }
.attach-tab.on { color: var(--accent); }
.attach-tab.on .attach-tab-icon { background: rgba(51, 144, 236, 0.16); }
.attach-send {
  position: absolute;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  animation: pop 0.18s var(--ease);
}
.attach-send-count {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--panel);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
}

/* Карточка контакта в ленте. */
.contact-card { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0 4px; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 500; }
.contact-login { color: var(--accent); }
.msg.mine .contact-login { color: var(--quote-out); }
.contact-btn { border: 0; border-radius: 14px; padding: 6px 12px; background: rgba(51, 144, 236, 0.14); color: var(--accent); font-weight: 500; cursor: pointer; }
.msg.mine .contact-btn { background: rgba(79, 174, 78, 0.18); color: var(--quote-out); }
.bubble:has(> .contact-card) > .meta { position: static; }

/* На сенсорном экране долгое нажатие на сообщение выделяет его, а не текст. */
@media (pointer: coarse) {
  .messages { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Панель едет за пальцем при жесте «смахнуть, чтобы закрыть». */
.profile-panel.dragging, .drawer.dragging, .attach-sheet.dragging { transition: none !important; }
/* Удалённое сообщение схлопывается, соседние плавно встают на его место. */
.msg.removing { height: 0 !important; padding-top: 0; opacity: 0; transform: scale(0.92); transition: height 0.2s var(--ease), padding 0.2s var(--ease), opacity 0.16s, transform 0.2s var(--ease); }
/* «Обновления G-Chat»: вместо поля ввода — кнопка звука, как у канала в Telegram. */
.channel-bar {
  border: 0;
  background: var(--panel, var(--bg));
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  cursor: pointer;
}

/* Загрузка голосовых и кружков: кольцо заполняется вокруг кнопки, как в Telegram. */
.load-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; opacity: 0; transition: opacity 0.2s; }
.load-ring-arc { fill: none; stroke: currentColor; stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.voice-play { position: relative; }
.voice-play-icon { display: grid; place-items: center; }
.voice-play.loading .load-ring { opacity: 1; animation: ring-spin 1.4s linear infinite; }
.voice-play.loading .voice-play-icon { opacity: 0.55; transform: scale(0.8); }
@keyframes ring-spin { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }
.round-video { opacity: 0; transition: opacity 0.25s; }
.round.ready .round-video { opacity: 1; }
.round:not(.ready) { background: linear-gradient(145deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.2)); }
.round-load {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: none;
  place-items: center;
  pointer-events: none;
}
.round-load .icon { width: 22px; height: 22px; }
.round.loading .round-load { display: grid; }
.round.loading .round-load .load-ring { opacity: 1; animation: ring-spin 1.4s linear infinite; }
.round.loading .round-play { display: none; }

/* Отправляемые фото и файлы: кольцо загрузки поверх превью или на месте значка файла. */
.msg.pending .att-image, .msg.pending .album { position: relative; }
.msg.pending .album-cell img, .msg.pending .album-cell video, .msg.pending .att-image img { filter: brightness(0.85); }
.upload-progress {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  pointer-events: none;
}
.upload-progress .load-ring { opacity: 1; animation: ring-spin 1.4s linear infinite; }
.att-icon { position: relative; }
.att-icon .upload-progress { inset: 0; left: 0; top: 0; width: 100%; height: 100%; margin: 0; background: var(--accent); }
.msg.mine .att-icon .upload-progress { background: var(--meta-out); }
.attach-caption { padding: 6px 12px 0; }
.attach-caption-input {
  width: 100%;
  border: 0;
  outline: none;
  border-radius: 20px;
  padding: 10px 16px;
  font: inherit;
  font-size: 16px;
  background: var(--hover);
  color: var(--text);
}
.attach-section { padding: 10px 16px 4px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }

/* Меню выбора звука поверх экрана звонка. */
body:has(.call-screen) .ctx-overlay { z-index: 95; }
