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

:root {
  --bg-app: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-main: #f8f9ff;
  --bg-sidebar: #ffffff;
  --bg-panel: #ffffff;
  --bg-header: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f0f2ff;
  --bg-badge: #667eea;
  --text-primary: #333333;
  --text-secondary: #888888;
  --text-muted: #aaa;
  --border: #eef0f5;
  --bubble-bg: #ffffff;
  --bubble-own: linear-gradient(135deg, #667eea, #764ba2);
  --bubble-own-hover: #5a6bd6;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-own: 0 4px 15px rgba(102, 126, 234, 0.3);
  --accent: #667eea;
  --accent2: #764ba2;
  --accent-text: #ffffff;
  --scrollbar: #d0d5f5;
  --sticker-bg: #f6f7ff;
  --quote-bg: rgba(102, 126, 234, 0.12);
  --meta-own: #cfd5f0;
  --danger: #e74c3c;
  --success: #2ecc71;
  --modal-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] {
  --bg-app: linear-gradient(135deg, #0b0d14 0%, #1a0f2e 100%);
  --bg-main: #07080d;
  --bg-sidebar: #0d1017;
  --bg-panel: #10141d;
  --bg-header: #0b0e15;
  --bg-input: #151a26;
  --bg-hover: #1a2030;
  --bg-badge: #7d86ff;
  --text-primary: #d9dce8;
  --text-secondary: #878ea5;
  --text-muted: #5a6177;
  --border: #191f2c;
  --bubble-bg: #141a28;
  --bubble-own: linear-gradient(135deg, #4658d9, #6a3da8);
  --bubble-own-hover: #3d4fc2;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  --shadow-own: 0 4px 20px rgba(60, 80, 220, 0.35);
  --accent: #7d86ff;
  --accent2: #9a6fd6;
  --accent-text: #ffffff;
  --scrollbar: #232a3d;
  --sticker-bg: #111524;
  --quote-bg: rgba(125, 134, 255, 0.14);
  --meta-own: #969dc9;
  --danger: #ff5f56;
  --success: #31d07e;
  --modal-shadow: 0 24px 70px rgba(0, 0, 0, 0.8);
}

body[data-theme="dark"] .chat-screen {
  background: transparent;
}

body[data-theme="dark"] .input-area input[type="text"],
body[data-theme="dark"] .caption-bar input[type="text"],
body[data-theme="dark"] .search-input,
body[data-theme="dark"] .gs-input {
  background: #0c0f16;
  color: var(--text-primary);
}

body[data-theme="dark"] .msg-meta .msg-time {
  color: #656d86;
}
body[data-theme="dark"] .msg-time span { color: #656d86; }

body[data-theme="dark"] .settings-range {
  background: #181c25;
}
body[data-theme="dark"] .settings-range::-webkit-slider-thumb {
  background: #8e6cf5;
}
body[data-theme="dark"] .settings-range::-moz-range-thumb {
  background: #8e6cf5;
}
body[data-theme="dark"] .settings-range::-webkit-slider-runnable-track {
  background: #252a37;
}

.settings-range {
  width: 100%;
  accent-color: var(--accent);
}
.settings-range::-webkit-slider-runnable-track {
  background: #e2e4ea;
  height: 6px;
  border-radius: 4px;
}
.settings-range::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -5px;
  cursor: pointer;
}
.settings-range::-moz-range-track {
  background: #e2e4ea;
  height: 6px;
  border-radius: 4px;
}
.settings-range::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.poll-msg.closed .poll-question { text-decoration: line-through; opacity: 0.6; }
.poll-msg.closed .poll-option { opacity: 0.6; pointer-events: none; }
.poll-msg .poll-closed { color: #666; font-size: 13px; margin: 6px 0 4px; }
.poll-msg .poll-close { background: none; border: 1px solid #e0e0e0; border-radius: 6px; padding: 4px 12px; color: #666; cursor: pointer; font-size: 13px; margin: 4px 0 6px; }
.poll-msg .poll-close:hover { background: rgba(255,70,70,0.1); color: #a00; border-color: #a00; }
body[data-theme="dark"] .poll-msg .poll-close { border-color: #383c47; color: #999; }
body[data-theme="dark"] .poll-msg .poll-close:hover { background: rgba(255,70,70,0.15); color: #ff6666; border-color: #a00; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-app);
  height: 100vh;
  overflow: hidden;
}

/* ===== Ссылка на меню сайтов ===== */
.menu-link {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1000;
  background: var(--bg-sidebar);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.menu-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--modal-shadow);
  background: var(--bg-hover);
}

/* ===== Экран входа ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--bg-sidebar);
  color: var(--text-primary);
  border-radius: 20px;
  padding: 40px 45px;
  width: 400px;
  text-align: center;
  box-shadow: var(--modal-shadow);
  animation: slideIn 0.5s ease;
  border: 1px solid var(--border);
}

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

.login-logo {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin: 0 auto 20px;
}

.login-logo svg { width: 38px; height: 38px; }

.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-card > p { color: var(--text-secondary); font-size: 14px; margin-bottom: 25px; }

.login-card input[type="text"] {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
  margin-bottom: 20px;
}

.login-card input[type="text"]:focus { border-color: var(--accent); }

.avatar-preview {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  margin: 0 auto 12px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 36px;
  font-weight: bold;
  color: var(--accent);
  border: 3px dashed var(--border);
}

.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

.avatar-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 20px;
  text-decoration: underline;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.login-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4); }
.login-btn:disabled { opacity: 0.6; cursor: default; transform: none; }

.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ===== Основной чат ===== */
.chat-screen { display: flex; height: 100vh; }

/* Сайдбар */
.sidebar {
  width: 300px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 20px rgba(0, 0, 0, 0.08);
  z-index: 1;
}

.tabs {
  display: flex;
  padding: 12px 12px 0;
  gap: 6px;
}

.tab {
  flex: 1;
  padding: 9px 0;
  background: transparent;
  border: none;
  border-radius: 10px 10px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab.active { background: var(--bg-main); color: var(--accent); }

.panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-main); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-list::-webkit-scrollbar, .users-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb, .users-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

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

.chat-avatar, .user-avatar, .me-avatar, .msg-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
  color: #fff;
}

.chat-avatar.common-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  font-size: 22px;
}

.user-avatar, .me-avatar { width: 42px; height: 42px; }
.msg-avatar { width: 36px; height: 36px; font-size: 15px; }
.chat-avatar img, .user-avatar img, .me-avatar img, .msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

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

.chat-name {
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.chat-time { font-size: 11px; color: var(--text-muted); }

.unread-badge {
  background: var(--bg-badge);
  color: #fff;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-search { padding: 10px 12px; }

.user-search input {
  width: 100%;
  padding: 9px 14px;
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: 20px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.3s;
}

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

.users-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

.user-name {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status { font-size: 12px; color: var(--text-secondary); }
.user-status.online { color: var(--success); }

/* ===== Мой профиль ===== */
.me {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.me-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-badge { font-size: 12px; color: var(--success); }

.me-change-avatar {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: 8px;
}

.me-change-avatar:hover { background: var(--bg-hover); }

/* ===== Основная панель чата ===== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  position: relative;
  min-width: 0;
}

.chat-header {
  padding: 14px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 2;
}

.back-btn {
  display: none;
  background: var(--bg-hover);
  border: none;
  color: var(--accent);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
}

.chat-title-wrap { flex: 1; min-width: 0; }

.chat-title-wrap h1 {
  font-size: 20px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle { font-size: 13px; color: var(--text-secondary); }

.typing-status {
  display: block;
  font-size: 12.5px;
  color: var(--accent);
  font-style: italic;
  min-height: 15px;
}

.header-actions { display: flex; gap: 6px; }

.header-actions button {
  width: 38px;
  height: 38px;
  border: none;
  background: var(--bg-hover);
  border-radius: 10px;
  font-size: 17px;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.header-actions button:hover { transform: scale(1.08); background: var(--border); }

/* ===== Сообщения ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: min(70%, 560px);
  animation: msgIn 0.25s ease;
}

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

.message.own { align-self: flex-end; flex-direction: row-reverse; }

.msg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.msg-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
}

.message.own .msg-meta { justify-content: flex-end; }

.msg-name { font-weight: 600; color: var(--accent); }

.msg-bubble {
  background: var(--bubble-bg);
  padding: 10px 15px;
  border-radius: 16px;
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
  font-size: 14.5px;
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.45;
}

.message.own .msg-bubble {
  background: var(--bubble-own);
  color: #fff;
  border-top-left-radius: 16px;
  border-top-right-radius: 4px;
  box-shadow: var(--shadow-own);
}

.reply-quote {
  border-left: 3px solid var(--accent);
  background: var(--quote-bg);
  border-radius: 6px;
  padding: 5px 9px;
  margin-bottom: 6px;
  font-size: 12.5px;
}

.reply-quote-name { font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.reply-quote-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message.own .reply-quote-name { color: #fff; }
.message.own .reply-quote-text { color: #dde3f5; }

.forward-banner {
  font-size: 11.5px;
  color: var(--accent);
  font-style: italic;
  margin-bottom: 4px;
}

.message.own .forward-banner { color: #e0e4f7; }

.deleted-text { font-style: italic; color: var(--text-muted); }
.message.own .deleted-text { color: #d5daf5; }

/* Медиа */
.msg-media {
  background: var(--bubble-bg);
  border-radius: 16px;
  border-top-left-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  padding: 5px;
  max-width: 340px;
}

.message.own .msg-media {
  background: var(--bubble-own-hover);
  border-top-left-radius: 16px;
  border-top-right-radius: 4px;
}

.msg-media img { max-width: 100%; max-height: 300px; border-radius: 12px; display: block; cursor: pointer; }
.msg-media video { max-width: 100%; max-height: 300px; border-radius: 12px; display: block; }
.msg-media audio { width: 250px; max-width: 100%; }

.msg-media.sticker {
  background: var(--sticker-bg);
  font-size: 110px;
  line-height: 1;
  text-align: center;
  padding: 10px 16px;
  user-select: none;
  cursor: default;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  text-decoration: none;
  color: var(--text-primary);
  min-width: 190px;
  border-radius: 10px;
  transition: background 0.15s;
}

.msg-file:hover { background: var(--bg-hover); }
.message.own .msg-file { color: #fff; }
.message.own .msg-file:hover { background: rgba(255, 255, 255, 0.12); }

.file-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 18px;
}

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

.file-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size { font-size: 12px; color: var(--text-secondary); display: block; margin-top: 2px; }
.message.own .file-size { color: #d5daf5; }

.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  margin-top: 2px;
}

.message:hover .msg-actions { opacity: 1; }
.message.own .msg-actions { justify-content: flex-end; }

.act {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}

.act:hover { border-color: var(--accent); color: var(--accent); }
.act.danger:hover { border-color: var(--danger); color: var(--danger); }

.msg-time { font-size: 11px; color: var(--text-muted); }

.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px;
  font-style: italic;
}

/* Лайтбокс */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: pointer;
}

.lightbox img { max-width: 90%; max-height: 90%; border-radius: 8px; }

/* ===== Панели эмодзи/стикеров ===== */
.emoji-panel, .sticker-panel {
  position: absolute;
  right: 18px;
  bottom: 130px;
  width: 350px;
  max-width: calc(100% - 36px);
  max-height: 320px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--modal-shadow);
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.emoji-cats { display: flex; overflow-x: auto; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }

.emoji-cats button {
  border: none;
  background: transparent;
  padding: 5px 11px;
  border-radius: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
}

.emoji-cats button.active { background: var(--bg-hover); color: var(--accent); }

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

.emoji-grid button {
  border: none;
  background: transparent;
  font-size: 24px;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.emoji-grid button:hover { background: var(--bg-hover); }

.sticker-panel { width: 400px; }

.sticker-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
}

.sticker-btn {
  border: none;
  border-radius: 14px;
  font-size: 52px;
  height: 84px;
  cursor: pointer;
  transition: transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.sticker-btn:hover { transform: scale(1.08); }

/* ===== Панель ответа ===== */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
}

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

.reply-label { font-size: 12.5px; color: var(--text-secondary); display: block; }
.reply-label b { color: var(--accent); }
.reply-preview { font-size: 13px; color: var(--text-primary); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reply-close {
  background: var(--bg-hover);
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
}

/* ===== Поле ввода ===== */
.input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
}

.attach-btn, .send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  font-size: 18px;
}

.attach-btn { background: var(--bg-hover); color: var(--accent); }
.attach-btn:hover { transform: scale(1.06); background: var(--border); }

.send-btn { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 17px; }
.send-btn:hover { transform: scale(1.08); box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); }

.input-area input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 12px 18px;
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.3s;
}

.input-area input[type="text"]::placeholder { color: var(--text-muted); }
.input-area input[type="text"]:focus { border-color: var(--accent); }

/* ===== Полоса загрузки ===== */
.upload-bar {
  background: var(--bg-header);
  padding: 0 18px 12px;
  border-top: 1px solid var(--border);
}

.upload-info { display: flex; align-items: center; gap: 15px; font-size: 13px; color: var(--text-secondary); }

.progress { flex: 1; height: 6px; background: var(--bg-hover); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; transition: width 0.3s; }

/* ===== Модалки ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-sidebar);
  color: var(--text-primary);
  border-radius: 18px;
  padding: 26px;
  width: 360px;
  max-width: calc(100% - 40px);
  box-shadow: var(--modal-shadow);
  animation: msgIn 0.2s ease;
}

.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal-hint { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.btn-cancel, .btn-primary {
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn-cancel { background: var(--bg-hover); color: var(--text-primary); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: default; transform: none; }

.forward-targets { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.forward-targets::-webkit-scrollbar { width: 6px; }
.forward-targets::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.forward-target {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.forward-target:hover { background: var(--bg-hover); }
.forward-target.selected { border-color: var(--accent); background: var(--bg-hover); }
.forward-target .user-avatar { width: 36px; height: 36px; font-size: 15px; }
.forward-target-name { font-size: 14px; font-weight: 500; color: var(--text-primary); }

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  font-size: 14.5px;
  color: var(--text-primary);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.setting-row input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* ===== Редактирование и статусы ===== */
.msg-edited { font-size: 10.5px; color: var(--text-muted); }
.msg-status { color: var(--success); font-size: 11px; }
.message.own .msg-status { color: #bfe3c8; }

/* ===== Реакции ===== */
.reaction-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction-chip {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  user-select: none;
}
.reaction-chip:hover { transform: scale(1.05); border-color: var(--accent); }
.reaction-chip.mine { border-color: var(--accent); background: var(--quote-bg); }

.reaction-palette {
  position: fixed;
  z-index: 300;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--modal-shadow);
  display: flex;
  gap: 2px;
  padding: 6px;
}
.rp-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
}
.rp-btn:hover { background: var(--bg-hover); transform: scale(1.15); }

/* ===== Поиск ===== */
.search-modal { width: 480px; }
.search-input {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.3s;
}
.search-input:focus { border-color: var(--accent); }
.search-results { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s;
}
.search-item:hover { background: var(--bg-hover); }
.search-item .user-avatar { width: 36px; height: 36px; font-size: 15px; }
.search-item-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.search-item-ch { color: var(--accent); font-weight: 600; }
.search-item-time { color: var(--text-muted); flex-shrink: 0; }
.search-item-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Группы ===== */
.chat-create-row { padding: 10px 12px 0; }
.create-group-btn {
  width: 100%;
  padding: 9px;
  background: var(--bg-hover);
  border: none;
  border-radius: 12px;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.create-group-btn:hover { background: var(--border); }

.group-actions { justify-content: space-between; }
.btn-danger {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--danger);
  color: #fff;
  transition: opacity 0.15s;
}
.btn-danger:hover { opacity: 0.85; }

/* Подсветка найденного сообщения */
.message.highlight .msg-bubble { box-shadow: 0 0 0 3px var(--accent); animation: highlightPulse 1.2s ease; }
@keyframes highlightPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent); }
  50% { box-shadow: 0 0 0 6px var(--accent); }
}

