/* ============================================================
   CSS Variables — Dark (default) & Light themes
   ============================================================ */
:root,
[data-theme="dark"] {
  --bg-deep: #071410;
  --bg-primary: #0a1f1a;
  --bg-secondary: #0f2b24;
  --bg-tertiary: #143530;
  --bg-hover: #1a4038;
  --bg-input: #0d2520;

  --accent: #00e676;
  --accent-dim: #00c853;
  --accent-glow: rgba(0, 230, 118, 0.25);
  --accent-subtle: rgba(0, 230, 118, 0.12);

  --text-primary: #e8f5e9;
  --text-secondary: #81c784;
  --text-muted: #4caf7a;
  --text-inverse: #071410;

  --border: rgba(0, 230, 118, 0.12);
  --border-strong: rgba(0, 230, 118, 0.25);

  --bubble-out: #0d4a3a;
  --bubble-out-text: #e8f5e9;
  --bubble-in: #143530;
  --bubble-in-text: #c8e6c9;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(0, 230, 118, 0.15);

  --sidebar-width: 360px;
  --header-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-bubble: 18px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

[data-theme="light"] {
  --bg-deep: #e8f5e9;
  --bg-primary: #f1f8f4;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e0f2e9;
  --bg-hover: #d4edda;
  --bg-input: #ffffff;

  --accent: #00a854;
  --accent-dim: #008f47;
  --accent-glow: rgba(0, 168, 84, 0.2);
  --accent-subtle: rgba(0, 168, 84, 0.1);

  --text-primary: #1b3a2d;
  --text-secondary: #2e7d52;
  --text-muted: #6aab82;
  --text-inverse: #ffffff;

  --border: rgba(0, 100, 60, 0.12);
  --border-strong: rgba(0, 100, 60, 0.22);

  --bubble-out: #00a854;
  --bubble-out-text: #ffffff;
  --bubble-in: #ffffff;
  --bubble-in-text: #1b3a2d;

  --shadow: 0 4px 16px rgba(0, 60, 30, 0.1);
  --shadow-glow: 0 0 16px rgba(0, 168, 84, 0.12);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
  border: none;
  outline: none;
  background: none;
}

button { cursor: pointer; }

a { color: var(--accent); text-decoration: none; }

.hidden,
#app.hidden,
#auth-screen.hidden { display: none !important; }

/* ============================================================
   Loader
   ============================================================ */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  z-index: 9999;
  transition: opacity 0.3s;
}

.loader.fade-out { opacity: 0; pointer-events: none; }

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Auth Screen
   ============================================================ */
.auth-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  box-sizing: border-box;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0, 230, 118, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 200, 83, 0.06) 0%, transparent 40%),
    var(--bg-deep);
  z-index: 100;
}

.auth-card {
  position: relative;
  margin: auto 0;
  max-height: none;
  width: 100%;
  max-width: 420px;
  padding: 40px 32px 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow), var(--shadow-glow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-badge {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--accent-subtle);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 18px var(--accent-glow);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.auth-logo-badge:hover {
  transform: scale(1.05);
  box-shadow: 0 0 24px var(--accent-glow);
}

.auth-logo-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 230, 118, 0.35));
}

.auth-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--accent-subtle);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.optional { font-weight: 400; color: var(--text-muted); }

.form-group input {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-error {
  color: #ff5252;
  font-size: 0.8125rem;
  padding: 8px 12px;
  background: rgba(255, 82, 82, 0.1);
  border-radius: var(--radius-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--text-inverse);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:active { transform: translateY(0); }

.btn-block { width: 100%; }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.btn-icon svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-icon .icon-moon { fill: currentColor; stroke: none; }

.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
}

/* ============================================================
   App Layout
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 10;
}

.sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  background: none;
  border: none;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  text-align: left;
}

.user-info:hover { background: var(--bg-hover); }

.user-info-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.my-display-name {
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-username {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions { display: flex; gap: 2px; flex-shrink: 0; }

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  transition: border-color 0.2s;
}

.search-box input:focus { border-color: var(--accent); }

.search-box input::placeholder { color: var(--text-muted); }

/* Search results */
.search-results {
  border-bottom: 1px solid var(--border);
  max-height: 240px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.search-result-item:hover { background: var(--bg-hover); }

.search-result-info { flex: 1; min-width: 0; }

.search-result-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-handle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-result-phone {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.chat-item:hover { background: var(--bg-hover); }

.chat-item.active {
  background: var(--accent-subtle);
  border-left: 3px solid var(--accent);
}

.chat-item-info { flex: 1; min-width: 0; }

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.chat-item-preview {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview .you { color: var(--text-secondary); }

.unread-badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: var(--text-inverse);
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-list-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}

.chat-list-empty p { margin-top: 8px; font-size: 0.875rem; }

/* ============================================================
   Avatar
   ============================================================ */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-subtle), var(--bg-tertiary));
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
  border: 2px solid var(--border-strong);
}

.avatar-sm { width: 36px; height: 36px; font-size: 0.8125rem; }
.avatar-md { width: 42px; height: 42px; font-size: 0.9375rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.125rem; }
.avatar-xl { width: 96px; height: 96px; font-size: 2rem; }

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ============================================================
   Chat Panel
   ============================================================ */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
  position: relative;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.chat-empty h2 {
  margin-top: 20px;
  color: var(--text-secondary);
  font-size: 1.25rem;
}

.chat-empty p { margin-top: 8px; font-size: 0.875rem; max-width: 280px; }

#chat-active,
.chat-panel > .chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  min-height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn { display: none; }

.chat-header-info { flex: 1; min-width: 0; }

.chat-header-info h2 {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-status {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.chat-status.online { color: var(--accent); }

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(0, 230, 118, 0.03) 0%, transparent 60%),
    var(--bg-primary);
}

.load-more-btn {
  align-self: center;
  padding: 6px 16px;
  margin-bottom: 12px;
  font-size: 0.8125rem;
  color: var(--accent);
  background: var(--accent-subtle);
  border-radius: 20px;
  transition: background 0.2s;
}

