/* ── CHAT LAYOUT ── */
#chat {
  display: none;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 680px;
  height: 100dvh;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  transition: max-width 0.3s ease;
}

#chat:not(.video-active) { flex-direction: column !important; }
#chat:not(.video-active) .chat-side { display: none !important; }
#chat:not(.video-active) .text-side {
  display: flex; flex-direction: column; width: 100%; height: 100%; flex: 1; min-height: 0;
}

#chat.video-active { max-width: 1100px; flex-direction: row; }
#chat.video-active .chat-side {
  display: flex; flex-direction: column; width: 50%; min-width: 0; border-right: 1px solid var(--border);
}
#chat.video-active .text-side {
  display: flex; flex-direction: column; width: 50%; min-width: 0; height: 100%;
}

.connection-banner {
  display: none; text-align: center; padding: 0.5rem;
  background: rgba(255,106,176,0.15); border-bottom: 1px solid rgba(255,106,176,0.3);
  font-size: 0.78rem; color: var(--accent2);
}
.connection-banner.show { display: block; }

/* Header */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--header-bg); backdrop-filter: blur(10px); gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-header-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.chat-meta { min-width: 0; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}

.chat-name { font-family: 'Syne', sans-serif; font-weight: 600; font-size: 0.95rem; }

.chat-status { font-size: 0.72rem; color: #4ade80; }
.chat-status.typing { color: var(--accent); }
.chat-status.disconnected { color: var(--accent2); }

.chat-header-right { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

.header-icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 50%; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 0.85rem; transition: all 0.2s;
}
.header-icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.header-icon-btn.muted { color: var(--accent2); border-color: var(--accent2); }

.next-btn {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 100px; padding: 0.35rem 0.8rem; font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s; font-family: 'DM Sans', sans-serif; white-space: nowrap;
}
.next-btn:hover { border-color: var(--accent2); color: var(--accent2); }

/* Info bar */
.chat-info-bar {
  display: flex; align-items: center; justify-content: center; gap: 1.5rem;
  padding: 0.4rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.72rem; color: var(--muted); background: var(--bg);
}

.info-item { display: flex; align-items: center; gap: 0.3rem; }

.common-tags { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: center; }
.common-tag {
  background: rgba(124,106,255,0.15); color: var(--accent);
  padding: 0.1rem 0.5rem; border-radius: 100px; font-size: 0.65rem;
}

/* Messages */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.35rem; scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-wrapper { display: flex; flex-direction: column; max-width: 75%; animation: msgIn 0.2s ease; }
.msg-wrapper.self { align-self: flex-end; align-items: flex-end; }
.msg-wrapper.other { align-self: flex-start; align-items: flex-start; }

.msg {
  padding: 0.7rem 1rem; border-radius: var(--radius); font-size: 0.95rem;
  line-height: 1.5; word-break: break-word; position: relative; cursor: default;
}

.msg-wrapper.self .msg {
  background: var(--msg-self); border: 1px solid rgba(124,106,255,0.2);
  border-bottom-right-radius: 4px; color: var(--text);
}
.msg-wrapper.other .msg {
  background: var(--msg-other); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; color: var(--text);
}

.msg-wrapper .msg.deleted {
  opacity: 0.4; font-style: italic;
}

.msg-footer { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.15rem; padding: 0 0.25rem; }
.msg-time { font-size: 0.62rem; color: var(--muted); }

.msg-actions { display: flex; gap: 0.3rem; }
.msg-action-btn {
  background: none; border: none; font-size: 0.65rem; color: var(--muted);
  cursor: pointer; padding: 0; transition: color 0.15s;
}
.msg-action-btn:hover { color: var(--accent2); }

.msg-reactions { display: flex; gap: 0.2rem; }
.msg-reaction {
  font-size: 0.7rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 100px; padding: 0.05rem 0.35rem; cursor: default; animation: msgIn 0.15s ease;
}

/* Reaction picker */
.reaction-picker {
  display: none; position: absolute; bottom: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.3rem; gap: 0.15rem; z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.msg-wrapper.self .reaction-picker { right: 0; }
.msg-wrapper.other .reaction-picker { left: 0; }
.reaction-picker.show { display: flex; }

.reaction-btn {
  background: none; border: none; font-size: 1.1rem; cursor: pointer;
  padding: 0.2rem 0.3rem; border-radius: 8px; transition: background 0.15s;
}
.reaction-btn:hover { background: var(--border); }

.system-msg {
  text-align: center; color: var(--muted); font-size: 0.78rem;
  padding: 0.5rem; font-style: italic;
}

.typing-indicator {
  display: none; align-self: flex-start;
  background: var(--msg-other); border: 1px solid var(--border);
  border-radius: var(--radius); border-bottom-left-radius: 4px;
  padding: 0.7rem 1rem; gap: 4px; align-items: center;
}
.typing-indicator.show { display: flex; }

.typing-dot {
  width: 6px; height: 6px; background: var(--muted);
  border-radius: 50%; animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.input-area {
  padding: 0.6rem 1rem; border-top: 1px solid var(--border);
  display: flex; gap: 0.5rem; align-items: center;
  background: var(--header-bg); backdrop-filter: blur(10px);
}

.emoji-toggle {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; padding: 0.2rem; transition: transform 0.15s; flex-shrink: 0;
}
.emoji-toggle:hover { transform: scale(1.15); }

.emoji-panel {
  display: none; padding: 0.5rem; border-top: 1px solid var(--border);
  background: var(--surface); flex-wrap: wrap; gap: 0.25rem;
  justify-content: center; max-height: 140px; overflow-y: auto;
}
.emoji-panel.show { display: flex; }

.emoji-item {
  background: none; border: none; font-size: 1.3rem; cursor: pointer;
  padding: 0.3rem; border-radius: 8px; transition: background 0.15s;
}
.emoji-item:hover { background: var(--border); }

#msg-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 100px; padding: 0.75rem 1.2rem; color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 0.95rem;
  outline: none; transition: border-color 0.2s; resize: none; min-width: 0;
}
#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--muted); }
#msg-input:disabled { opacity: 0.5; cursor: not-allowed; }

.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent);
  border: none; color: #fff; font-size: 1.1rem; cursor: pointer;
  transition: all 0.2s; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.send-btn:hover { background: #9b8dff; transform: scale(1.05); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; transform: none; }

/* Footer */
.chat-footer {
  display: flex; align-items: center; justify-content: center;
  gap: 0.5rem; padding: 0.6rem 1rem;
  background: var(--bg); border-top: 1px solid var(--border);
}
.footer-brand {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 0.8rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.footer-text { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.05em; }

/* Music player bar */
.music-bar {
  display: none; align-items: center; gap: 0.5rem;
  padding: 0.4rem 1rem; border-top: 1px solid var(--border);
  background: rgba(124,106,255,0.08); font-size: 0.75rem;
}
.music-bar.show { display: flex; }
.music-bar .music-title { flex: 1; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.music-bar .music-btn {
  background: none; border: none; font-size: 1rem; cursor: pointer; padding: 0.1rem 0.3rem;
}

@media (max-width: 680px) {
  #chat { border: none; }

  .chat-header {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .chat-header-right {
    width: 100%;
    justify-content: flex-end;
    gap: 0.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.4rem;
    margin-top: 0.2rem;
  }

  .header-icon-btn {
    width: 28px; height: 28px; font-size: 0.75rem;
  }

  .next-btn {
    padding: 0.25rem 0.6rem; font-size: 0.7rem;
  }
}

@media (max-width: 900px) {
  #chat.video-active { flex-direction: column !important; max-width: 680px; }
  #chat.video-active .chat-side { width: 100% !important; height: 45%; border-right: none !important; border-bottom: 1px solid var(--border); }
  #chat.video-active .text-side { width: 100% !important; height: 55%; }
}
