:root {
  --primary: #D32F2F;
  --primary-dark: #B71C1C;
  --accent: #FF5252;
  --bg: #F5F5F5;
  --surface: #FFFFFF;
  --text: #212121;
  --muted: #757575;
  --bubble-out: linear-gradient(135deg, #D32F2F, #E53935);
  --bubble-in: #FFFFFF;
  --border: #E0E0E0;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; border: none; background: none; }

input, textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus { border-color: var(--primary); }

/* ---------- AUTH ---------- */
.auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #FFFFFF 0%, #FFEBEE 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: 0 10px 40px rgba(211,47,47,.15);
}
.auth-logo {
  text-align: center;
  font-size: 34px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 20px;
  letter-spacing: 1px;
}
.auth-card h2 { font-size: 20px; margin-bottom: 16px; text-align: center; }
.auth-card input { margin-bottom: 12px; }
.btn {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
  transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.auth-switch {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}
.auth-switch a { color: var(--primary); cursor: pointer; font-weight: 600; }
.err {
  color: var(--primary);
  font-size: 13px;
  margin-bottom: 10px;
  text-align: center;
}

/* ---------- MAIN ---------- */
.main { display: flex; height: 100%; }
.sidebar {
  width: 360px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
}
.logo-mini { font-weight: 800; font-size: 20px; letter-spacing: .5px; }
.sidebar-header .spacer { flex: 1; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,.3); }

/* ---------- Профиль-кнопка с аватаром ---------- */
.profile-icon-btn {
  overflow: hidden;
  padding: 0;
}
.profile-icon-btn.has-avatar {
  background: none;
}
.profile-icon-btn.has-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.profile-icon-btn.has-avatar:hover {
  background: none;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

/* ---------- Полоса поиска по контактам ---------- */
.search-contacts-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  animation: slideDown .15s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.search-contacts-bar input {
  background: var(--bg);
  border: none;
  border-radius: 20px;
  padding: 9px 14px;
  flex: 1;
}
.search-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.search-close-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* ---------- CHAT LIST ---------- */
.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  position: relative;
}
.chat-item:hover { background: #FFF5F5; }
.chat-item.active { 
  background: #FFEBEE; 
  color: var(--text); 
}
.chat-item.active .chat-name {
  color: var(--text);
  font-weight: 700;
}
.chat-item.active .chat-preview {
  color: var(--muted);
}

.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.online::after {
  content: "";
  position: absolute; bottom: 0; right: 0;
  width: 12px; height: 12px;
  background: #4CAF50;
  border: 2px solid var(--surface);
  border-radius: 50%;
}

.saved-avatar {
  background: linear-gradient(135deg, #D32F2F, #E53935);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
}

.chat-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.chat-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-preview {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-width: 44px;
  padding-left: 4px;
}

.chat-menu-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chat-menu-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--primary);
}

.unread {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
  line-height: 16px;
  height: 16px;
}
.unread-empty {
  background: transparent;
  color: transparent;
  min-width: 18px;
  height: 16px;
  padding: 1px 7px;
}

.chat-time {
  font-size: 11px;
  color: var(--muted);
  line-height: 14px;
}

/* ---------- Контекстное меню чата ---------- */
.chat-menu {
  position: absolute;
  top: 44px;
  right: 12px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  padding: 4px 0;
  min-width: 170px;
  z-index: 20;
  overflow: hidden;
}
.chat-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  transition: background .1s;
}
.chat-menu-item:hover { background: #FFF5F5; }
.chat-menu-item.danger { color: var(--primary); }
.chat-menu-item.danger:hover { background: var(--primary); color: #fff; }

.empty-chat {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}
.empty-chat .big {
  font-size: 60px; color: var(--primary); opacity: .3; margin-bottom: 12px;
}

/* ---------- CONVERSATION ---------- */
.conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}
.conv-header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.conv-header .name { font-weight: 600; }
.conv-header .status { font-size: 12px; color: var(--muted); }
.back-btn {
  display: none;
  background: none; color: var(--primary); font-size: 20px; padding: 4px 8px;
}

.conv-peer {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  padding: 4px 8px 4px 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  border-radius: 8px;
  transition: background .15s;
  flex: 1;
  min-width: 0;
}
.conv-peer:hover { background: #FFF5F5; }
.conv-peer .name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-peer .status { font-size: 12px; color: var(--muted); }

/* ---------- MESSAGES ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 14px;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.35;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: #fff; border-bottom-right-radius: 4px; }
.msg .time {
  font-size: 11px;
  opacity: .7;
  margin-left: 8px;
  float: right;
  margin-top: 6px;
}
.msg .check { font-size: 12px; margin-left: 4px; }

/* ---------- Сетка фото в сообщении ---------- */
.msg-photos {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 320px;
}
.msg-photos.single {
  grid-template-columns: 1fr;
  max-width: 320px;
}
.msg-photos.single .msg-photo {
  max-height: 360px;
}
.msg-photos.two {
  grid-template-columns: 1fr 1fr;
  max-width: 320px;
}
.msg-photos.two .msg-photo {
  aspect-ratio: 1 / 1;
}
.msg-photos.three {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  max-width: 320px;
}
.msg-photos.three .msg-photo:first-child {
  grid-row: 1 / 3;
}
.msg-photos.three .msg-photo {
  aspect-ratio: 1 / 1;
}
.msg-photos.many {
  grid-template-columns: 1fr 1fr;
  max-width: 320px;
}
.msg-photos.many .msg-photo {
  aspect-ratio: 1 / 1;
}

.msg-photo {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
}
.msg-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .15s;
}
.msg-photo:hover img {
  transform: scale(1.02);
}
.msg-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background .15s;
  pointer-events: none;
}
.msg-photo:hover::after {
  background: rgba(0, 0, 0, 0.05);
}

