/* ==================================================================
   1. RESET + ПЕРЕМЕННЫЕ
   ================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

:root {
  --accent: #667eea;
  --accent-hover: #5568d3;
  --accent-soft: rgba(102, 126, 234, 0.12);
  --accent-soft-2: rgba(102, 126, 234, 0.25);
  --font-base: 15px;

  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f5f5f5;
  --bg-input: #f0f0f0;
  --bg-hover: #f0f0f0;

  --text-primary: #222;
  --text-secondary: #666;
  --text-muted: #888;
  --text-on-accent: #ffffff;

  --border: #e0e0e0;
  --border-light: #f0f0f0;

  --msg-own-bg: #effdde;
  --msg-own-text: #222;
  --msg-other-bg: #ffffff;
  --msg-other-text: #222;
}

/* Тёмная тема: светлее text-muted и ярче границы */
[data-theme="dark"] {
  --bg-primary: #17212b;
  --bg-secondary: #0e1621;
  --bg-tertiary: #1c2733;
  --bg-input: #242f3d;
  --bg-hover: #242f3d;
  --text-primary: #e8eaed;
  --text-secondary: #b0bac5;
  --text-muted: #8b95a1;
  --border: #38455a;
  --border-light: #2f3b4d;
  --msg-own-bg: #2b5278;
  --msg-own-text: #e8eaed;
  --msg-other-bg: #1e2a37;
  --msg-other-text: #e8eaed;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
}
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
  overflow: hidden;
}

/* ==================================================================
   2. САЙДБАР
   ================================================================== */
.sidebar {
  width: 320px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 15px 20px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  gap: 15px;
}
.sidebar-header .menu-btn {
  background: none; border: none; color: white;
  font-size: 1.5rem; cursor: pointer;
}
.sidebar-header h2 { font-size: 1.3rem; margin: 0; }
.user-info {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto; font-size: 0.8rem; text-align: right;
}
.avatar-container {
  width: 45px; height: 45px; border-radius: 50%;
  overflow: hidden; background: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; color: var(--accent); font-size: 1.2rem;
  border: 2px solid white; flex-shrink: 0;
}
.avatar-container img { width: 100%; height: 100%; object-fit: cover; }

.dropdown-menu {
  position: absolute; top: 60px; left: 10px;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  width: 220px; padding: 10px;
  display: none; z-index: 600;
}
.dropdown-menu.active { display: block; }
.dropdown-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px; border: none;
  background: none; cursor: pointer; border-radius: 8px;
  font-size: 0.95rem; color: var(--text-primary);
  font-family: inherit;
}
.dropdown-menu button:hover { background: var(--bg-hover); }
.dropdown-menu button i { width: 20px; color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; padding: 10px; }
.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 10px; cursor: pointer;
  margin-bottom: 5px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.chat-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.chat-item.active { background: var(--accent); color: var(--text-on-accent); }
.chat-item.active .chat-type,
.chat-item.active small { color: #e0e0e0 !important; }
.chat-item .chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-hover); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; overflow: hidden; flex-shrink: 0;
}
.chat-item .chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-item .chat-info { flex: 1; overflow: hidden; }
.chat-item .chat-name {
  font-weight: bold; font-size: 0.95rem; margin-bottom: 3px;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item.active .chat-name { color: var(--text-on-accent); }
.chat-item .chat-type { font-size: 0.75rem; color: var(--text-secondary); }

.fab-left {
  position: fixed; bottom: 30px; left: 30px;
  width: 60px; height: 60px;
  background: var(--accent); color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  cursor: pointer; z-index: 1000;
  transition: transform 0.3s;
}
.fab-left:hover { transform: scale(1.1); }
.fab-left-menu {
  position: fixed; bottom: 100px; left: 30px;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  width: 240px; padding: 10px;
  display: none; z-index: 1001;
}
.fab-left-menu.active { display: block; }
.fab-left-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px; border: none;
  background: none; cursor: pointer; border-radius: 8px;
  font-size: 0.95rem; text-align: left;
  color: var(--text-primary); font-family: inherit;
}
.fab-left-menu button:hover { background: var(--bg-hover); }
.fab-left-menu button i { width: 20px; color: var(--accent); }

/* ==================================================================
   3. ЧАТ
   ================================================================== */
