/* ═══════════════════════════════════════════════════════════
   ECLYSS WEB — CHAT UI
   ═══════════════════════════════════════════════════════════ */

/* ── Chat container ──────────────────────────────────────── */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}

/* ── Chat topbar ─────────────────────────────────────────── */
.chat__topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 0 var(--sp-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: var(--z-sticky);
}

.chat__topbar-back {
  display: none;
  color: var(--text-secondary);
  font-size: var(--text-xl);
  cursor: pointer;
}

.chat__topbar-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  cursor: pointer;
  border-radius: var(--radius-lg);
  padding: 6px;
  margin: -6px;
  transition: background var(--transition-fast);
}
.chat__topbar-info:hover { background: var(--bg-hover); }

.chat__topbar-details { overflow: hidden; }

.chat__topbar-name {
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__topbar-status {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 1px;
}

.chat__topbar-status--online { color: var(--success); font-weight: 500; }

.chat__topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Messages area ───────────────────────────────────────── */
.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

/* Scroll to bottom button */
.scroll-to-bottom {
  position: absolute;
  bottom: calc(var(--chat-input-height) + 16px);
  right: var(--sp-lg);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: var(--z-sticky);
}
.scroll-to-bottom.visible { opacity: 1; transform: translateY(0); }

/* Date separator */
.msg-date-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  margin: var(--sp-md) 0 var(--sp-sm);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: 600;
}

.msg-date-sep::before,
.msg-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.msg-date-sep__label {
  padding: 3px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

/* ── Message bubble ──────────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
  padding: 1px 0;
  animation: messageIn 0.2s ease both;
}

.msg-row--out {
  flex-direction: row-reverse;
}

/* Avatar space for group chats */
.msg-row__avatar { flex-shrink: 0; }
.msg-row--consecutive .msg-row__avatar { visibility: hidden; }

.msg-row__content {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  min-width: 60px;
}

.msg-row--out .msg-row__content { align-items: flex-end; }

/* Sender name (groups) */
.msg-row__sender {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent-glow);
  margin-bottom: 3px;
  margin-left: 2px;
}

/* Bubble */
.msg-bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  word-break: break-word;
  line-height: 1.5;
  font-size: var(--text-md);
  color: var(--text-primary);
  cursor: default;
  transition: background var(--transition-fast);
}

.msg-bubble:hover { background: var(--bg-card); }

/* Outgoing */
.msg-row--out .msg-bubble {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  border-bottom-right-radius: var(--radius-sm);
}

.msg-row--out .msg-bubble:hover {
  background: rgba(124,58,237,0.18);
}

/* Incoming */
.msg-row--in .msg-bubble {
  border-bottom-left-radius: var(--radius-sm);
}

/* Consecutive messages */
.msg-row--consecutive .msg-bubble { border-radius: var(--radius-md); }
.msg-row--out.msg-row--consecutive .msg-bubble { border-bottom-right-radius: var(--radius-sm); }
.msg-row--in.msg-row--consecutive  .msg-bubble { border-bottom-left-radius: var(--radius-sm); }

/* Deleted message */
.msg-bubble--deleted {
  background: transparent !important;
  border-style: dashed;
  color: var(--text-tertiary);
  font-style: italic;
  font-size: var(--text-sm);
}

/* Edited marker */
.msg-bubble__edited {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-left: 6px;
}

/* Message time + status */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.msg-row--out .msg-meta { flex-direction: row-reverse; }

.msg-status { font-size: 13px; }
.msg-status--sent     { color: var(--text-tertiary); }
.msg-status--delivered { color: var(--text-secondary); }
.msg-status--read      { color: var(--accent-glow); }

/* Reply preview in bubble */
.msg-reply {
  background: rgba(255,255,255,0.06);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 7px;
  font-size: var(--text-xs);
  cursor: pointer;
}

.msg-reply__author { font-weight: 600; color: var(--accent-glow); margin-bottom: 2px; }
.msg-reply__text   { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }

