/* ═══════════════════════════════════════════════
   REDIE — веб-мессенджер
   ═══════════════════════════════════════════════ */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #efe8e6;
  /* Фон чата — приглушённый, с лёгким «кровавым» дождем */
  --bg-chat: #b0a09c;
  --bg-chat-pattern: url("data:image/svg+xml,%3Csvg width='80' height='80' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='8' cy='8' r='1.2' fill='%235c1a22' fill-opacity='.07'/%3E%3Ccircle cx='48' cy='40' r='1' fill='%235c1a22' fill-opacity='.055'/%3E%3C/svg%3E");
  --bg-sidebar: #ffffff;
  --bg-input: #ebe2e0;
  --bg-hover: #e8dedc;
  --bg-active: #7a121c22;
  /* Исходящие / входящие — тёмнее, бордово-розовые */
  --bg-msg-out: #e4b8c2;
  --bg-msg-in: #ffffff;
  --bg-msg-out-hover: #d9a0ad;
  --bg-msg-in-hover: #efe6e4;
  --msg-bubble-shadow: 0 1px 2px rgba(50, 12, 18, 0.14);
  --text-primary: #141010;
  --text-secondary: #5c4a4a;
  --text-link: #7a1018;
  --text-msg-time: #6b3038;
  --text-msg-time-in: #756563;
  --msg-read-check: #a83242;
  --accent: #7a121c;
  --accent-hover: #5c0e15;
  --accent-light: #7a121c28;
  --green: #2e7d32;
  --border: #ddd0d0;
  --shadow: 0 1px 2px rgba(20, 8, 10, 0.12);
  --shadow-lg: 0 2px 8px rgba(20, 8, 10, 0.16);
  --radius: 10px;
  --radius-lg: 16px;
  --msg-radius: 12px;
  --sidebar-width: 420px;
  --header-height: 56px;
  --transition: .2s ease;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --msg-font-size: 15px;
  --voice-accent: #7a121c;
  --voice-bar-bg: #a89896;
  --voice-bar-played: #7a121c;
  --msg-select-border: #9e6a72;
  --msg-select-bg: rgba(255, 248, 248, 0.94);
}

[data-theme="dark"] {
  --bg-primary: #161212;
  --bg-secondary: #0f0c0c;
  --bg-chat: #1f1818;
  --bg-chat-pattern: url("data:image/svg+xml,%3Csvg width='80' height='80' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='10' cy='10' r='1' fill='%23c62828' fill-opacity='.045'/%3E%3C/svg%3E");
  --bg-sidebar: #161212;
  --bg-input: #261f1f;
  --bg-hover: #2a2222;
  --bg-active: #8b1c262e;
  --bg-msg-out: #3d1c22;
  --bg-msg-in: #1c1616;
  --bg-msg-out-hover: #4e252c;
  --bg-msg-in-hover: #241d1d;
  --msg-bubble-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
  --text-primary: #ede5e4;
  --text-secondary: #9a8585;
  --text-link: #e85a5a;
  --text-msg-time: #c08088;
  --text-msg-time-in: #8a7878;
  --msg-read-check: #e8707a;
  --accent: #b71c28;
  --accent-hover: #d12a36;
  --accent-light: #b71c2830;
  --green: #5a9e5e;
  --border: #332828;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --shadow-lg: 0 2px 8px rgba(0,0,0,.5);
  --voice-bar-bg: #3d3232;
  --voice-bar-played: #e05058;
  --msg-select-border: rgba(180, 90, 98, 0.35);
  --msg-select-bg: rgba(28, 20, 20, 0.97);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; font-size: inherit; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; opacity: .4; }
::-webkit-scrollbar-thumb:hover { opacity: .7; }

/* ═══ THEME TRANSITION — View Transition API ═══ */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) {
  z-index: 1;
}
::view-transition-new(root) {
  z-index: 9999;
}

/* ═══ THEME TRANSITION OVERLAY (fallback) ═══ */
.theme-transition-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10000;
  pointer-events: none;
  clip-path: circle(0px at var(--x, 50%) var(--y, 50%));
  transition: none;
  opacity: 1;
}
.theme-transition-overlay.expanding {
  clip-path: circle(var(--r, 2000px) at var(--x, 50%) var(--y, 50%));
  transition: clip-path 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
}
.theme-transition-overlay.collapsing {
  clip-path: circle(var(--r, 2000px) at var(--x, 50%) var(--y, 50%));
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* ═══ AUTH SCREEN ═══ */
/* Есть сохранённый токен: не мигать формой входа до проверки сессии (класс ставит скрипт в index.html) */
html.session-bootstrap #auth-screen {
  display: none !important;
}
/* Каркас мессенджера не показываем — только заставка с логотипом (как на экране входа) */
html.session-bootstrap #app.app.hidden {
  display: none !important;
}
#app-boot-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: max(12px, env(safe-area-inset-top, 0px)) 16px max(12px, env(safe-area-inset-bottom, 0px));
  background: var(--bg-primary);
  animation: fadeIn 0.35s ease;
  transition: opacity 0.28s ease;
}
html.session-bootstrap #app-boot-splash.app-boot-splash--hiding {
  opacity: 0;
  pointer-events: none;
}
html.session-bootstrap #app-boot-splash {
  display: flex !important;
}
.app-boot-splash-inner {
  text-align: center;
  max-width: 360px;
}
html.session-bootstrap #app-boot-splash .auth-logo {
  margin-bottom: 10px;
}
html.session-bootstrap #app-boot-splash .auth-title {
  margin: 0;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  background: var(--bg-primary);
  animation: fadeIn .3s ease;
}
/* Вертикальное центрирование, когда форма ниже экрана; при переполнении — скролл с верха */
.auth-screen::before,
.auth-screen::after {
  content: '';
  flex: 1 1 0;
  min-height: 6px;
  width: 100%;
  max-width: 100%;
  pointer-events: none;
}
.auth-container {
  flex: 0 0 auto;
  text-align: center;
  padding: 28px 20px;
  max-width: 360px;
  width: 100%;
}
@media (min-width: 480px) {
  .auth-container {
    padding: 40px 24px;
  }
}
.auth-brand {
  margin-bottom: 8px;
}
.auth-logo {
  width: 168px;
  height: 168px;
  margin: 0 auto 10px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}
