/* ============================================================
   СООБЩЕНИЯ
   ============================================================ */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg3);
  min-width: 0;
}

.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 16px 0 8px;
}

.date-separator::before,
.date-separator::after {
  display: none;
}

.date-separator span {
  display: inline-block;
  padding: 3px 12px;
  background: var(--bg3);
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--txt3);
  white-space: nowrap;
}

.msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 68%;
}

.msg-group.incoming { align-self: flex-start; align-items: flex-start; max-width: 68%; }
.msg-group.outgoing { align-self: flex-end; align-items: flex-end; max-width: 68%; }

.bubble {
  padding: 8px 13px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  border-radius: 16px;
}

.bubble.incoming {
  background: var(--bg);
  color: var(--msg-in-txt);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.outgoing {
  background: var(--msg-out);
  color: var(--msg-out-txt);
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 3px;
}

.msg-group.outgoing .bubble-meta { justify-content: flex-end; }

.bubble-time {
  font-size: 10.5px;
  color: var(--txt3);
}

.bubble-check {
  font-size: 12px;
  color: var(--txt3);
}
.bubble-check.read { color: var(--msg-out-check); }

/* Reply внутри пузыря */
.reply-preview-bubble {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  padding: 5px 10px;
  max-width: 100%;
  margin-bottom: -8px;
  padding-bottom: 12px;
}

.rpb-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1px;
}

.rpb-text {
  font-size: 12px;
  color: var(--txt2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   ЗОНА ВВОДА
   ============================================================ */
.input-zone {
  padding: 10px 16px 12px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Reply preview над полем ввода */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--accent-light);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  margin-bottom: -4px;
  border-left: 3px solid var(--accent);
}

.rp-bar {
  width: 3px;
  flex-shrink: 0;
  /* уже через border-left на .reply-preview */
}

.rp-content { flex: 1; min-width: 0; }

.rp-sender {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1px;
}

.rp-text {
  font-size: 12px;
  color: var(--txt2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-close {
  border: none;
  background: none;
  color: var(--txt3);
  font-size: 14px;
  padding: 2px 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--ease);
}
.rp-close:hover { color: var(--txt); }

/* Основная обёртка поля */
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg3);
  border: 1.5px solid var(--border2);
  border-radius: var(--r-md);
  padding: 7px 7px 7px 14px;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.message-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
  color: var(--txt);
  resize: none;
  height: 28px;
  max-height: 120px;
  line-height: 1.5;
  padding: 2px 0;
  overflow-y: auto;
}
.message-input::placeholder { color: var(--txt3); }

/* Кнопки справа */
.input-actions {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.input-act-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--txt2);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease);
}
.input-act-btn:hover { background: var(--bg4); color: var(--txt); }

.send-btn {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: none;
  border-radius: var(--r-sm);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease);
  margin-left: 2px;
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.06); }
.send-btn:active { transform: scale(0.96); }

/* ============================================================
   ПРАВАЯ ПАНЕЛЬ
   ============================================================ */
.right-panel {
  width: var(--rp-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.rp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.rp-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.rp-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.participant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  transition: background var(--ease);
}
.participant-item:hover { background: var(--bg3); }

.role-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
}
.role-badge.creator {
  background: var(--accent-light2);
  color: var(--accent);
}
.role-badge.admin {
  background: rgba(16,185,129,0.12);
  color: var(--success);
}

/* ============================================================
   МОДАЛЬНОЕ ОКНО
   ============================================================ */
#modal-container {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  animation: fadeIn 0.15s ease;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--txt3);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--ease);
}
.modal-close:hover { background: var(--bg3); color: var(--txt); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   УВЕДОМЛЕНИЯ
   ============================================================ */
.notifications-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 900;
  pointer-events: none;
}

.notification {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  color: var(--txt);
  pointer-events: all;
  animation: slideRight 0.2s ease;
  max-width: 300px;
}