.load-more-btn:hover { background: var(--accent-glow); }

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Главная строка сообщения — СТРОГО горизонтальный flex */
.message,
.message-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-end !important;
  gap: 8px !important;
  margin-bottom: 8px !important;
  max-width: 75%;
  animation: msgIn 0.2s ease;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

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

.message.outgoing {
  align-self: flex-end;
  justify-content: flex-end;
}
.message.incoming {
  align-self: flex-start;
  justify-content: flex-start;
}

/* Аватарка стоит слева снизу */
.message-avatar {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px !important;
  min-height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  flex-shrink: 0 !important;
  align-self: flex-end !important;
  margin: 0 !important;
}

.message-avatar img {
  width: 100% !important;
  height: 100% !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  display: block;
}

/* Правая колонка с текстом/именем — вертикальный flex */
.message-content-wrapper,
.message-bubble-wrapper,
.message-content {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  max-width: 100%;
}

.message.outgoing .message-content-wrapper,
.message.outgoing .message-bubble-wrapper,
.message.outgoing .message-content {
  align-items: flex-end !important;
}

.message-bubble {
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  align-items: flex-end !important;
  gap: 8px !important;
  padding: 6px 10px !important;
  max-width: 480px;
  border-radius: var(--radius-bubble);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

.message.outgoing .message-bubble {
  align-items: flex-end !important;
}

.message-actions {
  display: none !important;
}

.msg-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.msg-action-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.msg-action-btn svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.edited-badge {
  font-size: 0.6875rem;
  opacity: 0.7;
  margin-right: 4px;
}

.message-time,
.message-meta {
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  font-size: 11px !important;
  line-height: 1 !important;
  opacity: 0.7;
  white-space: nowrap !important;
  margin-left: auto !important;
  margin-bottom: 1px !important;
  flex-shrink: 0 !important;
}

/* Статусы отправки и прочтения (Галочки ✓ / ✓✓) */
.read-status {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -2px;
  margin-left: 2px;
  line-height: 1;
}
.read-status.sent {
  opacity: 0.6;
}
.read-status.read {
  color: var(--accent);
  opacity: 1;
}
.read-status.sent .check-read {
  display: none !important;
}
.read-status.read .check-sent {
  display: none !important;
}

/* Баббл с ответом переключается в вертикальную колонку */
.message-bubble:has(.message-reply-quote),
.message-bubble.has-reply {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 4px !important;
}

.message-reply-quote {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box !important;
  border-left: 3px solid var(--accent, #2ecc71) !important;
  padding: 3px 8px !important;
  margin-bottom: 4px !important;
  border-radius: 4px;
  background: rgba(46, 204, 113, 0.08);
  cursor: pointer;
  transition: background 0.15s ease;
}

.message-reply-quote:hover {
  background: rgba(46, 204, 113, 0.16);
}

.message-reply-author {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent, #2ecc71);
  margin-bottom: 2px;
}

.message-reply-preview {
  font-size: 0.8rem;
  color: var(--text-dim, rgba(255, 255, 255, 0.7));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-body-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-end !important;
  justify-content: space-between !important;
  gap: 8px !important;
  width: 100% !important;
}

/* Контейнер реакций всегда переносится на отдельную строчку вниз */
.message-reactions {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 4px !important;
  margin-top: 4px !important;
  width: 100% !important;
  align-self: flex-start !important;
}

.message.outgoing .message-reactions {
  align-self: flex-end !important;
  justify-content: flex-end !important;
}

.message.incoming .message-reactions {
  align-self: flex-start !important;
  justify-content: flex-start !important;
}

/* Для сообщений только с Big Emoji реакции прижаты снизу под смайликом */
.message-emoji-only ~ .message-reactions {
  margin-top: 6px !important;
}

.message.outgoing .message-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 230, 118, 0.1);
}

.message.incoming .message-bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

/* Имя автора — первая строчка в правой колонке */
.message-sender {
  display: block !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  color: var(--accent);
  margin-bottom: 2px !important;
}

.message-text {
  display: inline !important;
  margin: 0 !important;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Смайлики идут строго под именем автора */
.message-emoji-only {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.message-emoji-only .message-text,
.message-bubble.message-emoji-only .message-text {
  font-size: 56px !important;
  line-height: 1.1 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  margin: 0 !important;
}

.message-emoji-only::after,
.message-emoji-only::before,
.message-bubble.message-emoji-only::after,
.message-bubble.message-emoji-only::before {
  display: none !important;
}

.message-date-separator {
  align-self: center;
  padding: 4px 12px;
  margin: 12px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-radius: 12px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 20px 8px;
  font-size: 0.8125rem;
  color: var(--accent);
  flex-shrink: 0;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Message input */
.message-input-area {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative; /* Нужно для правильного позиционирования emoji-picker */
}

.message-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s;
}

.message-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.message-form textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 8px 0;
  line-height: 1.4;
  background: transparent;
}

.message-form textarea::placeholder { color: var(--text-muted); }

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--text-inverse);
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-send svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Edit banner */
.edit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  margin-bottom: 8px;
  background: var(--accent-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--accent);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.btn-text:hover {
  color: var(--accent);
  background: var(--bg-hover);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  margin: auto;
  z-index: 1000;
  padding: 16px;
}