.auth-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.auth-title {
  margin: 0;
  font-family: 'Pirata One', fantasy;
  font-size: clamp(2.25rem, 9vw, 3.2rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.12;
  color: #3d060c;
  text-shadow:
    0 0 22px rgba(100, 0, 24, 0.5),
    0 0 42px rgba(60, 0, 12, 0.28),
    0 2px 0 #1a0006,
    0 3px 8px rgba(0, 0, 0, 0.65);
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .auth-title {
    background: linear-gradient(
      180deg,
      #e84855 0%,
      #a81422 28%,
      #5c0a12 62%,
      #1a0306 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter:
      drop-shadow(0 0 12px rgba(160, 20, 40, 0.5))
      drop-shadow(0 0 28px rgba(90, 0, 20, 0.38))
      drop-shadow(0 3px 5px rgba(0, 0, 0, 0.9));
  }
}
[data-theme="dark"] .auth-title {
  color: #c87882;
  text-shadow:
    0 0 26px rgba(200, 40, 55, 0.45),
    0 0 48px rgba(120, 20, 30, 0.25),
    0 2px 0 #280008,
    0 3px 10px rgba(0, 0, 0, 0.85);
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  [data-theme="dark"] .auth-title {
    background: linear-gradient(
      180deg,
      #e898a0 0%,
      #d42840 32%,
      #7a1020 72%,
      #240810 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter:
      drop-shadow(0 0 14px rgba(220, 60, 75, 0.42))
      drop-shadow(0 0 32px rgba(120, 30, 40, 0.3))
      drop-shadow(0 2px 8px rgba(0, 0, 0, 0.95));
  }
}
.auth-subtitle { color: var(--text-secondary); margin: 0 0 32px; font-size: 15px; }
.auth-label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  margin: 10px 0 6px;
  color: var(--text-secondary);
}
.auth-hint { font-size: 13px; color: var(--text-secondary); margin: 0 0 14px; line-height: 1.45; text-align: left; }
.auth-switch { text-align: center; margin-top: 18px; margin-bottom: 0; }
.auth-link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 6px 8px; font-family: inherit; position: relative; z-index: 2; }
.auth-link-btn:hover { text-decoration: underline; }
.auth-screen .auth-switch { position: relative; z-index: 2; }
[data-theme="dark"] .auth-link-btn { color: var(--text-link); }
.user-id-mono { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.user-item-id { font-weight: 500; }
.group-member-id { display: block; font-size: 12px; color: var(--text-secondary); margin: 2px 0 4px; }
.input-group { margin-bottom: 16px; }
.input-group input {
  width: 100%; padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
  transition: border-color var(--transition);
  outline: none;
}
.input-group input:focus { border-color: var(--accent); }
.auth-form .input-group input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}
.btn-primary {
  width: 100%; padding: 14px;
  background: var(--accent);
  color: var(--on-accent, #fff);
  font-size: 16px; font-weight: 600;
  border: none; border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-danger {
  padding: 10px 20px;
  border-radius: var(--radius);
  background: #e53935;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}
.btn-danger:hover { filter: brightness(1.06); }
.btn-block { width: 100%; display: block; margin-bottom: 10px; box-sizing: border-box; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══ MAIN APP LAYOUT ═══ */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  background: var(--bg-primary);
}

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}
.sidebar-header {
  height: var(--header-height);
  padding: 0 8px 0 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 20px;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.small { width: 32px; height: 32px; font-size: 18px; }

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: 22px;
  padding: 0 12px;
  height: 40px;
  gap: 8px;
}
.search-box i { color: var(--text-secondary); font-size: 18px; flex-shrink: 0; }
.search-box input {
  flex: 1; border: none; background: none; outline: none;
  color: var(--text-primary); font-size: 14px;
}
.search-box input::placeholder { color: var(--text-secondary); }

/* ═══ CHAT LIST ═══ */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.chat-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 12px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item.active .chat-item-name { color: var(--accent); }
.chat-item-pinned { box-shadow: inset 3px 0 0 var(--accent); }

.chat-item-avatar {
  width: 54px; height: 54px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600;
  color: #fff;
  position: relative;
  /* visible: иначе круглый клип срезает точку «онлайн» в углу */
  overflow: visible;
}
.chat-item-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.avatar-online {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: var(--green);
  border: 2px solid var(--bg-sidebar);
  border-radius: 50%;
  z-index: 2;
  box-sizing: content-box;
  pointer-events: none;
}

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.chat-item-name {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
  min-width: 0;
}
.chat-item-time { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.chat-item-bottom { display: flex; align-items: center; justify-content: space-between; }
.chat-item-preview-row {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  margin-right: 8px;
  gap: 4px;
}
.chat-item-preview {
  font-size: 14px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.chat-item-preview-row .chat-item-preview {
  margin-right: 0;
}
.chat-item-out-status {
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1;
  margin-left: 1px;
}
.chat-item-out-status.message-check-single {
  color: var(--text-secondary);
  opacity: 0.88;
}
.chat-item-out-status.message-check.read {
  color: var(--msg-read-check);
}
.chat-item-preview .sender { color: var(--accent); font-weight: 500; }
.chat-item-badges {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.chat-item-badge {
  min-width: 22px; height: 22px;
  padding: 0 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 11px;
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-item-badge.mention {
  min-width: 22px;
  padding: 0 7px;
  background: var(--accent);
}
/* Muted chat: серые счётчики */
.chat-item-badge.muted {
  background: #9aa7b2;
  color: #fff;
}
html[data-theme="dark"] .chat-item-badge.muted {
  background: #5e6b78;
  color: rgba(255, 255, 255, 0.95);
}
.chat-item-typing { color: var(--accent); font-style: italic; }

.fab {
  position: absolute;
  bottom: 20px; right: 20px;
  width: 56px; height: 56px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: var(--shadow-lg);
  transition: background var(--transition), transform var(--transition);
  z-index: 5;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.05); }

.compose-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.22);
}
/* Привязка к сайдбару (как у FAB), а не к правому краю окна */
.compose-sheet {
  position: absolute;
  left: auto;
  top: auto;
  right: 20px;
  bottom: calc(20px + 56px + 10px);
  z-index: 45;
  min-width: 232px;
  max-width: min(320px, calc(100% - 40px));
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.compose-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-primary);
  text-align: left;
  font-family: inherit;
}
.compose-sheet-item:hover { background: var(--bg-hover); }
.compose-sheet-item i { font-size: 20px; color: var(--accent); flex-shrink: 0; }

.search-message-hit {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-message-hit:hover { background: var(--bg-hover); }
.search-message-hit-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.search-message-hit-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.search-message-hit-body {
  flex: 1;
  min-width: 0;
}
.search-message-hit-chat {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.search-message-hit-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.35;
}

/* ═══ SLIDE MENU ═══ */
.slide-menu-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
  transition: opacity var(--transition);
}
.slide-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: min(300px, calc(100vw - 24px));
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg-sidebar);
  z-index: 100;
  transform: translate3d(-100%, 0, 0);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  box-shadow: var(--shadow-lg);
  padding-top: env(safe-area-inset-top, 0);
  box-sizing: border-box;
  will-change: transform;
  overflow-x: hidden;
  overflow-y: auto;
}
.slide-menu.open {
  transform: translate3d(0, 0, 0);
}
.slide-menu-header {
  padding: 16px 16px 12px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
  flex-shrink: 0;
}
.slide-menu-profile-area {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  cursor: pointer;
  padding: 4px;
  border-radius: 10px;
  transition: background .15s;
}
.slide-menu-profile-area:hover { background: rgba(255,255,255,.15); }
.slide-menu-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600;
  background: rgba(255,255,255,.2);
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.slide-menu-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.slide-menu-user { flex: 1; min-width: 0; }
.slide-menu-name {
  font-size: 16px;
  font-weight: 600;
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slide-menu-header .icon-btn { color: #fff; flex-shrink: 0; }
.slide-menu-header .icon-btn:hover { background: rgba(255,255,255,.15); }
/* Без flex:1 — иначе на мобильных список растягивается на всю высоту и F.A.Q «уезжает» вниз */
.slide-menu-items {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.slide-menu-items li {
  padding: 12px 24px;
  display: flex; align-items: center; gap: 20px;
  font-size: 15px;
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text-primary);
  flex: 0 0 auto;
}
.slide-menu-items li:hover { background: var(--bg-hover); }
.slide-menu-items li i { font-size: 22px; color: var(--text-secondary); width: 24px; text-align: center; }

.slide-menu-divider {
  height: 0;
  margin: 8px 20px;
  padding: 0 !important;
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  cursor: default !important;
  pointer-events: none;
  list-style: none;
  flex: 0 0 auto;
}
/* Иначе min-height с touch-целей на всех li превращает разделитель в «пустой» блок ~48px */
.slide-menu-items li.slide-menu-divider {
  min-height: 0;
}
.slide-menu-items li[data-action="faq"] {
  margin-top: 0;
}
html[data-theme="dark"] .slide-menu-divider {
  border-top-color: rgba(0, 0, 0, 0.45);
}

/* ═══ CHAT AREA ═══ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
  background-image: var(--bg-chat-pattern);
  position: relative;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 16px;
}
.empty-state i { font-size: 72px; opacity: .3; }
.empty-state p { font-size: 16px; }

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Chat Header */
.chat-header {
  min-height: var(--header-height);
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}
.chat-header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--header-height);
  padding: 0 8px;
  flex-shrink: 0;
}
.chat-header-spacer { flex: 1; min-width: 0; }
.chat-selection-count {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.chat-selection-forward-btn,
.chat-selection-delete-btn {
  color: var(--accent);
}
.chat-selection-forward-btn:hover,
.chat-selection-delete-btn:hover {
  background: var(--bg-hover);
}
.chat-view.message-selection-active .chat-input-area,
.chat-view.message-selection-active .reply-preview,
.chat-view.message-selection-active .edit-preview,
.chat-view.message-selection-active .attachment-draft-bar {
  display: none !important;
}
.chat-header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
}
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
/* «Избранное»: фон и иконка следуют акценту темы / пользовательскому стилю */
.chat-item-avatar.saved-chat-avatar,
.chat-header-avatar.saved-chat-avatar {
  background: var(--accent);
  color: var(--on-accent);
}
.chat-item-avatar.saved-chat-avatar > i {
  font-size: 24px;
  line-height: 1;
  color: inherit;
}
.chat-header-avatar.saved-chat-avatar > i {
  font-size: 18px;
  line-height: 1;
  color: inherit;
}
.chat-header-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header-name {
  display: block;
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-status {
  display: block;
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-status.online { color: var(--accent); }
.chat-header-actions { display: flex; gap: 2px; }

/* Активное аудио под шапкой чата (компактно: десктоп + моб.) */
.chat-media-bar {
  flex-shrink: 0;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  /* Выше .chat-header (5), иначе меню режимов (выше кнопки) рисуется под шапкой и «не работает» */
  z-index: 6;
  overflow: visible;
  --cmb-art: 36px;
  --cmb-play: 34px;
  --cmb-step: 30px;
  --cmb-side: 32px;
}
.chat-media-bar.hidden {
  display: none !important;
}
.chat-media-bar-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  min-height: 46px;
  box-sizing: border-box;
  touch-action: manipulation;
  overflow: visible;
}
.chat-media-bar-transport {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.chat-media-bar-step {
  width: var(--cmb-step);
  height: var(--cmb-step);
  min-width: var(--cmb-step);
  min-height: var(--cmb-step);
  border-radius: 50%;
  color: var(--text-secondary);
  padding: 0;
}
.chat-media-bar-step:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-media-bar-step:disabled {
  opacity: 0.35;
  pointer-events: none;
}
.chat-media-bar-step i {
  font-size: 16px;
}
.chat-media-bar-playback-wrap {
  position: relative;
  flex-shrink: 0;
}
.chat-media-bar-playback-btn {
  width: var(--cmb-side);
  height: var(--cmb-side);
  min-width: var(--cmb-side);
  min-height: var(--cmb-side);
  padding: 0;
  color: var(--text-secondary);
}
.chat-media-bar-playback-btn i {
  font-size: 17px;
}
.chat-media-bar-playback-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-media-bar-playlist-toggle {
  flex-shrink: 0;
  width: var(--cmb-side);
  height: var(--cmb-side);
  min-width: var(--cmb-side);
  min-height: var(--cmb-side);
  padding: 0;
  color: var(--text-secondary);
}
.chat-media-bar-playlist-toggle i {
  font-size: 17px;
}
.chat-media-bar-playlist-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-media-bar-list-wrap {
  border-top: 1px solid var(--border);
  padding: 2px 4px 6px;
  max-height: min(200px, 34vh);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-media-bar-list-wrap.chat-media-bar-list-wrap--collapsed {
  display: none !important;
}
.chat-media-bar-list {
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  -webkit-overflow-scrolling: touch;
}
.chat-media-bar-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  box-sizing: border-box;
  touch-action: manipulation;
}
.chat-media-bar-list-item:hover {
  background: var(--bg-hover);
}
.chat-media-bar-list-item.active {
  background: var(--bg-active);
}
.chat-media-bar-list-kind {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 12px;
}
[data-theme="dark"] .chat-media-bar-list-kind {
  background: rgba(255, 255, 255, 0.08);
}
.chat-media-bar-list-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.chat-media-bar-list-title {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}
.chat-media-bar-list-sub {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.chat-media-bar-list-sub:empty {
  display: none;
}
.chat-media-bar-art {
  position: relative;
  width: var(--cmb-art);
  height: var(--cmb-art);
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.1));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
[data-theme="dark"] .chat-media-bar-art {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.chat-media-bar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.chat-media-bar-img.hidden {
  display: none !important;
}
.chat-media-bar-art-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--accent);
}
.chat-media-bar-art-fallback.hidden {
  display: none !important;
}
.chat-media-bar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chat-media-bar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.22;
}
.chat-media-bar-sub {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.chat-media-bar-sub:empty {
  display: none;
}
.chat-media-bar-progress-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  cursor: pointer;
  touch-action: none;
}
.chat-media-bar-progress-track {
  flex: 1;
  min-width: 0;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.1);
  overflow: hidden;
}
[data-theme="dark"] .chat-media-bar-progress-track {
  background: rgba(255, 255, 255, 0.12);
}
.chat-media-bar-progress {
  height: 100%;
  width: 0;
  max-width: 100%;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
  transition: width 0.22s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.chat-media-bar-times {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chat-media-bar-sep {
  margin: 0 1px;
  opacity: 0.7;
}
.chat-media-bar-play {
  flex-shrink: 0;
  width: var(--cmb-play);
  height: var(--cmb-play);
  min-width: var(--cmb-play);
  min-height: var(--cmb-play);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  padding: 0;
}
.chat-media-bar-play:hover {
  background: var(--accent-hover);
  color: #fff;
}
.chat-media-bar-play i {
  font-size: 17px;
}
.chat-media-bar-close {
  flex-shrink: 0;
  width: var(--cmb-side);
  height: var(--cmb-side);
  min-width: var(--cmb-side);
  min-height: var(--cmb-side);
  padding: 0;
  color: var(--text-secondary);
}
.chat-media-bar-close i {
  font-size: 18px;
}

/* Chat Search Bar */
.chat-search-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}
.chat-search-bar input {
  flex: 1; padding: 8px 12px;
  border: none; background: var(--bg-input);
  border-radius: 20px; outline: none;
  color: var(--text-primary);
}
.chat-search-bar span { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

.chat-search-hits {
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.chat-search-hits.hidden { display: none; }
.chat-search-hits-note {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}
.chat-search-hit-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.chat-search-hit-row:last-child { border-bottom: none; }
.chat-search-hit-row:hover,
.chat-search-hit-row.active {
  background: var(--bg-hover);
}
.chat-search-hit-row-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.chat-search-hit-row-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-search-hit-row-body {
  flex: 1;
  min-width: 0;
}
.chat-search-hit-row-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: background var(--transition);
}
.chat-pinned-bar:hover {
  background: var(--bg-hover);
}
.chat-pinned-bar-ic {
  flex-shrink: 0;
  font-size: 16px;
  color: var(--accent);
}
.chat-pinned-bar-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-pinned-bar-meta {
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-pinned-bar-text {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ═══ MESSAGES ═══ */
/* Обёртка: кнопка «вниз» не внутри overflow — иначе bottom привязывается к высоте всего чата */
.messages-area-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}
.messages-container {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.messages-list {
  display: flex;
  flex-direction: column;
  padding: 6px 0 10px;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}

.date-separator {
  text-align: center;
  padding: 10px 0 6px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.date-separator span {
  display: inline-block;
  padding: 4px 11px 5px;
  background: rgba(0, 0, 0, 0.22);
  color: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.25;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
[data-theme="dark"] .date-separator span {
  background: rgba(0, 0, 0, 0.4);
}

.message-wrapper {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: stretch;
  padding: 1px 11px 1px 13px;
}
/* Анимация только у новых сообщений (не при полной перерисовке всего чата) */
.message-wrapper.message-enter {
  animation: msgIn 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}
/* Чекбокс сразу слева от пузыря, блок целиком у края */
.message-wrapper-cluster {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}
.message-wrapper.in .message-wrapper-cluster {
  margin-right: auto;
}
.message-wrapper.out .message-wrapper-cluster {
  margin-left: auto;
}
.message-wrapper-content {
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(420px, calc(100vw - 52px));
  display: flex;
  align-items: flex-end;
}
.message-wrapper.out .message-wrapper-content {
  justify-content: flex-end;
}
.message-wrapper.in .message-wrapper-content {
  justify-content: flex-start;
}
.message-wrapper.in.message-group-in .message-wrapper-content {
  display: block;
  max-width: min(420px, calc(100vw - 52px));
}
.chat-view.message-selection-active .message-wrapper-content {
  max-width: min(420px, calc(100vw - 52px - 30px));
}
.chat-view.message-selection-active .message-wrapper.in.message-group-in .message-wrapper-content {
  max-width: min(420px, calc(100vw - 52px - 30px));
}
.message-select-cell {
  display: none;
  position: relative;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  margin-bottom: 5px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chat-view.message-selection-active .message-select-cell {
  display: flex;
}
.message-select-cell input.message-select-check {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.message-select-visual {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-sizing: border-box;
  border: 2px solid var(--msg-select-border);
  background: var(--msg-select-bg);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.06);
}
.message-select-cell input.message-select-check:checked + .message-select-visual {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}
.message-select-cell input.message-select-check:checked + .message-select-visual::after {
  content: '';
  width: 4.5px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-0.5px, -1px);
  border-radius: 0.5px;
}
.message-select-cell input.message-select-check:focus-visible + .message-select-visual {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[data-theme="dark"] .message-select-visual {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.message-wrapper.msg-pos-single,
.message-wrapper.msg-pos-first {
  padding-top: 3px;
}
.message-wrapper.msg-pos-last {
  padding-bottom: 3px;
}
.message-wrapper.in.message-group-in {
  padding-left: 0;
  padding-right: 8px;
}
.message-group-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}
.message-avatar-col {
  width: 36px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 4px;
}
.message-avatar-spacer {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.message-sender-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--bg-input);
}
.message-sender-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.message-bubble-col {
  flex: 1;
  min-width: 0;
  max-width: min(420px, 76vw);
}
.message-wrapper.in.message-group-in .message-bubble {
  max-width: 100%;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-bubble {
  max-width: min(420px, calc(100vw - 88px));
  min-width: 56px;
  padding: 4px 9px 5px 11px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.412;
  cursor: default;
  transition: background .12s ease, box-shadow .12s ease;
  box-shadow: var(--msg-bubble-shadow);
  display: flow-root;
}
/* Одиночное сообщение и верх цепочки */
.message-wrapper.out.msg-pos-single .message-bubble,
.message-wrapper.out.msg-pos-first .message-bubble {
  background: var(--bg-msg-out);
  border-radius: 12px 12px 4px 12px;
}
.message-wrapper.out.msg-pos-mid .message-bubble {
  background: var(--bg-msg-out);
  border-radius: 4px 12px 4px 12px;
}
.message-wrapper.out.msg-pos-last .message-bubble {
  background: var(--bg-msg-out);
  border-radius: 4px 12px 12px 4px;
}
.message-wrapper.in.msg-pos-single .message-bubble,
.message-wrapper.in.msg-pos-first .message-bubble {
  background: var(--bg-msg-in);
  border-radius: 12px 12px 12px 4px;
}
.message-wrapper.in.msg-pos-mid .message-bubble {
  background: var(--bg-msg-in);
  border-radius: 12px 4px 4px 12px;
}
.message-wrapper.in.msg-pos-last .message-bubble {
  background: var(--bg-msg-in);
  border-radius: 4px 4px 12px 12px;
}
.message-wrapper.out .message-bubble:hover { background: var(--bg-msg-out-hover); }
.message-wrapper.in .message-bubble:hover { background: var(--bg-msg-in-hover); }

.message-sender {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin: 1px 0 3px;
  letter-spacing: -0.01em;
}
button.message-sender {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
button.message-sender:hover {
  text-decoration: underline;
}
.message-reply {
  padding: 5px 8px 5px 10px;
  margin: 0 0 4px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  cursor: pointer;
}
[data-theme="dark"] .message-reply { background: rgba(255, 255, 255, 0.06); }
.message-reply-name { font-size: 13px; font-weight: 600; color: var(--accent); display: block; line-height: 1.25; }
.message-reply-text {
  font-size: 14px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: min(280px, 70vw); display: block; margin-top: 1px;
}

.message-text {
  font-size: var(--msg-font-size, 15px);
  white-space: pre-wrap;
  letter-spacing: -0.011em;
  line-height: 1.412;
}
.message-text a { color: var(--text-link); text-decoration: none; }
.message-text a:hover { text-decoration: underline; }
.message-text a.msg-mention,
.message-text a.msg-mention-name { color: var(--accent); font-weight: 500; }

.message-file { margin: 4px 0; }
/* Медиа сверху, аудио снизу */
.message-file-album-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(320px, 85vw);
}
.message-file-album-wrap > .message-file-album:first-child {
  max-width: min(280px, 72vw);
  align-self: flex-start;
}
.message-file-album {
  display: grid;
  gap: 3px;
  max-width: min(280px, 72vw);
  border-radius: 10px;
  overflow: hidden;
}
.message-file-album.album-audio-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(320px, 85vw);
}
.message-file-album.album-audio-stack .message-file-album-cell {
  width: 100%;
}
.message-file-album-cell {
  min-width: 0;
  overflow: hidden;
}
.message-file-album-cell .voice-message {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}
.message-file-album.album-cols-1 {
  grid-template-columns: 1fr;
}
.message-file-album.album-cols-2 {
  grid-template-columns: 1fr 1fr;
}
.message-file-album-cell.album-span-2 {
  grid-column: 1 / -1;
}
/* Одно фото в альбоме — как раньше, без жёсткого квадрата */
.message-file-album.album-cols-1 .message-file-album-cell .message-file-image,
.message-file-album.album-cols-1 .message-file-album-cell .message-file-video {
  width: 100%;
  max-width: none;
  max-height: 320px;
  height: auto;
  object-fit: contain;
  object-position: center;
  display: block;
  border-radius: 0;
}
/* 2+ фото: квадратные ячейки + cover — без полос фона сетки */
.message-file-album.album-cols-2 .message-file-album-cell:has(> .message-file-image),
.message-file-album.album-cols-2 .message-file-album-cell:has(> .message-file-video) {
  aspect-ratio: 1 / 1;
}
.message-file-album.album-cols-2 .message-file-album-cell.album-span-2:has(> .message-file-image),
.message-file-album.album-cols-2 .message-file-album-cell.album-span-2:has(> .message-file-video) {
  aspect-ratio: 2 / 1;
}
.message-file-album.album-cols-2 .message-file-album-cell .message-file-image,
.message-file-album.album-cols-2 .message-file-album-cell .message-file-video {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  object-position: center;
  display: block;
  border-radius: 0;
}
.message-file-album-cell .message-file-doc {
  flex-direction: column;
  padding: 10px;
  min-height: 72px;
  justify-content: center;
}
.message-file-video {
  display: block;
  max-width: min(280px, 72vw);
  max-height: 320px;
  border-radius: 10px;
  background: #000;
}
.message-file-image {
  max-width: min(320px, 72vw);
  max-height: 320px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity .15s;
}
.message-file-image:hover { opacity: .9; }
.message-file-doc {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: rgba(0,0,0,.05);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
}
[data-theme="dark"] .message-file-doc { background: rgba(255,255,255,.06); }
.message-file-doc:hover { background: rgba(0,0,0,.08); }
.message-file-doc i { font-size: 32px; color: var(--accent); }
.message-file-doc-info { min-width: 0; }
.message-file-doc-name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block; max-width: 220px;
}
.message-file-doc-size { font-size: 12px; color: var(--text-secondary); }
.message-file-unavailable {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
}
[data-theme="dark"] .message-file-unavailable { background: rgba(255, 255, 255, 0.06); }

/* ═══ VOICE MESSAGE ═══ */
.voice-message {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 4px 0;
  min-width: 240px;
  max-width: 320px;
}
.voice-track-meta {
  min-width: 0;
  padding-right: 4px;
}
.voice-track-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.voice-track-artist {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-message-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.voice-play-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.voice-play-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.voice-play-btn:active { transform: scale(0.95); }

.voice-waveform-wrap {
  flex: 1;
  position: relative;
  height: 32px;
  cursor: pointer;
  overflow: hidden;
  border-radius: 4px;
}
.voice-waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
  position: relative;
  z-index: 1;
}
.voice-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--voice-bar-bg);
  transition: background .15s;
  flex-shrink: 0;
}
.voice-bar.played {
  background: var(--voice-bar-played);
}
.voice-progress {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0;
  pointer-events: none;
  z-index: 0;
}
.voice-time {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 32px;
  text-align: right;
}

/* ═══ MUSIC TRACK CARD ═══ */
.music-message {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: min(320px, 85vw);
  padding: 4px 0;
  box-sizing: border-box;
}
.message-file-album-cell .music-message {
  max-width: 100%;
  width: 100%;
}
.music-art-btn {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
[data-theme="dark"] .music-art-btn {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
.music-cover-inner {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.12));
}
[data-theme="dark"] .music-cover-inner {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
}
.music-cover-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 22px;
  color: var(--accent);
  transition: opacity 0.15s;
}
.music-cover-placeholder.hidden {
  opacity: 0;
  pointer-events: none;
}
.music-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s;
}
.music-cover-img.visible {
  opacity: 1;
}
.music-play-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.48);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  pointer-events: none;
  line-height: 1;
}
.music-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.music-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.music-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Recording indicator */
.recording-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: var(--bg-input);
  border-radius: 20px;
  height: 40px;
}
.recording-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #e53935;
  animation: recordPulse 1s infinite;
}
@keyframes recordPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
.recording-time {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.recording-label {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
}
.recording-cancel-btn {
  flex-shrink: 0;
  margin-left: auto;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  cursor: pointer;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.recording-cancel-btn:hover {
  color: var(--text-primary);
  background: var(--bg-active);
  border-color: var(--accent);
}
.recording-cancel-btn:active {
  transform: scale(0.98);
}

.message-meta {
  display: inline-flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 3px;
  margin: 2px 0 0 10px;
  float: right;
  height: 18px;
  user-select: none;
  flex-shrink: 0;
}
.message-time {
  font-size: 11px;
  line-height: 14px;
  color: var(--text-msg-time-in);
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
}
.message-wrapper.out .message-time { color: var(--text-msg-time); opacity: 1; }
.message-edited {
  font-size: 11px;
  color: var(--text-msg-time-in);
  font-style: italic;
  line-height: 14px;
  margin-right: 2px;
}
.message-wrapper.out .message-edited { color: var(--text-msg-time); opacity: 0.9; }
.message-check,
.message-check-single {
  font-size: 16px;
  line-height: 14px;
  margin-left: 1px;
  vertical-align: middle;
}
.message-check.read { color: var(--msg-read-check); }
.message-check.sent { color: var(--text-msg-time); opacity: 0.85; }
.message-check-single { color: var(--text-msg-time); opacity: 0.75; }
.message-wrapper.out .message-check-single { color: var(--text-msg-time); opacity: 0.85; }

.message-pending-clock {
  color: var(--text-secondary);
  opacity: 0.9;
  font-size: 15px;
  animation: message-pending-pulse 1.2s ease-in-out infinite;
}
.message-wrapper.out .message-pending-clock {
  color: var(--text-msg-time);
  opacity: 0.88;
}
@keyframes message-pending-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.message-viewers-modal-inner { width: min(400px, 94vw); }
.message-viewers-body {
  max-height: min(360px, 50dvh);
  overflow-y: auto;
  padding: 4px 0 12px !important;
}
.message-viewers-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.message-viewers-row-text {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}
.message-viewers-seen {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
  margin-right: 2px;
  transform: translateX(-6px);
}
.message-viewers-row:last-child { border-bottom: none; }
.message-viewers-avatar {
  width: 40px;
  height: 40px;
  margin-left: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.message-viewers-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.message-viewers-avatar i {
  font-size: 22px;
  line-height: 1;
}
.message-viewers-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin-left: 4px;
}

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--accent-light);
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.reaction-badge:hover { background: var(--accent); color: #fff; }
.reaction-badge.mine { border-color: var(--accent); }
.reaction-badge .count { font-size: 12px; }

.system-message-wrap {
  text-align: center;
  padding: 2px 0;
}
.system-message {
  text-align: center;
  padding: 4px 8px;
}
.system-message span {
  display: inline-block;
  padding: 4px 11px 5px;
  background: rgba(0, 0, 0, 0.14);
  color: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 500;
}
[data-theme="dark"] .system-message span {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
}

.message-highlight {
  animation: highlight 1.5s ease;
}
@keyframes highlight {
  0%, 30% { background: var(--accent-light) !important; }
  100% { background: inherit; }
}

/* Scroll to bottom (якорь — низ видимой области чата) */
.scroll-bottom-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: none;
  background: var(--bg-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  font-size: 22px;
  color: var(--text-secondary);
  transition: transform var(--transition);
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}
.scroll-bottom-btn:hover { transform: scale(1.1); }
.scroll-bottom-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.unread-badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* ═══ REPLY / EDIT PREVIEW ═══ */
.reply-preview, .edit-preview {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  margin: 0 8px;
  border-radius: 4px;
}
.reply-preview-content, .edit-preview-content { flex: 1; min-width: 0; }
.reply-preview-name, .edit-preview-label {
  font-size: 13px; font-weight: 600; color: var(--accent); display: block;
}
.reply-preview-text, .edit-preview-text {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block;
}
.edit-preview i { font-size: 20px; color: var(--accent); }

/* ═══ ATTACHMENT DRAFT ═══ */
.attachment-draft-bar {
  flex-shrink: 0;
  padding: 8px 8px 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.attachment-draft-bar.hidden { display: none !important; }
.attachment-draft-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 4px;
}
.attachment-draft-toolbar-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
}
.attachment-draft-toolbar-hint i {
  font-size: 14px;
  opacity: 0.85;
}
@media (hover: none) {
  .attachment-draft-toolbar-hint {
    display: none;
  }
}
.attachment-draft-clear-all {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}
.attachment-draft-clear-all:hover:not(:disabled) {
  background: var(--bg-secondary);
}
.attachment-draft-clear-all:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.attachment-draft-upload-status {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 0 4px 2px;
}
.attachment-draft-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.attachment-draft-scroll.hidden {
  display: none !important;
}
.attachment-draft-audio-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.attachment-draft-audio-stack.hidden {
  display: none !important;
}
.attachment-draft-audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 40px 8px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  position: relative;
  box-sizing: border-box;
}
.attachment-draft-audio-row .ri-music-2-line {
  font-size: 22px;
  color: var(--accent);
  flex-shrink: 0;
}
.attachment-draft-audio-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.attachment-draft-audio-remove {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.attachment-draft-audio-remove:hover {
  background: rgba(0, 0, 0, 0.65);
}
[data-theme="dark"] .attachment-draft-audio-remove {
  background: rgba(255, 255, 255, 0.2);
}
[data-theme="dark"] .attachment-draft-audio-remove:hover {
  background: rgba(255, 255, 255, 0.3);
}
.attachment-draft-scroll::-webkit-scrollbar { height: 4px; }
.attachment-draft-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.attachment-draft-chip {
  position: relative;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.attachment-draft-draggable {
  cursor: grab;
}
.attachment-draft-draggable:active {
  cursor: grabbing;
}
.attachment-draft-dragging {
  opacity: 0.55;
}
.attachment-draft-chip-duration {
  position: absolute;
  right: 4px;
  bottom: 22px;
  z-index: 3;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.62);
  pointer-events: none;
}
.attachment-draft-scroll-end-drop {
  flex: 0 0 auto;
  width: 20px;
  min-height: 72px;
  align-self: stretch;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg-secondary);
  opacity: 0.65;
}
.attachment-draft-audio-stack-end-drop {
  min-height: 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg-secondary);
  opacity: 0.55;
}
.attachment-draft-audio-preview-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}
.attachment-draft-audio-preview-btn:hover:not(:disabled) {
  background: var(--bg-secondary);
}
.attachment-draft-audio-preview-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.attachment-draft-audio-preview-btn--chip {
  position: absolute;
  left: 4px;
  bottom: 4px;
  z-index: 3;
  width: 28px;
  height: 28px;
  font-size: 14px;
}
.attachment-draft-chip-uploading .attachment-draft-remove,
.attachment-draft-audio-row-uploading .attachment-draft-audio-remove {
  pointer-events: none;
  opacity: 0.35;
}
.attachment-draft-upload-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
  border-radius: inherit;
  pointer-events: none;
}
.attachment-draft-upload-overlay-interactive {
  padding-bottom: 5px;
}
.attachment-draft-upload-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 28px 6px;
  box-sizing: border-box;
}
.attachment-draft-upload-queue-label {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  text-align: center;
  line-height: 1.2;
}
.attachment-draft-upload-cancel {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 3;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  pointer-events: auto;
  font-size: 16px;
  line-height: 1;
}
.attachment-draft-upload-cancel:hover {
  background: rgba(0, 0, 0, 0.75);
}
.attachment-draft-upload-bar-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 0 0 11px 11px;
  overflow: hidden;
}
.attachment-draft-chip .attachment-draft-upload-bar-track {
  border-radius: 0 0 11px 11px;
}
.attachment-draft-audio-row .attachment-draft-upload-bar-track {
  border-radius: 0 0 11px 11px;
}
.attachment-draft-upload-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width 0.08s linear;
}
.attachment-draft-upload-pct {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  min-height: 1em;
}
.attachment-draft-chip img,
.attachment-draft-chip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attachment-draft-chip-doc {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  text-align: center;
}
.attachment-draft-chip-doc i {
  font-size: 28px;
  color: var(--accent);
}
.attachment-draft-chip-doc span {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.attachment-draft-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.attachment-draft-remove:hover { background: rgba(0, 0, 0, 0.75); }

.chat-drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(0, 122, 255, 0.14);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  margin: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.chat-drop-overlay.hidden { display: none !important; }
.chat-drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  max-width: 280px;
}
.chat-drop-overlay-inner i {
  font-size: 48px;
  color: var(--accent);
}

