/* ═══════════════════════════════════════════════════
   QIVA MESSENGER — Design System
   ═══════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────── */
:root {
  --text-xs:   clamp(0.72rem, 0.68rem + 0.2vw, 0.82rem);
  --text-sm:   clamp(0.85rem, 0.8rem  + 0.25vw, 0.95rem);
  --text-base: clamp(0.95rem, 0.9rem  + 0.25vw, 1.05rem);
  --text-lg:   clamp(1.1rem,  1rem    + 0.5vw,  1.3rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 4px; --radius-md: 10px; --radius-lg: 16px;
  --radius-xl: 20px; --radius-full: 9999px;

  --transition: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --font-display: 'Cabinet Grotesk', 'Helvetica Neue', sans-serif;
  --font-body:    'Satoshi', 'Inter', sans-serif;
  --sidebar-width: 320px;
}

/* ── Light theme ─────────────────────────────────── */
:root, [data-theme="light"] {
  --bg:              #f2f0ec;
  --surface:         #ffffff;
  --surface-2:       #f8f7f5;
  --surface-hover:   #eeece8;
  --surface-active:  #e5e2dc;
  --border:          #dedad4;
  --divider:         #eae7e2;
  --text:            #1a1815;
  --text-muted:      #68666a;
  --text-faint:      #aaa9a6;
  --primary:         #5b67f8;
  --primary-hover:   #4554f4;
  --primary-bubble:  #5b67f8;
  --primary-bubble-text: #ffffff;
  --incoming-bubble: #ffffff;
  --incoming-bubble-text: #1a1815;
  --online:          #22c55e;
  --unread-bg:       #5b67f8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.09);
}

/* ── Dark theme ──────────────────────────────────── */
[data-theme="dark"] {
  --bg:              #0f0f10;
  --surface:         #18181b;
  --surface-2:       #1c1c20;
  --surface-hover:   #222228;
  --surface-active:  #2a2a32;
  --border:          #2c2c34;
  --divider:         #25252c;
  --text:            #e8e8ec;
  --text-muted:      #7a7a86;
  --text-faint:      #4a4a56;
  --primary:         #7b88ff;
  --primary-hover:   #6974ff;
  --primary-bubble:  #4c54cc;
  --primary-bubble-text: #e8e8f8;
  --incoming-bubble: #25252e;
  --incoming-bubble-text: #e0e0e8;
  --online:          #22c55e;
  --unread-bg:       #7b88ff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
}

/* ── Modern theme Liquid Glass effects ───────────── */
[data-ui-theme="modern"][data-theme="dark"] {
  --surface:   rgba(30, 30, 36, 0.92);
  --surface-2: rgba(28, 28, 34, 0.88);
}
[data-ui-theme="modern"] .modal {
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  background: var(--surface) !important;
  border: 1px solid rgba(255,255,255,0.08);
}
[data-ui-theme="modern"] .sidebar {
  backdrop-filter: blur(12px);
}

/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}
.hidden { display: none !important; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }

/* ── Auth ────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--bg);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
}
.auth-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--space-5);
}
.auth-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: calc(var(--radius-md) - 2px);
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--text-muted);
  transition: var(--transition);
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label { font-size: var(--text-sm); font-weight: 500; color: var(--text-muted); }
.field input, .field textarea, .field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.field-hint { font-size: var(--text-xs); color: var(--text-faint); }
.auth-error { font-size: var(--text-sm); color: #ef4444; min-height: 1.2em; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  font-weight: 600;
  font-size: var(--text-sm);
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-weight: 500;
  font-size: var(--text-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger-outline {
  background: transparent;
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-weight: 500;
  font-size: var(--text-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition);
}
.btn-danger-outline:hover { background: rgba(239,68,68,0.08); }

/* ── App layout ──────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--divider);
}
.logo { display: flex; align-items: center; gap: var(--space-2); font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); }
.logo-text { color: var(--text); }
.sidebar-actions { display: flex; gap: var(--space-1); }

/* Tab bar */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--divider);
  background: var(--surface-2);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: var(--space-2) var(--space-1);
  font-size: 0.68rem;
  color: var(--text-faint);
  transition: color var(--transition);
  border-bottom: 2px solid transparent;
  position: relative;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn svg { transition: color var(--transition); }

