#chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 75vh;
  min-height: 500px;
  background: #1a1d20;
  border: 1px solid #333;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

/* Верхняя панель настроек */
#chat-header {
  background: #121416;
  padding: 10px 15px;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.settings-dropdown {
  position: relative;
  display: inline-block;
}

#settings-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 30px;
  background: #2b3035;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 10px;
  min-width: 200px;
  z-index: 1001;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.mute-option {
  display: block;
  width: 100%;
  padding: 5px 10px;
  background: none;
  border: none;
  color: #eee;
  text-align: left;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 4px;
}

.mute-option:hover {
  background: #3d4246;
}
.mute-active {
  color: #ffc107 !important;
}

#auth-gate {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 19, 0.98);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column-reverse;
  background-image: linear-gradient(rgba(15, 17, 19, 0.9), rgba(15, 17, 19, 0.9)), url("https://www.transparenttextures.com/patterns/dark-matter.png");
}

.day-messages-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.msg-bubble {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #2b3035;
  color: #eee;
  min-width: 250px;
  max-width: 80%;
  align-self: flex-start;
  position: relative;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: background 0.2s;
  word-break: break-word;
}

.msg-bubble.own {
  align-self: flex-end;
  margin-left: auto;
  background: #a9ffd0;
  color: #0b2e13;
  border-bottom-right-radius: 4px;
}

.msg-bubble:not(.own) {
  border-bottom-left-radius: 4px;
  border-left: 3px solid #0dcaf0;
}

.msg-text {
  white-space: pre-wrap;
  display: block;
  line-height: 1.4;
}

.msg-info {
  font-size: 1.08rem;
  font-weight: bold;
  margin-bottom: 4px;
  opacity: 0.7;
  padding-right: 40px;
}

.msg-actions {
  position: absolute;
  top: 6px;
  right: 8px;
  display: none;
  gap: 5px;
  z-index: 10;
}

.msg-bubble:hover .msg-actions {
  display: flex;
}

.msg-btn {
  font-size: 0.7rem;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.msg-btn:hover {
  background: #0dcaf0;
  color: white;
}
.own .msg-btn:hover {
  background: #0b2e13;
  color: #a9ffd0;
}

.reply-quote {
  background: rgba(0, 0, 0, 0.15);
  border-left: 3px solid #0dcaf0;
  padding: 4px 10px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

#reply-preview {
  display: none;
  padding: 8px 15px;
  background: #212529;
  border-top: 1px solid #333;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

#chat-input-area {
  padding: 15px;
  background: #121416;
  border-top: 1px solid #333;
}

#chat-messages::-webkit-scrollbar {
  width: 5px;
}
#chat-messages::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 10px;
}

/* Контейнер аватарки в модалке */
.avatar-edit-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto;
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
}

/* Эффект при наведении */
.avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  color: white;
  font-size: 0.8rem;
}

.avatar-edit-container:hover .avatar-overlay {
  opacity: 1;
}

/* Скрытая панель инструментов */
#avatar-editor-controls {
  display: none; /* Скрыто по умолчанию */
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Сетка сообщений --- */
/* --- Сетка сообщений (не меняем, тут всё ок) --- */
.msg-media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 8px 0;
  border-radius: 12px;
  overflow: hidden;
  max-width: 400px;
}

.msg-img-link {
  display: block;
  flex: 1 1 calc(50% - 4px);
  height: 150px;
  position: relative;
  overflow: hidden;
}

.items-1 .msg-img-link {
  flex: 1 1 100%;
  height: auto;
  max-height: 350px;
}

.msg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-info {
  display: flex;
  align-items: center;
  gap: 8px; /* Отступ между элементами */
  margin-bottom: 4px;
}

.msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%; /* Круглый аватар */
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.msg-time {
  font-size: 0.75rem;
  color: #888;
}

/* --- ФИКС PHOTOSWIPE (Убираем растягивание и прыжки) --- */

/* 1. Скрываем "призраков" */
.pswp__img--placeholder {
  display: none !important;
}