/* ===== Адаптивность ===== */
@media (max-width: 768px) {
  .back-btn { display: flex; }

  .sidebar { width: 78px; }
  .sidebar .tab { font-size: 0; }
  .sidebar .tab::first-letter { font-size: 14px; }
  .chat-item { justify-content: center; padding: 10px 4px; }
  .chat-avatar { width: 46px; height: 46px; }
  .chat-info, .chat-side, .chat-time, .unread-badge, .user-info, .me-info, .me-change-avatar, .user-search, .reply-preview, .chat-create-row { display: none; }
  .panel { align-items: center; }
  .chat-list, .users-list { width: 100%; align-items: center; }
  .me { justify-content: center; padding: 10px 4px; }

  .message { max-width: 85%; }
  .messages { padding: 14px; }
  .input-area { padding: 10px; }
  .emoji-panel, .sticker-panel { bottom: 120px; right: 8px; width: calc(100% - 16px); }
  .login-card { width: 90%; padding: 30px 24px; }
  .search-modal { width: calc(100% - 30px); }
}

/* ===== Закреплённые сообщения ===== */
.pin-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  margin: 8px 14px 0;
  background: var(--accent-gradient, linear-gradient(135deg, #667eea, #764ba2));
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  flex-shrink: 0;
}
.pin-banner-title { white-space: nowrap; font-weight: 600; }
.pin-banner-text {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
}
.pin-banner-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.7;
}
.pin-banner-close:hover { opacity: 1; }