/* Tab content */
.sidebar-tab-content { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.sidebar-tab-content.active { display: flex; }

/* Search */
.search-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
}
.search-icon { color: var(--text-faint); flex-shrink: 0; }
.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  color: var(--text);
}
.search-input::placeholder { color: var(--text-faint); }

/* ── Chat list ───────────────────────────────────── */
.chat-list { flex: 1; overflow-y: auto; padding: var(--space-2) 0; }
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
.chat-list-empty { padding: var(--space-6) var(--space-4); color: var(--text-faint); font-size: var(--text-sm); text-align: center; line-height: 1.6; }
.chat-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--transition);
  border-radius: var(--radius-md);
  margin: 1px var(--space-2);
}
.chat-item:hover { background: var(--surface-hover); }
.chat-item.active { background: var(--surface-active); }
.chat-info { flex: 1; min-width: 0; }
.chat-meta { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 2px; }
.chat-name { font-weight: 600; font-size: var(--text-sm); truncate: ellipsis; white-space: nowrap; overflow: hidden; max-width: 160px; }
.chat-time { font-size: var(--text-xs); color: var(--text-faint); flex-shrink: 0; margin-left: var(--space-2); }
.chat-preview-row { display: flex; align-items: center; gap: var(--space-2); }
.chat-preview { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.badge {
  background: var(--unread-bg);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* ── Avatar ──────────────────────────────────────── */
.avatar {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  position: relative;
}
.avatar.sm  { width: 32px; height: 32px; font-size: 11px; }
.avatar.xl  { width: 72px; height: 72px; font-size: 24px; }
.avatar.group { background: var(--surface-active); color: var(--primary); }
.avatar.online::after {
  content: '';
  position: absolute;
  bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: var(--online);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface);
}
.avatar.sm.online::after { width: 8px; height: 8px; }
.avatar.xl.online::after { width: 14px; height: 14px; bottom: 2px; right: 2px; }

/* ── Profile panel ───────────────────────────────── */
.profile-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6) var(--space-4);
  gap: var(--space-4);
  overflow-y: auto;
  flex: 1;
}
.profile-avatar-wrap { position: relative; display: inline-block; }
.avatar-edit-btn {
  position: absolute;
  bottom: 0; right: 0;
  background: var(--primary);
  color: #fff;
  width: 26px; height: 26px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
}
.avatar-edit-btn:hover { background: var(--primary-hover); }
.profile-info { text-align: center; }
.profile-name { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); }
.profile-username { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.profile-bio { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); text-align: center; }
.profile-actions { display: flex; flex-direction: column; gap: var(--space-2); width: 100%; }

/* ── Welcome pane ────────────────────────────────── */
.welcome-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--text-faint);
  text-align: center;
  padding: var(--space-8);
}
.welcome-pane h2 { font-family: var(--font-display); font-weight: 800; font-size: var(--text-lg); color: var(--text-muted); }
.welcome-pane p { font-size: var(--text-sm); max-width: 280px; line-height: 1.6; }

/* ── Chat main ───────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  position: relative; /* FIX5: для абсолютного позиционирования emoji picker */
}
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.chat-header-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header-name { display: block; font-weight: 700; font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { display: block; font-size: var(--text-xs); color: var(--text-faint); }
.chat-header-actions { display: flex; gap: var(--space-1); }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.back-btn { display: none; }

/* ── Chat search bar ─────────────────────────────── */
.chat-search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
}