.modal:not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  margin: auto;
  width: 90%;
  max-width: 400px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow), var(--shadow-glow);
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.profile-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.profile-avatar-section {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.profile-avatar-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.avatar-change-hint {
  font-size: 0.8125rem;
  color: var(--accent);
  transition: opacity 0.2s;
}

.profile-avatar-label:hover .avatar-change-hint {
  text-decoration: underline;
}

.profile-form textarea,
.input-disabled {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s;
}

.profile-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-disabled {
  min-height: auto;
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

@media (hover: none) {
  .message.outgoing .message-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ============================================================
   Mobile Responsive (<= 768px: Telegram/WhatsApp UX)
   ============================================================ */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .app {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
  }

  /* По умолчанию: открыт только список чатов (сайдбар) на 100% ширины и высоты */
  .sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    z-index: 10;
    border-right: none;
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  }

  /* Окно активного диалога по умолчанию скрыто */
  .chat-panel {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  }

  /* При наличии класса chat-active на body или корневом контейнере:
     сайдбар со списком чатов скрывается, а окно открытого диалога занимает 100% */
  body.chat-active .sidebar,
  #app.chat-active .sidebar,
  .app.chat-active .sidebar,
  .sidebar.hidden-mobile {
    display: none !important;
    transform: translateX(-100%) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  body.chat-active .chat-panel,
  #app.chat-active .chat-panel,
  .app.chat-active .chat-panel,
  .chat-panel.active-mobile {
    display: flex !important;
    width: 100% !important;
    transform: translateX(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* На мобильных устройствах кнопка "Назад" видна */
  .back-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    margin-right: 4px;
    cursor: pointer;
    border-radius: 50%;
  }

  /* Зафиксированная высота окна сообщений и скролл */
  #chat-active,
  .chat-panel > .chat-active {
    height: 100%;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .messages-container {
    flex: 1;
    min-height: 0;
    height: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Нижняя панель ввода сообщения и безопасные зоны */
  .message-input-area {
    padding: 8px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  /* Центрирование и адаптивность всех модальных окон */
  .modal {
    position: fixed !important;
    inset: 0 !important;
    margin: auto !important;
    padding: 16px !important;
    z-index: 1000 !important;
  }

  .modal:not(.hidden) {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .modal.hidden {
    display: none !important;
  }

  .modal-card {
    position: relative !important;
    margin: auto !important;
    width: calc(100% - 32px) !important;
    max-width: 400px !important;
    max-height: 85vh !important;
    max-height: 85dvh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain;
  }

  /* Панель эмодзи на мобильных: 48vh снизу экрана */
  .emoji-picker {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 48vh !important;
    max-height: 48vh !important;
    margin-bottom: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6) !important;
    z-index: 1000 !important;
  }

  .message { max-width: 85%; }

  .auth-card {
    padding: 32px 24px 24px;
  }
}

/* ============================================================
   Desktop Layout (> 768px): гарантированный двухколоночный вид
   ============================================================ */
@media (min-width: 769px) {
  .app:not(.hidden),
  #app:not(.hidden),
  body.chat-active .app:not(.hidden),
  body.chat-active #app:not(.hidden),
  .app.chat-active:not(.hidden),
  #app.chat-active:not(.hidden) {
    display: flex !important;
    flex-direction: row !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    position: relative !important;
  }

  /* .sidebar ВСЕГДА видим (display: flex, фиксированная ширина 320px–360px) */
  .sidebar,
  body.chat-active .sidebar,
  #app.chat-active .sidebar,
  .app.chat-active .sidebar,
  .sidebar.hidden-mobile {
    display: flex !important;
    width: var(--sidebar-width, 360px) !important;
    min-width: var(--sidebar-width, 360px) !important;
    max-width: var(--sidebar-width, 360px) !important;
    height: 100% !important;
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    border-right: 1px solid var(--border) !important;
    z-index: 10 !important;
  }

  /* .chat-panel ВСЕГДА занимает оставшуюся часть экрана (flex: 1; display: flex) */
  .chat-panel,
  body.chat-active .chat-panel,
  #app.chat-active .chat-panel,
  .app.chat-active .chat-panel,
  .chat-panel.active-mobile {
    display: flex !important;
    flex: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100% !important;
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Кнопка «Назад» (#back-btn) ВСЕГДА скрыта на десктопе */
  #back-btn,
  .back-btn,
  body.chat-active #back-btn,
  body.chat-active .back-btn {
    display: none !important;
  }

  .admin-modal-card {
    max-width: 700px !important;
    width: 650px !important;
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ============================================================
   Media Panel & Voice UI
   ============================================================ */
.message-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.voice-recording-ui {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ff4757;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.recording-dot {
  width: 10px;
  height: 10px;
  background: #ff4757;
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(255, 71, 87, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 71, 87, 0); }
}

.btn-cancel-voice { color: var(--text-dim); }
.btn-cancel-voice:hover { color: #ff4757; background: rgba(255,71,87,0.1); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ═══════════════════════════ EMOJI PICKER (ТЁМНАЯ ТЕМА) ═══════════════════════════ */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 16px;
  margin-bottom: 12px;
  width: 350px;
  max-width: calc(100vw - 32px);
  height: 400px;
  max-height: 55vh;
  background-color: #132f25 !important;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 1px rgba(0, 168, 132, 0.4) !important;
  z-index: 500 !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  animation: emojiPickerFadeIn 0.15s ease-out;
}

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

.emoji-picker.hidden {
  display: none !important;
}

.emoji-picker-header {
  flex-shrink: 0;
  background: #0f241d;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
}

.emoji-search-box {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px 12px 6px;
}

.emoji-search-icon {
  position: absolute;
  left: 22px;
  color: #8696a0;
  pointer-events: none;
}

.emoji-search-input {
  width: 100%;
  height: 36px;
  background: #132f25;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 0 32px 0 34px;
  color: #e9edef;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.emoji-search-input:focus {
  border-color: #00a884;
  box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.25);
}

.emoji-search-input::placeholder {
  color: #8696a0;
}

.emoji-search-clear {
  position: absolute;
  right: 20px;
  background: none;
  border: none;
  color: #8696a0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-search-clear:hover {
  color: #e9edef;
  background: rgba(255, 255, 255, 0.08);
}

.emoji-tabs-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.emoji-tabs-bar::-webkit-scrollbar {
  display: none;
}

.emoji-tab-btn {
  flex: 1;
  min-width: 38px;
  height: 34px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #8696a0;
  transition: background 0.15s, transform 0.15s, color 0.15s;
  position: relative;
}

.emoji-tab-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.emoji-tab-btn.active {
  background: rgba(0, 168, 132, 0.18);
  color: #00a884;
}

.emoji-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2.5px;
  background: #00a884;
  border-radius: 2px;
}

.emoji-picker-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  background: #132f25;
  scrollbar-width: thin;
  scrollbar-color: #1e4537 #0f241d;
}

.emoji-picker-body::-webkit-scrollbar {
  width: 6px;
}
.emoji-picker-body::-webkit-scrollbar-track {
  background: #0f241d;
}
.emoji-picker-body::-webkit-scrollbar-thumb {
  background: #1e4537;
  border-radius: 4px;
}
.emoji-picker-body::-webkit-scrollbar-thumb:hover {
  background: #2a5d4b;
}

.emoji-section {
  margin-bottom: 12px;
}

.emoji-section-title {
  font-size: 11px;
  font-weight: 700;
  color: #8696a0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 6px 6px;
  position: sticky;
  top: -8px;
  background: rgba(19, 47, 37, 0.95);
  backdrop-filter: blur(6px);
  z-index: 2;
  border-radius: 6px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-item {
  width: 100%;
  aspect-ratio: 1;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
  line-height: 1;
  padding: 0;
}

.emoji-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.22);
}

.emoji-item:active {
  transform: scale(0.92);
}

.emoji-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: #8696a0;
  font-size: 13px;
  text-align: center;
}

@media (max-width: 480px) {
  .emoji-picker {
    width: 92vw;
    right: 4vw;
    height: 380px;
    max-height: 50vh;
  }
  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }
}

.attachment-preview {
  display: block;
  max-width: 380px;
  max-height: 380px;
  width: auto;
  height: auto;
  object-fit: cover;
  border-radius: 12px;
  margin-top: 6px;
  cursor: pointer;
}

.attachment-video {
  display: block;
  max-width: 380px;
  max-height: 380px;
  width: auto;
  height: auto;
  border-radius: 12px;
  margin-top: 6px;
}

@media (max-width: 600px) {
  .auth-screen {
    align-items: flex-start;
    padding: 20px 12px 40px;
  }

  .attachment-preview,
  .attachment-video {
    max-width: 100%;
  }
}

/* Баббл сообщения только с картинкой (без текста) */
.message-bubble.bubble-image-only {
  width: fit-content !important;
  max-width: 320px !important;
  padding: 0 !important;
  overflow: hidden !important;
  position: relative !important;
  display: inline-block !important;
  border: none !important;
}

@media (max-width: 600px) {
  .message-bubble.bubble-image-only {
    max-width: calc(100% - 40px) !important;
  }
}

.message-bubble.bubble-image-only .message-attachments {
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  line-height: 0 !important;
  display: block !important;
}

.message-bubble.bubble-image-only .attachment-preview {
  display: block !important;
  width: 100% !important;
  max-width: 320px !important;
  height: auto !important;
  border-radius: inherit !important;
  margin: 0 !important;
  object-fit: cover !important;
}

.message-bubble.bubble-image-only .message-meta,
.message-bubble.bubble-image-only .meta-overlay {
  position: absolute !important;
  right: 8px !important;
  bottom: 8px !important;
  background: rgba(0, 0, 0, 0.55) !important;
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
  padding: 2px 8px !important;
  border-radius: 12px !important;
  color: #ffffff !important;
  font-size: 0.72rem !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  z-index: 2 !important;
  margin: 0 !important;
  pointer-events: none !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35) !important;
}

.message-bubble.bubble-image-only .message-meta svg,
.message-bubble.bubble-image-only .meta-overlay svg {
  color: #ffffff !important;
  stroke: #ffffff !important;
}

.attachment-audio {
  width: 100%;
  margin-top: 8px;
  height: 40px;
}
/* Voice player */
.custom-voice-player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-hover);
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  max-width: 300px;
  margin-top: 6px;
}

