/* ==========================================================================
   QWERO — MESSENGER MODULE
   Two-column chat layout in Qwero's dark graphite design system.
   Variables inherit from styles.css :root tokens.
   ========================================================================== */

/* ── Overlay & Layout ────────────────────────────────────────────────────── */
#qweroMessenger {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#qweroMessenger.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.qm-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.qm-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 56px;
  min-height: 56px;
  border-bottom: 1px solid var(--border-card);
  background: var(--bg-card);
  flex-shrink: 0;
}

.qm-topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.qm-topbar-title span { color: var(--accent-primary); }

.qm-close-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.qm-close-btn:hover { color: var(--text-primary); background: var(--bg-pill-hover); }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.qm-sidebar {
  width: 320px;
  min-width: 280px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-card);
  background: var(--bg-card);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.qm-sidebar-header { padding: 14px 16px 10px; flex-shrink: 0; }

.qm-search-wrap { position: relative; }
.qm-search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.qm-search-input {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: var(--radius-pill); color: var(--text-primary);
  font-family: var(--font-sans); font-size: 13.5px;
  padding: 8px 14px 8px 34px; outline: none;
  transition: border-color 0.15s; box-sizing: border-box;
}
.qm-search-input:focus { border-color: var(--accent-primary); }
.qm-search-input::placeholder { color: var(--text-muted); }

.qm-conv-list { flex: 1; overflow-y: auto; overflow-x: hidden; }
.qm-conv-list::-webkit-scrollbar { width: 4px; }
.qm-conv-list::-webkit-scrollbar-thumb { background: var(--border-card); border-radius: 2px; }

.qm-conv-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px; cursor: pointer;
  transition: background 0.12s; position: relative;
}
.qm-conv-item:hover { background: var(--bg-card-hover); }
.qm-conv-item.active { background: var(--bg-pill-hover); }
.qm-conv-item.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--accent-primary); border-radius: 0 2px 2px 0;
}

.qm-conv-avatar-wrap { position: relative; flex-shrink: 0; }
.qm-conv-avatar { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }
.qm-online-dot {
  position: absolute; bottom: 1px; right: 1px; width: 11px; height: 11px;
  border-radius: 50%; background: #22c55e; border: 2px solid var(--bg-card);
}

.qm-conv-body { flex: 1; min-width: 0; }
.qm-conv-row1 { display: flex; align-items: baseline; gap: 4px; }
.qm-conv-name {
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.qm-conv-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.qm-conv-preview {
  font-size: 12.5px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px; display: flex; align-items: center; gap: 4px;
}
.qm-conv-preview.unread { color: var(--text-primary); font-weight: 500; }
.qm-unread-badge {
  background: var(--accent-primary); color: var(--accent-contrast);
  font-size: 10.5px; font-weight: 700; border-radius: var(--radius-pill);
  padding: 1px 6px; min-width: 18px; text-align: center; flex-shrink: 0; margin-left: auto;
}
.qm-conv-empty { text-align: center; padding: 48px 24px; color: var(--text-muted); font-size: 13px; }
.qm-conv-empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }

.qm-new-chat-btn {
  margin: 12px 16px; padding: 9px 16px;
  background: var(--accent-primary); color: var(--accent-contrast);
  border: none; border-radius: var(--radius-pill);
  font-family: var(--font-sans); font-size: 13px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  gap: 6px; transition: opacity 0.15s; flex-shrink: 0;
}
.qm-new-chat-btn:hover { opacity: 0.88; }

/* ── Chat Panel ──────────────────────────────────────────────────────────── */
.qm-chat-panel {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: var(--bg-page); position: relative;
}

.qm-chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); gap: 12px; font-size: 14px;
}
.qm-chat-empty-icon { font-size: 56px; opacity: 0.25; }