/* ===== Системные сообщения ===== */
.message.system {
  justify-content: center;
  padding: 14px 0 4px;
}
.message.system .system-bubble {
  background: rgba(127, 127, 127, 0.14);
  color: var(--text-dim, #888);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  max-width: 90%;
}

/* ===== Упоминания ===== */
.mention {
  background: rgba(102, 126, 234, 0.18);
  color: var(--accent, #667eea);
  border-radius: 4px;
  padding: 0 2px;
  font-weight: 600;
}
.mention-menu {
  position: fixed;
  z-index: 1000;
  width: 240px;
  background: var(--card, #fff);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  padding: 4px;
  border: 1px solid rgba(127, 127, 127, 0.2);
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.mention-item.active, .mention-item:hover { background: rgba(102, 126, 234, 0.12); }
.mention-item-name { font-size: 14px; }

/* ===== Drag & drop ===== */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 20, 0.5);
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
}
.drag-overlay.visible { display: flex; }

/* ===== Профиль ===== */
.profile-modal { width: 360px; }
.profile-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.profile-avatar { width: 64px !important; height: 64px !important; font-size: 26px !important; border-radius: 50% !important; }
.profile-avatar img { width: 100% !important; height: 100% !important; object-fit: cover !important; border-radius: 50% !important; }
.profile-name { font-size: 18px; font-weight: 700; }
.profile-status { font-size: 13px; color: var(--text-dim, #888); }
.profile-status.online { color: var(--success, #2ecc71); }
.profile-info { margin-bottom: 12px; }
.profile-info .system-message { text-align: left; }
.profile-actions { flex-wrap: wrap; gap: 8px; }

/* ===== Группа: участники и модерация ===== */
.group-members-block { margin-bottom: 6px; }
.group-members-header { font-size: 13px; font-weight: 600; color: var(--text-dim, #888); margin: 8px 0 4px; }
.member-row { display: flex; align-items: center; }
.member-row .forward-target-name { flex: 1; }
.member-actions { display: flex; gap: 6px; }
.member-btn {
  border: none;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(102, 126, 234, 0.12);
  color: var(--accent, #667eea);
}
.member-btn.danger { background: rgba(231, 76, 60, 0.12); color: var(--danger, #e74c3c); }

/* ===== Экспорт ===== */
.export-row { display: flex; gap: 8px; margin: 6px 0 4px; }

/* ===== Голосовые сообщения ===== */
.voice-btn.rec { background: var(--danger, #e74c3c); color: #fff; animation: rec-pulse 1.2s infinite; }
@keyframes rec-pulse { 50% { opacity: 0.55; } }
.voice-bar {
  position: absolute;
  left: 10px; right: 10px; bottom: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg-hover, #2a2a3d);
  border: 1px solid var(--border, #333);
  font-size: 14px;
  animation: rise-in 0.15s ease-out;
}
@keyframes rise-in { from { transform: translateY(6px); opacity: 0; } }
.voice-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger, #e74c3c); animation: rec-pulse 1.2s infinite; }
.voice-timer { font-weight: 700; font-variant-numeric: tabular-nums; }
.voice-hint { color: var(--text-dim, #888); font-size: 13px; flex: 1; }
.voice-cancel {
  border: none; background: none; color: var(--text-dim, #888);
  font-size: 16px; cursor: pointer; padding: 2px 4px; border-radius: 6px;
}
.voice-cancel:hover { color: var(--danger, #e74c3c); background: rgba(231, 76, 60, 0.12); }
.voice-stop {
  border: none; background: var(--danger, #e74c3c); color: #fff;
  width: 34px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.voice-msg { display: flex; align-items: center; gap: 8px; }
.voice-play {
  border: none; border-radius: 50%;
  width: 38px; height: 38px; font-size: 14px; cursor: pointer;
  background: var(--accent, #667eea); color: #fff; flex: none;
}
.voice-play:hover { opacity: 0.88; }
.voice-label { font-size: 13px; color: var(--text-dim, #888); }

/* ===== Кнопка «к непрочитанным» ===== */
.jump-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 62px;
  z-index: 8;
  border: 1px solid var(--border, #333);
  background: var(--accent, #667eea);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.jump-bottom:hover { filter: brightness(1.1); }
.jump-bottom .count { opacity: 0.85; }

/* ===== Контекстное меню ===== */
.context-menu {
  position: fixed;
  z-index: 120;
  min-width: 190px;
  background: var(--bg-hover, #2a2a3d);
  border: 1px solid var(--border, #333);
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text, #eee);
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
}
.context-menu button:hover { background: rgba(102, 126, 234, 0.15); }
.context-menu .cmi.danger { color: var(--danger, #e74c3c); }

/* ===== Настройки группы ===== */
.group-settings { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.gs-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gs-input {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--border, #333);
  background: var(--bg, #232338);
  color: var(--text, #eee);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
}
.member-btn.primary { background: var(--accent, #667eea); color: #fff; }
.member-btn.danger { background: rgba(231, 76, 60, 0.12); color: var(--danger, #e74c3c); }

/* ===== Свачи цвета профиля ===== */
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent, #667eea); }

/* ===== Лайтбокс ===== */
.lb-counter {
  position: fixed;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 14px;
  padding: 4px 12px;
}
.lb-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 26px;
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.25); }
.lb-nav.prev { left: 18px; }
.lb-nav.next { right: 18px; }
.lb-close {
  position: fixed;
  top: 12px; right: 16px;
  z-index: 2;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.lb-close:hover { background: rgba(255, 255, 255, 0.25); }
/* ===== Batch 3: markdown / saved / favorites / status / select / stickers / invite ===== */
.markdown { line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; font-size: var(--msg-font, 14px); }
.markdown code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: Consolas, Menlo, monospace;
  font-size: 0.88em;
  color: var(--accent);
}
.dark .markdown code { background: rgba(255, 255, 255, 0.14); }
.markdown a { color: var(--accent); text-decoration: underline; }
.markdown s { opacity: 0.7; }
.markdown em { font-style: italic; }
.mention { background: rgba(102, 126, 234, 0.14); border-radius: 6px; padding: 0 3px; }

.sticker-grid { display: flex; flex-wrap: wrap; gap: 8px; max-height: 180px; overflow-y: auto; padding: 8px; }
.sticker-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; cursor: pointer; }
.sticker-thumb:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.sticker-add { width: 100%; margin-top: 6px; }

.me-status-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.me-status-select {
  border: none; background: transparent; color: var(--text-secondary);
  font-size: 12px; cursor: pointer; outline: none;
  max-width: 110px;
}
.st-busy { color: var(--danger, #e74c3c) !important; }
.st-away { color: #e67e22 !important; }
.st-ok { color: var(--success, #2ecc71) !important; }
.st-offline { color: var(--text-secondary) !important; }

.select-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.select-count { font-weight: 600; margin-right: 4px; white-space: nowrap; }
.sel-delete { background: rgba(231, 76, 60, 0.12) !important; color: var(--danger, #e74c3c) !important; }
.messages.select-mode .message { cursor: pointer; }
.messages.select-mode .message:hover { background: rgba(102, 126, 234, 0.05); }
.message.selected { outline: 2px solid var(--accent); border-radius: 14px; }
.message.selected::before {
  content: "✓"; position: absolute; top: 8px; left: 8px; z-index: 3;
  background: var(--accent); color: #fff; width: 20px; height: 20px;
  border-radius: 50%; font-size: 12px; line-height: 20px; text-align: center;
}
.message { position: relative; }

.invite-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px 4px; flex-wrap: wrap; }
.invite-code {
  background: rgba(102, 126, 234, 0.12); color: var(--accent);
  padding: 4px 10px; border-radius: 8px; font-family: Consolas, monospace;
  cursor: pointer; font-size: 13px;
}
.join-open { margin-top: 6px; }

.fav-overlay-list { max-height: 400px; overflow-y: auto; }
.forward-targets { max-height: 300px; overflow-y: auto; }

.chat-create-row .ghost {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  flex: 1;
}
.chat-create-row .ghost:hover { border-color: var(--accent); color: var(--accent); background: rgba(102, 126, 234, 0.06); }

.sticker-panel { padding: 6px; overflow-y: auto; }

/* Batch 4 */
.modal-overlay[hidden] { display: none !important; }
.thread-pane {
  position: fixed; top: 0; right: 0; width: 360px; height: 100vh;
  background: var(--bg-secondary, #fff); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
}
.thread-pane[hidden] { display: none !important; }
.thread-pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.thread-pane-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); }
.thread-pane-parent {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: rgba(102,126,234,0.05); font-size: 12px; color: var(--text-secondary); max-height: 120px; overflow-y: auto;
}
.thread-pane-messages { flex: 1; overflow-y: auto; padding: 8px; }
.thread-pane-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.thread-pane-input input { flex: 1; }

.poll-overlay { display: none; }
.poll-overlay[hidden] { display: none !important; }
.poll-modal { min-width: 340px; }
.poll-q { width: 100%; margin-bottom: 8px; }
.poll-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 250px; overflow-y: auto; }
.poll-opt-row { display: flex; gap: 6px; }
.poll-opt-row input { flex: 1; }
.poll-remove { background: rgba(231,76,60,0.12) !important; color: var(--danger, #e74c3c) !important; padding: 4px 8px !important; }
.poll-msg { padding: 10px; background: rgba(102,126,234,0.05); border-radius: 12px; margin: 4px 0; }
.poll-question { font-weight: 600; margin-bottom: 8px; }
.poll-option {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font-size: 13px; margin-bottom: 4px; position: relative; overflow: hidden;
}
.poll-option:hover { background: rgba(102,126,234,0.08); }
.poll-option.voted { border-color: var(--accent); background: rgba(102,126,234,0.12); }
.poll-bar {
  position: absolute; left: 0; top: 0; height: 100%;
  background: rgba(102,126,234,0.10); transition: width 0.3s ease;
}
.poll-pct { font-weight: 600; font-size: 12px; margin-left: auto; z-index: 1; white-space: nowrap; }
.poll-text { z-index: 1; }
.poll-meta { font-size: 11px; color: var(--text-secondary); margin-top: 6px; }

.secret-overlay { display: none; }
.secret-overlay[hidden] { display: none !important; }
.secret-modal select { width: 100%; margin: 8px 0; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-secondary, #fff); color: var(--text-primary); }

.read-tick { font-size: 11px; margin-left: 4px; vertical-align: middle; }
.read-tick.tick { color: var(--text-secondary); }
.read-tick.tickread { color: var(--accent, #667eea); }

.compress-progress {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel); border: 1px solid var(--accent); border-radius: 12px;
  padding: 8px 16px; font-size: 12px; z-index: 200; display: none;
}
.compress-progress.active { display: block; }

.video-record-btn {
  background: #e74c3c !important; color: #fff !important;
  border-radius: 50% !important; width: 36px; height: 36px; padding: 0 !important;
  font-size: 16px;
}
.video-record-btn.recording { animation: pulse-red 1s infinite; }
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); } 50% { box-shadow: 0 0 0 8px rgba(231,76,60,0); } }

.auth-overlay { display: none; }
.auth-overlay[hidden] { display: none !important; }
.auth-modal { min-width: 320px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 12px; }
.auth-tab {
  flex: 1; padding: 8px; text-align: center; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-secondary); font-size: 13px;
}
.auth-tab:first-child { border-radius: 8px 0 0 8px; }
.auth-tab:last-child { border-radius: 0 8px 8px 0; }
.auth-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg-secondary, #fff); color: var(--text-primary); }
.auth-error { color: var(--danger, #e74c3c); font-size: 12px; margin-top: 4px; }

.msg-copied {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel); border: 1px solid var(--success, #2ecc71); border-radius: 12px;
  padding: 8px 16px; font-size: 12px; z-index: 200; opacity: 0; transition: opacity 0.2s;
}
.msg-copied.show { opacity: 1; }

.thread-btn {
  background: rgba(102,126,234,0.12) !important; color: var(--accent) !important;
  font-size: 11px; padding: 2px 8px !important;
}

.dl-btn { background: rgba(102,126,234,0.12) !important; color: var(--accent) !important; }

.settings-row { margin: 4px 0; }

.new-badge {
  position: absolute; top: 2px; right: 4px; width: 8px; height: 8px;
  background: var(--danger, #e74c3c); border-radius: 50%;
}
.mention-all { background: rgba(102,126,234,0.18); font-weight: 600; border-radius: 4px; padding: 0 2px; }
.msg-caption {
  font-size: 13px; color: var(--text-secondary); margin-top: 4px; padding: 4px 8px;
  background: var(--bg-hover); border-radius: 10px; word-wrap: break-word;
}
.caption-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border);
  background: var(--bg-panel); font-size: 13px;
}
.caption-bar[hidden] { display: none; }
.caption-bar input { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg-secondary); color: var(--text-primary); }
.cap-skip { color: var(--text-secondary); font-size: 12px; }

/* ===== Batch 5: папки, архив, пин, темы, PWA, i18n, черновик голосового, стикерпаки ===== */
#chat-wallpaper {
  position: fixed; inset: 0; z-index: -1;
  background-size: cover; background-position: center;
}
#chat-wallpaper[hidden] { display: none; }

.chat-filter {
  display: flex; gap: 4px; padding: 6px 8px 2px;
  border-bottom: 1px solid var(--border);
}
.filter-btn {
  flex: 1; padding: 4px 2px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font-size: 12px; cursor: pointer; white-space: nowrap;
}
.filter-btn:hover { background: var(--bg-hover); }
.filter-btn.active {
  background: var(--accent); color: #fff; font-weight: 600;
}
.chat-item.pinned { background: rgba(102,126,234,0.06); }
.chat-item .chat-cat {
  position: absolute; left: 6px; top: 2px; font-size: 10px;
  background: var(--accent); color: #fff; border-radius: 6px;
  padding: 0 4px; line-height: 14px;
}

.voice-draft-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-top: 1px solid var(--border); background: var(--bg-panel); font-size: 13px;
}
.voice-draft-bar[hidden] { display: none; }
.voice-draft-label { white-space: nowrap; font-weight: 600; }
.voice-draft-audio { flex: 1; min-width: 0; height: 36px; }

.sticker-pack { margin-bottom: 8px; }
.sticker-pack-head {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  padding: 4px 8px 2px; text-transform: uppercase; letter-spacing: 0.3px;
}

.accent-row { display: flex; gap: 8px; padding: 4px 0 8px; }
.accent-dot {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.accent-dot.active { border-color: var(--text-primary); transform: scale(1.15); }
.set-label { min-width: 130px; }
.setting-row select { max-width: 200px; }

@media (max-width: 720px) {
  .thread-pane { width: 100%; }
}


/* ===== Batch 6: звонки, снап, код, статистика ===== */
.call-overlay {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(10, 14, 24, 0.55); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.call-overlay[hidden] { display: none; }
.call-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 34px; text-align: center; min-width: 260px; box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
.call-avatar-img { width: 84px; height: 84px; font-size: 34px; border-radius: 50%; margin: 0 auto 12px; }
.call-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.call-state { color: var(--text-secondary); font-size: 13px; margin-bottom: 6px; min-height: 18px; }
.call-timer { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.call-timer[hidden] { display: none; }
.call-actions { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }
.call-btn {
  border: none; border-radius: 50%; width: 52px; height: 52px; font-size: 20px;
  cursor: pointer; color: #fff; background: #3a4356; display: inline-flex;
  align-items: center; justify-content: center;
}
.call-btn.accept { background: #2ecc71; }
.call-btn.decline { background: #e74c3c; }
.call-btn[hidden] { display: none; }
.call-btn:hover { filter: brightness(1.12); }

.snap-modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10, 14, 24, 0.55); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.snap-modal[hidden] { display: none; }
.snap-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px 28px; text-align: center; min-width: 260px;
}
.snap-timer-row { display: flex; justify-content: center; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.snap-opt {
  border: 1px solid var(--border); background: none; cursor: pointer; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; color: var(--text-primary);
}
.snap-opt.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.snap-preview-row { display: flex; justify-content: center; gap: 8px; }
.snap-preview-row img { max-width: 180px; max-height: 120px; border-radius: 10px; object-fit: cover; }

.search-filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 6px 10px; border-top: 1px solid var(--border); }
.search-filters select {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: 4px 6px; font-size: 12px; max-width: 160px;
}
.search-filters button {
  background: none; border: 1px solid var(--border); color: var(--text-secondary);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.search-filters button:hover { color: var(--text-primary); }

.wp-preset {
  width: 40px; height: 34px; border-radius: 8px; border: 2px solid rgba(127,127,127,0.3);
  cursor: pointer; padding: 0; background-size: cover; background-position: center;
}
.wp-preset.active { border-color: var(--accent); transform: scale(1.1); }
.wp-primary { background: var(--accent); }

.dnd-time-row { display: flex; gap: 6px; align-items: center; }
.dnd-time-row input[type="time"] {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: 4px 6px; font-size: 12px;
}

.profile-stats { padding: 8px 12px; }
.profile-stats-row { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--text-secondary); }
.profile-stats-row b { color: var(--text-primary); }
.profile-calls-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
  color: var(--text-secondary); margin: 10px 0 4px;
}
.profile-call-item { font-size: 12px; color: var(--text-secondary); padding: 2px 0; }

.code-block {
  background: #1b2233; border: 1px solid var(--border); border-radius: 10px;
  margin: 6px 0; overflow: hidden;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 10px; background: rgba(255,255,255,0.05); font-size: 11px;
}
.code-lang { color: var(--text-secondary); }
.code-copy {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 11px; padding: 2px 4px;
}
.code-copy:hover { text-decoration: underline; }
.code-block pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.code-block code {
  font-family: Consolas, 'Courier New', monospace; font-size: 12.5px;
  color: #e6e9f2; white-space: pre; background: none; padding: 0;
}

.long-msg { max-height: 220px; overflow: hidden; }
.more-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 12px; margin: 2px 0 4px; padding: 0;
}

.thread-pane-typing {
  font-size: 11px; color: var(--text-secondary); flex: 1; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.caption-snap-btn.active { background: var(--accent); color: #fff; }
.date-separator { cursor: pointer; }
.date-separator:hover .date-separator-text { background: var(--accent); color: #fff; }

/* ===== Batch 7: видео-звонки, меню чата, галерея, статистика, поиск людей ===== */
.chat-main { position: relative; }
.chat-menu {
  position: absolute; top: 52px; right: 10px; z-index: 120;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25); padding: 6px; min-width: 220px;
  display: flex; flex-direction: column;
}
.chat-menu[hidden] { display: none; }
.chat-menu-item {
  background: none; border: none; color: var(--text-primary); text-align: left;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.chat-menu-item:hover { background: rgba(127,127,127,0.14); }

.call-videos { position: relative; width: 300px; height: 190px; border-radius: 12px; overflow: hidden; background: #111; margin: 0 auto 10px; }
.call-videos[hidden] { display: none; }
.call-video-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.call-video-remote[hidden] { display: none; }
.call-video-local {
  position: absolute; right: 8px; bottom: 8px; width: 96px; height: 72px;
  border-radius: 8px; object-fit: cover; border: 2px solid rgba(255,255,255,0.35); background: #000;
}
.call-video-local[hidden] { display: none; }
.call-btn.call-mini { width: 44px; height: 44px; font-size: 17px; background: #3a4356; position: relative; }
.call-mini-off {
  position: absolute; bottom: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: #e74c3c; border: 2px solid #fff;
}
.call-mini-off[hidden] { display: none; }

.gallery-modal { max-width: 640px; max-height: 80vh; display: flex; flex-direction: column; }
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px;
  overflow-y: auto; max-height: 58vh; padding: 4px;
}
.gallery-cell {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: rgba(127,127,127,0.12);
}
.gallery-cell img, .gallery-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-video-play {
  position: absolute; inset: 0; margin: auto; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.5); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 15px; pointer-events: none;
}

.stats-modal { max-width: 420px; }
.stats-bars { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 18px 6px 6px; min-height: 150px; }
.stats-col { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 4px; }
.stats-bar {
  width: 100%; max-width: 46px; border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--accent), rgba(142,108,245,0.45)); min-height: 4px;
}
.stats-val { font-size: 11px; color: var(--text-secondary); }
.stats-day { font-size: 11px; color: var(--text-secondary); }
.stats-meta { font-size: 12px; color: var(--text-secondary); padding: 4px 6px 8px; }
.stats-top { background: rgba(127,127,127,0.1); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.stats-top-title { font-weight: 600; margin-bottom: 4px; }
.stats-top-row { color: var(--text-primary); padding: 2px 0; }

.find-modal { max-width: 420px; }
.find-results { max-height: 45vh; overflow-y: auto; padding: 4px 0; }
.find-row {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px;
}
.find-row:hover { background: rgba(127,127,127,0.1); }
.find-name { font-weight: 600; font-size: 14px; }
.find-status { font-size: 12px; color: var(--text-secondary); }
.find-row .user-info { flex: 1; }

.account-result-msg { padding: 4px 2px; font-size: 13px; }
.account-result-msg.err { color: #e74c3c; }
.account-result-msg.ok { color: #2ecc71; }

.msg-status.read { color: #4aa8ff; }

/* ===== Кнопки групповых ограничений ===== */
.gs-row select { max-width: 180px; }

/* ===== Быстрые реакции при наведении ===== */
.quick-react {
  position: absolute; top: -13px; right: 10px; z-index: 6;
  display: flex; gap: 1px; align-items: center;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 5px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.15s ease;
}
.message:hover .quick-react { opacity: 1; pointer-events: auto; }
.qr-btn {
  background: none; border: none; font-size: 15px; line-height: 1; cursor: pointer;
  padding: 4px 4px; border-radius: 999px; transition: transform 0.12s ease, background 0.12s ease;
}
.qr-btn:hover { transform: scale(1.2); background: var(--bg-hover); }