/* ── Reply preview ───────────────────────────────── */
.reply-preview {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-2);
  border-top: 1px solid var(--divider);
  border-left: 3px solid var(--primary);
}
.reply-preview-bar { width: 3px; height: 32px; background: var(--primary); border-radius: var(--radius-full); display: none; }
.reply-preview-content { flex: 1; min-width: 0; }
.reply-preview-name { display: block; font-size: var(--text-xs); font-weight: 600; color: var(--primary); }
.reply-preview-text { display: block; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview-close { width: 24px; height: 24px; }

/* ── Messages area ───────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }

/* ── Date divider ────────────────────────────────── */
.date-divider {
  text-align: center;
  margin: var(--space-3) 0;
  position: relative;
}
.date-divider span {
  font-size: var(--text-xs);
  color: var(--text-faint);
  background: var(--bg);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
}

/* ── Message bubbles ─────────────────────────────── */
.message {
  display: flex;
  gap: var(--space-2);
  max-width: 72%;
  animation: msgIn 0.18s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.message.outgoing { flex-direction: row-reverse; align-self: flex-end; }
.message.incoming { align-self: flex-start; }
.message-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.outgoing .message-body { align-items: flex-end; }

.msg-sender-name {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--primary);
  display: block;
  margin-bottom: 2px;
}

.bubble {
  background: var(--incoming-bubble);
  color: var(--incoming-bubble-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.outgoing .bubble {
  background: var(--primary-bubble);
  color: var(--primary-bubble-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
}

/* Изображение без баббла */
.bubble-image {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: transparent !important;
  padding: 0 !important;
  box-shadow: none !important;
  position: relative;
}
.bubble-image .msg-time {
  position: absolute;
  bottom: var(--space-2);
  right: var(--space-2);
  background: rgba(0,0,0,0.5);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 1px 6px;
  font-size: 11px;
  backdrop-filter: blur(4px);
}

/* Одиночный эмодзи */
.bubble-emoji {
  font-size: 2.6rem;
  line-height: 1.2;
  padding: var(--space-1);
  display: inline-flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: transparent;
  word-break: break-word;
}

.bubble p { margin: 0; }
.msg-time {
  font-size: 10px;
  color: var(--text-faint);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
  align-self: flex-end;
  flex-shrink: 0;
}
.outgoing .bubble .msg-time { color: rgba(255,255,255,0.65); }
.bubble .msg-time { float: right; margin-left: var(--space-2); margin-top: 2px; }
.edited-mark { font-style: italic; opacity: 0.7; margin-right: 3px; }
.read-icon { color: var(--primary-bubble-text); opacity: 0.75; }

/* Images in bubble */
.msg-image {
  max-width: 280px;
  max-height: 360px;
  border-radius: var(--radius-lg);
  display: block;
  cursor: zoom-in;
}

/* File message */
.file-msg {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}
.file-msg-icon { font-size: 1.8rem; }
.file-msg-info { min-width: 0; }
.file-msg-name { font-weight: 500; font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-msg-size { font-size: var(--text-xs); color: var(--text-faint); }
.outgoing .file-msg-size { color: rgba(255,255,255,0.55); }

/* Reply block */
.reply-block {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  cursor: pointer;
}
.reply-bar { width: 3px; border-radius: var(--radius-full); background: var(--primary); flex-shrink: 0; }
.outgoing .reply-bar { background: rgba(255,255,255,0.5); }
.reply-body { min-width: 0; }
.reply-name { font-size: var(--text-xs); font-weight: 600; color: var(--primary); display: block; }
.reply-text { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 200px; }
.outgoing .reply-name { color: rgba(255,255,255,0.8); }
.outgoing .reply-text { color: rgba(255,255,255,0.6); }

/* Forward label */
.forward-label {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-2);
  font-style: italic;
}
.outgoing .forward-label { color: rgba(255,255,255,0.6); }

/* Typing */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  align-self: flex-start;
  margin-top: var(--space-2);
}
.typing-bubble {
  background: var(--incoming-bubble);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 6px; height: 6px;
  background: var(--text-faint);
  border-radius: var(--radius-full);
  animation: typingPulse 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingPulse { 0%,80%,100% { transform: scale(1); opacity: 0.4; } 40% { transform: scale(1.2); opacity: 1; } }

/* ── Input panel ─────────────────────────────────── */
.input-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}
.input-panel .reply-preview {
  border-radius: 0;
  border-top: none;
  border-bottom: 1px solid var(--divider);
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}
.attach-btn { color: var(--text-muted); cursor: pointer; }
.input-wrap {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: flex-end;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  gap: var(--space-1);
  transition: border-color var(--transition);
}
.input-wrap:focus-within { border-color: var(--primary); }
.msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-size: var(--text-sm);
  max-height: 120px;
  line-height: 1.5;
  color: var(--text);
  padding: 4px 0;
}
.msg-input::placeholder { color: var(--text-faint); }
.emoji-btn { color: var(--text-faint); width: 30px; height: 30px; border-radius: var(--radius-md); }
.emoji-btn:hover { color: var(--primary); background: var(--surface-hover); }
.send-btn {
  width: 40px; height: 40px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:active { transform: scale(0.92); }
.file-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  flex-shrink: 0;
  max-width: 200px;
}
.file-preview-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview-remove { color: var(--text-faint); font-size: 14px; }

/* ── Emoji picker ────────────────────────────────── */
.emoji-picker {
  position: fixed; /* FIX5: fixed — позиция задаётся JS через style */
  width: 320px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.emoji-tabs {
  display: flex;
  overflow-x: auto;
  padding: var(--space-2) var(--space-2) 0;
  gap: 2px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}
.emoji-tabs::-webkit-scrollbar { height: 0; }
.emoji-tab-btn {
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background var(--transition);
}
.emoji-tab-btn:hover, .emoji-tab-btn.active { background: var(--surface-active); }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: var(--space-2);
  overflow-y: auto;
  max-height: 240px;
}
.emoji-grid::-webkit-scrollbar { width: 3px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); }
.emoji-item {
  font-size: 1.3rem;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  cursor: pointer;
}
.emoji-item:hover { background: var(--surface-hover); transform: scale(1.15); }

/* ── Modals ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-wide { max-width: 560px; }
.modal::-webkit-scrollbar { width: 4px; }
.modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.modal-header h3 { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.modal-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--space-4);
}
.modal-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: calc(var(--radius-md) - 2px);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--transition);
}
.modal-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.modal-close { color: var(--text-faint); font-size: 18px; width: 28px; height: 28px; }
.section-label { font-size: var(--text-xs); color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin: var(--space-3) 0 var(--space-2); }

/* ── User results ────────────────────────────────── */
.user-results { display: flex; flex-direction: column; gap: 2px; }
.user-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.user-result-item:hover { background: var(--surface-hover); }
.user-result-item.selected { background: rgba(91,103,248,0.12); }
.user-result-item .name { font-weight: 500; font-size: var(--text-sm); }
.user-result-item .uname { font-size: var(--text-xs); color: var(--text-faint); }
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(91,103,248,0.15);
  color: var(--primary);
  border-radius: var(--radius-full);
  padding: 3px 10px 3px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  margin: 2px;
}
.member-chip button { color: var(--primary); opacity: 0.7; font-size: 11px; }
.selected-members { display: flex; flex-wrap: wrap; gap: 4px; margin-top: var(--space-2); }

