/* ══════════════════════════════════════════════════════════
   LSF MESSAGES — Direct chat UI (WhatsApp/Messenger style)
   Uses the same design tokens as the rest of LSF (style.css)
══════════════════════════════════════════════════════════ */

/* Tell the browser this page manages its own light/dark styling.
   Without this, some Android Chrome builds "Force Dark"-invert
   native form controls (input/textarea) regardless of our own
   CSS colors — which is what was making the composer text and
   placeholder invisible. */
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* CRITICAL FIX — this is the actual "can't type" bug.
   Sitewide, style.css sets body { user-select: none } to make the PWA feel
   app-like (no accidental text selection on taps/swipes), then re-enables
   selection only for .glass-card, .modal-content, p, h1-h4. It never
   accounted for real form fields, because this chat composer is the first
   heavy free-typing surface on the site. An inherited user-select:none on
   a textarea/input is a well-documented cause of exactly what was
   reported: the field is clickable, but several Chrome/WebView builds
   refuse to render or move a caret in it and keystrokes don't register —
   identically on desktop and mobile, since it's the same CSS rule either
   way, and unaffected by cache-clearing since it's not a caching issue. */
input, textarea {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

.msg-app {
  display: flex;
  height: calc(100vh - 64px);
  max-width: 1400px;
  margin: 0 auto;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* ── shared small controls ── */
.msg-icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--r-pill);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 1rem;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.msg-icon-btn:hover { background: var(--bg-alt); color: var(--text-main); }

/* ═══════════ LEFT PANE — conversation list ═══════════ */
.msg-list-pane {
  width: 380px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100%;
}
.msg-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 10px;
}
.msg-list-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; color: var(--text-main); margin: 0; }

.msg-search-wrap {
  margin: 4px 16px 12px;
  background: var(--bg-alt);
  border-radius: var(--r-pill);
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
}
.msg-search-wrap i { color: var(--text-muted); font-size: .85rem; }
.msg-search-wrap input {
  border: none; background: transparent; outline: none;
  font-family: var(--font-body); font-size: .88rem; color: var(--text-main);
  width: 100%;
}
.msg-search-wrap input::placeholder { color: var(--text-muted); }

.msg-conv-list { flex: 1; overflow-y: auto; padding-bottom: 90px; }

.msg-conv-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--r-md);
  margin: 0 8px 2px;
  transition: background .15s;
  position: relative;
}
.msg-conv-row:hover { background: var(--bg-alt); }
.msg-conv-row.active { background: var(--coral-light); }

.msg-avatar-wrap { position: relative; flex-shrink: 0; }
.msg-avatar, .cm-fallback-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--gradient); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
  overflow: hidden; position: relative; flex-shrink: 0;
}
.msg-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.msg-avatar.sm, .msg-thread-avatar { width: 40px; height: 40px; font-size: .9rem; }
.msg-online-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--emerald);
  border: 2.5px solid var(--card);
}

.msg-conv-main { flex: 1; min-width: 0; }
.msg-conv-toprow { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.msg-conv-name { font-weight: 700; font-size: .93rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-conv-time { font-size: .72rem; color: var(--text-muted); flex-shrink: 0; }
.msg-conv-row.unread .msg-conv-time { color: var(--coral); font-weight: 700; }
.msg-conv-bottomrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.msg-conv-preview { font-size: .82rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-conv-row.unread .msg-conv-preview { color: var(--text-dim); font-weight: 600; }
.msg-conv-row.unread .msg-conv-name { font-weight: 800; }
.msg-unread-badge {
  background: var(--coral); color: #fff; font-size: .68rem; font-weight: 800;
  min-width: 19px; height: 19px; border-radius: var(--r-pill);
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
  flex-shrink: 0;
}
.msg-conv-preview .msg-tick { margin-right: 3px; }

.msg-list-skeleton { padding: 4px 16px; }
.msg-skel-row { height: 60px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--bg-alt) 25%, var(--card-hover) 50%, var(--bg-alt) 75%); background-size: 200% 100%; animation: msgShimmer 1.4s infinite; margin-bottom: 8px; }
@keyframes msgShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.msg-empty-list { padding: 60px 30px; text-align: center; color: var(--text-muted); }
.msg-empty-icon { font-size: 2.4rem; color: var(--border); margin-bottom: 14px; }
.msg-empty-list p { font-weight: 700; color: var(--text-dim); margin: 0 0 6px; }
.msg-empty-list span { font-size: .82rem; line-height: 1.5; }

/* ═══════════ RIGHT PANE — thread ═══════════ */
.msg-thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.msg-thread-placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center; padding: 30px;
}
.msg-placeholder-icon { font-size: 2.6rem; color: var(--border); margin-bottom: 16px; }
.msg-thread-placeholder h2 { font-family: var(--font-display); color: var(--text-dim); margin: 0 0 6px; }