.attach-wrap {
  position: relative;
  flex-shrink: 0;
}
.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 55;
}
.attach-menu.hidden { display: none !important; }
.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.attach-menu-item:hover { background: var(--bg-hover); }
.attach-menu-item i {
  font-size: 22px;
  color: var(--accent);
  width: 24px;
  text-align: center;
}
@media (max-width: 600px) {
  .attach-menu {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: auto;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
    min-width: unset;
    border-radius: 16px 16px 0 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
}

/* ═══ INPUT AREA ═══ */
.chat-input-area {
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 8px;
  gap: 4px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}

.mention-suggestions {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 100%;
  margin-bottom: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  z-index: 40;
  padding: 4px;
}
[data-theme="dark"] .mention-suggestions {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}
.mention-suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.mention-suggestion-item:hover,
.mention-suggestion-item.active {
  background: var(--bg-hover);
}
.mention-suggestion-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.mention-suggestion-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.mention-suggestion-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.mention-suggestion-user {
  font-weight: 600;
  color: var(--accent);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mention-suggestion-name {
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.input-wrapper {
  flex: 1;
  background: var(--bg-input);
  border-radius: 20px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
}
.input-wrapper textarea {
  flex: 1;
  border: none; background: none; outline: none;
  color: var(--text-primary);
  font-size: 15px;
  resize: none;
  max-height: 160px;
  line-height: 1.4;
}
.input-wrapper textarea::placeholder { color: var(--text-secondary); }

.send-btn { color: var(--accent); }
.send-btn:hover { color: var(--accent-hover); }
.voice-btn { color: var(--text-secondary); }
.voice-btn.recording { color: #e53935; animation: pulse 1s infinite; }

/* ═══ EMOJI PICKER ═══ */
.emoji-picker {
  position: absolute;
  bottom: 60px; left: 8px;
  width: 340px;
  max-height: 380px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.emoji-picker-header {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.emoji-picker-header input {
  width: 100%; padding: 8px 12px;
  border: none; background: var(--bg-input);
  border-radius: 20px; outline: none;
  color: var(--text-primary); font-size: 14px;
}
.emoji-tabs {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  min-height: 44px;
  max-height: 48px;
  padding: 4px 8px;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
  align-items: center;
}
.emoji-tab {
  padding: 6px 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  transition: background .15s;
  flex-shrink: 0;
}
.emoji-tab:hover { background: var(--bg-hover); }
.emoji-tab.active { background: var(--accent-light); }
.emoji-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-item {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  cursor: pointer;
  border-radius: 8px;
  transition: background .15s, transform .1s;
}
.emoji-item:hover { background: var(--bg-hover); transform: scale(1.2); }
.emoji-category-title {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 4px 4px;
}

/* ═══ CONTEXT MENU ═══ */
.context-menu {
  position: fixed;
  background: var(--bg-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  z-index: 200;
  min-width: 200px;
  padding: 6px 0;
  animation: menuIn .15s ease;
}
@keyframes menuIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}
.context-menu ul { list-style: none; }
.context-menu li {
  padding: 10px 16px;
  display: flex; align-items: center; gap: 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
  color: var(--text-primary);
}
.context-menu li:hover { background: var(--bg-hover); }
.context-menu li i { font-size: 18px; color: var(--text-secondary); width: 20px; text-align: center; }
.context-menu li.danger { color: #e53935; }
.context-menu li.danger i { color: #e53935; }
.context-menu .separator { height: 1px; background: var(--border); margin: 4px 0; }
.context-reactions-row {
  display: flex; gap: 4px; padding: 8px 12px; justify-content: center;
}
.context-reaction-btn {
  font-size: 22px; cursor: pointer; padding: 4px; border-radius: 8px;
  transition: background .15s, transform .1s;
}
.context-reaction-btn:hover { background: var(--bg-hover); transform: scale(1.2); }

/* ═══ MODALS ═══ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 150;
  animation: fadeIn .2s ease;
}

/* Алерт подтверждения (компактный, две кнопки в ряд) */
.modal-overlay.tg-confirm-overlay {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.42);
  z-index: 220;
}
.tg-confirm-dialog {
  width: min(300px, calc(100vw - 40px));
  max-width: 100%;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.22s ease;
}
.tg-confirm-title {
  margin: 0;
  padding: 18px 18px 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.03em;
  text-align: center;
  color: var(--text-primary);
  line-height: 1.25;
}
.tg-confirm-message {
  margin: 10px 0 0;
  padding: 0 18px 18px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-secondary);
  text-align: center;
  max-height: min(40vh, 220px);
  overflow-y: auto;
}
.tg-confirm-actions {
  display: flex;
  border-top: 1px solid var(--border);
}
.tg-confirm-btn {
  flex: 1;
  margin: 0;
  padding: 14px 12px;
  font-size: 17px;
  font-family: inherit;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s ease;
  min-height: 48px;
}
.tg-confirm-btn-cancel {
  color: var(--text-primary);
  border-right: 1px solid var(--border);
}
.tg-confirm-btn-cancel:hover,
.tg-confirm-btn-cancel:active {
  background: var(--bg-hover);
}
.tg-confirm-btn-ok {
  color: var(--accent);
  font-weight: 600;
}
.tg-confirm-btn-ok:hover,
.tg-confirm-btn-ok:active {
  background: var(--bg-hover);
}
.tg-confirm-btn-ok.danger {
  color: #e53935;
}
[data-theme="dark"] .tg-confirm-btn-ok.danger {
  color: #ff6b6b;
}
.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-body input {
  width: 100%; padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  margin-bottom: 12px;
  transition: border-color var(--transition);
}
.modal-body input:focus { border-color: var(--accent); }
.modal-section-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}

/* ═══ GROUP CREATION (improved) ═══ */
.group-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  padding-top: 8px;
}
.group-avatar-preview {
  position: relative;
  width: 90px; height: 90px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 2px dashed var(--border);
  cursor: pointer;
  overflow: hidden;
  margin-bottom: 10px;
  transition: border-color .2s, background .2s;
}
.group-avatar-preview:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.group-avatar-preview .settings-avatar-overlay {
  border-radius: 50%;
}
.group-avatar-preview:hover .settings-avatar-overlay {
  opacity: 1;
}
.group-avatar-preview img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.group-description-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  margin-bottom: 4px;
  resize: none;
  font-family: inherit;
  font-size: inherit;
  transition: border-color var(--transition);
}
.group-description-textarea:focus { border-color: var(--accent); }
.group-members-counter {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.group-members-selected {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 8px;
}
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.member-chip:hover { background: var(--accent); color: #fff; }
.member-chip i { font-size: 14px; }
.member-chip-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.member-chip-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}

.group-search-results { max-height: 300px; overflow-y: auto; }

.user-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background .15s;
}
.user-item:hover { background: var(--bg-hover); }
.user-item-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.user-item-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.user-item-info { flex: 1; min-width: 0; }
.user-item-name { font-size: 15px; font-weight: 500; display: block; }
.user-item-status { font-size: 13px; color: var(--text-secondary); }
.user-item-add {
  color: var(--accent);
  font-size: 22px;
  flex-shrink: 0;
  display: flex; align-items: center;
}

.chat-item-muted-ic {
  font-size: 15px;
  color: var(--text-secondary);
  opacity: 0.75;
  margin-left: 6px;
  vertical-align: -2px;
}
.chat-item-muted-ic:hover {
  opacity: 1;
  color: var(--accent);
}

.username-input-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  overflow: hidden;
  box-sizing: border-box;
}
.username-input-at {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 4px 0 12px;
  font-weight: 600;
  font-size: 16px;
  line-height: 1;
  color: var(--text-secondary);
  user-select: none;
  position: relative;
  top: -7px;
}
.username-input-field {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 11px 12px 11px 2px;
  font-size: 15px;
  line-height: 1.35;
  outline: none;
  color: inherit;
  font-family: inherit;
  box-sizing: border-box;
}

.settings-info-tappable {
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s ease;
}
.settings-info-tappable:hover {
  background: var(--bg-hover);
}

.mute-duration-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mute-duration-body .mute-duration-btn {
  width: 100%;
  justify-content: center;
  text-align: center;
}
/* Не растягивать тело модалки — убирает лишний вертик./горизонт. скролл */
#mute-duration-modal .modal {
  max-height: none;
}
#mute-duration-modal .modal-body {
  flex: 0 0 auto;
  overflow: visible;
  overflow-x: hidden;
  min-width: 0;
}

