/* ============================================================
   css/messages.css — FufaAdvertise Messages Page
   ============================================================ */

/* ── Layout ── */
.msg-wrap {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
  overflow: hidden;
}
@media (max-width: 768px) {
  .msg-wrap { grid-template-columns: 1fr; }
  .msg-list.hidden { display: none !important; }
}

/* ── Sidebar ── */
.msg-list {
  background: var(--panel, #111827);
  border-right: 1px solid var(--border, #1f2937);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border, #1f2937);
}
.sidebar-top h3 {
  margin: 0;
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text, #e5e7eb);
}
.sidebar-top .back {
  color: var(--text, #e5e7eb);
  text-decoration: none;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: background 0.15s;
}
.sidebar-top .back:hover { background: var(--panel-2, #1f2937); }

/* New Chat / New Group buttons */
.msg-list .btn-new {
  display: block;
  background: none;
  border: 1px solid var(--primary, #4f46e5);
  color: var(--primary, #4f46e5);
  border-radius: 8px;
  margin: 0.6rem 1rem;
  width: calc(100% - 2rem);
  cursor: pointer;
  padding: 0.5rem;
  font-size: 0.9rem;
  text-align: center;
  transition: background 0.15s ease;
}
.msg-list .btn-new:hover { background: rgba(79, 70, 229, 0.12); }
.msg-list .btn-new:disabled { opacity: 0.5; cursor: not-allowed; }

/* Search */
.conversation-search {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border, #1f2937);
}
.conversation-search input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: #0b1220;
  border: 1px solid var(--border, #1f2937);
  border-radius: 8px;
  color: var(--text, #e5e7eb);
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.conversation-search input:focus { border-color: var(--primary, #4f46e5); }

/* Conversation list */
.conversation-list { flex: 1; overflow-y: auto; min-height: 0; }

.conv-item {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border, #1f2937);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.conv-item:hover, .conv-item.active { background: var(--panel-2, #1f2937); }

.conv-item .conv-icon,
.conv-item .conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-2, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.9rem;
  flex-shrink: 0;
  object-fit: cover;
}
.conv-item .conv-meta { flex: 1; min-width: 0; }
.conv-item .conv-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
  color: var(--text, #e5e7eb);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .conv-preview {
  font-size: 0.78rem;
  color: var(--muted, #94a3b8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main Chat ── */
.msg-main {
  display: flex;
  flex-direction: column;
  background: var(--bg, #0b1220);
  min-height: 0;
  min-width: 0;
}

/* Header */
.msg-header {
  padding: 0.8rem 1rem;
  background: var(--panel, #111827);
  border-bottom: 1px solid var(--border, #1f2937);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.msg-header.chat-header { justify-content: space-between; }

.chat-title { display: flex; flex-direction: column; min-width: 0; }
.chat-title strong {
  color: var(--text, #e5e7eb);
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-title small.muted {
  color: var(--muted, #94a3b8);
  font-size: 0.75rem;
}

.chat-actions { display: flex; gap: 0.4rem; margin-left: auto; }

/* Message log */
.msg-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}

.bubble {
  max-width: 75%;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  background: var(--panel, #111827);
  color: var(--text, #e5e7eb);
  font-size: 0.88rem;
  word-break: break-word;
  align-self: flex-start;
  position: relative;
  animation: bubbleIn 0.15s ease;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble.self {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary, #4f46e5), var(--primary-2, #7c3aed));
  color: #fff;
}
.bubble .who {
  font-size: 0.7rem;
  color: var(--primary, #4f46e5);
  font-weight: 600;
  display: block;
}
.bubble.self .who { display: none; }
.bubble img, .bubble video {
  max-width: 240px;
  border-radius: 8px;
  display: block;
  margin-top: 0.3rem;
}
.bubble audio { max-width: 240px; margin-top: 0.3rem; }
.bubble .sticker { font-size: 2.2rem; line-height: 1; }
.bubble .time {
  display: block;
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 0.2rem;
  text-align: right;
}
.bubble.pending { opacity: 0.6; }
.bubble.error { border: 1px solid #ef4444; }
.bubble .tick { font-size: 0.65rem; margin-left: 0.3rem; opacity: 0.6; }
.bubble .tick.read { color: #22c55e; opacity: 1; }

/* Reply / Edit bars */
.reply-bar, .edit-bar {
  display: none;
  padding: 0.4rem 0.8rem;
  background: #1f2937;
  border-top: 1px solid #374151;
  align-items: center;
  gap: 0.5rem;
}
.reply-bar .reply-text,
.edit-bar .edit-text {
  flex: 1;
  font-size: 0.8rem;
  color: #94a3b8;
}

/* Message form */
.msg-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem;
  background: var(--panel, #111827);
  border-top: 1px solid var(--border, #1f2937);
  position: relative;
  align-items: center;
  flex-wrap: wrap;
}
.msg-form input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 0.55rem 0.8rem;
  background: #0b1220;
  border: 1px solid var(--border, #1f2937);
  border-radius: 8px;
  color: var(--text, #e5e7eb);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.msg-form input[type="text"]:focus { border-color: var(--primary, #4f46e5); }

.msg-form button {
  background: var(--primary, #4f46e5);
  border: none;
  color: #fff;
  width: 42px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s ease;
}
.msg-form button:hover { filter: brightness(1.1); }
.msg-form button.alt { background: var(--panel-2, #1f2937); }
.msg-form .icon-btn {
  background: transparent;
  border: 1px solid var(--border, #1f2937);
  color: var(--text, #e5e7eb);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  transition: background 0.15s;
}
.msg-form .icon-btn:hover { background: var(--panel-2, #1f2937); }
.msg-form .btn-send {
  background: var(--primary, #4f46e5);
  border: none;
  color: #fff;
  width: 42px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
}

/* Sticker picker */
.sticker-picker {
  position: absolute;
  bottom: 60px;
  left: 1rem;
  background: var(--panel, #111827);
  border: 1px solid var(--border, #1f2937);
  border-radius: 10px;
  padding: 0.5rem;
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  max-width: 280px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.sticker-picker.show { display: grid; }
.sticker-picker span {
  font-size: 1.6rem;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  user-select: none;
  transition: transform 0.1s ease;
  padding: 0.2rem;
  border-radius: 6px;
}
.sticker-picker span:hover {
  transform: scale(1.2);
  background: var(--panel-2, #1f2937);
}

/* New chat modal */
#newChatModal.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#newChatModal.modal:not(.hidden) { display: flex; }
#newChatModal .modal-box {
  background: var(--panel, #111827);
  padding: 1.5rem;
  border-radius: 14px;
  width: min(440px, 92vw);
  color: var(--text, #e5e7eb);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
#newChatModal h2 { margin: 0 0 1rem; font-size: 1.1rem; }
#newChatModal label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted, #94a3b8);
  margin-top: 0.5rem;
}
#newChatModal input {
  width: 100%;
  padding: 0.55rem;
  margin: 0.3rem 0 0.8rem;
  background: #0b1220;
  border: 1px solid var(--border, #1f2937);
  border-radius: 8px;
  color: var(--text, #e5e7eb);
  outline: none;
  font-family: inherit;
}
#newChatModal input:focus { border-color: var(--primary, #4f46e5); }
#newChatModal #ncSearchBtn {
  margin: 0 0 0.8rem;
  width: 100%;
}
#newChatModal #ncResults {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 0.8rem;
}
#newChatModal .modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Drag-over state */
.msg-log.drag-over {
  outline: 2px dashed var(--primary, #4f46e5);
  outline-offset: -4px;
  background: rgba(79, 70, 229, 0.05);
}

/* Unread badge */
.unread-badge {
  background: var(--primary, #4f46e5);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: auto;
}

/* Presence dot */
.presence-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  margin-left: 4px;
  transition: background 0.2s;
}
.presence-dot.online { background: #22c55e; }

/* Typing dots */
.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted, #94a3b8);
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%            { opacity: 1;   transform: translateY(-3px); }
}

/* Helpers */
.hidden { display: none !important; }
.muted { color: var(--muted, #94a3b8); }