/* 2. КРИТИЧНО: Сбрасываем CSS, который может растягивать картинку */
.pswp__img {
  width: auto; /* Никаких !important здесь! */
  height: auto; /* PhotoSwipe сам подставит нужные px в style */
  max-width: none;
  object-fit: contain;
}

/* 3. Гарантируем черный фон сразу */
.pswp__bg {
  background: #000 !important;
  opacity: 1 !important;
}

/* Настройки для многострочного поля ввода */
#msg-field {
  resize: none; /* Запрещаем пользователю тянуть за угол */
  overflow-y: hidden; /* Скрываем скролл, пока он не нужен */
  min-height: 38px;
  max-height: 150px; /* Максимальная высота, после которой появится прокрутка */
  line-height: 20px;
  padding: 8px 12px;
  transition: height 0.1s ease; /* Плавное изменение высоты */
  scrollbar-width: thin; /* Для Firefox */
}

/* Стилизация скролла внутри textarea для Chrome/Safari */
#msg-field::-webkit-scrollbar {
  width: 4px;
}
#msg-field::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 10px;
}

/* Фикс для Bootstrap: чтобы кнопки и textarea дружили при разной высоте */
.input-group > .btn {
  height: 38px; /* Фиксируем высоту кнопок */
  display: flex;
  align-items: center;
}

/* Контейнер для реакций */
.reactions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  padding-bottom: 2px;
}

/* Пузырек реакции */
.reaction-badge {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 2px 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

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

/* Подсветка своей реакции */
.reaction-badge.active {
  background: rgba(13, 202, 240, 0.15);
  border-color: rgba(13, 202, 240, 0.5);
}

.reaction-count {
  font-size: 0.75rem;
  font-weight: bold;
  color: #ccc;
}

.own .reaction-count {
  color: #0b2e13; /* Для темного текста на светлом фоне твоих сообщений */
}

/* Мини-аватарки в реакции */
.reaction-avatars {
  display: flex;
  align-items: center;
  margin-left: 2px;
}

.reaction-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #1a1d20;
  margin-left: -5px;
  object-fit: cover;
}

.reaction-avatar:first-child {
  margin-left: 0;
}

/* Базовый контейнер */
#reaction-picker-container {
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
  line-height: 0; /* Убирает лишние отступы внутри */
}

/* Адаптивность для мобильных устройств */
@media (max-width: 576px) {
  #reaction-picker-container {
    /* Игнорируем JS-координаты и ставим по центру */
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 90% !important;
    display: flex;
    justify-content: center;
  }

  #reaction-picker-container em-emoji-picker {
    width: 100% !important;
    max-width: 350px;
    height: 60vh !important; /* Делаем чуть ниже на мобилках */
  }
}

/* Затемнение фона при открытом пикере (опционально) */
.picker-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9998;
}

.link-preview {
  margin-top: 10px;
  border-left: 3px solid #0dcaf0;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px 8px 8px 4px;
  overflow: hidden;
  max-width: 400px;
  text-decoration: none !important;
  display: block;
  transition: background 0.2s;
}

.link-preview:hover {
  background: rgba(255, 255, 255, 0.08);
}

.lp-image {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.lp-content {
  padding: 8px 12px;
}

.lp-title {
  font-weight: bold;
  font-size: 0.9rem;
  color: #0dcaf0;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lp-desc {
  font-size: 0.8rem;
  color: #0751ff;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lp-site {
  font-size: 0.7rem;
  color: #777;
  margin-top: 4px;
  text-transform: uppercase;
}

.date-separator {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
  width: 100%;
  pointer-events: none; /* Чтобы не мешал кликам */
}

.date-badge {
  background: rgba(0, 0, 0, 0.25);
  color: #eee;
  padding: 4px 15px;
  border-radius: 15px;
  font-size: 0.85rem;
  font-weight: 500;
  backdrop-filter: blur(4px); /* Легкий эффект стекла */
  text-transform: lowercase;
}