/* ═══ ЭКРАН ГРУППЫ ═══ */
.tg-group-profile {
  background: var(--bg-secondary);
}
.tg-group-profile .settings-panel-header {
  background: var(--bg-primary);
}
.tg-group-topbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.tg-group-body {
  padding: 0 0 24px;
  background: var(--bg-secondary);
}
.tg-group-hero {
  text-align: center;
  padding: 20px 20px 24px;
  background: var(--bg-primary);
  border-bottom: none;
}
.tg-group-avatar-ring {
  display: inline-flex;
  padding: 4px;
  margin-bottom: 4px;
}
.tg-group-avatar {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  cursor: default;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.tg-group-avatar .settings-avatar-overlay {
  border-radius: 50%;
  font-size: 32px;
}
.tg-group-avatar:hover .settings-avatar-overlay {
  opacity: 1;
}
.tg-group-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.tg-group-name {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.03em;
  margin: 8px 0 4px;
  padding: 0 12px;
  word-break: break-word;
}
.tg-group-meta {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text-secondary);
  margin: 0;
  padding: 0 16px;
}
/* Карточка смены названия группы (прежний вид) */
.tg-group-card {
  margin: 10px 12px 8px;
  padding: 14px 16px 16px;
  background: var(--bg-primary);
  border-radius: 10px;
  box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
}
[data-theme="dark"] .tg-group-card {
  box-shadow: none;
}
.tg-group-card-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.tg-group-field {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.tg-group-field:focus {
  border-color: var(--accent);
}
.tg-btn-primary-block {
  width: 100%;
  margin-top: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--on-accent, #fff);
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.tg-btn-primary-block:hover {
  background: var(--accent-hover);
}
.tg-btn-primary-block:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.tg-group-card-hint {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
}
/* Плоский список настроек группы */
.tg-group-flat {
  background: var(--bg-primary);
}
.tg-group-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.tg-group-list-label {
  flex-shrink: 0;
  width: 92px;
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.tg-group-list-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
  text-align: right;
  padding: 4px 0;
}
.tg-group-list-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.75;
}
.tg-group-search-row .tg-group-list-input {
  text-align: left;
}
.tg-group-search-row-icon {
  font-size: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.tg-group-subhead {
  padding: 12px 16px 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}
.tg-group-subhead--members {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
  padding-top: 14px;
}
.tg-group-separator {
  height: 8px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.tg-group-members-section {
  padding-bottom: 8px;
}
.tg-group-inline-results {
  border-top: 1px solid var(--border);
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-primary);
}
.tg-group-add-bulk {
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}
.tg-group-add-counter {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.tg-group-add-chips {
  margin-bottom: 10px;
  min-height: 0;
}
.tg-group-add-chips:empty {
  display: none;
}
.user-item.group-add-picked {
  background: var(--bg-active);
}
.user-item.group-add-picked .user-item-name {
  color: var(--accent);
}
.tg-members-count {
  font-weight: 500;
  color: var(--text-secondary);
}

.group-members-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* Bottom sheet — действия над участником */
.modal-overlay.tg-sheet-overlay {
  align-items: stretch;
  justify-content: flex-end;
  padding: 0;
  background: transparent;
  animation: none;
}
.tg-sheet-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: 100%;
  justify-content: flex-end;
  pointer-events: none;
}
.tg-sheet-inner > * {
  pointer-events: auto;
}
.tg-sheet-scrim {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.45);
  animation: fadeIn 0.2s ease;
}
.tg-bottom-sheet {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-primary);
  border-radius: 12px 12px 0 0;
  padding: 6px 0 max(10px, env(safe-area-inset-bottom, 0));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  animation: tgSheetUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tgSheetUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.tg-bottom-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 10px;
  opacity: 0.85;
}
.tg-bottom-sheet-title {
  padding: 0 20px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: -0.02em;
}
.tg-bottom-sheet-list {
  display: flex;
  flex-direction: column;
}
.tg-sheet-action {
  display: block;
  width: 100%;
  padding: 14px 20px;
  text-align: center;
  font-size: 17px;
  font-weight: 400;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s ease;
}
.tg-sheet-action:hover,
.tg-sheet-action:active {
  background: var(--bg-hover);
}
.tg-sheet-action.danger {
  color: #e53935;
}
.tg-bottom-sheet-cancel {
  display: block;
  width: calc(100% - 16px);
  max-width: 504px;
  margin: 10px auto 0;
  padding: 14px 20px;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
}
.tg-bottom-sheet-cancel:hover {
  filter: brightness(0.97);
}
[data-theme="dark"] .tg-bottom-sheet-cancel {
  background: var(--bg-input);
}
.contacts-list {
  display: flex;
  flex-direction: column;
}
.contacts-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}
.group-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px 8px 16px;
  transition: background .12s ease;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.group-member-row:last-child {
  border-bottom: none;
}
.group-member-row:hover,
.group-member-row:active {
  background: var(--bg-hover);
}
.group-member-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}
.group-member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.group-member-info {
  flex: 1;
  min-width: 0;
  padding-right: 8px;
}
.group-member-name {
  font-size: 16px;
  font-weight: 500;
  display: block;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.group-member-role {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.group-member-menu-btn {
  flex-shrink: 0;
  margin-left: auto;
  -webkit-tap-highlight-color: transparent;
}
.group-member-menu-btn i {
  font-size: 22px;
}

.settings-notify-hint {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 20px 4px;
  line-height: 1.45;
  margin: 0;
}

.group-add-search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  margin-bottom: 10px;
}
.group-add-members-results .user-item { border-bottom: 1px solid var(--border); }
.group-add-members-results .user-item:last-child { border-bottom: none; }

.delete-chat-modal-inner { max-width: 420px; width: calc(100% - 32px); }
.delete-chat-modal-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.45;
}
.delete-chat-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: -4px 0 14px;
  line-height: 1.35;
}
.delete-chat-hint.danger-hint { color: #e57373; }

/* ═══ IMAGE VIEWER (zoom/pan) ═══ */
.image-viewer {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  touch-action: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.image-viewer .icon-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  color: #fff;
  font-size: 24px;
  width: 44px;
  height: 44px;
  z-index: 2;
  border-radius: 50%;
}
.image-viewer #image-viewer-close {
  right: max(12px, env(safe-area-inset-right));
}
.image-viewer .image-viewer-download {
  right: max(64px, calc(env(safe-area-inset-right) + 52px));
}
.image-viewer .image-viewer-reset {
  right: max(116px, calc(env(safe-area-inset-right) + 92px));
}
.image-viewer .icon-btn:hover { background: rgba(255,255,255,.12); }
.image-viewer .image-viewer-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  font-size: 28px;
  z-index: 2;
}
.image-viewer .image-viewer-prev {
  left: max(10px, env(safe-area-inset-left));
  right: auto;
}
.image-viewer .image-viewer-next {
  right: max(10px, env(safe-area-inset-right));
  left: auto;
}
.image-viewer .image-viewer-nav:disabled {
  opacity: 0.3;
  pointer-events: none;
}
.image-viewer .image-viewer-nav.hidden {
  display: none !important;
}
.image-viewer-stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.image-viewer-stage:active { cursor: grabbing; }
.image-viewer img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  max-width: min(96vw, 1400px);
  max-height: min(85vh, 900px);
  object-fit: contain;
  border-radius: 4px;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.image-viewer-hint {
  flex-shrink: 0;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,.55);
  padding: 8px 16px 12px;
  line-height: 1.35;
}
.chat-header-dropdown { z-index: 250; }