.voice-play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.voice-play-btn:hover { opacity: 0.9; }
.voice-play-btn svg { margin-left: 2px; }
.voice-play-btn .icon-pause { margin-left: 0; }

.voice-waveform {
  flex: 1;
  height: 24px;
  background: repeating-linear-gradient(90deg,var(--border) 0px,var(--border) 2px,transparent 2px,transparent 4px);
  position: relative;
  border-radius: 2px;
  overflow: hidden;
}
.voice-progress {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg,var(--accent) 0px,var(--accent) 2px,transparent 2px,transparent 4px);
  transition: width 0.1s linear;
}
.voice-duration {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

/* User profile modal */
.user-profile-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: 90vh !important;
  max-height: 90dvh !important;
  padding: 0;
}
.user-profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 16px;
  background: var(--surface);
}
.avatar-xxl {
  width: 140px;
  height: 140px;
  font-size: 3rem;
  margin-bottom: 16px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 3px solid var(--accent);
  transition: transform 0.2s ease, filter 0.2s ease, box-shadow 0.2s ease;
}
.avatar-xxl[style*="cursor: pointer"]:hover {
  transform: scale(1.04);
  filter: brightness(1.05);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
.avatar-xxl img { width: 100%; height: 100%; object-fit: cover; }
.user-profile-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  text-align: center;
}
.user-profile-status {
  font-size: 0.875rem;
  color: var(--text-dim);
  text-align: center;
}
.user-profile-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px 16px;
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.profile-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  padding: 12px 4px 8px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
  min-height: 64px;
}
.profile-action-btn:hover { background: var(--surface-hover); }
.profile-action-btn svg { color: var(--accent); }
.profile-action-btn span { font-size: 0.72rem; }
.user-profile-info { padding: 8px 0; background: var(--bg); }
.info-block {
  padding: 10px 20px;
  cursor: default;
  transition: background 0.15s;
}
.info-block:hover { background: var(--surface); }
.info-value { font-size: 1rem; color: var(--text); margin-bottom: 2px; }
.info-label { font-size: 0.8rem; color: var(--text-dim); }