.notification.success { border-left: 3px solid var(--success); }
.notification.error   { border-left: 3px solid var(--danger); }
.notification.warning { border-left: 3px solid var(--warning); }
.notification.info    { border-left: 3px solid var(--accent); }

/* ============================================================
   ОВЕРЛЕЙ
   ============================================================ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 50;
}
.overlay.active { display: block; }

/* ============================================================
   ИКОНКИ (svg-inline fallback для auth)
   ============================================================ */
.icon-moon::before { content: "☾"; font-style: normal; }
.icon-sun::before  { content: "☀"; font-style: normal; }
.icon-eye::before  { content: "👁"; font-style: normal; font-size: 13px; }

/* ============================================================
   АНИМАЦИИ
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes slideRight {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

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

.bubble { animation: msgIn 0.2s ease; }

/* ============================================================
   СОСТОЯНИЯ ЗАГРУЗКИ
   ============================================================ */
.loading-state {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--txt2);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ============================================================
   ГРУППОВОЙ ЧАТ — аватары и имена отправителей
   ============================================================ */

/* Строка с аватаром + тело сообщения */
.group-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* Маленький аватар отправителя */
.msg-sender-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px; /* выравнивание по нижнему краю пузыря */
}

/* Колонка: имя + пузырь + время */
.group-msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

/* Имя отправителя над пузырём */
.msg-sender-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent);
  padding: 0 2px;
  white-space: nowrap;
}

/* Разные цвета имён участников */
.group-msg-row:nth-child(3n+1) .msg-sender-name { color: #3b82f6; }
.group-msg-row:nth-child(3n+2) .msg-sender-name { color: #ec4899; }
.group-msg-row:nth-child(3n+3) .msg-sender-name { color: #8b5cf6; }

/* msg-group в группе — убираем левый отступ (аватар его даёт) */
.msg-group.group-msg {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 72%;
}

/* Входящий пузырь в группе чуть светлее */
.group-msg-body .bubble.incoming {
  background: var(--bg);
}

/* reply-preview-bubble внутри group-msg-body */
.group-msg-body .reply-preview-bubble {
  max-width: 100%;
}

/* Аватар чата (квадратный) в шапке */
.chat-header-avatar.square {
  border-radius: 10px;
}


/* ============================================================
   TYPING ИНДИКАТОР
   ============================================================ */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-width: 48px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--txt3);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ============================================================
   ФАЙЛОВЫЕ ПУЗЫРИ
   ============================================================ */
.file-bubble {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}

.msg-image {
  max-width: 280px;
  max-height: 220px;
  border-radius: var(--r-sm);
  object-fit: cover;
  cursor: pointer;
  display: block;
  transition: opacity var(--ease);
}
.msg-image:hover { opacity: 0.9; }

.msg-audio {
  width: 100%;
  min-width: 220px;
  max-width: 320px;
  height: 36px;
  border-radius: var(--r-sm);
}

.file-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.file-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.file-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--txt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.file-size {
  font-size: 11.5px;
  color: var(--txt3);
}

.file-download {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.file-download:hover { text-decoration: underline; }

/* ============================================================
   ПУСТОЕ СОСТОЯНИЕ В ЧАТЕ
   ============================================================ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--txt3);
  user-select: none;
}

.empty-state-icon { font-size: 40px; }

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--txt2);
}

.empty-state p {
  font-size: 13.5px;
  color: var(--txt3);
  max-width: 260px;
  line-height: 1.6;
}

/* ── Центрирование контента на широких экранах ───────────── */
@media (min-width: 1280px) {
  .messages-container {
    padding: 16px calc(50% - 380px);
  }

  .input-zone {
    padding: 10px calc(50% - 380px) 12px;
  }

  .chat-header {
    padding: 0 calc(50% - 380px);
  }
}

@media (min-width: 1600px) {
  .messages-container {
    padding: 16px calc(50% - 420px);
  }

  .input-zone {
    padding: 10px calc(50% - 420px) 12px;
  }

  .chat-header {
    padding: 0 calc(50% - 420px);
  }
}