/* ═══ SETTINGS PANEL ═══ */
.settings-panel, .user-profile-panel {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: slideInLeft .25s cubic-bezier(.4,0,.2,1);
  border-right: 1px solid var(--border);
}
@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}
.settings-panel-header {
  height: var(--header-height);
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-panel-header h3 {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
}
.settings-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.settings-profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  background: var(--bg-primary);
}
.settings-profile-avatar {
  width: 100px; height: 100px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 600;
  color: #fff;
  position: relative;
  overflow: hidden;
  margin-bottom: 14px;
  cursor: pointer;
}
.settings-profile-avatar img {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
}
.settings-avatar-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .2s;
  font-size: 28px; color: #fff;
  cursor: pointer;
}
.settings-profile-avatar:hover .settings-avatar-overlay { opacity: 1; }
.avatar-remove-text-btn {
  margin-top: 10px;
  padding: 6px 12px;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: #e53935;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.avatar-remove-text-btn:hover { opacity: 0.88; }
.avatar-remove-text-btn.hidden { display: none !important; }
.tg-group-remove-avatar {
  width: 100%;
  text-align: center;
  margin-top: 12px;
}

.settings-profile-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  text-align: center;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-profile-status {
  font-size: 14px;
  color: var(--accent);
}
.settings-profile-status.offline { color: var(--text-secondary); }

.settings-section {
  padding: 8px 0;
  border-bottom: 8px solid var(--bg-secondary);
}
.settings-section:last-child { border-bottom: none; }
.settings-section-title {
  padding: 12px 20px 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.settings-info-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 20px;
  gap: 20px;
  cursor: pointer;
  transition: background .15s;
}
.settings-info-row:hover { background: var(--bg-hover); }
.settings-info-row > i {
  font-size: 22px;
  color: var(--text-secondary);
  width: 24px; text-align: center;
  margin-top: 2px;
}
.settings-info-content { flex: 1; min-width: 0; }
.settings-info-value {
  display: block;
  font-size: 15px;
  color: var(--text-primary);
  word-break: break-word;
}
.settings-info-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.settings-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 20px;
  cursor: pointer;
  transition: background .15s;
  color: var(--text-primary);
}
.settings-item:hover { background: var(--bg-hover); }
.settings-item > i:first-child {
  font-size: 22px;
  color: var(--text-secondary);
  width: 24px; text-align: center;
}
.settings-item > span:first-of-type { flex: 1; font-size: 15px; }
.settings-item-value {
  font-size: 14px;
  color: var(--text-secondary);
  margin-left: auto;
}
.settings-arrow {
  font-size: 20px;
  color: var(--text-secondary);
  opacity: .5;
}
.settings-item.danger { color: #e53935; }
.settings-item.danger i { color: #e53935; }
.settings-item-disabled {
  cursor: default;
  opacity: .7;
}
.settings-item-disabled:hover { background: transparent; }

/* Settings sub-page */
.settings-subpage {
  position: absolute; inset: 0;
  background: var(--bg-sidebar);
  z-index: 2;
  display: flex;
  flex-direction: column;
  animation: slideInLeft .2s ease;
}

/* Toggle switch */
.settings-toggle-row {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 16px;
}
.settings-toggle-row > i {
  font-size: 22px;
  color: var(--text-secondary);
  width: 24px; text-align: center;
}
.settings-toggle-row .toggle-label {
  flex: 1;
  font-size: 15px;
}
.settings-toggle-row .toggle-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.toggle-switch {
  width: 44px; height: 24px;
  background: var(--text-secondary);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-switch.active { background: var(--accent); }
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch.active::after { transform: translateX(20px); }

/* Range slider */
.settings-range-row {
  padding: 10px 20px 16px;
}
.settings-range-row label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.settings-range-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings-range-preview {
  text-align: center;
  padding: 8px;
  margin-top: 8px;
  background: var(--bg-input);
  border-radius: 8px;
  transition: font-size .2s;
}

/* Палитра акцента (настройки → оформление) */
.accent-palette-hint {
  padding: 0 20px 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
}
.accent-palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 10px;
  padding: 4px 20px 12px;
  max-width: 100%;
}
.accent-swatch {
  width: 100%;
  aspect-ratio: 1;
  max-width: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.accent-swatch:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.accent-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.accent-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-sidebar), 0 0 0 4px var(--accent);
}
.accent-swatch.custom-swatch {
  background: conic-gradient(from 0deg, #7a121c, #6a1b9a, #1565c0, #2e7d32, #f9a825, #7a121c);
}
.accent-swatch.custom-swatch i {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}
.accent-palette-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.accent-palette-actions {
  padding: 4px 20px 16px;
}
.accent-reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.accent-reset-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}
.accent-preview-bar {
  margin: 0 20px 12px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-hover) 100%);
  opacity: 0.95;
}