/* Toast notification */
.toast-notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  background: #1e293b;
  color: #ffffff;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 99999;
  pointer-events: none;
  max-width: 90vw;
  backdrop-filter: blur(8px);
}
.toast-notification.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Group info modal */
.group-info-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: 90vh;
  max-height: 90dvh;
}
.group-members-list { overflow-y: auto; max-height: 260px; }
.group-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  transition: background 0.15s;
}
.group-member-row:hover { background: var(--surface-hover); }
.group-member-row .member-name { flex: 1; font-size: 0.95rem; }
.member-role-badge {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  margin-left: auto;
  padding-right: 8px;
  white-space: nowrap;
}
.btn-remove-member {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.btn-remove-member:hover { color: #e53935; background: rgba(229,57,53,0.1); }

/* ═══════════════════════════ ПРИВИЛЕГИИ ДЛЯ @Yurik ═══════════════════════════ */
.admin-crown {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  font-size: 0.9em;
  vertical-align: middle;
  filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.7));
}

.sender-name-yurik {
  background: linear-gradient(135deg, #ffd700, #ffaa00) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.4) !important;
  font-weight: 700 !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.avatar-yurik {
  position: relative;
  box-shadow: 0 0 0 2px #ffd700, 0 0 10px rgba(255, 215, 0, 0.6) !important;
  animation: yurikAvatarGlow 2s infinite alternate ease-in-out !important;
}

@keyframes yurikAvatarGlow {
  0% {
    box-shadow: 0 0 0 2px #ffd700, 0 0 8px rgba(255, 215, 0, 0.4);
  }
  100% {
    box-shadow: 0 0 0 3px #ffaa00, 0 0 16px rgba(255, 215, 0, 0.85);
  }
}

/* ═══════════════════════════ ОТВЕТЫ НА СООБЩЕНИЯ (REPLIES) ═══════════════════════════ */
.reply-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.reply-banner-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
}

.reply-banner-author {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.75rem;
}

.reply-banner-text {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.reply-cancel-btn {
  color: var(--text-dim);
}

.reply-cancel-btn:hover {
  color: var(--text);
}

/* ═══════════════════════════ ИНДИКАТОР ПРОГРЕССА ЗАГРУЗКИ (UPLOAD PROGRESS) ═══════════════════════════ */
.upload-progress-banner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  transition: all 0.2s ease;
}

.upload-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-progress-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.upload-progress-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.upload-progress-spinner {
  animation: spin 1s linear infinite;
}

.upload-progress-filename {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

.upload-progress-percent {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.upload-progress-track {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.15s ease;
  box-shadow: 0 0 8px var(--accent-glow);
}

.message-reply-quote {
  background: rgba(0, 0, 0, 0.15);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: background 0.2s;
  text-align: left;
}

.message-reply-quote:hover {
  background: rgba(0, 0, 0, 0.28);
}

.message-reply-author {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.message-reply-preview {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.message-highlight {
  animation: messageFlash 1.6s ease-out;
}

@keyframes messageFlash {
  0% {
    box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(16, 185, 129, 0.5);
    background-color: rgba(16, 185, 129, 0.25);
  }
  100% {
    box-shadow: none;
    background-color: transparent;
  }
}

/* ═══════════════════════════ РЕАКЦИИ НА СООБЩЕНИЯ (REACTIONS) ═══════════════════════════ */
.message {
  position: relative;
}

.message-reactions-popup,
.message-reactions-picker {
  display: none !important;
}

.reaction-popup-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.15rem;
  padding: 2px;
  border-radius: 4px;
  transition: transform 0.12s ease;
  line-height: 1;
}

.reaction-popup-btn:hover {
  transform: scale(1.35);
}

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}

.reaction-badge:hover {
  background: rgba(255, 255, 255, 0.15);
}

.reaction-badge.active {
  background: rgba(16, 185, 129, 0.22);
  border-color: var(--accent);
}

.reaction-badge .reaction-count {
  font-weight: 600;
  color: var(--text);
  font-size: 0.7rem;
}

/* ═══════════════════════════ LIGHTBOX ДЛЯ ИЗОБРАЖЕНИЙ ═══════════════════════════ */
.image-viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(6px);
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1001;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.image-viewer-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.image-viewer-content {
  position: relative;
  z-index: 1001;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-content img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.7);
  animation: zoomIn 0.2s ease-out;
}

@keyframes zoomIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ═══════════════════════════ ПРОФИЛЬ И БЕЗОПАСНОСТЬ ═══════════════════════════ */
.profile-section-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0 12px;
}

.profile-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  text-align: left;
}

.profile-section-title.danger-title {
  color: #e53935;
}

.btn-danger {
  background-color: #e53935;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-danger:hover {
  background-color: #d32f2f;
}

.btn-warning {
  background-color: #f57c00;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-warning:hover {
  background-color: #ef6c00;
}