/* ── Chat Header ─────────────────────────────────────────────────────────── */
.qm-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border-card);
  background: var(--bg-card); flex-shrink: 0;
}
.qm-chat-header-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; cursor: pointer; }
.qm-chat-header-info { flex: 1; min-width: 0; }
.qm-chat-header-name { font-size: 15px; font-weight: 700; color: var(--text-primary); cursor: pointer; }
.qm-chat-header-name:hover { color: var(--accent-primary); }
.qm-chat-header-status { font-size: 12px; color: var(--text-muted); }
.qm-chat-header-status.online { color: #22c55e; }
.qm-chat-header-actions { display: flex; gap: 6px; }
.qm-icon-btn {
  background: transparent; border: none; cursor: pointer; color: var(--text-secondary);
  padding: 6px; border-radius: 8px; display: flex; align-items: center;
  transition: color 0.15s, background 0.15s;
}
.qm-icon-btn:hover { color: var(--text-primary); background: var(--bg-pill-hover); }

/* ── Safe Deal Banner ────────────────────────────────────────────────────── */
.qm-deal-banner {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  background: linear-gradient(90deg, rgba(168,85,247,0.10) 0%, rgba(59,130,246,0.08) 100%);
  border-bottom: 1px solid rgba(168,85,247,0.2); flex-shrink: 0;
}
.qm-deal-banner-icon { font-size: 20px; flex-shrink: 0; }
.qm-deal-banner-info { flex: 1; min-width: 0; }
.qm-deal-title { font-size: 12.5px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qm-deal-meta { font-size: 11px; color: var(--text-muted); }
.qm-deal-amount { font-weight: 700; color: #22c55e; }
.qm-deal-btn {
  background: var(--accent-primary); color: var(--accent-contrast);
  border: none; border-radius: var(--radius-pill);
  font-family: var(--font-sans); font-size: 11.5px; font-weight: 600;
  padding: 5px 12px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: opacity 0.15s;
}
.qm-deal-btn:hover { opacity: 0.85; }

/* ── Security Alert ──────────────────────────────────────────────────────── */
.qm-security-alert {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: rgba(245,158,11,0.08); border-bottom: 1px solid rgba(245,158,11,0.2);
  font-size: 11.5px; color: #f59e0b; flex-shrink: 0;
}
.qm-security-alert svg { flex-shrink: 0; }

/* ── Messages Area ───────────────────────────────────────────────────────── */
.qm-messages-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px;
}
.qm-messages-area::-webkit-scrollbar { width: 4px; }
.qm-messages-area::-webkit-scrollbar-thumb { background: var(--border-card); border-radius: 2px; }

.qm-date-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; }
.qm-date-sep-line { flex: 1; height: 1px; background: var(--border-card); }
.qm-date-sep-label { font-size: 11px; color: var(--text-muted); font-weight: 500; white-space: nowrap; padding: 0 4px; }

.qm-load-more {
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: var(--radius-pill); color: var(--text-secondary);
  font-family: var(--font-sans); font-size: 12px; padding: 6px 16px;
  cursor: pointer; align-self: center; margin-bottom: 8px;
  transition: background 0.15s, color 0.15s;
}
.qm-load-more:hover { background: var(--bg-pill-hover); color: var(--text-primary); }

.qm-msg-group { display: flex; flex-direction: column; margin-bottom: 4px; }
.qm-msg-group.self { align-items: flex-end; }
.qm-msg-group.other { align-items: flex-start; }

.qm-msg-sender-name { font-size: 11px; font-weight: 600; color: var(--accent-primary); margin-bottom: 3px; padding-left: 12px; }

.qm-bubble {
  max-width: 72%; padding: 9px 13px; border-radius: 18px;
  font-size: 14px; line-height: 1.5; color: var(--text-primary);
  position: relative; word-break: break-word;
}
.qm-msg-group.other .qm-bubble {
  background: var(--bg-card); border: 1px solid var(--border-card); border-bottom-left-radius: 4px;
}
.qm-msg-group.self .qm-bubble {
  background: var(--accent-primary); color: var(--accent-contrast); border-bottom-right-radius: 4px;
}
.qm-bubble.system {
  background: transparent; border: 1px dashed var(--border-card);
  color: var(--text-muted); font-size: 12px; text-align: center;
  align-self: center; max-width: 80%; padding: 6px 14px; border-radius: 10px;
}

.qm-reply-quote { border-left: 3px solid var(--accent-primary); padding: 4px 8px; margin-bottom: 6px; border-radius: 2px; opacity: 0.8; }
.qm-reply-quote-sender { font-size: 11px; font-weight: 600; color: var(--accent-primary); }
.qm-reply-quote-text { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.qm-bubble-image { max-width: 280px; max-height: 220px; border-radius: 12px; object-fit: cover; cursor: pointer; display: block; margin-bottom: 4px; transition: opacity 0.2s; }
.qm-bubble-image:hover { opacity: 0.9; }

.qm-file-attach {
  display: flex; align-items: center; gap: 8px; padding: 8px;
  background: rgba(255,255,255,0.06); border-radius: 10px; margin-bottom: 4px;
  text-decoration: none; color: inherit; transition: background 0.15s;
}
.qm-file-attach:hover { background: rgba(255,255,255,0.10); }
.qm-file-attach-icon { font-size: 22px; flex-shrink: 0; }
.qm-file-attach-info { min-width: 0; flex: 1; }
.qm-file-attach-name { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qm-file-attach-size { font-size: 11px; opacity: 0.6; }

.qm-bubble-meta {
  display: flex; align-items: center; gap: 4px; margin-top: 4px;
  justify-content: flex-end; opacity: 0.6; font-size: 11px;
}
.qm-msg-group.other .qm-bubble-meta { justify-content: flex-start; }
.qm-check-icon { font-size: 12px; }
.qm-check-icon.read { opacity: 1; color: #3b82f6; }

.qm-typing-indicator {
  display: flex; align-items: center; gap: 6px; padding: 4px 0 2px;
  font-size: 12px; color: var(--text-muted); font-style: italic; min-height: 24px;
}
.qm-typing-dots { display: flex; gap: 3px; align-items: center; }
.qm-typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted);
  animation: qm-typing-bounce 1.2s infinite ease-in-out;
}
.qm-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.qm-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes qm-typing-bounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input Area ──────────────────────────────────────────────────────────── */
.qm-input-area {
  border-top: 1px solid var(--border-card); background: var(--bg-card);
  padding: 10px 14px 12px; flex-shrink: 0;
}

.qm-attach-preview-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.qm-attach-preview-item { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-card); }
.qm-attach-preview-img { width: 72px; height: 72px; object-fit: cover; display: block; }
.qm-attach-preview-file { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--bg-input); font-size: 12px; color: var(--text-secondary); max-width: 180px; }
.qm-attach-remove {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.65);
  border: none; border-radius: 50%; width: 18px; height: 18px;
  color: #fff; font-size: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}

