/* ======================================================================
   FutiaSpace · chat.css  —  WhatsApp-inspired modern redesign
   ====================================================================== */

/* =====================================================================
   Bottom nav — hide completely when chat is open
   ===================================================================== */
body.chat-open #bottomNav,
body.chat-open [id="bottomNav"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* =====================================================================
   Chat list page
   ===================================================================== */
.chat-list-page {
  padding-bottom: 16px;
  animation: fadeIn var(--t-base) var(--ease);
}
.chat-list-page h2 {
  font-size: var(--fs-xl);
  letter-spacing: -0.02em;
}

#chatListContainer {
  display: flex;
  flex-direction: column;
  padding: 0 6px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
  border-bottom: 1px solid var(--border-subtle);
}
.chat-list-item:last-child { border-bottom: none; }
.chat-list-item:hover { background: var(--bg-elevated); }
.chat-list-item:active { transform: scale(0.99); }

/* Unread conversations stand out */
.chat-list-item.has-unread strong { font-weight: 700; }
.chat-list-item.has-unread .chat-list-info span { color: var(--text-primary); font-weight: 500; }

.chat-list-avatar {
  position: relative;
  width: 52px; height: 52px;
  flex-shrink: 0;
}
.chat-list-avatar img,
.chat-list-avatar .avatar-placeholder {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.chat-list-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-list-info strong {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-list-info span {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.chat-list-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* =====================================================================
   Chat detail page — shell
   ===================================================================== */
.chat-detail-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h));
  background: var(--bg-base);
  overflow: hidden;
  animation: fadeIn var(--t-base) var(--ease);
  position: relative;
}

/* ── Sticky top bar (header + disclaimer grouped) ──────────── */
.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
  background: var(--bg-surface);
  box-shadow: 0 1px 10px rgba(0,0,0,0.18);
}

/* ── Header ──────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.chat-back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast);
  flex-shrink: 0;
}
.chat-back-btn:hover { background: var(--bg-elevated); }
.chat-back-btn [data-lucide],
.chat-back-btn svg.lucide { width: 22px; height: 22px; }

.chat-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
}
.chat-header-avatar img,
.chat-header-avatar .avatar-placeholder {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chat-header-info strong {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-last-seen {
  display: block;
  font-size: 0.7rem;
  color: var(--color-success, #4ade80);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.chat-header-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.chat-header-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.chat-header-btn [data-lucide],
.chat-header-btn svg.lucide { width: 20px; height: 20px; }

/* ── Privacy / disclaimer notice (restyled) ──────────────── */
.chat-privacy-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  background: color-mix(in srgb, var(--violet-500, #8b5cf6) 10%, var(--bg-surface));
  border-top: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.68rem;
  line-height: 1.3;
  text-align: center;
}
.chat-privacy-notice .chat-privacy-icon,
.chat-privacy-notice [data-lucide],
.chat-privacy-notice svg.lucide {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  color: var(--violet-400, #a78bfa);
}
.chat-privacy-notice span {
  opacity: 0.9;
}

/* ── Chat background ─────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* subtle tiled chat background */
  background-color: var(--bg-base);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(139,92,246,0.06) 1px, transparent 0);
  background-size: 28px 28px;
}

/* FIX: keep the list invisible until we've jumped to the latest message,
   so the user never sees it scroll from the top on open. */
.chat-messages.chat-messages-loading {
  opacity: 0;
  scroll-behavior: auto;
}

/* ── Date divider ────────────────────────────────────────── */
.chat-date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0 6px;
}
.chat-date-divider span {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-subtle);
  letter-spacing: 0.02em;
}

/* ── Message rows ────────────────────────────────────────── */
.message-row {
  display: flex;
  width: 100%;
  animation: msgIn 0.18s ease-out;
  margin-bottom: 2px;
  position: relative;
  touch-action: pan-y; /* allow vertical scroll, we handle horizontal swipe */
}
.message-row.mine   { justify-content: flex-end; }
.message-row.theirs { justify-content: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Swipe-to-reply cue ──────────────────────────────────── */
.swipe-reply-cue {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) scale(0.6);
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--violet-400, #a78bfa);
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
  z-index: 1;
}
.message-row.theirs .swipe-reply-cue { left: 6px; }
.message-row.mine   .swipe-reply-cue { right: 6px; }
.swipe-reply-cue [data-lucide],
.swipe-reply-cue svg.lucide { width: 16px; height: 16px; }