/* Цвета отправителей в группе */
.sender-color-0 { color: #e57373 !important; }
.sender-color-1 { color: #81c784 !important; }
.sender-color-2 { color: #64b5f6 !important; }
.sender-color-3 { color: #ba68c8 !important; }
.sender-color-4 { color: #ffb74d !important; }
.sender-color-5 { color: #4db6ac !important; }
.sender-color-6 { color: #f06292 !important; }
.sender-color-7 { color: #aed581 !important; }
.sender-color-8 { color: #4fc3f7 !important; }
.sender-color-9 { color: #dce775 !important; }

/* ═══════════════════════════ КОНТЕКСТНОЕ МЕНЮ (ПКМ / Long Press) ═══════════════════════════ */
.context-menu {
  position: fixed;
  background: var(--bg-secondary, #17212b);
  border: 1px solid var(--border, #242f3d);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55), 0 0 1px rgba(0, 230, 118, 0.25);
  padding: 8px 6px;
  min-width: 185px;
  max-width: calc(100vw - 24px);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 2px;
  user-select: none;
  -webkit-user-select: none;
  animation: context-menu-fade 0.12s ease-out;
  box-sizing: border-box;
}

@keyframes context-menu-fade {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.context-reactions-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 4px;
  padding: 2px 4px 6px;
  overflow-x: auto;
}

.context-reaction-btn {
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  background: transparent;
  border: none;
}

.context-reaction-btn:hover,
.context-reaction-btn:active {
  transform: scale(1.25);
  background: var(--bg-hover);
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text, #fff);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.context-menu-item:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.08));
}

.context-menu-item.context-menu-danger {
  color: #ff5252;
}

.context-menu-item.context-menu-danger:hover {
  background: rgba(255, 82, 82, 0.15);
}

.context-menu-icon {
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
}

.context-menu-divider {
  height: 1px;
  background: var(--border, rgba(255, 255, 255, 0.08));
  margin: 4px 0;
}

/* ═══════════════════════════ ATTACH MENU (СКРЕПКА) ═══════════════════════════ */
.attach-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 220px;
  max-width: calc(100vw - 24px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55), 0 0 20px var(--shadow-glow);
  z-index: 600;
  user-select: none;
  -webkit-user-select: none;
  animation: attachMenuPop 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

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

.attach-menu.hidden {
  display: none !important;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  min-height: 48px; /* крупный удобный хитбокс под пальцы min 44px */
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
}

.attach-menu-item:hover,
.attach-menu-item:active {
  background: var(--bg-hover);
  color: var(--accent);
}

.attach-menu-icon {
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.emoji-picker-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  margin-left: 6px;
  transition: background 0.15s, color 0.15s;
  background: transparent;
  border: none;
}

.emoji-picker-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ═══════════════════════════ ВИДЕО И АУДИО В СООБЩЕНИЯХ ═══════════════════════════ */
.message-video {
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
  display: block;
  cursor: pointer;
  background: #000;
}

#image-viewer-video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
  outline: none;
  background: #000;
}

/* ═══════════════════════════ КАСТОМНЫЙ АУДИОПЛЕЕР (MP3 И ГОЛОСОВЫЕ) ═══════════════════════════ */
.custom-audio-card,
.voice-message-card,
.message-audio-track {
  background: var(--bg-primary, #0e1621);
  border-radius: 12px;
  padding: 8px 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 340px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  user-select: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.audio-card-play-btn,
.voice-play-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.audio-card-play-btn:hover,
.voice-play-btn:hover {
  opacity: 0.92;
  transform: scale(1.04);
}

.audio-card-play-btn:active,
.voice-play-btn:active {
  transform: scale(0.96);
}

.audio-card-play-btn svg,
.voice-play-btn svg {
  margin-left: 2px;
}

.audio-card-play-btn .icon-pause,
.voice-play-btn .icon-pause {
  margin-left: 0;
}

.audio-card-content,
.voice-wave-container {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.audio-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.audio-card-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.audio-card-waveform,
.voice-waveform {
  width: 100%;
  height: 22px;
  background: repeating-linear-gradient(90deg, var(--border, rgba(255,255,255,0.2)) 0px, var(--border, rgba(255,255,255,0.2)) 2px, transparent 2px, transparent 4px);
  position: relative;
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
}

.audio-card-waveform-fill,
.voice-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--accent) 0px, var(--accent) 2px, transparent 2px, transparent 4px);
  transition: width 0.08s linear;
  pointer-events: none;
}

.audio-card-track-line {
  width: 100%;
  height: 5px;
  background: var(--border, rgba(255, 255, 255, 0.15));
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  margin: 2px 0;
}

.audio-card-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.08s linear;
  pointer-events: none;
}

.audio-card-bottom,
.voice-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-dim, rgba(255, 255, 255, 0.6));
}

.audio-card-time,
.voice-duration {
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--text-dim, rgba(255, 255, 255, 0.7));
}

.audio-card-sep {
  opacity: 0.5;
}

.audio-card-size,
.voice-size {
  opacity: 0.85;
}

/* ═══════════════════════════ РЕАКЦИИ В КОНТЕКСТНОМ МЕНЮ (ПКМ) ═══════════════════════════ */
.context-reactions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  gap: 4px;
}

.context-reaction-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.35rem;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
  transition: transform 0.15s ease, background 0.15s ease;
}

.context-reaction-btn:hover {
  transform: scale(1.3);
  background: var(--bg-hover, rgba(255, 255, 255, 0.1));
}

/* ═══════════════════════════ ОБЩИЕ МЕДИА (SHARED MEDIA) ═══════════════════════════ */
.shared-media-section {
  border-top: 1px solid var(--border);
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shared-media-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.shared-tab-btn {
  background: none;
  border: none;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.shared-tab-btn.active {
  background: var(--bg-hover);
  color: var(--accent);
  font-weight: 600;
}

.shared-media-content {
  max-height: 260px;
  overflow: hidden;
}

.shared-tab-pane {
  max-height: 260px;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-bottom: 16px !important;
}

.shared-media-grid,
.shared-media-container,
.shared-content-area,
.shared-media-list {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: 260px !important;
  padding-bottom: 16px !important;
  padding-right: 4px;
}
/* Кастомный тонкий скроллбар в тон темы */
.shared-tab-pane::-webkit-scrollbar,
.shared-media-grid::-webkit-scrollbar,
.shared-media-container::-webkit-scrollbar,
.shared-content-area::-webkit-scrollbar,
.shared-media-content::-webkit-scrollbar,
.shared-media-list::-webkit-scrollbar {
  width: 5px;
}
.shared-tab-pane::-webkit-scrollbar-track,
.shared-media-grid::-webkit-scrollbar-track,
.shared-media-container::-webkit-scrollbar-track,
.shared-content-area::-webkit-scrollbar-track,
.shared-media-content::-webkit-scrollbar-track,
.shared-media-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}
.shared-tab-pane::-webkit-scrollbar-thumb,
.shared-media-grid::-webkit-scrollbar-thumb,
.shared-media-container::-webkit-scrollbar-thumb,
.shared-content-area::-webkit-scrollbar-thumb,
.shared-media-content::-webkit-scrollbar-thumb,
.shared-media-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}
.shared-tab-pane::-webkit-scrollbar-thumb:hover,
.shared-media-grid::-webkit-scrollbar-thumb:hover,
.shared-media-container::-webkit-scrollbar-thumb:hover,
.shared-content-area::-webkit-scrollbar-thumb:hover,
.shared-media-content::-webkit-scrollbar-thumb:hover,
.shared-media-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

.shared-media-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 3px !important;
  padding: 4px 0 16px 0 !important;
  padding-bottom: 16px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: 260px !important;
}

.shared-media-list {
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
  padding: 4px 0 16px 0 !important;
  padding-bottom: 16px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: 260px !important;
}

.profile-avatar-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.profile-avatar-wrapper {
  position: relative;
  display: inline-block;
}

.group-member-row {
  cursor: pointer;
  transition: background 0.15s ease;
}
.group-member-row:hover {
  background: rgba(255, 255, 255, 0.04);
}
.group-member-perm-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 4px;
  user-select: none;
}
.group-member-perm-checkbox {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.shared-media-item {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 4px;
  background: var(--bg-tertiary, #242f3d);
  cursor: pointer;
}

.shared-media-item img,
.shared-media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.shared-media-item:hover img,
.shared-media-item:hover video {
  transform: scale(1.04);
}

.shared-video-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 4px;
  border-radius: 4px;
  pointer-events: none;
}

/* Files / Audio list */
.shared-files-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

.shared-file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background 0.15s;
}
.shared-file-row:hover { background: var(--bg-hover); }

.shared-file-icon {
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.shared-file-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shared-file-name {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shared-file-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.shared-file-action {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.shared-file-action:hover { background: var(--surface-hover); }

/* Telegram-style custom voice cards in Shared Media */
.shared-voice-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: background 0.15s;
}
.shared-voice-card:hover { background: var(--bg-hover); }

.shared-voice-play-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}
.shared-voice-play-btn:hover { transform: scale(1.05); }

.shared-voice-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.shared-voice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.shared-voice-progress-wrap {
  position: relative;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
}

.shared-voice-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

.shared-empty-text {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 24px 0;
}

/* Switch account button rotation animation */
#switch-account-btn:hover svg,
#switch-account-btn:active svg,
.btn-switch-account:hover svg,
.btn-switch-account:active svg {
  transform: rotate(180deg);
  transition: transform 0.4s ease-in-out;
}

/* Exclusive Yuri VIP profile card styles */
.profile-card-yurik {
  box-shadow: 0 0 0 2px #ffd700, 0 8px 32px rgba(255, 215, 0, 0.3) !important;
  border: 1px solid #ffd700 !important;
}

.yurik-badge-creator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 170, 0, 0.1));
  color: #ffd700;
  border: 1px solid #ffd700;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  animation: yurik-badge-pulse 2.5s infinite ease-in-out;
}

@keyframes yurik-badge-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 215, 0, 0.3); }
  50% { box-shadow: 0 0 16px rgba(255, 215, 0, 0.7); }
}