/* ── Chat info modal ─────────────────────────────── */
.chat-info-profile { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding-bottom: var(--space-4); border-bottom: 1px solid var(--divider); margin-bottom: var(--space-4); }
.chat-info-name { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.chat-info-username { font-size: var(--text-sm); color: var(--text-muted); }
.chat-info-bio { font-size: var(--text-sm); color: var(--text-muted); text-align: center; }
.chat-info-meta { font-size: var(--text-xs); color: var(--text-faint); text-align: center; }
.chat-info-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center; }
.chat-info-section { margin-bottom: var(--space-4); }
.chat-info-date { font-size: var(--text-sm); color: var(--text-muted); }
.status-online { color: var(--online); }
.status-offline { color: var(--text-faint); }
.chat-files-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: var(--space-2); }
.chat-file-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-md); cursor: zoom-in; }
.chat-file-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2); background: var(--surface-2); border-radius: var(--radius-md); font-size: var(--text-xs); }

/* ── Settings ────────────────────────────────────── */
.settings-body { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-section { background: var(--surface-2); border-radius: var(--radius-lg); padding: var(--space-4); }
.settings-section-title { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: var(--space-3); }
.setting-row { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-sm); padding: var(--space-2) 0; }
.setting-row span { flex-shrink: 0; color: var(--text-muted); }
.setting-row select {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  outline: none;
}
.toggle-group { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 2px; }
.toggle-btn { padding: 4px 12px; border-radius: calc(var(--radius-md) - 1px); font-size: var(--text-xs); font-weight: 500; color: var(--text-muted); transition: var(--transition); }
.toggle-btn.active { background: var(--primary); color: #fff; }
.wallpaper-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--space-2); }
.wallpaper-btn {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  overflow: hidden;
}
.wallpaper-btn:hover { border-color: var(--primary); transform: scale(1.05); }