/* When the swipe passes the trigger threshold */
.message-row.swiping-armed .swipe-reply-cue {
  opacity: 1;
  transform: translateY(-50%) scale(1);
  background: var(--violet-500, #8b5cf6);
  color: #fff;
  border-color: transparent;
}

/* The bubble translates inline via JS transform; this keeps it smooth */
.message-row .message-bubble {
  will-change: transform;
}

/* ── Bubbles ─────────────────────────────────────────────── */
.message-bubble {
  max-width: 76%;
  padding: 8px 12px 6px;
  border-radius: 18px;
  font-size: var(--fs-base);
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* Tail for sent messages */
.message-row.mine .message-bubble {
  background: var(--gradient-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message-row.mine .message-bubble::after {
  content: '';
  position: absolute;
  bottom: 0; right: -6px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 0 10px 8px;
  /* match the END of the brand gradient so the tail blends in */
  border-color: transparent transparent transparent var(--violet-600, #7c3aed);
}

/* Tail for received messages */
.message-row.theirs .message-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.message-row.theirs .message-bubble::after {
  content: '';
  position: absolute;
  bottom: 0; left: -6px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 10px 8px 0 0;
  border-color: var(--bg-surface) transparent transparent transparent;
}

.message-bubble p { margin: 0; }

/* Group consecutive messages — remove tail between same-sender rows */
.message-row.mine + .message-row.mine .message-bubble {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 18px;
}
.message-row.mine + .message-row.mine .message-bubble::after { display: none; }

.message-row.theirs + .message-row.theirs .message-bubble {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 18px;
}
.message-row.theirs + .message-row.theirs .message-bubble::after { display: none; }

/* ── Message timestamp & read receipt ───────────────────── */
.message-time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: 0.62rem;
  opacity: 0.72;
}
.message-row.mine .message-time { color: rgba(255,255,255,0.85); }
.message-row.theirs .message-time { color: var(--text-muted); }

.msg-read-icon {
  width: 13px !important;
  height: 13px !important;
  flex-shrink: 0;
}

/* ── Deleted message ─────────────────────────────────────── */
.msg-deleted {
  margin: 0;
  font-style: italic;
  opacity: 0.55;
  font-size: 0.85em;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ── Edited label ────────────────────────────────────────── */
.edited-label {
  font-size: 0.65em;
  opacity: 0.65;
  margin-left: 3px;
}

/* ── Reply quote inside bubble ───────────────────────────── */
.msg-reply-quote {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px 8px;
  margin-bottom: 5px;
  border-radius: 8px;
  border-left: 3px solid rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.12);
  font-size: 0.78rem;
  max-width: 100%;
  overflow: hidden;
}
.message-row.theirs .msg-reply-quote {
  border-left-color: var(--violet-400, #a78bfa);
  background: rgba(139,92,246,0.08);
}
.msg-reply-quote-author {
  font-weight: 600;
  font-size: 0.72rem;
  opacity: 0.9;
}
.msg-reply-quote-text {
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Incoming highlight flash ─────────────────────────────── */
.msg-incoming-highlight .message-bubble {
  animation: incomingFlash 0.8s ease-out;
}
@keyframes incomingFlash {
  0%   { box-shadow: 0 0 0 0 rgba(139,92,246,0.4); }
  60%  { box-shadow: 0 0 0 8px rgba(139,92,246,0); }
  100% { box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
}

/* ── Empty state ─────────────────────────────────────────── */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  gap: 6px;
  margin: auto;
  padding: 40px 20px;
}

/* =====================================================================
   Scroll-to-bottom floating button
   ===================================================================== */
.scroll-bottom-btn {
  position: absolute;
  right: 14px;
  bottom: 84px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 18;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
  transition: transform var(--t-fast), background var(--t-fast);
  animation: popupIn 0.16s ease-out;
}
.scroll-bottom-btn:hover { background: var(--bg-elevated); }
.scroll-bottom-btn:active { transform: scale(0.92); }
.scroll-bottom-btn [data-lucide],
.scroll-bottom-btn svg.lucide { width: 20px; height: 20px; }

.scroll-bottom-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--gradient-brand);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}

/* =====================================================================
   Voice note bubble  — WhatsApp style
   ===================================================================== */
.vn-message-bubble {
  padding: 8px 10px 6px !important;
  min-width: 200px;
}

.voice-note-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Play / Pause button */
.voice-play-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.12s;
  color: #fff;
}
.message-row.theirs .voice-play-btn {
  background: var(--violet-500, #8b5cf6);
  color: #fff;
}
.voice-play-btn:hover { background: rgba(255,255,255,0.3); transform: scale(1.05); }
.message-row.theirs .voice-play-btn:hover { background: var(--violet-600, #7c3aed); }
.voice-play-btn:active { transform: scale(0.95); }
.voice-play-btn [data-lucide],
.voice-play-btn svg.lucide { width: 18px; height: 18px; }

/* Body: waveform + duration */
.vn-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Waveform container */
.vn-waveform {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  overflow: hidden;
}

/* Individual bars */
.wf-bar {
  display: inline-block;
  width: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.45);
  flex-shrink: 0;
  align-self: center;
  transition: background 0.1s;
}
.message-row.theirs .wf-bar {
  background: rgba(139,92,246,0.3);
}

/* Progress overlay — clips bars to show played portion */
.vn-waveform-progress {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgba(255,255,255,0.75) 0%,
    rgba(255,255,255,0.75) 100%
  );
  mix-blend-mode: screen;
  border-radius: 2px;
  transition: width 0.1s linear;
}
.message-row.theirs .vn-waveform-progress {
  background: linear-gradient(
    to right,
    rgba(139,92,246,0.65) 0%,
    rgba(139,92,246,0.65) 100%
  );
  mix-blend-mode: multiply;
}

/* Duration */
.vn-duration {
  font-size: 0.7rem;
  opacity: 0.75;
  color: #fff;
  letter-spacing: 0.02em;
}
.message-row.theirs .vn-duration { color: var(--text-muted); }

.vn-uploading {
  font-size: 0.68rem;
  opacity: 0.6;
  color: #fff;
  font-style: italic;
  align-self: flex-end;
}

/* =====================================================================
   Sticky bottom bar (reply preview + recording + input grouped)
   ===================================================================== */
.chat-bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: 19;
  flex-shrink: 0;
  background: var(--bg-surface);
  box-shadow: 0 -1px 10px rgba(0,0,0,0.18);
}

/* =====================================================================
   Reply preview bar
   ===================================================================== */
.reply-preview-bar {
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  animation: slideUp 0.15s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.reply-preview-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.reply-preview-accent {
  width: 3px;
  height: 36px;
  background: var(--gradient-brand);
  border-radius: 4px;
  flex-shrink: 0;
}

.reply-preview-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reply-preview-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--violet-400, #a78bfa);
}
.reply-preview-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.reply-cancel-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.reply-cancel-btn [data-lucide],
.reply-cancel-btn svg.lucide { width: 16px; height: 16px; }

/* =====================================================================
   Voice recording UI
   ===================================================================== */
.voice-recording-bar {
  flex-shrink: 0;
  display: none; /* controlled via JS */
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

.rec-cancel-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast);
  flex-shrink: 0;
}
.rec-cancel-btn:hover { background: rgba(239,68,68,0.1); }
.rec-cancel-btn [data-lucide],
.rec-cancel-btn svg.lucide { width: 20px; height: 20px; }

.rec-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Pulsing red dot */
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  animation: recPulse 1.2s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.4); opacity: 0.6; }
}