/* Forwarded label */
.msg-forwarded {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-style: italic;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Media messages ──────────────────────────────────────── */
.msg-media {
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 280px;
  cursor: pointer;
  position: relative;
}

.msg-media img {
  width: 100%;
  display: block;
  transition: filter var(--transition-fast);
}

.msg-media:hover img { filter: brightness(0.9); }

.msg-media__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.msg-media:hover .msg-media__overlay { opacity: 1; }

.msg-media__play {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

/* Audio message (voice note) */
.msg-audio {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px 4px;
  min-width: 220px;
}

.msg-audio__play {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.msg-audio__play:hover { background: var(--accent-glow); }

.msg-audio__waveform {
  flex: 1;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

.msg-audio__bar {
  width: 3px;
  border-radius: var(--radius-full);
  background: var(--border-medium);
  transition: background var(--transition-fast);
}

.msg-audio__bar--played { background: var(--accent-glow); }

.msg-audio__time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 500;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Document message */
.msg-document {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px 4px;
  min-width: 200px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.msg-document:hover .msg-document__icon { background: var(--accent); }

.msg-document__icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.msg-document__info { overflow: hidden; }
.msg-document__name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.msg-document__size { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Video note (круглое видео) */
.msg-video-note {
  width: 160px; height: 160px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  border: 2px solid var(--border-default);
}

.msg-video-note video { width: 100%; height: 100%; object-fit: cover; }

/* ── Chat input ──────────────────────────────────────────── */
.chat__input-area {
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  padding: var(--sp-sm) var(--sp-md);
}

/* Reply preview */
.chat__reply-preview {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent);
  margin-bottom: var(--sp-sm);
  animation: fadeInUp 0.15s ease;
}

.chat__reply-preview-info { flex: 1; overflow: hidden; }
.chat__reply-preview-author { font-size: var(--text-xs); font-weight: 600; color: var(--accent-glow); }
.chat__reply-preview-text   { font-size: var(--text-xs); color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__reply-preview-close  { color: var(--text-tertiary); cursor: pointer; font-size: 14px; }
.chat__reply-preview-close:hover { color: var(--text-primary); }

/* Input row */
.chat__input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
}

.chat__input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  gap: var(--sp-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat__input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.10);
}

.chat__input-attach {
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
  transition: color var(--transition-fast);
  padding: 2px;
  margin-bottom: 2px;
}
.chat__input-attach:hover { color: var(--accent-glow); }

.chat__input-text {
  flex: 1;
  background: none;
  outline: none;
  resize: none;
  font-size: var(--text-md);
  color: var(--text-primary);
  caret-color: var(--accent-glow);
  max-height: 140px;
  min-height: 24px;
  line-height: 1.5;
  overflow-y: auto;
  padding: 0;
}
.chat__input-text::placeholder { color: var(--text-tertiary); }

.chat__input-emoji {
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
  padding: 2px;
  margin-bottom: 2px;
  transition: color var(--transition-fast);
}
.chat__input-emoji:hover { color: var(--accent-glow); }

.chat__send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--gradient-h);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow-purple);
  transition: transform var(--transition-fast), filter var(--transition-fast);
  border: none;
}

.chat__send-btn:hover  { transform: scale(1.08); filter: brightness(1.1); }
.chat__send-btn:active { transform: scale(0.95); }
.chat__send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* Voice note record button */
.chat__record-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.chat__record-btn:hover { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.chat__record-btn.recording {
  background: var(--error);
  border-color: var(--error);
  color: white;
  animation: glowPulse 1.2s ease infinite;
}

/* Attach menu */
.attach-menu {
  position: absolute;
  bottom: calc(var(--chat-input-height) + 8px);
  left: var(--sp-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--sp-sm);
  display: flex;
  gap: var(--sp-sm);
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.2s ease;
  z-index: var(--z-sticky);
}

.attach-menu__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.attach-menu__item:hover { background: var(--bg-hover); }

.attach-menu__icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.attach-menu__label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── Typing indicator row ────────────────────────────────── */
.chat__typing {
  padding: 2px var(--sp-md) var(--sp-sm);
  min-height: 28px;
}

.chat__typing-text {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
  animation: fadeIn 0.2s ease;
}

/* ── Reactions ───────────────────────────────────────────── */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.msg-reaction {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.msg-reaction:hover { background: var(--bg-elevated); border-color: var(--border-default); }
.msg-reaction--mine { border-color: var(--accent-border); background: var(--accent-soft); }
.msg-reaction__count { font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); }

/* ── System message ──────────────────────────────────────── */
.msg-system {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  padding: var(--sp-xs) var(--sp-md);
  font-style: italic;
}

/* ── Media query chat mobile ─────────────────────────────── */
@media (max-width: 750px) {
  .chat__topbar-back { display: flex; }
  .msg-row__content { max-width: 80%; }
  .msg-media { max-width: 220px; }
}