.chat-area {
  flex: 1; display: flex; flex-direction: column;
  height: 100%; min-width: 0;
}
.chat-header {
  background: var(--accent); color: white;
  padding: 15px 20px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.chat-header .chat-title {
  font-size: 1.2rem; font-weight: bold; cursor: pointer;
}
.chat-header .chat-type-label {
  font-size: 0.75rem; background: rgba(255,255,255,0.2);
  padding: 3px 8px; border-radius: 5px; margin-left: 10px;
}
.chat-header .chat-status { font-size: 0.75rem; margin-left: 10px; }
.chat-header .header-buttons { display: flex; gap: 8px; }
.add-member-btn {
  background: rgba(255,255,255,0.2); border: none; color: white;
  padding: 8px 12px; border-radius: 8px;
  cursor: pointer; font-size: 0.85rem;
}
.add-member-btn:hover { background: rgba(255,255,255,0.4); }
.back-btn {
  background: none; border: none; color: white;
  font-size: 1.5rem; cursor: pointer; display: none;
  margin-right: 10px;
}

.chat-body {
  flex: 1; overflow-y: auto; padding: 20px;
  background: var(--bg-tertiary); min-height: 0;
}
.message {
  margin-bottom: 15px; padding: 10px; border-radius: 12px;
  max-width: 70%; font-size: 0.95rem; line-height: 1.4;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  position: relative; overflow-wrap: anywhere; word-break: break-word;
}
.message.own {
  background: var(--msg-own-bg); color: var(--msg-own-text);
  margin-left: auto; border-bottom-right-radius: 4px;
}
.message.other {
  background: var(--msg-other-bg); color: var(--msg-other-text);
  margin-right: auto; border-bottom-left-radius: 4px;
}
.message .username {
  font-weight: bold; font-size: 0.85rem;
  margin-bottom: 3px; display: inline-block;
  cursor: pointer; color: var(--accent);
}
/* Ник в своих сообщениях — по цвету пузыря, а не белый */
.message.own .username {
  color: var(--msg-own-text);
  opacity: 0.85;
}
[data-theme="dark"] .message.own .username {
  color: var(--msg-own-text);
  opacity: 0.95;
}

/* Метка прочтения */
.message .read-mark {
  font-size: 0.72rem;
  margin-left: 5px;
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
}
.message .read-mark.unread  { color: #7c8a99; }
.message .read-mark.read    { color: #2b8ce0; }

[data-theme="dark"] .message .read-mark.unread { color: #b0bac5; }
[data-theme="dark"] .message .read-mark.read   { color: #6fb4ff; }
[data-theme="dark"] .message.own .read-mark.unread { color: #c8d1da; }
[data-theme="dark"] .message.own .read-mark.read   { color: #9cd0ff; }

.message .time {
  font-size: 0.7rem; opacity: 0.6;
  display: block; margin-top: 4px;
  text-align: right; float: right; margin-left: 10px;
}
.message .reply-block {
  background: rgba(0,0,0,0.05);
  border-left: 3px solid var(--accent);
  padding: 5px 10px; margin-bottom: 5px;
  border-radius: 5px; font-size: 0.8rem;
  display: block; overflow-wrap: anywhere;
  cursor: pointer;
  transition: background-color 0.15s;
}
.message .reply-block:hover { filter: brightness(0.96); }
.message.own .reply-block {
  background: rgba(255,255,255,0.4);
  border-left: 3px solid #fff;
}
.message .reactions {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-top: 5px; clear: both;
}
.message .reaction-chip {
  background: var(--accent-soft); border-radius: 15px;
  padding: 2px 8px; font-size: 0.8rem;
  cursor: pointer; transition: background 0.2s;
}
.message .reaction-chip:hover { background: var(--accent-soft-2); }
.message .reaction-chip.reacted { background: var(--accent-soft-2); }
.message-actions {
  position: absolute; top: 5px; right: 5px;
  display: none; gap: 3px;
  background: var(--bg-primary);
  border-radius: 8px; padding: 3px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.message:hover .message-actions { display: flex; }
.message-actions button {
  border: none; background: none; cursor: pointer;
  font-size: 0.9rem; padding: 3px 5px;
  border-radius: 5px; color: var(--text-secondary);
}
.message-actions button:hover { background: var(--bg-hover); }

/* Подсветка сообщения при переходе из блока ответа */
.message.message-highlight {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px var(--accent-soft);
  transition: outline-color 0.5s ease, box-shadow 0.5s ease;
  border-radius: 12px;
  animation: msg-highlight-pulse 1.2s ease-out 2;
}
@keyframes msg-highlight-pulse {
  0%   { box-shadow: 0 0 0 6px var(--accent-soft); }
  50%  { box-shadow: 0 0 0 12px var(--accent-soft); }
  100% { box-shadow: 0 0 0 6px var(--accent-soft); }
}
[data-theme="dark"] .message.message-highlight {
  outline-color: var(--accent);
  box-shadow: 0 0 0 6px var(--accent-soft-2);
}

.empty-chat {
  display: flex; justify-content: center; align-items: center;
  height: 100%; color: var(--text-muted);
  font-size: 1.2rem; text-align: center;
}

/* Верхний лоадер (подгрузка старых сообщений) */
.top-loader {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}
.top-loader.active {
  display: flex;
}

/* Форматирование */
.message b, .message strong { font-weight: 700; }
.message i, .message em { font-style: italic; }
.message s { text-decoration: line-through; opacity: 0.7; }
.message a {
  color: #4a90e2; text-decoration: none;
  border-bottom: 1px dashed rgba(74,144,226,0.5);
}
.message.own a {
  color: #1e40af;
  border-bottom-color: rgba(30,64,175,0.5);
}
.message a:hover { border-bottom-style: solid; }
.message .inline-code {
  background: rgba(0,0,0,0.08); padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.88em;
}
.message.own .inline-code { background: rgba(255,255,255,0.4); }
.message .code-block {
  background: #1e1e1e; color: #d4d4d4;
  padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; margin: 6px 0;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85em; white-space: pre; max-width: 100%;
}
.message .code-block code {
  font-family: inherit; background: none;
  padding: 0; color: inherit;
}
.message .code-lang {
  color: #808080; font-size: 0.75em;
  margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 1px;
}
.message .spoiler {
  background: #2b2b2b; color: transparent;
  padding: 0 4px; border-radius: 4px;
  cursor: pointer; transition: all 0.2s;
  user-select: none;
}
.message .spoiler:hover { background: #444; }
.message .spoiler.revealed {
  background: var(--accent-soft-2);
  color: inherit; user-select: text;
}
.message blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 10px; margin: 4px 0;
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}
.message.own blockquote {
  border-left-color: #fff;
  background: rgba(255,255,255,0.3);
  color: var(--text-primary);
}

/* Плашка канала */
.channel-notice {
  padding: 12px 15px;
  background: var(--accent-soft);
  border-top: 1px solid var(--accent-soft-2);
  border-bottom: 1px solid var(--accent-soft-2);
  color: var(--text-primary);
  font-size: 0.85rem; flex-shrink: 0;
}
.channel-notice-content {
  display: flex; align-items: center;
  justify-content: center; gap: 12px; flex-wrap: wrap;
}
.channel-notice-btn {
  width: auto !important; height: auto !important;
  padding: 8px 16px !important;
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  border-radius: 20px !important;
  cursor: pointer; font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s; margin: 0 !important;
}
.channel-notice-btn:hover {
  background: var(--accent-hover) !important;
  transform: translateY(-1px);
}

/* ==================================================================
   4. ПОДВАЛ ЧАТА
   ================================================================== */
.chat-footer {
  padding: 12px 15px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  gap: 6px; flex-shrink: 0;
}
.reply-bar {
  display: none; background: var(--bg-input);
  border-left: 3px solid var(--accent);
  padding: 5px 10px; border-radius: 5px;
  font-size: 0.85rem; margin-bottom: 5px;
  align-items: center; gap: 8px;
}
.reply-bar.active { display: flex; }

.format-toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.format-toolbar button {
  width: auto !important; height: 30px !important;
  padding: 0 10px !important;
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  cursor: pointer; font-size: 0.85rem;
  font-weight: 500; transition: all 0.15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.format-toolbar button:hover {
  background: var(--accent) !important;
  color: white !important;
  border-color: var(--accent) !important;
}

.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row .attach-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  background: transparent !important;
  border: none !important;
  font-size: 1.4rem; cursor: pointer;
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50% !important; padding: 0;
}
.input-row .attach-btn:hover { background: var(--accent-soft) !important; }
.input-row .send-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  border-radius: 50% !important;
  cursor: pointer; font-size: 1.1rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.input-row .send-btn:hover { background: var(--accent-hover) !important; }

#messageInput {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: none; border-radius: 20px; outline: none;
  font-size: 0.95rem; font-family: inherit;
  resize: none; height: 40px;
  min-height: 40px; max-height: 140px;
  line-height: 20px; overflow-y: auto;
  box-sizing: border-box;
}
#messageInput::placeholder { color: var(--text-muted); }

/* ==================================================================
   5. EMOJI PICKER
   ================================================================== */
.emoji-picker {
  position: fixed; background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  padding: 12px; display: none; z-index: 9999;
  border: 1px solid var(--border); gap: 10px;
}
.emoji-picker.active { display: flex; }
.emoji-picker span {
  cursor: pointer; font-size: 1.5rem;
  padding: 5px; border-radius: 5px;
}
.emoji-picker span:hover { background: var(--bg-hover); }

/* ==================================================================
   6. МОДАЛКИ (общие)
   ================================================================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none; justify-content: center; align-items: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 25px; border-radius: 16px;
  width: 400px; max-width: 100%;
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h2 {
  color: var(--text-primary); font-size: 1.3rem;
  margin-bottom: 20px; text-align: center;
}
.modal .form-group { margin-bottom: 15px; }
.modal label {
  display: block; margin-bottom: 5px;
  font-weight: 500; color: var(--text-secondary);
  font-size: 0.9rem;
}
.modal input, .modal textarea {
  width: 100%; padding: 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: none; border-radius: 10px;
  outline: none; font-family: inherit;
  font-size: 0.95rem;
}
.modal button {
  width: 100%; padding: 12px;
  background: var(--accent); color: white;
  border: none; border-radius: 10px;
  cursor: pointer; font-weight: bold;
  margin-top: 10px;
}
.modal .close-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  margin-top: 5px;
}
.modal-error {
  color: #dc2626; font-size: 0.85rem;
  margin-top: 10px; display: none;
}
.modal-success {
  color: #16a34a; font-size: 0.85rem;
  margin-top: 10px; display: none;
}

.modal input[readonly],
.modal input:disabled,
.modal textarea[readonly],
.settings-input.readonly {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  cursor: not-allowed; opacity: 1;
}
#profileUserId {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
  -webkit-text-fill-color: var(--text-primary) !important;
}

/* Профиль пользователя */
.profile-header { text-align: center; margin-bottom: 20px; }
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; margin: 0 auto 15px;
  overflow: hidden; font-weight: bold;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 1.2rem; font-weight: bold; }
.profile-nickname { color: var(--accent); margin-bottom: 5px; }
.profile-bio { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 10px; }
.profile-status { font-size: 0.85rem; margin-bottom: 15px; }
.profile-extra {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border-light);
  text-align: left;
}
.profile-extra-row {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; font-size: 0.88rem;
  color: var(--text-secondary);
}
.profile-extra-row i { width: 18px; color: var(--accent); text-align: center; }
.profile-extra-row a { color: var(--accent); text-decoration: none; }
.profile-extra-row a:hover { text-decoration: underline; }

/* Авторизация */
.auth-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex; justify-content: center; align-items: center;
  z-index: 2000; padding: 20px;
}
.auth-box {
  background: white; padding: 40px;
  border-radius: 20px; text-align: center;
  width: 400px; max-width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.auth-box h2 { color: #667eea; font-size: 1.8rem; margin-bottom: 25px; }
.auth-box input {
  width: 100%; padding: 14px; margin: 10px 0;
  background: #f0f0f0; border: none;
  border-radius: 12px; outline: none; font-size: 0.95rem;
}
.auth-box button {
  width: 100%; padding: 14px;
  background: #667eea; color: white;
  border: none; border-radius: 12px;
  cursor: pointer; margin-top: 10px; font-weight: bold;
}
.auth-box button.secondary { background: #f0f0f0; color: #333; }
#authError {
  color: #dc2626; font-size: 0.9rem;
  margin-top: 10px; display: none;
}

/* Аватар-аплоадер */
.avatar-uploader { text-align: center; margin-bottom: 20px; }
.avatar-uploader .current-avatar {
  width: 100px; height: 100px; border-radius: 50%;
  background: var(--bg-input); margin: 0 auto 10px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 2px dashed var(--accent);
  font-size: 2rem; color: var(--accent); font-weight: bold;
}
.avatar-uploader .current-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

/* ==================================================================
   7. ИНФО-ПАНЕЛЬ КАНАЛА/ГРУППЫ
   ================================================================== */
.chat-info-modal {
  position: relative; padding: 0; overflow: hidden;
  max-height: 85vh; display: flex; flex-direction: column;
  background: var(--bg-primary);
}
.chat-info-modal .chat-info-close {
  position: absolute !important;
  top: 12px !important; right: 12px !important;
  left: auto !important;
  width: 34px !important; height: 34px !important;
  padding: 0 !important; margin: 0 !important;
  background: rgba(0,0,0,0.35) !important;
  color: white !important;
  border: none !important;
  border-radius: 50% !important;
  cursor: pointer !important;
  font-size: 1rem !important;
  font-weight: normal !important;
  z-index: 10;
  display: flex !important;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
  transition: background 0.15s, transform 0.15s !important;
}
.chat-info-modal .chat-info-close:hover {
  background: rgba(0,0,0,0.55) !important;
  transform: scale(1.08);
}
.chat-info-header {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white; padding: 32px 20px 24px;
  text-align: center; flex-shrink: 0;
}
.chat-info-avatar {
  width: 90px; height: 90px; border-radius: 50%;
  background: white; color: var(--accent);
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; font-weight: bold;
  overflow: hidden; border: 3px solid rgba(255,255,255,0.5);
}
.chat-info-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-info-name { font-size: 1.4rem; font-weight: bold; margin-bottom: 4px; }
.chat-info-type { font-size: 0.8rem; opacity: 0.9; margin-bottom: 4px; }
.chat-info-members-count { font-size: 0.85rem; opacity: 0.85; }
.chat-info-actions {
  display: flex; gap: 4px; padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; flex-shrink: 0;
}
.chat-info-actions button {
  flex: 1 1 0; min-width: 80px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: none; border-radius: 12px;
  padding: 12px 6px; cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  font-size: 0.75rem; transition: background 0.15s;
  margin: 0 !important; width: auto !important;
}
.chat-info-actions button:hover { background: var(--bg-hover); }
.chat-info-actions button i { font-size: 1.1rem; }
.chat-info-linked {
  padding: 12px 16px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-soft-2);
  flex-shrink: 0;
}
.chat-info-linked-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 10px;
  font-size: 0.85rem; color: var(--text-primary);
}
.chat-info-linked-row button {
  width: auto !important;
  padding: 6px 14px !important;
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  border-radius: 20px !important;
  cursor: pointer; font-size: 0.8rem;
  margin: 0 !important; font-weight: 600;
}
.chat-info-linked-row button:hover {
  background: var(--accent-hover) !important;
}
.chat-info-section-title {
  padding: 14px 16px 8px;
  font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); font-weight: 600;
  flex-shrink: 0;
}
.chat-info-members {
  flex: 1; overflow-y: auto;
  padding-bottom: 12px; min-height: 0;
}
.chat-info-member {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; cursor: pointer;
  transition: background-color 0.2s, transform 0.15s;
}
.chat-info-member:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}
.chat-info-member-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-hover); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; overflow: hidden; flex-shrink: 0;
}
.chat-info-member-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.chat-info-member-info { flex: 1; min-width: 0; }
.chat-info-member-name {
  font-size: 0.92rem; font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center;
  gap: 6px; flex-wrap: wrap;
}
.chat-info-member-nick {
  font-size: 0.78rem; color: var(--accent); font-weight: 400;
}
.chat-info-member-status { font-size: 0.78rem; margin-top: 2px; }
.chat-info-badge {
  font-size: 0.65rem; padding: 1px 6px;
  border-radius: 8px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.chat-info-badge.admin { background: #e3f0ff; color: #1976d2; }
.chat-info-badge.creator { background: #fff3cd; color: #b8860b; }

/* ==================================================================
   8. НАСТРОЙКИ КАНАЛА
   ================================================================== */
.chat-settings-modal {
  padding: 0; display: flex; flex-direction: column;
  max-height: 90vh; width: 440px;
  background: var(--bg-primary);
}
.chat-settings-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-settings-back {
  background: none; border: none;
  font-size: 1.1rem; color: var(--text-primary);
  cursor: pointer; padding: 6px 10px;
  border-radius: 8px;
  margin: 0 !important; width: auto !important;
}
.chat-settings-back:hover { background: var(--bg-hover); }
.chat-settings-header h2 {
  font-size: 1.15rem; font-weight: 600;
  color: var(--text-primary);
  margin: 0 !important; text-align: left !important; flex: 1;
}
.chat-settings-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px; min-height: 0;
}
.chat-settings-avatar-row {
  display: flex; align-items: center;
  gap: 16px; margin-bottom: 20px;
}
.chat-settings-avatar {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--bg-input); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: bold; cursor: pointer;
  overflow: hidden; border: 2px dashed var(--accent);
  flex-shrink: 0; transition: transform 0.15s;
}
.chat-settings-avatar:hover { transform: scale(1.04); }
.chat-settings-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.chat-settings-name-block { flex: 1; min-width: 0; }
.chat-settings-name-block label {
  display: block; font-size: 0.8rem;
  color: var(--accent); font-weight: 600;
  margin-bottom: 4px;
}
.chat-settings-field { margin-bottom: 16px; }
.chat-settings-field label {
  display: block; font-size: 0.8rem;
  color: var(--text-muted); margin-bottom: 6px;
}
.chat-settings-input {
  width: 100%; padding: 10px 12px;
  background: transparent;
  border: none; border-bottom: 2px solid var(--border);
  outline: none; font-size: 0.95rem;
  font-family: inherit; color: var(--text-primary);
  transition: border-color 0.15s;
}
.chat-settings-input:focus { border-bottom-color: var(--accent); }
.chat-settings-input:disabled { color: var(--text-muted); }
textarea.chat-settings-input {
  resize: vertical; min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  background: var(--bg-input);
}
.chat-settings-hint {
  font-size: 0.8rem; color: var(--text-muted);
  margin-top: 6px;
}
.chat-settings-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 4px; cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
  border-radius: 8px;
}
.chat-settings-row:hover { background: var(--bg-hover); }
.chat-settings-row i {
  width: 22px; color: var(--text-muted);
  font-size: 1rem; text-align: center;
}
.chat-settings-row span:nth-of-type(1) {
  flex: 1; font-size: 0.95rem; color: var(--text-primary);
}
.chat-settings-value {
  color: var(--accent) !important;
  font-size: 0.9rem !important; font-weight: 500;
}
.chat-settings-row-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.chat-settings-link-btn {
  width: auto !important;
  padding: 8px 16px !important;
  border: none !important;
  border-radius: 8px !important;
  cursor: pointer; font-size: 0.85rem;
  font-weight: 600; color: white !important;
  margin: 0 !important;
}
.chat-settings-link-btn.green { background: #16a34a !important; }
.chat-settings-link-btn.orange { background: #f59e0b !important; }
.chat-settings-danger-btn {
  width: 100% !important; padding: 12px !important;
  background: rgba(220,38,38,0.1) !important;
  color: #dc2626 !important;
  border: 1px solid rgba(220,38,38,0.3) !important;
  border-radius: 10px !important;
  cursor: pointer; font-weight: 600;
  margin: 16px 0 0 0 !important;
  display: flex; align-items: center;
  justify-content: center; gap: 8px;
  font-size: 0.9rem;
}
.chat-settings-danger-btn:hover {
  background: rgba(220,38,38,0.18) !important;
}
.chat-settings-footer {
  display: flex; justify-content: flex-end;
  gap: 8px; padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-settings-cancel,
.chat-settings-save {
  width: auto !important;
  padding: 10px 20px !important;
  border: none !important;
  border-radius: 10px !important;
  cursor: pointer; font-size: 0.9rem;
  font-weight: 600; margin: 0 !important;
}
.chat-settings-cancel {
  background: transparent !important;
  color: var(--accent) !important;
}
.chat-settings-cancel:hover {
  background: var(--accent-soft) !important;
}
.chat-settings-save {
  background: var(--accent) !important;
  color: white !important;
}
.chat-settings-save:hover {
  background: var(--accent-hover) !important;
}

/* Реакции */
.reactions-picker {
  display: flex; flex-direction: column;
  gap: 4px; margin-bottom: 12px;
}
.reactions-option {
  display: flex; align-items: center;
  gap: 12px; padding: 12px;
  border-radius: 10px; cursor: pointer;
  transition: background 0.15s; font-size: 0.95rem;
}
.reactions-option:hover { background: var(--bg-hover); }
.reactions-option input {
  margin: 0 !important; width: auto !important;
}

/* Пригласительные */
.invites-list { margin-bottom: 12px; }
.invite-item {
  padding: 12px; background: var(--bg-input);
  border-radius: 10px; margin-bottom: 8px;
}
.invite-token {
  font-size: 0.75rem; text-transform: uppercase;
  color: var(--text-muted); letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.invite-link {
  font-size: 0.85rem; color: var(--accent);
  word-break: break-all;
  font-family: 'Consolas', monospace;
}
.empty-hint {
  padding: 20px; text-align: center;
  color: var(--text-muted); font-size: 0.9rem;
}

/* ==================================================================
   9. ПАНЕЛЬ УЧАСТНИКОВ
   ================================================================== */
.members-panel-modal {
  padding: 0; display: flex; flex-direction: column;
  width: 460px; max-height: 85vh;
  background: var(--bg-primary);
}
.members-panel-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px; flex-shrink: 0;
}
.members-panel-header h2 {
  margin: 0 !important; font-size: 1.15rem;
  font-weight: 600; color: var(--text-primary);
  text-align: left !important;
}
.members-panel-close {
  background: none !important; border: none !important;
  color: var(--text-muted); cursor: pointer;
  font-size: 1rem; padding: 6px 10px !important;
  width: auto !important;
  border-radius: 8px !important;
  margin: 0 !important;
}
.members-panel-close:hover { background: var(--bg-hover) !important; }
.members-panel-search-wrap {
  display: flex; align-items: center; gap: 10px;
  margin: 0 20px 10px; padding: 10px 14px;
  background: var(--bg-input);
  border-radius: 22px; flex-shrink: 0;
}
.members-panel-search-wrap i {
  color: var(--text-muted); font-size: 0.9rem;
}
.members-panel-search {
  flex: 1; border: none; background: transparent;
  outline: none; font-size: 0.95rem;
  font-family: inherit; color: var(--text-primary);
  width: 100% !important;
  padding: 0 !important; margin: 0 !important;
}
.members-panel-list {
  flex: 1; overflow-y: auto;
  padding: 0 12px 12px; min-height: 0;
}
.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.15s;
}
.member-row:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}
.member-row-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--bg-hover); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; overflow: hidden; flex-shrink: 0;
}
.member-row-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.member-row-info { flex: 1; min-width: 0; }
.member-row-name {
  font-size: 0.95rem; font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center;
  gap: 6px; flex-wrap: wrap;
}
.member-row-status { font-size: 0.78rem; margin-top: 2px; }
.member-row-kebab {
  background: none !important; border: none !important;
  width: 34px !important; height: 34px !important;
  border-radius: 8px !important;
  cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  padding: 0 !important; margin: 0 !important;
  flex-shrink: 0;
}
.member-row-kebab:hover {
  background: var(--accent-soft) !important;
  color: var(--accent);
}
.members-panel-footer {
  display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.members-panel-add {
  width: auto !important;
  background: transparent !important;
  color: var(--accent) !important;
  border: none !important;
  padding: 10px 12px !important;
  border-radius: 8px !important;
  cursor: pointer; font-weight: 600;
  font-size: 0.9rem;
  display: flex; align-items: center; gap: 8px;
  margin: 0 !important;
}
.members-panel-add:hover {
  background: var(--accent-soft) !important;
}
.members-panel-done {
  width: auto !important;
  background: transparent !important;
  color: #dc2626 !important;
  border: none !important;
  padding: 10px 12px !important;
  border-radius: 8px !important;
  cursor: pointer; font-weight: 600;
  font-size: 0.9rem; margin: 0 !important;
}
.members-panel-done:hover {
  background: rgba(220,38,38,0.1) !important;
}

/* ==================================================================
   10. ПРАВА АДМИНА
   ================================================================== */
.admin-rights-modal {
  padding: 0; display: flex; flex-direction: column;
  width: 460px; max-height: 85vh;
  background: var(--bg-primary);
}
.admin-rights-header {
  display: flex; align-items: center; gap: 14px;
  padding: 20px 20px 8px; flex-shrink: 0;
}
.admin-rights-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--bg-hover); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; overflow: hidden;
  flex-shrink: 0; font-size: 1.4rem;
}
.admin-rights-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.admin-rights-info { flex: 1; min-width: 0; }
.admin-rights-name {
  font-size: 1.1rem; font-weight: 600;
  color: var(--text-primary); font-style: italic;
}
.admin-rights-status {
  font-size: 0.8rem; color: var(--text-muted); margin-top: 2px;
}
.admin-rights-by {
  padding: 10px 20px; font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.admin-rights-by .link { color: #dc2626; }
.admin-rights-title {
  padding: 14px 20px 6px;
  font-size: 0.9rem; font-weight: 600;
  color: #dc2626; flex-shrink: 0;
}
.admin-rights-list {
  flex: 1; overflow-y: auto;
  padding: 0 20px 12px; min-height: 0;
}
.admin-perm-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.admin-perm-row:last-child { border-bottom: none; }
.admin-perm-label {
  font-size: 0.92rem; color: var(--text-primary);
  flex: 1; padding-right: 12px;
}
.admin-rights-footer {
  display: flex; justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.admin-rights-ok {
  width: auto !important;
  background: transparent !important;
  color: #dc2626 !important;
  border: none !important;
  padding: 10px 24px !important;
  cursor: pointer; font-weight: 600;
  font-size: 0.95rem; margin: 0 !important;
  border-radius: 8px !important;
}
.admin-rights-ok:hover {
  background: rgba(220,38,38,0.1) !important;
}

/* Switch */
.switch {
  position: relative; display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0; cursor: pointer;
}
.switch.disabled { opacity: 0.5; cursor: not-allowed; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: #ccc; border-radius: 24px;
  transition: background 0.2s;
}
.switch .slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white; border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider,
.switch.on .slider { background: #dc2626; }
.switch input:checked + .slider::before,
.switch.on .slider::before { transform: translateX(20px); }

/* Action sheet */
.action-sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end;
  justify-content: center; z-index: 3000;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.action-sheet {
  background: var(--bg-primary);
  width: 100%; max-width: 440px;
  border-radius: 16px 16px 0 0;
  padding: 8px;
  display: flex; flex-direction: column;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.action-sheet-btn {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: transparent; border: none;
  border-radius: 10px; cursor: pointer;
  font-size: 0.95rem; color: var(--text-primary);
  text-align: left;
  width: 100% !important;
  margin: 0 !important; font-weight: 500;
}
.action-sheet-btn:hover { background: var(--bg-hover); }
.action-sheet-btn i { width: 20px; text-align: center; color: var(--accent); }
.action-sheet-btn.danger { color: #dc2626; }
.action-sheet-btn.danger i { color: #dc2626; }
.action-sheet-btn.cancel {
  margin-top: 6px !important;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  padding-top: 16px;
  justify-content: center;
  color: var(--accent); font-weight: 600;
}

/* ==================================================================
   11. КАСТОМНЫЙ СЕЛЕКТ
   ================================================================== */
.custom-select { position: relative; user-select: none; }
.custom-select-trigger {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}
.custom-select-trigger:hover { border-color: var(--accent); }
.custom-select-trigger i {
  color: var(--accent); font-size: 0.75rem;
  transition: transform 0.2s;
}
.custom-select:has(.custom-select-dropdown.open) .custom-select-trigger {
  border-color: var(--accent);
  background: var(--bg-primary);
}
.custom-select:has(.custom-select-dropdown.open) .custom-select-trigger i {
  transform: rotate(180deg);
}
.custom-select-dropdown {
  position: absolute; top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  max-height: 260px; overflow-y: auto;
  z-index: 100; display: none;
  padding: 6px 0;
}
.custom-select-dropdown.open { display: block; }
.custom-select-group {
  padding: 8px 16px 4px;
  font-size: 0.72rem; color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.custom-select-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer;
  font-size: 0.92rem; color: var(--text-primary);
  background: var(--bg-primary);
  transition: background 0.12s;
}
.custom-select-item:hover { background: var(--bg-hover); }
.custom-select-item.selected {
  background: var(--accent-soft);
  color: var(--accent); font-weight: 600;
}
.custom-select-icon {
  display: inline-block; width: 22px;
  text-align: center; font-size: 1rem;
}
.custom-select-empty {
  padding: 16px; text-align: center;
  color: var(--text-muted); font-size: 0.85rem;
}
.custom-select-dropdown::-webkit-scrollbar { width: 6px; }
.custom-select-dropdown::-webkit-scrollbar-thumb {
  background: #cbd5e1; border-radius: 3px;
}

/* ==================================================================
   12. НАСТРОЙКИ ПРОФИЛЯ
   ================================================================== */
.settings-modal {
  padding: 0; display: flex; flex-direction: column;
  width: 500px; max-width: 100%; max-height: 90vh;
  background: var(--bg-primary);
}
.settings-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-header h2 {
  margin: 0 !important; font-size: 1.15rem;
  color: var(--text-primary);
  text-align: left !important;
}
.settings-close {
  background: none !important; border: none !important;
  color: var(--text-muted); font-size: 1rem;
  cursor: pointer; padding: 6px 12px !important;
  width: auto !important;
  border-radius: 8px !important;
  margin: 0 !important;
}
.settings-close:hover { background: var(--bg-hover) !important; }
.settings-tabs {
  display: flex; gap: 2px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; overflow-x: auto;
}
.settings-tabs button {
  width: auto !important;
  padding: 10px 14px !important;
  background: transparent !important;
  border: none !important;
  border-radius: 8px 8px 0 0 !important;
  cursor: pointer;
  color: var(--text-secondary) !important;
  font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; margin: 0 !important;
  border-bottom: 2px solid transparent !important;
  transition: color 0.15s, border-color 0.15s;
}
.settings-tabs button:hover { color: var(--text-primary) !important; }
.settings-tabs button.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}
.settings-tabs button i { font-size: 0.8rem; }
.settings-body {
  flex: 1; overflow-y: auto;
  padding: 18px 22px 22px; min-height: 0;
}
.settings-field { margin-bottom: 14px; }
.settings-field label {
  display: block; font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 5px; font-weight: 500;
}
.settings-input {
  width: 100%; padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: inherit; font-size: 0.92rem;
  outline: none; transition: border-color 0.15s;
  box-sizing: border-box;
}
.settings-input:focus { border-color: var(--accent); }
textarea.settings-input { resize: vertical; min-height: 60px; }
.settings-save-btn {
  width: 100% !important;
  padding: 11px !important;
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  border-radius: 10px !important;
  font-weight: 600; font-size: 0.9rem;
  cursor: pointer; margin: 8px 0 0 0 !important;
  transition: background 0.15s;
}
.settings-save-btn:hover {
  background: var(--accent-hover) !important;
}
.settings-danger-btn {
  width: 100% !important; padding: 11px !important;
  background: rgba(220,38,38,0.1) !important;
  color: #dc2626 !important;
  border: 1px solid rgba(220,38,38,0.3) !important;
  border-radius: 10px !important;
  font-weight: 600; font-size: 0.9rem;
  cursor: pointer; margin: 0 !important;
  display: flex; align-items: center;
  justify-content: center; gap: 8px;
}
.settings-danger-btn:hover {
  background: rgba(220,38,38,0.18) !important;
}
.settings-link-btn {
  width: auto !important;
  padding: 6px 12px !important;
  background: transparent !important;
  border: none !important;
  color: var(--accent) !important;
  cursor: pointer; font-size: 0.85rem;
  font-weight: 500;
  border-radius: 8px !important;
  margin: 0 !important;
}
.settings-link-btn:hover {
  background: var(--accent-soft) !important;
}
.settings-link-btn.danger { color: #dc2626 !important; }
.settings-link-btn.danger:hover {
  background: rgba(220,38,38,0.1) !important;
}

.privacy-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.privacy-row:last-child { border-bottom: none; }
.privacy-row-label {
  font-size: 0.9rem; color: var(--text-primary);
  margin-bottom: 8px; font-weight: 500;
}
.privacy-row-options {
  display: flex; gap: 4px;
  background: var(--bg-input);
  padding: 3px; border-radius: 10px;
}
.privacy-row-options button {
  flex: 1; padding: 8px 6px !important;
  background: transparent !important;
  border: none !important;
  border-radius: 8px !important;
  cursor: pointer;
  color: var(--text-secondary) !important;
  font-size: 0.8rem; font-weight: 500;
  margin: 0 !important; width: auto !important;
  transition: all 0.15s;
}
.privacy-row-options button:hover {
  color: var(--text-primary) !important;
}
.privacy-row-options button.active {
  background: var(--bg-primary) !important;
  color: var(--accent) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ==================================================================
   13. МОДАЛКА ОФОРМЛЕНИЯ
   ================================================================== */
.appearance-modal {
  padding: 0; display: flex; flex-direction: column;
  width: 480px; max-width: 100%; max-height: 88vh;
  background: var(--bg-primary);
}
.appearance-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.appearance-header h2 {
  margin: 0 !important; font-size: 1.2rem;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 10px;
  text-align: left !important;
}
.appearance-header h2 i { color: var(--accent); }
.appearance-close {
  background: none !important; border: none !important;
  color: var(--text-muted); font-size: 1.1rem;
  cursor: pointer; padding: 6px 12px !important;
  width: auto !important;
  border-radius: 8px !important;
  margin: 0 !important;
}
.appearance-close:hover { background: var(--bg-hover) !important; }
.appearance-body {
  flex: 1; overflow-y: auto;
  padding: 16px 22px; min-height: 0;
}
.appearance-section { margin-bottom: 22px; }
.appearance-section:last-child { margin-bottom: 8px; }
.appearance-label {
  font-size: 0.85rem; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.appearance-btn-group {
  display: flex; gap: 6px;
  background: var(--bg-input);
  padding: 4px; border-radius: 12px;
}
.appearance-btn-group button {
  flex: 1; padding: 10px 8px !important;
  background: transparent !important;
  border: none !important;
  border-radius: 9px !important;
  cursor: pointer;
  color: var(--text-secondary) !important;
  font-weight: 500; font-size: 0.85rem;
  display: flex; align-items: center;
  justify-content: center; gap: 6px;
  margin: 0 !important; width: auto !important;
  transition: all 0.15s;
}
.appearance-btn-group button:hover {
  color: var(--text-primary) !important;
}
.appearance-btn-group button.active {
  background: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.appearance-btn-group button i { font-size: 0.9rem; }

.accent-presets {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.accent-swatch {
  width: 100% !important; aspect-ratio: 1;
  border-radius: 50% !important;
  border: 3px solid transparent !important;
  cursor: pointer; padding: 0 !important;
  margin: 0 !important;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.accent-swatch:hover { transform: scale(1.1); }
.accent-swatch.active {
  border-color: var(--text-primary) !important;
  transform: scale(1.12);
}
.accent-swatch.auto {
  background: var(--bg-input) !important;
  color: var(--accent);
  display: flex; align-items: center;
  justify-content: center; font-size: 0.9rem;
}
.accent-swatch.auto i { pointer-events: none; }

.appearance-custom-color {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--bg-input);
  border-radius: 10px; font-size: 0.9rem;
  color: var(--text-secondary);
}
.appearance-custom-color label { flex-shrink: 0; }
.appearance-custom-color input[type="color"] {
  width: 40px; height: 34px; padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary); cursor: pointer;
}
.appearance-custom-color input[type="text"] {
  flex: 1; padding: 8px 10px !important;
  background: var(--bg-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  font-family: monospace;
  color: var(--text-primary) !important;
  font-size: 0.9rem; margin: 0 !important;
}

.wallpaper-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.wallpaper-swatch {
  aspect-ratio: 16/10;
  border-radius: 10px !important;
  border: 3px solid transparent !important;
  cursor: pointer; padding: 0 !important;
  margin: 0 !important;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  background-size: cover;
  background-position: center;
}
.wallpaper-swatch:hover { transform: scale(1.04); }
.wallpaper-swatch.active {
  border-color: var(--accent) !important;
}
.wallpaper-swatch.auto {
  display: flex; align-items: center;
  justify-content: center;
  color: var(--accent); font-size: 1rem;
}
.appearance-upload-wallpaper { margin-top: 4px; }
.appearance-upload-btn {
  display: inline-flex !important;
  align-items: center; gap: 8px;
  padding: 10px 16px !important;
  background: var(--bg-input) !important;
  border-radius: 10px !important;
  cursor: pointer; font-size: 0.9rem;
  color: var(--text-primary);
  transition: background 0.15s;
  width: auto !important; margin: 0 !important;
}
.appearance-upload-btn:hover {
  background: var(--bg-hover) !important;
}
.appearance-upload-btn i { color: var(--accent); }
.appearance-footer {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.appearance-reset {
  width: auto !important;
  background: transparent !important;
  color: #ef4444 !important;
  border: none !important;
  padding: 10px 16px !important;
  border-radius: 10px !important;
  cursor: pointer; font-weight: 600;
  font-size: 0.9rem; margin: 0 !important;
}
.appearance-reset:hover {
  background: rgba(239,68,68,0.1) !important;
}
.appearance-done {
  width: auto !important;
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  padding: 10px 24px !important;
  border-radius: 10px !important;
  cursor: pointer; font-weight: 600;
  font-size: 0.9rem; margin: 0 !important;
}
.appearance-done:hover {
  background: var(--accent-hover) !important;
}

/* Плотность сообщений */
body.density-compact .message { margin-bottom: 6px; padding: 8px 10px; line-height: 1.3; }
body.density-compact .chat-body { padding: 12px; }
body.density-normal .message { margin-bottom: 15px; padding: 10px; }
body.density-normal .chat-body { padding: 20px; }
body.density-relaxed .message { margin-bottom: 22px; padding: 14px; line-height: 1.6; }
body.density-relaxed .chat-body { padding: 28px; }

/* ==================================================================
   14. АНИМАЦИИ
   ================================================================== */
@keyframes message-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.message.message-new {
  animation: message-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes message-send {
  0%   { opacity: 0; transform: scale(0.85); }
  50%  { opacity: 1; transform: scale(1.02); }
  100% { opacity: 1; transform: scale(1); }
}
.message.own.message-new {
  animation: message-send 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chat-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-body.chat-enter {
  animation: chat-enter 0.3s ease-out;
}

@keyframes chat-item-in {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: translateX(0); }
}
.chat-item--new {
  animation: chat-item-in 0.32s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.chat-item:active { transform: scale(0.98); transition: transform 0.08s; }

@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-pop-in {
  from { opacity: 0; transform: scale(0.93) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-overlay.active {
  animation: modal-fade-in 0.2s ease-out;
}
.modal-overlay.active .modal {
  animation: modal-pop-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.dropdown-menu.active {
  animation: dropdown-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top left;
}
.fab-left-menu.active {
  animation: dropdown-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom left;
}

@keyframes emoji-pop {
  from { opacity: 0; transform: scale(0.9) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.emoji-picker.active {
  animation: emoji-pop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.emoji-picker span { transition: transform 0.15s ease; }
.emoji-picker span:hover { transform: scale(1.3); }

@keyframes fab-pulse {
  0%, 100% { box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
  50%      { box-shadow: 0 4px 25px var(--accent-soft-2), 0 0 0 10px var(--accent-soft); }
}
.fab-left { animation: fab-pulse 2.8s ease-in-out infinite; }
.fab-left:active { transform: scale(0.92) !important; }

.modal button,
.send-btn,
.attach-btn,
.channel-notice-btn,
.chat-settings-save,
.settings-save-btn,
.appearance-done,
.members-panel-add {
  transition: transform 0.12s ease, background-color 0.2s ease, color 0.2s ease;
}
.modal button:active,
.send-btn:active,
.attach-btn:active,
.channel-notice-btn:active,
.chat-settings-save:active,
.settings-save-btn:active,
.appearance-done:active {
  transform: scale(0.95);
}

.add-member-btn,
.members-panel-close,
.settings-close,
.appearance-close,
.chat-settings-back {
  transition: background-color 0.2s, color 0.2s, transform 0.15s;
}
.add-member-btn:hover { transform: translateY(-1px); }
.add-member-btn:active { transform: scale(0.96); }

@keyframes badge-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,71,87,0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(255,71,87,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,71,87,0); }
}
.chat-item .chat-name span[style*="ff4757"] {
  animation: badge-pulse 2s infinite;
}

.message .spoiler {
  transition: background-color 0.3s ease, color 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
.shake { animation: shake 0.3s ease; }

html, body, .app-container, .sidebar, .chat-area {
  transition: background-color 0.4s ease, color 0.3s ease;
}

@keyframes tab-glow {
  0%, 100% { box-shadow: inset 0 -1px 0 var(--accent); }
  50%      { box-shadow: inset 0 -3px 0 var(--accent); }
}
.settings-tabs button.active {
  animation: tab-glow 2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .fab-left { animation: none !important; }
  .settings-tabs button.active { animation: none !important; }
}

/* ==================================================================
   15. ATTACHMENT PREVIEW
   ================================================================== */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 4px 6px;
  animation: attach-slide-in 0.25s ease-out;
}
@keyframes attach-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.attachment-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.attachment-item:hover { transform: scale(1.03); }
.attachment-item img {
  width: 100%; height: 100%; object-fit: cover;
}
.attachment-file {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1.8rem;
  color: var(--accent);
  background: var(--accent-soft);
}
.attachment-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 20px !important;
  height: 20px !important;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0 !important;
  margin: 0 !important;
  transition: background 0.15s, transform 0.15s;
}
.attachment-remove:hover {
  background: #dc2626;
  transform: scale(1.1);
}
.attachment-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 3px 6px;
  font-size: 0.65rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
@media (max-width: 768px) {
  .attachment-item { width: 64px; height: 64px; }
  .attachment-preview { gap: 6px; padding: 8px 2px 4px; }
}

/* ==================================================================
   16. DRAG & DROP OVERLAY
   ================================================================== */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(102, 126, 234, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}
.drop-overlay.active { opacity: 1; }
.drop-overlay-inner {
  background: var(--bg-primary);
  border: 3px dashed var(--accent);
  border-radius: 24px;
  padding: 48px 64px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: drop-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes drop-pop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.drop-overlay-inner i {
  font-size: 4rem;
  color: var(--accent);
  margin-bottom: 12px;
  display: block;
  animation: drop-bounce 1.2s ease-in-out infinite;
}
@keyframes drop-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.drop-overlay-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.drop-overlay-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
}
@media (max-width: 768px) {
  .drop-overlay-inner { padding: 32px 40px; }
  .drop-overlay-inner i { font-size: 3rem; }
  .drop-overlay-title { font-size: 1.15rem; }
}

/* ==================================================================
   17. IMAGE VIEWER
   ================================================================== */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.95);
  animation: viewer-fade-in 0.2s ease-out;
}
@keyframes viewer-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.image-viewer-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}
.image-viewer-img {
  max-width: 90vw;
  max-height: 90vh;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.15s ease-out;
  will-change: transform;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.image-viewer-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 20px 70px 20px 20px;
  z-index: 3;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #fff;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.image-viewer-name {
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.image-viewer-counter {
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
}

.image-viewer-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 3;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px;
  border-radius: 16px;
  animation: viewer-slide-up 0.25s ease-out;
}
@keyframes viewer-slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}
.image-viewer-btn {
  width: 42px;
  height: 42px;
  background: transparent;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.15s, transform 0.12s;
  text-decoration: none;
  padding: 0 !important;
  margin: 0 !important;
}
.image-viewer-btn:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.08);
}
.image-viewer-btn:active { transform: scale(0.94); }

.image-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
  height: 54px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  z-index: 3;
  transition: background 0.15s, transform 0.15s;
}
.image-viewer-nav:hover {
  background: rgba(255,255,255,0.25);
}
.image-viewer-nav.prev { left: 20px; }
.image-viewer-nav.next { right: 20px; }
.image-viewer-nav:active { transform: translateY(-50%) scale(0.92); }

.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 42px;
  height: 42px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  transition: background 0.15s, transform 0.15s;
}
.image-viewer-close:hover {
  background: rgba(255,80,80,0.6);
  transform: rotate(90deg);
}

.chat-image {
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  margin-top: 5px;
  display: block;
  cursor: zoom-in;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.2s;
  object-fit: cover;
}
.chat-image:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0.95;
}
.chat-image:active { transform: scale(0.99); }

@media (max-width: 768px) {
  .image-viewer-img { max-width: 100vw; max-height: 88vh; border-radius: 0; }
  .image-viewer-top { padding: 14px 60px 14px 14px; }
  .image-viewer-name { font-size: 0.85rem; max-width: 55vw; }
  .image-viewer-counter { font-size: 0.75rem; padding: 3px 9px; }
  .image-viewer-nav { width: 44px; height: 44px; font-size: 1.1rem; }
  .image-viewer-nav.prev { left: 10px; }
  .image-viewer-nav.next { right: 10px; }
  .image-viewer-close { width: 38px; height: 38px; top: 14px; right: 14px; }
  .image-viewer-bottom { padding: 6px; gap: 4px; bottom: 14px; }
  .image-viewer-btn { width: 38px; height: 38px; font-size: 0.9rem; }
  .chat-image { max-width: 220px; max-height: 220px; }
}

/* ==================================================================
   18. CHAT PREVIEW (ссылка-приглашение)
   ================================================================== */
.chat-preview-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 2500; padding: 20px;
}
.chat-preview-card {
  background: var(--bg-primary);
  border-radius: 20px;
  width: 400px; max-width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: modal-pop-in 0.3s cubic-bezier(0.16,1,0.3,1);
}
.chat-preview-header {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff; padding: 32px 20px 24px;
  text-align: center; flex-shrink: 0;
}
.chat-preview-avatar {
  width: 88px; height: 88px; border-radius: 50%;
  background: #fff; color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: bold;
  margin: 0 auto 14px; overflow: hidden;
  border: 3px solid rgba(255,255,255,0.5);
}
.chat-preview-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-preview-type { font-size: 0.8rem; opacity: 0.9; margin-bottom: 4px; }
.chat-preview-name { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.chat-preview-members { font-size: 0.85rem; opacity: 0.85; }

.chat-preview-description {
  padding: 18px 22px;
  flex: 1; overflow-y: auto; min-height: 70px;
  color: var(--text-secondary);
  font-size: 0.92rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.chat-preview-description:empty::before {
  content: 'Описание отсутствует';
  color: var(--text-muted); font-style: italic;
}
.chat-preview-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0;
}
.chat-preview-join {
  width: 100%; padding: 14px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.15s, transform 0.1s;
}
.chat-preview-join:hover { background: var(--accent-hover); }
.chat-preview-join:active { transform: scale(0.98); }
.chat-preview-join:disabled { opacity: 0.6; cursor: not-allowed; }
.chat-preview-cancel {
  width: 100%; padding: 12px;
  background: transparent; color: var(--text-secondary);
  border: none; border-radius: 12px;
  font-size: 0.9rem; cursor: pointer; font-family: inherit;
}
.chat-preview-cancel:hover { background: var(--bg-hover); }

@media (max-width: 768px) {
  .chat-preview-overlay { padding: 0; align-items: flex-end; }
  .chat-preview-card {
    width: 100vw; max-width: 100vw;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
  }
  .chat-preview-footer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .chat-preview-join { font-size: 1rem; padding: 15px; }
}

/* ==================================================================
   19. МОБИЛЬНАЯ ВЕРСИЯ
   ================================================================== */
@media (max-width: 768px) {

  /* ✅ Используем --app-height: JS из mobile.js обновляет его при
     появлении клавиатуры в Firefox Android, где 100dvh не работает */
  html, body {
    overflow: hidden;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    width: 100vw;
    position: fixed;
  }
  .app-container {
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
  }
  .sidebar {
    width: 100%;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    border-right: none;
  }
  .sidebar-header { padding: 14px 16px; gap: 10px; }
  .sidebar-header h2 { font-size: 1.15rem; }
  .user-info { gap: 8px; }
  .user-info > div:first-child { display: none; }
  .avatar-container { width: 40px; height: 40px; font-size: 1rem; }
  .back-btn { display: none; }

  .chat-area {
    width: 100vw;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    display: none;
    position: fixed; top: 0; left: 0; right: 0;
    bottom: auto;
    z-index: 100; background: var(--bg-primary);
    flex-direction: column; overflow: hidden;
  }
  .chat-area.mobile-open { display: flex; }
  .chat-header { padding: 12px 14px; gap: 8px; }
  .chat-header .chat-title {
    font-size: 1rem; max-width: 45vw;
    overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-header .chat-type-label {
    font-size: 0.7rem; padding: 2px 6px; margin-left: 6px;
  }
  .chat-header .chat-status { display: none; }
  .back-btn {
    display: flex !important; align-items: center;
    font-size: 1.3rem; padding: 4px 8px 4px 0;
    margin-right: 4px;
  }
  .header-buttons { gap: 6px; flex-shrink: 0; }
  .add-member-btn { padding: 8px 10px; font-size: 0.85rem; }
  .chat-body {
    flex: 1 1 0; min-height: 0;
    overflow-y: auto; overflow-x: hidden;
    padding: 12px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .message {
    max-width: 86%; font-size: 0.92rem;
    padding: 8px 11px; margin-bottom: 10px; line-height: 1.4;
  }
  .message .message-actions { display: none; }
  /* Long-press показывает actions — см. mobile.js */
  .message.actions-visible .message-actions { display: flex; }

  .chat-footer {
    flex-shrink: 0; padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
  }
  .format-toolbar {
    gap: 3px; margin-bottom: 6px;
    overflow-x: auto; padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; flex-wrap: nowrap;
  }
  .format-toolbar::-webkit-scrollbar { display: none; }
  .format-toolbar button {
    padding: 0 9px !important;
    height: 28px !important;
    font-size: 0.8rem; flex-shrink: 0;
  }
  .input-row { gap: 6px; align-items: flex-end; }
  .input-row .attach-btn { width: 38px; height: 38px; font-size: 1.2rem; }
  .input-row .send-btn { width: 38px; height: 38px; font-size: 1rem; }
  #messageInput {
    min-height: 38px; max-height: 100px;
    padding: 9px 14px;
    font-size: 16px;
    line-height: 20px; height: 38px;
    border-radius: 19px;
  }
  .reply-bar { font-size: 0.8rem; padding: 6px 10px; margin-bottom: 4px; }

  .channel-notice {
    padding: 10px 12px; font-size: 0.8rem; flex-shrink: 0;
  }
  .channel-notice-content { gap: 8px; }
  .channel-notice-btn { padding: 6px 12px !important; font-size: 0.8rem; }

  .modal-overlay {
    padding: 0; align-items: flex-end;
    justify-content: center;
  }
  .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 18px 16px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    animation: modal-slide-up 0.25s ease;
  }
  @keyframes modal-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
  .modal h2 { font-size: 1.1rem; margin-bottom: 14px; }
  .modal input, .modal textarea { font-size: 16px; }
  .modal button { font-size: 0.95rem; padding: 13px; }

  /* ✅ Одинаковая высота у всех модалок — табы не прыгают */
  .settings-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex;
    flex-direction: column;
  }
  .settings-header { flex-shrink: 0; }
  .settings-tabs   { flex-shrink: 0; }
  .settings-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }
  .settings-header { padding: 14px 16px; }
  .settings-header h2 { font-size: 1.05rem; }
  .settings-tabs {
    padding: 6px 6px 0; gap: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .settings-tabs::-webkit-scrollbar { display: none; }
  .settings-tabs button {
    padding: 10px 10px !important;
    font-size: 0.78rem; flex-shrink: 0;
  }
  .settings-tabs button i { font-size: 0.7rem; }
  .settings-body { padding: 14px 16px; }
  .avatar-uploader .current-avatar {
    width: 84px; height: 84px; font-size: 1.7rem;
  }
  .privacy-row-options button {
    padding: 7px 4px !important; font-size: 0.75rem;
  }

  .chat-settings-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex; flex-direction: column;
  }
  .chat-settings-header { flex-shrink: 0; }
  .chat-settings-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
  .chat-settings-footer { flex-shrink: 0; }
  .chat-settings-header { padding: 14px 16px; }
  .chat-settings-header h2 { font-size: 1.05rem; }
  .chat-settings-body { padding: 14px 16px; }
  .chat-settings-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .chat-settings-footer button {
    padding: 11px 18px !important; font-size: 0.88rem;
  }
  .chat-settings-row { padding: 13px 4px; }
  .chat-settings-row i { font-size: 1rem; }
  .chat-settings-row span:nth-of-type(1) { font-size: 0.9rem; }
  .chat-settings-value { font-size: 0.85rem !important; }
  .chat-settings-avatar { width: 64px; height: 64px; font-size: 1.6rem; }
  .chat-settings-avatar-row { gap: 12px; }
  .chat-settings-input,
  .custom-select-trigger {
    padding: 10px 12px; font-size: 16px;
  }
  .custom-select-trigger { font-size: 0.9rem; }
  .custom-select-dropdown { max-height: 50dvh; }

  .chat-info-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex; flex-direction: column;
  }
  .chat-info-header  { flex-shrink: 0; }
  .chat-info-actions { flex-shrink: 0; }
  .chat-info-members {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    max-height: none;
  }
  .chat-info-header { padding: 24px 16px 18px; }
  .chat-info-avatar { width: 72px; height: 72px; font-size: 1.9rem; }
  .chat-info-name { font-size: 1.15rem; }
  .chat-info-actions { padding: 10px; gap: 6px; }
  .chat-info-actions button {
    min-width: 70px; padding: 10px 6px; font-size: 0.72rem;
  }
  .chat-info-actions button i { font-size: 1rem; }

  .members-panel-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex; flex-direction: column;
  }
  .members-panel-header      { flex-shrink: 0; }
  .members-panel-search-wrap { flex-shrink: 0; }
  .members-panel-list        { flex: 1 1 auto; min-height: 0; overflow-y: auto; max-height: none; }
  .members-panel-footer      { flex-shrink: 0; }
  .members-panel-header { padding: 14px 16px 8px; }
  .members-panel-header h2 { font-size: 1.05rem; }
  .members-panel-search-wrap { margin: 0 16px 8px; }
  .members-panel-search { font-size: 16px; }
  .members-panel-list { padding: 0 8px 8px; }
  .member-row { padding: 8px 8px; gap: 10px; }
  .member-row-avatar { width: 40px; height: 40px; }
  .member-row-name { font-size: 0.88rem; }
  .member-row-status { font-size: 0.72rem; }
  .members-panel-footer {
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    flex-direction: column; gap: 6px; align-items: stretch;
  }
  .members-panel-add, .members-panel-done { justify-content: center; }

  .admin-rights-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex; flex-direction: column;
  }
  .admin-rights-header { flex-shrink: 0; }
  .admin-rights-by     { flex-shrink: 0; }
  .admin-rights-title  { flex-shrink: 0; }
  .admin-rights-list   { flex: 1 1 auto; min-height: 0; overflow-y: auto; max-height: none; }
  .admin-rights-footer { flex-shrink: 0; }
  .admin-rights-header { padding: 16px 16px 6px; }
  .admin-rights-avatar { width: 52px; height: 52px; font-size: 1.2rem; }
  .admin-rights-name { font-size: 1rem; }
  .admin-rights-list { padding: 0 16px 12px; }
  .admin-perm-row { padding: 10px 0; }
  .admin-perm-label { font-size: 0.85rem; }

  .appearance-modal {
    width: 100vw !important;
    height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex; flex-direction: column;
  }
  .appearance-header { flex-shrink: 0; }
  .appearance-body   { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
  .appearance-footer { flex-shrink: 0; }
  .appearance-header { padding: 14px 16px; }
  .appearance-header h2 { font-size: 1.05rem; }
  .appearance-body { padding: 14px 16px; }
  .appearance-btn-group button {
    padding: 9px 4px !important; font-size: 0.78rem;
  }
  .appearance-btn-group button i { font-size: 0.8rem; }
  .accent-presets {
    grid-template-columns: repeat(6, 1fr); gap: 6px;
  }
  .wallpaper-presets {
    grid-template-columns: repeat(3, 1fr); gap: 6px;
  }
  .appearance-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .profile-avatar { width: 68px; height: 68px; font-size: 1.7rem; }
  .profile-name { font-size: 1.05rem; }

  .fab-left {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    width: 52px; height: 52px; font-size: 1.5rem;
  }
  .fab-left-menu {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    width: calc(100vw - 32px); max-width: 260px;
  }
  body.mobile-chat-open .fab-left,
  body.mobile-chat-open .fab-left-menu { display: none !important; }

  /* ==============================================================
     АНИМАЦИИ ВЫХОДА / ВХОДА В ЧАТ
     ============================================================== */
  @keyframes chat-slide-out-right {
    from { transform: translateX(0);     opacity: 1; }
    to   { transform: translateX(35%);   opacity: 0; }
  }
  .chat-area.mobile-closing {
    animation: chat-slide-out-right 0.28s cubic-bezier(0.4, 0, 1, 1) forwards;
    pointer-events: none;
  }

  @keyframes chat-list-return {
    from { opacity: 0.4; transform: translateX(-14px); }
    to   { opacity: 1;   transform: translateX(0); }
  }
  .sidebar.mobile-returning {
    animation: chat-list-return 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes chat-slide-in-right {
    from { transform: translateX(35%); opacity: 0; }
    to   { transform: translateX(0);   opacity: 1; }
  }
  .chat-area.mobile-opening {
    animation: chat-slide-in-right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

@media (max-width: 400px) {
  .format-toolbar button {
    padding: 0 7px !important; font-size: 0.75rem;
  }
  .settings-tabs button {
    padding: 9px 8px !important; font-size: 0.72rem;
  }
  .settings-tabs button i { display: none; }
  .chat-info-actions button {
    min-width: 60px; padding: 9px 4px; font-size: 0.68rem;
  }
  .appearance-btn-group button {
    padding: 8px 2px !important; font-size: 0.72rem;
  }
  .accent-presets { grid-template-columns: repeat(5, 1fr); }
  .modal h2 { font-size: 1rem; }
  .message { max-width: 90%; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .chat-header { padding: 8px 12px; }
  .format-toolbar { margin-bottom: 4px; }
  .format-toolbar button { height: 26px !important; }
  .chat-footer { padding: 6px 8px; }
  .chat-body { padding: 8px 10px; }
  .modal { max-height: 96dvh !important; }
  .modal-overlay { align-items: center; padding: 8px; }
  .modal { border-radius: 16px !important; max-width: 480px !important; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 280px; }
  .chat-item .chat-name { font-size: 0.9rem; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .chat-footer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* Ссылка на файл в сообщении */
.chat-file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 5px;
  background: rgba(102,126,234,0.1);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-primary);
  max-width: 100%;
  transition: background 0.15s;
}
.chat-file-link:hover { background: rgba(102,126,234,0.2); }
.chat-file-link .file-icon { font-size: 1.4rem; flex-shrink: 0; }
.chat-file-link .file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  font-weight: 500;
}

/* ==================================================================
   20. ВИДИМОСТЬ ИКОНОК ЗАКРЫТИЯ (обе темы)
   ================================================================== */
.settings-close,
.appearance-close,
.members-panel-close,
.chat-settings-back,
.chat-info-close {
  color: var(--text-secondary) !important;
  opacity: 0.85;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s;
}
.settings-close:hover,
.appearance-close:hover,
.members-panel-close:hover,
.chat-settings-back:hover {
  color: var(--text-primary) !important;
  opacity: 1;
  background: var(--bg-hover) !important;
}
.chat-info-close:hover {
  opacity: 1;
  background: rgba(0,0,0,0.55) !important;
}
[data-theme="dark"] .settings-close,
[data-theme="dark"] .appearance-close,
[data-theme="dark"] .members-panel-close,
[data-theme="dark"] .chat-settings-back {
  color: #d0d8e2 !important;
}
[data-theme="dark"] .modal-error    { color: #ff6b6b; }
[data-theme="dark"] .modal-success  { color: #4ade80; }
[data-theme="dark"] .empty-hint     { color: #8b95a1; }
[data-theme="dark"] .profile-bio    { color: #b0bac5; }
[data-theme="dark"] .chat-settings-hint { color: #8b95a1; }

/* ==================================================================
   21. МУЛЬТИАККАУНТ (выпадашка)
   ================================================================== */
.dropdown-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 10px 4px;
  font-weight: 600;
}
.dropdown-account {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px !important;
  border: none !important; background: transparent !important;
  border-radius: 8px !important;
  cursor: pointer; text-align: left;
  color: var(--text-primary);
  font-family: inherit;
  margin: 0 !important;
}
.dropdown-account:hover { background: var(--bg-hover) !important; }
.dropdown-account.active { background: var(--accent-soft) !important; }
.dropdown-account-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 0.9rem;
  overflow: hidden; flex-shrink: 0;
}
.dropdown-account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.dropdown-account-info { flex: 1; min-width: 0; }
.dropdown-account-name {
  font-size: 0.88rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dropdown-account-id {
  font-size: 0.7rem; color: var(--text-muted);
}
.dropdown-account-check {
  color: var(--accent); font-weight: bold;
  font-size: 0.95rem; flex-shrink: 0;
}
.dropdown-account-remove {
  color: var(--text-muted); font-size: 0.8rem;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.dropdown-account-remove:hover {
  background: rgba(220,38,38,0.15);
  color: #dc2626;
}
.dropdown-divider {
  height: 1px; background: var(--border);
  margin: 6px 4px;
}

/* ==================================================================
   EMOJI PICKER — мобильная адаптация
   ================================================================== */
.emoji-picker {
  flex-wrap: wrap;
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
}
.emoji-picker.active {
  display: flex;
}
.emoji-picker span {
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .emoji-picker {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: none;
    justify-content: center;
    padding: 10px;
    gap: 4px;
  }
  .emoji-picker span {
    font-size: 1.4rem;
    padding: 4px;
  }
}

/* ==================================================================
   КОНТЕКСТНОЕ МЕНЮ СООБЩЕНИЯ (как в Telegram)
   ================================================================== */
.msg-menu-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  z-index: 3000;
  align-items: center; justify-content: center;
  padding: 20px;
}
.msg-menu-overlay.active { display: flex; }

.msg-menu {
  background: var(--bg-primary);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-width: 360px; width: 100%;
  overflow: hidden;
  animation: menu-pop 0.18s cubic-bezier(0.16,1,0.3,1);
}
@keyframes menu-pop {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.msg-menu-emojis {
  display: flex; gap: 2px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  justify-content: center;
  flex-wrap: wrap;
}
.msg-menu-emojis::-webkit-scrollbar { display: none; }
.msg-menu-emojis button {
  background: transparent; border: none;
  font-size: 1.5rem;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  flex-shrink: 0;
  line-height: 1;
}
.msg-menu-emojis button:hover {
  background: var(--bg-hover);
  transform: scale(1.2);
}
.msg-menu-emojis button:active { transform: scale(1); }

.msg-menu-actions {
  padding: 6px;
  max-height: 50vh;
  overflow-y: auto;
}
.msg-menu-actions button {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 11px 14px;
  background: transparent; border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-primary);
  text-align: left;
  font-family: inherit;
  transition: background 0.15s;
}
.msg-menu-actions button:hover { background: var(--bg-hover); }
.msg-menu-actions button i {
  width: 22px; text-align: center;
  color: var(--text-secondary);
  font-size: 1rem;
}
.msg-menu-actions button.danger { color: #dc2626; }
.msg-menu-actions button.danger i { color: #dc2626; }

@media (max-width: 768px) {
  .msg-menu-overlay { align-items: flex-end; padding: 0; }
  .msg-menu {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    animation: menu-slide-up 0.22s cubic-bezier(0.16,1,0.3,1);
  }
  @keyframes menu-slide-up {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
  .msg-menu-emojis {
    padding: 12px 10px;
    justify-content: space-between;
    flex-wrap: nowrap;
  }
  .msg-menu-emojis button { font-size: 1.4rem; padding: 2px 3px; }
  .msg-menu-actions {
    padding: 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .msg-menu-actions button { padding: 13px 14px; }
}