.rec-timer {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 38px;
  font-variant-numeric: tabular-nums;
}

/* Animated wave bars during recording */
.rec-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}
.rec-wave span {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--violet-400, #a78bfa);
  animation: recWave 0.8s ease-in-out infinite;
}
.rec-wave span:nth-child(1) { animation-delay: 0.0s; animation-duration: 0.9s; }
.rec-wave span:nth-child(2) { animation-delay: 0.15s; animation-duration: 0.7s; }
.rec-wave span:nth-child(3) { animation-delay: 0.1s; animation-duration: 1.0s; }
.rec-wave span:nth-child(4) { animation-delay: 0.25s; animation-duration: 0.75s; }
.rec-wave span:nth-child(5) { animation-delay: 0.05s; animation-duration: 0.85s; }
@keyframes recWave {
  0%, 100% { height: 4px; }
  50%       { height: 18px; }
}

.rec-send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--gradient-brand);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(139,92,246,0.35);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.rec-send-btn:hover { box-shadow: 0 6px 20px rgba(139,92,246,0.5); }
.rec-send-btn:active { transform: scale(0.92); }
.rec-send-btn [data-lucide],
.rec-send-btn svg.lucide { width: 18px; height: 18px; }

/* =====================================================================
   Chat input area
   ===================================================================== */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px calc(10px + var(--safe-bottom, 0px));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 11px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: var(--fs-base);
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
  min-width: 0;
}
.chat-input:focus {
  border-color: var(--violet-500);
  box-shadow: var(--shadow-glow);
  outline: none;
}
.chat-input::placeholder { color: var(--text-muted); }