.msg.deleted {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--muted) !important;
  font-style: italic;
  opacity: 0.85;
}
.msg.deleted i { font-style: italic; font-size: 13px; }
.msg.deleted .time { opacity: 0.6; }

.msg .edited {
  font-size: 10px;
  opacity: 0.65;
  font-style: italic;
  margin-left: 2px;
}

.msg-actions {
  position: absolute;
  top: -12px;
  right: 6px;
  display: none;
  gap: 2px;
  background: var(--surface);
  border-radius: 8px;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  z-index: 5;
}
.msg.out:hover .msg-actions { display: flex; }
.msg-actions button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.msg-actions .msg-edit:hover { background: #FFF5F5; color: var(--primary); }
.msg-actions .msg-del:hover { background: var(--primary); color: #fff; }

.msg-edit-wrap { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.msg-edit-photo-hint {
  font-size: 12px;
  opacity: 0.75;
  font-style: italic;
  margin-bottom: 4px;
}
.msg-edit-input {
  width: 100%;
  min-height: 60px;
  max-height: 200px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font: inherit;
  font-size: 14px;
  outline: none;
}
.msg-edit-input:focus { border-color: #fff; background: rgba(255, 255, 255, .25); }
.msg-edit-btns { display: flex; gap: 6px; justify-content: flex-end; }
.btn-mini {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  border: none;
}
.btn-mini.save { background: #fff; color: var(--primary); }
.btn-mini.save:hover { background: #FFEBEE; }
.btn-mini.cancel { background: rgba(255, 255, 255, .2); color: #fff; }
.btn-mini.cancel:hover { background: rgba(255, 255, 255, .35); }

.msg.in .msg-edit-input { border-color: var(--border); background: #fff; color: var(--text); }
.msg.in .msg-edit-input:focus { border-color: var(--primary); background: #fff; }
.msg.in .btn-mini.save { background: var(--primary); color: #fff; }
.msg.in .btn-mini.save:hover { background: var(--primary-dark); }
.msg.in .btn-mini.cancel { background: #eee; color: var(--text); }
.msg.in .btn-mini.cancel:hover { background: #ddd; }

.typing-bar {
  font-size: 12px; color: var(--primary);
  padding: 0 16px 6px; min-height: 18px;
}

/* ---------- LIGHTBOX ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.lightbox-img-wrap {
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-img-wrap img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  z-index: 2;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  z-index: 2;
  padding-bottom: 4px;
}
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.3);
}
.lightbox-nav.prev { left: 16px; }
.lightbox-nav.next { right: 16px; }
.lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 12px;
  border-radius: 12px;
  z-index: 2;
}

/* ---------- COMPOSER ---------- */
.composer {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}
.composer textarea {
  resize: none;
  border-radius: 20px;
  padding: 10px 14px;
  min-height: 42px; max-height: 120px;
  background: var(--bg);
  border: none;
}
.composer .send {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  flex-shrink: 0;
}
.composer .attach {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 20px;
  color: var(--primary);
  flex-shrink: 0;
}
.composer .emoji-btn {
  color: #FFB300; /* Желтоватый цвет для смайлика */
}

/* ---------- Превью нескольких фото в композере ---------- */
.photo-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.photo-preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .1);
  flex-shrink: 0;
}
.photo-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 2;
  transition: background .15s;
}
.photo-preview-remove:hover {
  background: var(--primary);
}

/* ---------- MODAL ---------- */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 22px;
  width: 100%; max-width: 420px;
  max-height: 80vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 14px; color: var(--primary); }
.modal .row {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.modal .row:hover { background: #FFF5F5; }

/* ---------- Избранное — кнопка в модалке "Новый чат" ---------- */
.saved-chat-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: #FFF5F5;
  cursor: pointer;
  transition: background .15s;
  text-align: left;
  margin-bottom: 14px;
}
.saved-chat-btn:hover {
  background: #FFEBEE;
}
.saved-chat-btn .saved-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.saved-chat-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.modal-divider {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 12px;
  position: relative;
}
.modal-divider::before,
.modal-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}
.modal-divider::before { left: 0; }
.modal-divider::after { right: 0; }

/* ---------- PROFILE ---------- */
.profile-modal .field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.profile-modal input,
.profile-modal textarea { margin-bottom: 4px; }
.profile-modal input:disabled {
  background: #F0F0F0;
  color: var(--muted);
  cursor: not-allowed;
}
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(211, 47, 47, .25);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-btn {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  padding: 4px 8px;
  background: none;
  border: none;
  cursor: pointer;
}
.profile-avatar-btn:hover { text-decoration: underline; }

/* ---------- Кликабельный аватар (лайтбокс) ---------- */
.clickable-avatar {
  cursor: zoom-in;
  transition: box-shadow .15s, transform .15s;
}
.clickable-avatar:hover {
  box-shadow: 0 4px 20px rgba(211, 47, 47, .45), 0 0 0 3px rgba(211, 47, 47, .2);
  transform: scale(1.02);
}

/* ---------- История аватаров (сетка под большим) ---------- */
.avatar-history {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.avatar-history-title {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}
.avatar-history-item {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  cursor: zoom-in;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
  transition: transform .15s, box-shadow .15s;
  flex-shrink: 0;
}
.avatar-history-item:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(211, 47, 47, .4);
}
.avatar-history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- CONTACT PROFILE ---------- */
.contact-modal { text-align: center; max-width: 360px; }
.contact-avatar-wrap { display: flex; justify-content: center; margin-bottom: 10px; }
.contact-modal .profile-avatar { width: 112px; height: 112px; font-size: 42px; }
.contact-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.contact-username {
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 8px;
}
.contact-status {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.contact-bio {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  margin-bottom: 4px;
  white-space: pre-wrap;
}

/* ---------- EMOJI PANEL ---------- */
.emoji-panel {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  animation: slideUp .15s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.emoji-panel-header {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
  padding-left: 4px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
}
.emoji-item {
  width: 100%;
  aspect-ratio: 1 / 1;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s, transform .1s;
  background: none;
  border: none;
  padding: 0;
}
.emoji-item:hover {
  background: #FFF5F5;
  transform: scale(1.15);
}
.emoji-item:active {
  transform: scale(0.95);
}

/* ---------- MOBILE ---------- */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .main.chat-open .sidebar { display: none; }
  .main:not(.chat-open) .conv { display: none; }
  .back-btn { display: inline-block; }
  .msg { max-width: 85%; }

  .chat-menu-btn {
    width: 28px;
    height: 28px;
    font-size: 20px;
  }
  .chat-right { min-width: 48px; }
  .chat-menu {
    top: auto;
    bottom: -8px;
    right: 4px;
    min-width: 160px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .logo-mini { font-size: 18px; }
  .sidebar-header { gap: 6px; padding: 12px; }

  .search-contacts-bar {
    padding: 8px 10px;
  }
  .search-contacts-bar input {
    padding: 8px 12px;
    font-size: 14px;
  }

  .msg-edit-wrap { min-width: 180px; }
  .msg-edit-input { font-size: 15px; min-height: 50px; }
  .conv-peer:hover { background: none; }
  .contact-modal .profile-avatar { width: 96px; height: 96px; font-size: 36px; }
  .contact-name { font-size: 18px; }

  /* Сетка фото — компактнее на мобильном */
  .msg-photos,
  .msg-photos.single,
  .msg-photos.two,
  .msg-photos.three,
  .msg-photos.many {
    max-width: 260px;
  }
  .msg-photos.single .msg-photo {
    max-height: 280px;
  }

  /* Лайтбокс — компактнее */
  .lightbox {
    padding: 10px;
  }
  .lightbox-close {
    width: 36px;
    height: 36px;
    font-size: 18px;
    top: 10px;
    right: 10px;
  }
  .lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  .lightbox-nav.prev { left: 8px; }
  .lightbox-nav.next { right: 8px; }
  .lightbox-counter {
    bottom: 12px;
    font-size: 12px;
  }

  /* Превью в композере — меньше */
  .photo-preview {
    gap: 6px;
    padding: 6px 10px;
  }
  .photo-preview-item {
    width: 60px;
    height: 60px;
  }

  /* История аватаров — компактнее */
  .avatar-history-item {
    width: 42px;
    height: 42px;
  }

  /* Панель эмодзи на мобильном */
  .emoji-panel {
    max-height: 180px;
  }
  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  }
  .emoji-item {
    font-size: 20px;
  }
}
/* ---------- ТЕМА ХАКЕР ---------- */
body.theme-hacker {
  --primary: #00ff00;
  --primary-dark: #00aa00;
  --bg: #000000;
  --surface: #051005;
  --text: #00ff00;
  --muted: #008800;
  --bubble-out: linear-gradient(135deg, #003300, #005500);
  --bubble-in: #0a0a0a;
  --border: #00ff00;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 2px #00ff00;
}
body.theme-hacker .sidebar-header, body.theme-hacker .conv-header {
  background: #001100;
  border-bottom: 1px solid #00ff00;
}
body.theme-hacker input, body.theme-hacker textarea {
  background: #000; border: 1px solid #00ff00; color: #00ff00;
}
body.theme-hacker .msg.in { border: 1px solid #005500; }
body.theme-hacker .msg.out { border: 1px solid #00ff00; }
body.theme-hacker .chat-item:hover { background: #003300; }
body.theme-hacker .avatar { background: #002200; border: 1px solid #00ff00; }
/* ---------- ФИКС: Счётчик непрочитанных в теме Хакер ---------- */
body.theme-hacker .unread {
  color: #000000 !important;
  font-weight: 700;
  text-shadow: none; /* Убираем зелёное свечение вокруг цифры */
}
/* ---------- РАЗДЕЛИТЕЛЬ ПО ДАТЕ ---------- */
.date-divider {
  display: flex;
  justify-content: center;
  margin: 12px 0 6px;
  position: relative;
}
.date-divider span {
  background: rgba(211, 47, 47, 0.1);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 12px;
  border: 1px solid rgba(211, 47, 47, 0.2);
  text-transform: capitalize;
}
/* Тёмная тема «Хакер» */
body.theme-hacker .date-divider span {
  background: rgba(0, 255, 0, 0.08);
  color: #00ff00;
  border-color: rgba(0, 255, 0, 0.4);
  text-shadow: 0 0 4px #00ff00;
}
body.theme-hacker .chat-item.active {
  background: #003300;
  border-left: 3px solid #00ff00;
}
body.theme-hacker .chat-item.active .chat-name { color: #00ff00; }
body.theme-hacker .chat-item.active .chat-preview { color: #008800; }