/* public/css/messages.css — Messaging interface styles.
   Dark theme, cyan (#00F2EA) for own messages, dark gray for inbound.
   Coral (#FF4D6D) for unread badges. Amber for typing indicator. */

/* ── Layout ─────────────────────────────────────────────────────────────────── */

.messages-layout {
  display: flex;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

/* ── Sidebar (Conversation List) ─────────────────────────────────────────────── */

.messages-sidebar {
  width: 340px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  height: 100vh;
}

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

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -0.02em;
}

.new-msg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--cyan);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.new-msg-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 20px rgba(0, 242, 234, 0.35);
}

.conversation-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.conversation-search input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--white);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.conversation-search input::placeholder { color: var(--text-muted); }
.conversation-search input:focus { border-color: var(--cyan); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(0, 242, 234, 0.06); }

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  border: 1.5px solid var(--border);
}

.conv-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
}

.conv-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.conv-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conv-preview {
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-preview.has-unread {
  color: var(--white);
  font-weight: 600;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: var(--coral);
  color: white;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

/* Empty state */
.sidebar-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}

.sidebar-empty svg { width: 48px; height: 48px; margin-bottom: 16px; color: var(--text-muted); }
.sidebar-empty h3 { font-size: 0.95rem; color: var(--white); margin-bottom: 8px; }
.sidebar-empty p { font-size: 0.825rem; color: var(--text); line-height: 1.5; }

/* ── Chat Area ──────────────────────────────────────────────────────────────── */

.messages-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 70px;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-header-info h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--white);
}

.chat-header-info span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Messages Thread ─────────────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Message bubbles */
.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 72%;
}

.msg-bubble-wrap.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-bubble-wrap.other {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  border: 1px solid var(--border);
}

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

.msg-content { max-width: 100%; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.msg-bubble.own {
  background: var(--cyan);
  color: #050507;
  border-bottom-right-radius: 4px;
}

.msg-bubble.other {
  background: #1e1e26;
  color: var(--white);
  border-bottom-left-radius: 4px;
}

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

.msg-meta.own { justify-content: flex-end; }

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.msg-sender {
  font-size: 0.7rem;
  color: var(--text);
  font-weight: 600;
}

/* Attachment pills */
.msg-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--white);
  text-decoration: none;
  transition: background 0.15s;
}

.msg-attachment:hover { background: rgba(0,0,0,0.4); }

.msg-attachment svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Typing Indicator ────────────────────────────────────────────────────── */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 24px 8px;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FFB020;
  animation: typing-bounce 1.2s infinite;
}

.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(-4px); opacity: 1; }
}

.typing-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Message Input ────────────────────────────────────────────────────────── */

.chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  color: var(--white);
  font-size: 0.9rem;
  font-family: var(--ff-body);
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
  max-height: 160px;
  overflow-y: auto;
}

.chat-textarea::placeholder { color: var(--text-muted); }
.chat-textarea:focus { border-color: var(--cyan); }

.chat-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.send-btn {
  width: 44px;
  height: 44px;
  background: var(--cyan);
  color: var(--bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}

.send-btn:hover { transform: scale(1.08); box-shadow: 0 0 16px rgba(0,242,234,0.4); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn svg { width: 18px; height: 18px; }

/* ── No Conversation Selected ────────────────────────────────────────────── */

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
}

.chat-empty svg { width: 64px; height: 64px; color: var(--text-muted); margin-bottom: 20px; }
.chat-empty h3 { font-size: 1.1rem; color: var(--white); margin-bottom: 10px; }
.chat-empty p { font-size: 0.875rem; color: var(--text); line-height: 1.6; max-width: 360px; }

/* ── New Conversation Modal ─────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.new-conv-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  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: 1rem; font-weight: 800; color: var(--white); }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--bg-2); }

.modal-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-search input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--white);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.modal-search input::placeholder { color: var(--text-muted); }
.modal-search input:focus { border-color: var(--cyan); }

.modal-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.modal-results::-webkit-scrollbar { width: 4px; }
.modal-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.modal-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.modal-result-item:hover { background: rgba(255,255,255,0.04); }

.modal-result-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
  flex-shrink: 0;
  border: 1.5px solid var(--border);
}

.modal-result-avatar img { width: 100%; height: 100%; object-fit: cover; }

.modal-result-info { flex: 1; min-width: 0; }
.modal-result-name { font-size: 0.875rem; font-weight: 700; color: var(--white); }
.modal-result-meta { font-size: 0.78rem; color: var(--text-muted); }

.modal-empty {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Date separator ─────────────────────────────────────────────────────── */

.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
}

.date-separator span {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .messages-layout { flex-direction: column; }

  .messages-sidebar {
    width: 100%;
    height: 100vh;
    border-right: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    transform: translateX(0);
    transition: transform 0.3s;
  }

  .messages-sidebar.hidden {
    transform: translateX(-100%);
  }

  .messages-chat {
    position: absolute;
    inset: 0;
    z-index: 9;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.3s;
  }

  .messages-chat.active {
    transform: translateX(0);
  }

  .msg-bubble-wrap { max-width: 85%; }

  .back-btn {
    display: flex;
  }
}

.back-btn {
  display: none;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s;
}

.back-btn:hover { color: var(--white); }

/* ── Scroll to bottom button ────────────────────────────────────────────── */

.scroll-bottom-btn {
  position: absolute;
  bottom: 90px;
  right: 32px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}

.scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── System messages (auto-created convs, etc) ──────────────────────────── */

.system-msg {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 4px 16px;
}