.chat-mic-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-input);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.chat-mic-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.chat-mic-btn:active { transform: scale(0.92); }
.chat-mic-btn [data-lucide],
.chat-mic-btn svg.lucide { width: 19px; height: 19px; }

.chat-send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(139,92,246,0.32);
  transition: transform var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.chat-send-btn:hover { box-shadow: 0 6px 20px rgba(139,92,246,0.45); }
.chat-send-btn:active { transform: scale(0.92); }
.chat-send-btn [data-lucide],
.chat-send-btn svg.lucide { width: 18px; height: 18px; }

/* =====================================================================
   Message action popup
   ===================================================================== */
.msg-action-popup {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 6px 0;
  z-index: 3000;
  min-width: 140px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  animation: popupIn 0.14s ease-out;
}
@keyframes popupIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

.popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: var(--fs-sm);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast);
}
.popup-item:hover { background: var(--bg-card); }
.popup-item [data-lucide],
.popup-item svg.lucide { width: 16px; height: 16px; flex-shrink: 0; }
.popup-item.danger { color: #ef4444; }
.popup-item.danger:hover { background: rgba(239,68,68,0.08); }

/* =====================================================================
   Delete confirmation overlay
   ===================================================================== */
.msg-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.14s ease-out;
}
.msg-confirm-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg, 16px);
  padding: 20px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  animation: popupIn 0.16s ease-out;
}
.msg-confirm-title {
  margin: 0 0 6px;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-primary);
}
.msg-confirm-text {
  margin: 0 0 16px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.msg-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn-danger {
  background: #ef4444;
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #dc2626; }

/* =====================================================================
   Inline message edit
   ===================================================================== */
.edit-msg-input {
  width: 100%;
  background: var(--bg-input, var(--bg-elevated));
  border: 1.5px solid var(--violet-500);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text-primary);
  font-size: var(--fs-base);
  outline: none;
  transition: box-shadow var(--t-fast);
}
.edit-msg-input:focus { box-shadow: var(--shadow-glow); }
.edit-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

/* =====================================================================
   Message action sheet (long-press / right-click → Reply, Delete)
   ===================================================================== */
.msg-action-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1200;
  animation: msgSheetFade 0.16s ease;
}
.msg-action-sheet {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  background: var(--bg-elevated, #1c1c22);
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  border-radius: 16px;
  padding: 6px;
  z-index: 1201;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: msgSheetSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.msg-action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  background: transparent;
  border: none;
  border-radius: 11px;
  color: var(--text-primary);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast, 0.15s);
}
.msg-action-item:hover,
.msg-action-item:active { background: var(--bg-hover, rgba(255, 255, 255, 0.06)); }
.msg-action-item i { width: 20px; height: 20px; flex-shrink: 0; }
.msg-action-item.danger { color: var(--danger, #f0506e); }

@keyframes msgSheetFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes msgSheetSlide {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .message-row,
  .msg-action-popup,
  .msg-action-sheet,
  .msg-action-backdrop,
  .scroll-bottom-btn,
  .reply-preview-bar,
  .msg-confirm-overlay,
  .msg-confirm-card { animation: none !important; }
  .chat-messages { scroll-behavior: auto !important; }
  .swipe-reply-cue,
  .message-row .message-bubble { transition: none !important; }
}