/* Radio options */
.settings-radio-group { padding: 4px 20px; }
.settings-radio-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  gap: 14px;
  cursor: pointer;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.settings-radio-item:last-child { border-bottom: none; }
.radio-dot {
  width: 20px; height: 20px;
  border: 2px solid var(--text-secondary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: border-color .2s;
}
.radio-dot::after {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform .2s;
}
.settings-radio-item.active .radio-dot { border-color: var(--accent); }
.settings-radio-item.active .radio-dot::after { transform: scale(1); }

/* Chat background preview */
.bg-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 20px;
}
.bg-preview-item {
  height: 80px;
  border-radius: 10px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color .2s, transform .15s;
  position: relative;
  overflow: hidden;
}
.bg-preview-item:hover { transform: scale(1.05); }
.bg-preview-item.active { border-color: var(--accent); }
.bg-preview-item.bg-default { background: #e8dfd5; }
[data-theme="dark"] .bg-preview-item.bg-default { background: #0e1621; }
.bg-preview-item.bg-blue { background: linear-gradient(135deg, #667eea, #764ba2); }
.bg-preview-item.bg-green { background: linear-gradient(135deg, #11998e, #38ef7d); }
.bg-preview-item.bg-sunset { background: linear-gradient(135deg, #f093fb, #f5576c); }
.bg-preview-item.bg-ocean { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.bg-preview-item.bg-dark { background: #1a1a2e; }

/* ═══ EDIT PROFILE ═══ */
.edit-profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}
.edit-profile-avatar {
  width: 90px; height: 90px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 600;
  color: #fff;
  overflow: hidden;
  margin-bottom: 10px;
}
.edit-profile-avatar img {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
}
.edit-profile-avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  border: none;
  font-family: inherit;
}
.edit-profile-avatar-btn:hover { background: var(--accent); color: #fff; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  margin-top: 4px;
}
.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: -8px;
  margin-bottom: 12px;
}
.form-hint.error { color: #e53935; }
.form-char-count {
  text-align: right;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: -8px;
  margin-bottom: 12px;
}

.modal-body textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  margin-bottom: 12px;
  resize: none;
  font-family: inherit;
  font-size: inherit;
  transition: border-color var(--transition);
}
.modal-body textarea:focus { border-color: var(--accent); }

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  font-family: inherit;
  margin-right: 8px;
}
.btn-secondary:hover { background: var(--bg-hover); }

/* ═══ AVATAR CROP MODAL ═══ */
.avatar-crop-area {
  width: 280px; height: 280px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  background: #000;
  cursor: grab;
  border: 3px solid var(--accent);
}
.avatar-crop-area:active { cursor: grabbing; }
.avatar-crop-area img {
  position: absolute;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
}
.avatar-crop-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 12px;
}

/* ═══ MOBILE RESPONSIVE ═══ */
.mobile-only { display: none; }

@media (max-width: 768px) {
  html, body {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100vw;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  .app {
    position: fixed;
    inset: 0;
    max-height: 100dvh;
    overflow: hidden;
    touch-action: pan-y;
  }
  .sidebar {
    width: 100%;
    min-width: 100%;
    flex: 1;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0);
  }
  .app:has(.chat-area.open) .fab {
    visibility: hidden;
    pointer-events: none;
  }
  .chat-area {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
    /* 100vw на мобилках часто шире вьюпорта (полоса прокрутки) → субпиксельный сдвиг после анимации */
    width: 100%;
    max-width: 100%;
    transform: translateX(100%);
    transition: transform 0.34s cubic-bezier(0.25, 0.46, 0.45, 0.99);
    background-color: var(--bg-chat);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-y;
  }
  .chat-area.open {
    transform: translateX(0);
  }
  .message-wrapper.message-enter {
    animation: none;
  }
  .chat-view {
    flex: 1;
    min-height: 0;
    height: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
  }
  .messages-area-wrap {
    flex: 1;
    min-height: 0;
  }
  .messages-container {
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  .chat-header {
    padding-top: env(safe-area-inset-top, 0);
    min-height: calc(var(--header-height) + env(safe-area-inset-top, 0));
    flex-shrink: 0;
  }
  .mobile-only { display: flex; }
  .emoji-picker { left: 4px; right: 4px; width: auto; bottom: 56px; max-height: 45dvh; }
  .modal { width: min(95vw, 520px); max-width: 95vw; max-height: calc(100dvh - 24px); overflow-y: auto; }
  .message-bubble { max-width: calc(100vw - 56px); }
  .message-wrapper.in.message-group-in .message-bubble-col .message-bubble {
    max-width: calc(100vw - 88px);
  }
  .settings-panel, .user-profile-panel { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; }
  .voice-message { min-width: 160px; max-width: calc(100vw - 80px); }
  .message-file-album-cell .voice-message {
    min-width: 0;
    max-width: 100%;
  }
  .music-message {
    max-width: calc(100vw - 80px);
  }
  .message-file-album-cell .music-message {
    max-width: 100%;
  }
  /* Плеер аудио: компактнее, safe area, не раздувается под глобальные 44px icon-btn */
  .chat-media-bar {
    --cmb-art: 32px;
    --cmb-play: 30px;
    --cmb-step: 28px;
    --cmb-side: 30px;
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }
  .chat-media-bar-inner {
    padding: 4px 6px;
    gap: 4px;
    min-height: 42px;
  }
  .chat-media-bar-title {
    font-size: 12px;
  }
  .chat-media-bar-sub {
    font-size: 10px;
  }
  .chat-media-bar-art-fallback {
    font-size: 15px;
  }
  .chat-media-bar-step i {
    font-size: 15px;
  }
  .chat-media-bar-play i {
    font-size: 15px;
  }
  .chat-media-bar-playlist-toggle i {
    font-size: 16px;
  }
  .chat-media-bar-close i {
    font-size: 17px;
  }
  .chat-media-bar-times {
    font-size: 9px;
  }
  .chat-media-bar-progress-wrap {
    gap: 5px;
    margin-top: 1px;
    min-height: 28px;
    align-items: center;
  }
  .chat-media-bar-progress-track {
    height: 6px;
    align-self: center;
  }
  .chat-media-bar-list-wrap {
    max-height: min(42dvh, 280px);
    padding: 2px 2px max(6px, env(safe-area-inset-bottom, 0));
  }
  .chat-media-bar-list-item {
    padding: 8px 6px;
    min-height: 40px;
  }
  .chat-media-bar .icon-btn.chat-media-bar-step,
  .chat-media-bar .icon-btn.chat-media-bar-play,
  .chat-media-bar .icon-btn.chat-media-bar-playlist-toggle,
  .chat-media-bar .icon-btn.chat-media-bar-playback-btn,
  .chat-media-bar .icon-btn.chat-media-bar-close {
    min-width: unset;
    min-height: unset;
  }
  .chat-input-area {
    flex-shrink: 0;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0));
    padding-left: max(4px, env(safe-area-inset-left, 0));
    padding-right: max(4px, env(safe-area-inset-right, 0));
  }
  #message-input, .search-box input, .group-add-search-input, .tg-group-list-input, .tg-group-search-inline, .tg-group-field { font-size: 16px; }
  .fab {
    bottom: max(20px, calc(20px + env(safe-area-inset-bottom, 0)));
    right: max(16px, calc(16px + env(safe-area-inset-right, 0)));
  }
  .compose-sheet {
    right: max(16px, calc(16px + env(safe-area-inset-right, 0)));
    bottom: calc(
      56px + max(20px, calc(20px + env(safe-area-inset-bottom, 0))) + 10px
    );
    max-width: min(320px, calc(100% - 32px));
  }
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }
  .icon-btn.small {
    min-width: 40px;
    min-height: 40px;
  }
  .slide-menu {
    width: min(320px, calc(100vw - 32px));
  }
  .slide-menu-items li {
    padding: 14px 20px;
    min-height: 48px;
    align-items: center;
  }
  .context-menu {
    max-width: calc(100vw - 16px);
  }

  @media (prefers-reduced-motion: reduce) {
    .chat-area {
      transition-duration: 0.2s;
      transition-timing-function: ease;
    }
  }
}

@media (max-width: 480px) {
  :root { --sidebar-width: 100%; }
  .chat-item-avatar { width: 48px; height: 48px; }
  .chat-item-name { max-width: 140px; }
  .chat-media-bar {
    --cmb-art: 30px;
    --cmb-play: 28px;
    --cmb-step: 26px;
    --cmb-side: 28px;
  }
  .chat-media-bar-inner {
    gap: 3px;
    padding: 3px 5px;
    min-height: 40px;
  }
  .chat-media-bar-title {
    font-size: 11px;
  }
  .chat-media-bar-list-title {
    font-size: 11px;
  }
}