.qm-reply-preview {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--bg-input); border-radius: 8px; margin-bottom: 8px;
  border-left: 3px solid var(--accent-primary);
}
.qm-reply-preview-text { flex: 1; min-width: 0; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qm-reply-preview-close { background: transparent; border: none; cursor: pointer; color: var(--text-muted); font-size: 14px; line-height: 1; padding: 0; }

.qm-input-row { display: flex; align-items: flex-end; gap: 8px; }
.qm-textarea {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 22px; color: var(--text-primary);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.5;
  padding: 9px 14px; resize: none; outline: none;
  min-height: 40px; max-height: 160px; overflow-y: auto;
  transition: border-color 0.15s; box-sizing: border-box;
}
.qm-textarea:focus { border-color: var(--accent-primary); }
.qm-textarea::placeholder { color: var(--text-muted); }

.qm-attach-btn, .qm-send-btn {
  background: transparent; border: none; cursor: pointer; padding: 8px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.qm-attach-btn { color: var(--text-secondary); }
.qm-attach-btn:hover { background: var(--bg-pill-hover); color: var(--text-primary); }
.qm-send-btn { background: var(--accent-primary); color: var(--accent-contrast); width: 38px; height: 38px; }
.qm-send-btn:hover { opacity: 0.88; }
.qm-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.qm-file-input { display: none; }

/* ── New Chat User Search ─────────────────────────────────────────────────── */
.qm-new-chat-modal {
  position: absolute; inset: 0; background: var(--bg-card);
  z-index: 100; display: flex; flex-direction: column;
  padding: 14px; gap: 10px; overflow-y: auto;
  opacity: 0; pointer-events: none; transform: translateX(-8px);
  transition: opacity 0.18s, transform 0.18s;
}
.qm-new-chat-modal.visible { opacity: 1; pointer-events: auto; transform: translateX(0); }
.qm-new-chat-modal-header { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; color: var(--text-primary); }
.qm-user-search-list { display: flex; flex-direction: column; gap: 2px; }
.qm-user-search-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; cursor: pointer; transition: background 0.12s; }
.qm-user-search-item:hover { background: var(--bg-card-hover); }
.qm-user-search-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }
.qm-user-search-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.qm-user-search-handle { font-size: 12px; color: var(--text-muted); }

/* ── Scroll to bottom ─────────────────────────────────────────────────────── */
.qm-scroll-down-btn {
  position: absolute; bottom: 80px; right: 20px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border-card);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  transition: opacity 0.18s, transform 0.18s; z-index: 5;
}
.qm-scroll-down-btn.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .qm-sidebar {
    width: 100%; max-width: 100%;
    position: absolute; inset: 0; z-index: 10;
    transform: translateX(0); transition: transform 0.22s ease;
  }
  .qm-sidebar.hidden-mobile { transform: translateX(-100%); }
  .qm-chat-panel {
    position: absolute; inset: 0; z-index: 11;
    transform: translateX(100%); transition: transform 0.22s ease;
  }
  .qm-chat-panel.visible-mobile { transform: translateX(0); }
  .qm-bubble { max-width: 86%; }
  .qm-back-btn { display: flex !important; }
}
.qm-back-btn {
  display: none; background: transparent; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 6px; border-radius: 8px;
  align-items: center; transition: color 0.15s;
}
.qm-back-btn:hover { color: var(--text-primary); }

/* ── Message Appear Animation ────────────────────────────────────────────── */
.qm-msg-in { animation: qm-msg-appear 0.18s ease-out forwards; }
@keyframes qm-msg-appear {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