/* Global broadcast banner */
.broadcast-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #fff;
  border: 1px solid #ffd700;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 12px rgba(255, 215, 0, 0.3);
  padding: 12px 20px;
  border-radius: 12px;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
  width: 480px;
  animation: broadcastIn 0.3s ease;
}

@keyframes broadcastIn {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ═══════════════════════════ ЗАГЛУШКА ТЕХОБСЛУЖИВАНИЯ (MAINTENANCE) ═══════════════════════════ */
.maintenance-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary, #0e1621);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.maintenance-card {
  background: var(--surface, #182533);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.maintenance-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 16px;
  animation: pulse 2.5s infinite;
}

.maintenance-card h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text, #fff);
}

.maintenance-card p {
  font-size: 0.92rem;
  color: var(--text-dim, #7f91a4);
  line-height: 1.5;
  margin: 0;
}

/* Закреплённое сообщение (Pinned message banner) */
.pinned-message-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
  z-index: 5;
}

.pinned-message-banner:hover {
  background: var(--bg-hover);
}

.pinned-icon {
  font-size: 1.1rem;
}

.pinned-content {
  flex: 1;
  overflow: hidden;
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.pinned-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.2;
}

.pinned-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.pinned-unpin-btn {
  opacity: 0.6;
  padding: 4px;
}

.pinned-unpin-btn:hover {
  opacity: 1;
  color: var(--danger);
}

/* Подсветка сообщения при переходе по цитате или закреплению */
@keyframes messageHighlight {
  0% { background: rgba(0, 230, 118, 0.45); }
  100% { background: transparent; }
}

.message-highlight {
  animation: messageHighlight 1.2s ease-out;
  border-radius: var(--radius-bubble);
}

/* Анимация точек набора текста («печатает...») */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
}

.typing-dots span {
  animation: typingDot 1.4s infinite;
  display: inline-block;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingDot {
  0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.typing-indicator-sidebar {
  color: var(--accent) !important;
  font-style: italic;
  font-weight: 500;
}

.message-avatar,
.message-sender {
  cursor: pointer;
}

/* ═══════════════════════════ ПОДСВЕТКА И МУЛЬТИ-ЗАКРЕПЫ ═══════════════════════════ */
@keyframes pinHighlight {
  0% { background-color: rgba(46, 204, 113, 0.4); }
  70% { background-color: rgba(46, 204, 113, 0.2); }
  100% { background-color: transparent; }
}

.message-pinned-highlight .message-bubble {
  animation: pinHighlight 1.5s ease-out forwards !important;
}

.pinned-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pinned-counter {
  font-size: 0.72rem;
  color: var(--accent, #2ecc71);
  background: rgba(46, 204, 113, 0.15);
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}

.pinned-bar-indicator {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent, #2ecc71);
  border-radius: 2px 0 0 2px;
}

/* Фикс контекстного меню (ПКМ) */
#message-context-menu {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#message-context-menu.hidden {
  display: none !important;
}

.context-menu-item {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  width: 100% !important;
  position: static !important;
  margin: 0 !important;
  padding: 8px 14px !important;
  box-sizing: border-box !important;
}

.context-menu-item span,
.context-label {
  position: static !important;
  margin: 0 !important;
  white-space: nowrap !important;
}

.context-menu-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 4px 0;
}
.context-menu-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  user-select: none;
}
.context-menu-footer .ctx-status-icon {
  font-size: 14px;
  color: #2ecc71;
  font-weight: bold;
}