.msg-thread { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.msg-thread-header {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.msg-back-btn { display: none; }
.msg-thread-identity { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; padding: 4px 6px; border-radius: var(--r-md); }
.msg-thread-identity:hover { background: var(--bg-alt); }
.msg-thread-avatar-wrap { position: relative; flex-shrink: 0; }
.msg-thread-namewrap { min-width: 0; }
.msg-thread-name { font-weight: 700; font-size: .95rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-thread-status { font-size: .75rem; color: var(--text-muted); }
.msg-thread-status.typing { color: var(--emerald); font-weight: 600; }
.msg-thread-actions { position: relative; flex-shrink: 0; }

.msg-dropdown {
  position: absolute; top: 46px; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); min-width: 210px; padding: 6px;
  display: none; flex-direction: column;
}
.msg-dropdown.open { display: flex; }
.msg-dropdown button {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-sm);
  background: none; border: none; text-align: left; cursor: pointer;
  font-family: var(--font-body); font-size: .85rem; color: var(--text-dim);
}
.msg-dropdown button:hover { background: var(--bg-alt); }
.msg-dropdown-danger { color: #dc2626 !important; }

/* ── Message list ── */
.msg-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 4%; display: flex; flex-direction: column; }
.msg-load-older { text-align: center; margin-bottom: 10px; }
.msg-load-older button { background: var(--bg-alt); border: none; border-radius: var(--r-pill); padding: 6px 16px; font-size: .78rem; color: var(--text-dim); cursor: pointer; }
.msg-bubbles { display: flex; flex-direction: column; gap: 3px; margin-top: auto; }

.msg-day-sep { text-align: center; margin: 16px 0 10px; }
.msg-day-sep span { background: var(--bg-alt); color: var(--text-muted); font-size: .72rem; font-weight: 600; padding: 4px 12px; border-radius: var(--r-pill); }

.msg-row { display: flex; max-width: 100%; margin-bottom: 2px; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.msg-bubble-col { display: flex; flex-direction: column; max-width: 68%; }
.msg-bubble {
  max-width: 100%; width: fit-content; padding: 8px 12px; border-radius: 16px;
  position: relative; font-size: .89rem; line-height: 1.42;
  word-wrap: break-word; white-space: pre-wrap; cursor: default;
  box-shadow: var(--shadow-sm);
}
.msg-row.mine .msg-bubble-col { align-items: flex-end; }
.msg-row.mine .msg-bubble { background: var(--coral); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.theirs .msg-bubble { background: var(--card); color: var(--text-main); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-row.mine .msg-bubble a { color: #fff; text-decoration: underline; }
.msg-row.theirs .msg-bubble a { color: var(--coral); text-decoration: underline; }
.msg-mention-tag-inline { font-weight: 700; cursor: pointer; text-decoration: none; }
.msg-row.mine .msg-mention-tag-inline { color: #fff; text-decoration: underline; }
.msg-row.theirs .msg-mention-tag-inline { color: var(--coral); }
.msg-bubble.selected { outline: 2px solid var(--indigo); }

.msg-meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 3px; font-size: .66rem; opacity: .82; }
.msg-row.theirs .msg-meta { color: var(--text-muted); }
.msg-edited-tag { font-style: italic; }
.msg-tick { font-size: .78rem; }
.msg-tick.seen { color: #93c5fd; }
.msg-deleted { font-style: italic; opacity: .7; }

.msg-media-bubble { padding: 4px; overflow: hidden; }
.msg-media-bubble img, .msg-media-bubble video { display: block; max-width: 260px; max-height: 320px; border-radius: 12px; cursor: pointer; background: var(--bg-alt); }
.msg-media-caption { padding: 6px 8px 2px; }
.msg-doc-card { display: flex; align-items: center; gap: 10px; padding: 4px 6px; min-width: 200px; }
.msg-doc-icon { width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.msg-row.theirs .msg-doc-icon { background: var(--bg-alt); color: var(--coral); }
.msg-doc-info { min-width: 0; flex: 1; }
.msg-doc-name { font-weight: 600; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-doc-size { font-size: .7rem; opacity: .8; }
.msg-voice-bubble { display: flex; align-items: center; gap: 8px; min-width: 220px; }
.msg-voice-bubble audio { height: 34px; max-width: 210px; }
.msg-skel-media { width: 220px; height: 140px; border-radius: 12px; background: var(--bg-alt); display: flex; align-items: center; justify-content: center; color: var(--text-muted); }

.msg-typing-row { padding: 4px 0 10px; }
.msg-typing-bubble { display: inline-flex; gap: 4px; background: var(--card); border: 1px solid var(--border); padding: 10px 14px; border-radius: 16px; border-bottom-left-radius: 4px; }
.msg-typing-bubble span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: msgTypingBounce 1.1s infinite; }
.msg-typing-bubble span:nth-child(2) { animation-delay: .15s; }
.msg-typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes msgTypingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ── Attachment preview & edit banner ── */
.msg-attach-preview { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--card); }
.msg-attach-preview img, .msg-attach-preview video { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; }
.msg-attach-info { flex: 1; font-size: .82rem; color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-attach-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; }

.msg-edit-banner { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: var(--indigo-light); border-top: 1px solid var(--border); font-size: .82rem; color: var(--indigo); font-weight: 600; }
.msg-edit-banner button { background: none; border: none; color: var(--indigo); cursor: pointer; }

/* ── Composer ── */
.msg-composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
  position: relative;
}
.msg-input-wrap {
  flex: 1; border-radius: 22px; padding: 8px 16px; display: flex; align-items: center;
  min-height: 42px; box-sizing: border-box;
  background: #E4E7EC; /* solid fallback for browsers without color-mix() support (older Android WebView) */
  background: color-mix(in srgb, var(--bg-alt) 75%, white 10%);
  border: 1.5px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.12);
  transition: border-color .15s, background .15s;
}
[data-theme="dark"] .msg-input-wrap {
  background: #262A33; /* solid fallback for browsers without color-mix() support */
  background: color-mix(in srgb, var(--bg-alt) 80%, white 12%);
}
.msg-input-wrap:focus-within {
  border-color: var(--coral);
  background: #E9EDFB;
}
[data-theme="dark"] .msg-input-wrap:focus-within { background: color-mix(in srgb, var(--bg-alt) 80%, white 16%); }
.msg-input-wrap textarea {
  width: 100%; border: none; background: transparent !important; outline: none; resize: none;
  font-family: var(--font-body); font-size: .9rem; color: var(--text-main) !important;
  -webkit-text-fill-color: var(--text-main); caret-color: var(--text-main);
  max-height: 120px; min-height: 22px; line-height: 1.4;
}
.msg-input-wrap textarea::placeholder {
  color: var(--text-muted) !important; opacity: 1 !important; -webkit-text-fill-color: var(--text-muted);
}
.msg-send-btn { background: var(--coral); color: #fff; }
.msg-send-btn:hover { background: var(--coral); opacity: .9; }
.msg-mic-btn.recording { background: #dc2626; color: #fff; }
.msg-mic-btn {
  width: 46px; height: 46px; font-size: 1.2rem;
  background: var(--coral); color: #fff;
}
.msg-mic-btn:hover { background: var(--coral); opacity: .9; }

.msg-recording-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 66px; background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
}
.msg-rec-dot { width: 11px; height: 11px; border-radius: 50%; background: #dc2626; animation: msgPulse 1s infinite; }
@keyframes msgPulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
#msg-rec-timer { font-weight: 700; color: var(--text-main); font-variant-numeric: tabular-nums; }
.msg-rec-hint { flex: 1; text-align: center; font-size: .78rem; color: var(--text-muted); }
#msg-rec-cancel-btn { background: var(--bg-alt); border: none; width: 38px; height: 38px; border-radius: 50%; color: #dc2626; cursor: pointer; }

/* ── Long-press context menu ── */
.msg-ctx-backdrop { position: fixed; inset: 0; background: transparent; z-index: 1165; display: none; pointer-events: none; }
.msg-ctx-backdrop.open { display: block; pointer-events: auto; }
.msg-ctx-menu {
  position: fixed; z-index: 1170; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 6px; min-width: 160px;
  display: none; flex-direction: column;
}
.msg-ctx-menu.open { display: flex; }
.msg-ctx-menu button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: none; border: none; text-align: left; cursor: pointer; font-size: .85rem; color: var(--text-dim); }
.msg-ctx-menu button:hover { background: var(--bg-alt); }

/* ── Lightbox ── */
.msg-lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 1150; display: none; align-items: center; justify-content: center; pointer-events: none; }
.msg-lightbox.open { pointer-events: auto; display: flex; }
.msg-lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
.msg-lightbox-close { position: absolute; top: 18px; right: 18px; width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; border: none; font-size: 1.1rem; cursor: pointer; }

/* ── Modals (report / new chat) ── */
.msg-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1160; display: none; align-items: center; justify-content: center; padding: 20px; pointer-events: none; }
.msg-modal-overlay.open { display: flex; pointer-events: auto; }
/* The member action sheet (promote/demote/remove) opens ON TOP of the
   group-info panel (z-index:1160), so it needs to sit above that, not
   just above the base .msg-ctx-menu z-index used elsewhere. */
#msg-member-menu { z-index: 1180; }
.msg-modal { background: var(--card); border-radius: var(--r-lg); padding: 22px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.msg-modal h3 { margin: 0 0 6px; font-family: var(--font-display); color: var(--text-main); }
.msg-modal p { margin: 0 0 14px; font-size: .84rem; color: var(--text-muted); }
.msg-modal textarea { width: 100%; border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 12px; font-family: var(--font-body); font-size: .86rem; resize: vertical; background: var(--bg-alt); color: var(--text-main); box-sizing: border-box; }
.msg-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.msg-btn-ghost { background: var(--bg-alt); color: var(--text-dim); border: none; padding: 10px 18px; border-radius: var(--r-pill); font-weight: 600; cursor: pointer; font-size: .85rem; }
.msg-btn-danger { background: #dc2626; color: #fff; border: none; padding: 10px 18px; border-radius: var(--r-pill); font-weight: 700; cursor: pointer; font-size: .85rem; }
.msg-modal-search { margin: 0 0 12px; }
.msg-newchat-results { max-height: 320px; overflow-y: auto; }
.msg-newchat-row { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: var(--r-md); cursor: pointer; }
.msg-newchat-row:hover { background: var(--bg-alt); }
.msg-newchat-name { font-weight: 700; font-size: .88rem; color: var(--text-main); }
.msg-newchat-username { font-size: .76rem; color: var(--text-muted); }

/* ── New group / group info ── */
.msg-modal-lg { max-width: 480px; }
.msg-btn-primary { background: var(--coral); color: #fff; border: none; padding: 10px 18px; border-radius: var(--r-pill); font-weight: 700; cursor: pointer; font-size: .85rem; }
.msg-btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.msg-newgroup-entry {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: none; padding: 10px 6px; margin-bottom: 8px;
  cursor: pointer; text-align: left; border-radius: var(--r-md); font-weight: 700; color: var(--text-main); font-size: .88rem;
}
.msg-newgroup-entry:hover { background: var(--bg-alt); }
.msg-newgroup-entry-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--coral); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem; }

.msg-newgroup-header { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.msg-newgroup-avatar-btn {
  width: 60px; height: 60px; border-radius: 50%; background: var(--bg-alt); border: 1.5px dashed var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); cursor: pointer; flex-shrink: 0; font-size: 1.1rem;
  position: relative; overflow: hidden;
}
.msg-newgroup-avatar-btn img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.msg-avatar-edit-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; color: #fff; }
.msg-newgroup-name-input {
  flex: 1; border: none; border-bottom: 1.5px solid var(--border); background: transparent; outline: none;
  font-family: var(--font-body); font-size: 1rem; font-weight: 700; color: var(--text-main); padding: 8px 4px;
}
.msg-newgroup-name-input:focus { border-bottom-color: var(--coral); }
.msg-newgroup-name-input[readonly] { border-bottom-color: transparent; cursor: default; }

.msg-newgroup-selected { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; max-height: 90px; overflow-y: auto; }
.msg-newgroup-chip { display: flex; align-items: center; gap: 6px; background: var(--coral-light); color: var(--coral); border-radius: var(--r-pill); padding: 4px 6px 4px 4px; font-size: .78rem; font-weight: 600; }
.msg-newgroup-chip img, .msg-newgroup-chip .msg-avatar { width: 22px; height: 22px; font-size: .6rem; }
.msg-newgroup-chip button { background: none; border: none; color: var(--coral); cursor: pointer; font-size: .75rem; display: flex; }
.msg-newchat-row.selected { background: var(--coral-light); }

.msg-groupinfo-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; margin-bottom: 10px; }
.msg-groupinfo-head .msg-newgroup-avatar-btn { width: 84px; height: 84px; font-size: 1.6rem; }
.msg-groupinfo-head .msg-newgroup-name-input { text-align: center; font-size: 1.15rem; }
.msg-groupinfo-count { font-size: .82rem; color: var(--text-muted); }
.msg-groupinfo-members { max-height: 320px; overflow-y: auto; margin: 10px 0; }
.msg-groupinfo-row { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: var(--r-md); }
.msg-groupinfo-row:hover { background: var(--bg-alt); cursor: pointer; }
.msg-groupinfo-row-name { font-weight: 700; font-size: .87rem; color: var(--text-main); display: flex; align-items: center; gap: 6px; }
.msg-groupinfo-role-tag { font-size: .66rem; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: .02em; }
.msg-groupinfo-role-tag.owner { background: #fef3c7; color: #92400e; }
.msg-groupinfo-role-tag.admin { background: var(--coral-light); color: var(--coral); }
[data-theme="dark"] .msg-groupinfo-role-tag.owner { background: rgba(251,191,36,.15); color: #fbbf24; }

/* ── Group message sender label + system messages ── */
.msg-sender-label { font-size: .74rem; font-weight: 700; margin: 0 0 2px 2px; opacity: .85; }
.msg-system-row { text-align: center; margin: 10px 0; }
.msg-system-row span { background: var(--bg-alt); color: var(--text-muted); font-size: .74rem; padding: 5px 14px; border-radius: var(--r-pill); }

/* ── Reactions ── */
.msg-quick-react { display: flex; justify-content: space-between; padding: 4px 4px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.msg-quick-react button { background: none; border: none; font-size: 1.3rem; cursor: pointer; padding: 4px; border-radius: 50%; line-height: 1; transition: transform .1s; }
.msg-quick-react button:hover { transform: scale(1.25); background: var(--bg-alt); }
.msg-reaction-pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg-reaction-pill { display: inline-flex; align-items: center; gap: 3px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 1px 7px; font-size: .74rem; cursor: pointer; }
.msg-reaction-pill.mine { border-color: var(--coral); background: var(--coral-light); }
.msg-row.mine .msg-reaction-pills { justify-content: flex-end; }

/* ── Pinned banner ── */
.msg-pinned-banner { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--bg-alt); border-bottom: 1px solid var(--border); cursor: pointer; }
.msg-pinned-banner i.fa-thumbtack { color: var(--coral); flex-shrink: 0; }
.msg-pinned-banner-text { flex: 1; min-width: 0; font-size: .8rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-pinned-banner-count { font-size: .72rem; color: var(--text-muted); flex-shrink: 0; }

/* ── Reply preview (inside bubble + in the compose banner) ── */
.msg-reply-quote { border-left: 3px solid var(--coral); background: rgba(0,0,0,.06); border-radius: 6px; padding: 4px 8px; margin-bottom: 4px; font-size: .78rem; cursor: pointer; }
.msg-row.mine .msg-reply-quote { background: rgba(255,255,255,.15); }
.msg-reply-quote-name { font-weight: 700; }
.msg-reply-quote-text { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ── @Mention autocomplete + inline highlight ── */
.msg-mention-list { position: absolute; bottom: 64px; left: 12px; right: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-lg); max-height: 180px; overflow-y: auto; z-index: 30; }
.msg-mention-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.msg-mention-row:hover, .msg-mention-row.active { background: var(--bg-alt); }
.msg-mention-tag { color: var(--coral); font-weight: 700; }

/* ── Invite link row ── */
.msg-invite-link-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 6px 0; }
.msg-invite-link-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--bg-alt); color: var(--coral); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ── Privacy settings ── */
.msg-privacy-option { display: flex; align-items: flex-start; gap: 12px; padding: 12px 6px; cursor: pointer; border-bottom: 1px solid var(--border); }
.msg-privacy-option:last-child { border-bottom: none; }
.msg-privacy-option input { margin-top: 4px; }
.msg-privacy-option strong { display: block; font-size: .88rem; color: var(--text-main); }
.msg-privacy-option span { display: block; font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ── In-chat search ── */
.msg-inchat-search { margin: 8px 16px; }
.msg-inchat-search button { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.msg-inchat-results { max-height: 260px; overflow-y: auto; border-bottom: 1px solid var(--border); }
.msg-inchat-result-row { display: flex; flex-direction: column; gap: 2px; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.msg-inchat-result-row:hover { background: var(--bg-alt); }
.msg-inchat-result-row .who { font-size: .72rem; color: var(--text-muted); }
.msg-inchat-result-row .snippet { font-size: .85rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── QR code for invite link ── */
.msg-invite-qr { display: block; margin: 10px auto 0; border-radius: var(--r-md); border: 1px solid var(--border); }

/* ═══════════ Responsive: mobile single-pane behaviour ═══════════ */
@media (max-width: 900px) {
  .msg-app { border: none; height: calc(100vh - 64px); }
  .msg-list-pane { width: 100%; border-right: none; }
  .msg-conv-list { padding-bottom: 100px; }
  .msg-thread-pane { display: none; position: fixed; inset: 64px 0 0 0; z-index: 1000; background: var(--bg); }
  .msg-thread-placeholder { display: none; }
  .msg-app.thread-open .msg-list-pane { display: none; }
  .msg-app.thread-open .msg-thread-pane { display: flex; }
  .msg-back-btn { display: flex; }
  .msg-recording-bar { padding-bottom: env(safe-area-inset-bottom, 0px); }
}
@media (min-width: 901px) {
  .msg-back-btn { display: none !important; }
}

/* Hide the floating bottom-nav pill while a thread is open on mobile so the composer sits flush at the bottom */
body.msg-hide-bnav .lsf-bnav { display: none !important; }