/* ── Context menu ────────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 400;
  padding: var(--space-2);
  min-width: 160px;
  animation: ctxIn 0.12s ease;
}
@keyframes ctxIn { from { opacity: 0; transform: scale(0.95); } }
.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  color: var(--text);
  transition: background var(--transition);
}
.ctx-item:hover { background: var(--surface-hover); }

/* ── Lightbox ────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius-lg); object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  color: #fff;
  font-size: 24px;
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
}

/* ── Toast ───────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  z-index: 600;
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1), opacity 0.3s;
  opacity: 0;
  white-space: nowrap;
}
.toast.visible { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-error { border-color: #ef4444; color: #ef4444; }

/* ── Divider ─────────────────────────────────────── */
.divider { height: 1px; background: var(--divider); }

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 768px) {
  .back-btn { display: flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(0); transition: transform var(--transition); }
  .sidebar.hidden-mobile { transform: translateX(-100%); }
  .chat-main { position: fixed; inset: 0; transform: translateX(100%); transition: transform var(--transition); }
  .chat-main.visible-mobile { transform: translateX(0); }
  .welcome-pane { display: none; }
  .emoji-picker { width: 290px; right: 4px; }
}


/* ── FIX8: Отключить выделение текста везде кроме сообщений ──────────── */
* { user-select: none; }
.bubble p,
.bubble-emoji,
.bubble-image p,
.msg-input,
.search-input,
input[type="text"],
input[type="password"],
textarea,
.reply-preview-text,
.reply-preview-name,
.file-msg-name,
.chat-info-name,
.chat-info-username,
.chat-info-bio,
.profile-name,
.profile-username,
.profile-bio { user-select: text; }


/* ── FIX10: Закреплённые чаты ────────────────────────────────────────── */
.chat-item.pinned { background: var(--surface-2); }
.chat-item.pinned::after {
  content: "📌";
  font-size: 10px;
  position: absolute;
  top: 6px;
  right: 8px;
  opacity: 0.6;
}
.chat-item { position: relative; }

/* ── Message highlight (reply scroll) ───────────── */
@keyframes msgHighlight {
  0%, 100% { background: transparent; }
  40% { background: rgba(99, 102, 241, 0.18); }
}
.msg-highlight {
  animation: msgHighlight 1.5s ease;
  border-radius: var(--radius-lg);
}

/* ── Scrollbar global ────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