/* Telegram-style Waveform Voice Player & Компактность */
.message-bubble.type-voice,
.message-bubble:has(.voice-message-player) {
  position: relative !important;
  display: inline-flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 8px 12px 6px 12px !important;
  width: fit-content !important;
  max-width: 380px !important;
  min-width: 240px !important;
  height: auto !important;
  min-height: auto !important;
  aspect-ratio: auto !important;
}

/* Мета-блок (время и статус прочтения) прижимаем вправо вниз */
.message-bubble.type-voice .voice-standalone-meta,
.message-bubble:has(.voice-message-player) .voice-standalone-meta,
.message-bubble.type-voice .message-meta {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  align-self: flex-end !important;
  margin-top: 2px !important;
  margin-left: auto !important;
  font-size: 11px !important;
  line-height: 1 !important;
  gap: 4px !important;
}

.message-bubble:has(.voice-message-player) .message-attachments,
.message-bubble.type-voice .message-attachments {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

.message-bubble:has(.voice-message-player) .custom-voice-player,
.message-bubble.type-voice .custom-voice-player {
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  max-width: 100% !important;
}

.voice-message-player {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  width: 100% !important;
  height: auto !important;
  box-sizing: border-box !important;
  padding: 0 !important;
}
.voice-play-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #3498db;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}
.voice-play-btn:hover {
  transform: scale(1.05);
}
.voice-play-btn svg {
  width: 18px;
  height: 18px;
}
.voice-content,
.voice-wave-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.voice-waveform {
  display: flex !important;
  align-items: center !important;
  gap: 2px !important;
  height: 22px !important;
  max-height: 22px !important;
  cursor: pointer;
  padding: 2px 0;
  background: none !important;
}
.waveform-bar {
  width: 2px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 1px;
  transition: background-color 0.1s ease;
  flex-shrink: 0;
}
.waveform-bar.played {
  background: #3498db;
}
.voice-info-row,
.voice-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
}
.voice-unread-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3498db;
  display: inline-block;
  flex-shrink: 0;
}
.voice-unread-dot.hidden {
  display: none !important;
}

/* ============================================================
   Fluent 3D Animated Emojis (Exclusive VIP Pack)
   ============================================================ */
.chat-fluent-emoji {
  width: 24px;
  height: 24px;
  vertical-align: -4px;
  display: inline-block;
  object-fit: contain;
  will-change: transform;
  transform: translateZ(0);
  image-rendering: auto;
  backface-visibility: hidden;
}

.chat-fluent-emoji.chat-fluent-big {
  width: 52px !important;
  height: 52px !important;
  vertical-align: middle;
  will-change: transform;
  transform: translateZ(0);
  image-rendering: auto;
  backface-visibility: hidden;
}

/* Emoji picker Fluent VIP styling */
.emoji-tab-vip {
  color: #ffd700 !important;
  position: relative;
}

.emoji-tab-vip.active {
  color: #ffd700 !important;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.7);
}

.emoji-section-vip .vip-title {
  color: #ffd700 !important;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.emoji-grid-fluent {
  grid-template-columns: repeat(6, 1fr) !important;
}

.emoji-item-fluent {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 4px !important;
}

.picker-fluent-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  pointer-events: none;
  display: block;
  will-change: transform;
  transform: translateZ(0);
  image-rendering: auto;
  backface-visibility: hidden;
}

/* ============================================================
   Splash Screen (Заставка первого входа)
   ============================================================ */
#splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 99999;
  background-color: #071410;
  background: radial-gradient(circle at center, #0e2720 0%, #071410 70%, #040b09 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.55s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: all;
  user-select: none;
  -webkit-user-select: none;
}

#splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.splash-logo-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Мягкий неоновый ореол вокруг пальмы */
.splash-logo-wrap::before {
  content: '';
  position: absolute;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 230, 118, 0.28) 0%, rgba(0, 230, 118, 0) 70%);
  filter: blur(14px);
  animation: splashAura 2s ease-in-out infinite alternate;
  pointer-events: none;
}

.splash-logo {
  position: relative;
  width: 130px;
  height: 130px;
  max-width: 40vw;
  max-height: 40vh;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(0, 230, 118, 0.35));
  animation: splashLogoScaleIn 1.1s cubic-bezier(0.34, 1.35, 0.64, 1) forwards;
  will-change: transform, opacity;
}

@keyframes splashLogoScaleIn {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  70% {
    opacity: 1;
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes splashAura {
  0% {
    transform: scale(0.85);
    opacity: 0.45;
  }
  100% {
    transform: scale(1.2);
    opacity: 0.85;
  }
}

/* ============================================================
   Кастомное контекстное меню для чатов
   ============================================================ */
.chat-context-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-card, #1e293b);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: var(--radius-md, 12px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  padding: 6px;
  min-width: 170px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: contextMenuIn 0.12s ease-out forwards;
}

@keyframes contextMenuIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  font-size: 0.9rem;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text, #ffffff);
  transition: background 0.15s, color 0.15s;
}

.context-menu-item:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.08));
}

.context-menu-item.text-danger {
  color: #ef4444;
}

.context-menu-item.text-danger:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}