/* ============================================================
   message.css — X-style messaging (light + dark via shared-nav vars)
   ============================================================ */

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--xn-bg);
  color: var(--xn-fg);
}

/* ───── Layout grid override (desktop) ─────
   Collapsed sidebar (~72px) + chat list (380px) + conversation (flex) + groups (320px) */
@media (min-width: 1025px) {
  .x-layout.msg-layout {
    display: grid;
    grid-template-columns: 88px 380px minmax(0, 1fr);
    max-width: 100%;
    height: 100vh;
    gap: 0;
  }
}
@media (min-width: 1280px) {
  .x-layout.msg-layout {
    grid-template-columns: 88px 380px minmax(0, 1fr) 320px;
  }
}

/* ───── Collapsed shared sidebar (desktop only) ─────
   Pages set body.xn-collapsed to render the X sidebar as icon-only. */
@media (min-width: 1025px) {
  body.xn-collapsed .xn-sidebar {
    width: 72px !important;
    max-width: 72px !important;
    padding: 8px 6px 16px !important;
    align-items: center !important;
    left: 0 !important;
    position: sticky !important;
    height: 100vh;
  }
  body.xn-collapsed .xn-sidebar .xn-item {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    gap: 0;
    border-radius: 9999px;
  }
  body.xn-collapsed .xn-sidebar .xn-item span:not(.xn-badge) { display: none !important; }
  body.xn-collapsed .xn-sidebar .xn-item svg { width: 26px; height: 26px; }
  body.xn-collapsed .xn-sidebar .xn-item .xn-badge {
    position: absolute;
    top: 4px; right: 6px;
    margin: 0;
  }
  body.xn-collapsed:not(.xn-has-layout) { padding-left: 72px !important; }
}

/* Hide stray body padding from shared-nav defaults on this page */
@media (min-width: 1025px) {
  body.msg-page.xn-has-layout { padding: 0 !important; }
}

/* ───── Chat list pane ───── */
.msg-list-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--xn-border);
  height: 100vh;
  position: relative;
  background: var(--xn-bg);
  min-width: 0;
}
.msg-list-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  position: sticky; top: 0; z-index: 5;
  background: var(--xn-bg);
}
.msg-list-head h1 { font-size: 20px; font-weight: 800; margin: 0; flex: 1; }
.msg-mobile-back {
  display: none;
  background: transparent; border: 0; color: var(--xn-fg);
  padding: 6px; border-radius: 50%; cursor: pointer;
}
.msg-mobile-back:hover { background: var(--xn-hover); }
@media (max-width: 1024px) { .msg-mobile-back { display: inline-flex; } }

.msg-head-actions { display: flex; align-items: center; gap: 6px; }
.msg-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--xn-card); color: var(--xn-fg);
  border: 1px solid var(--xn-border); border-radius: 9999px;
  padding: 6px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.msg-pill:hover { background: var(--xn-hover); }
.msg-icon-btn {
  background: var(--xn-card); color: var(--xn-fg);
  border: 1px solid var(--xn-border); border-radius: 50%;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.msg-icon-btn:hover { background: var(--xn-hover); }

.msg-search-wrap {
  position: relative;
  margin: 4px 16px 12px;
}
.msg-search-wrap svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--xn-muted);
}
.msg-search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border-radius: 9999px;
  border: 1px solid transparent;
  background: var(--xn-card);
  color: var(--xn-fg);
  font: inherit;
  outline: none;
}
.msg-search-wrap input:focus { border-color: var(--xn-accent, #f4c542); background: var(--xn-bg); }

.msg-list { flex: 1; overflow-y: auto; }
.msg-list::-webkit-scrollbar { width: 6px; }
.msg-list::-webkit-scrollbar-thumb { background: var(--xn-border); border-radius: 6px; }

.thread-row {
  display: flex; gap: 12px; padding: 12px 16px;
  cursor: pointer; border-left: 2px solid transparent;
  transition: background .12s ease;
}
.thread-row:hover { background: var(--xn-hover); }
.thread-row.active { background: var(--xn-card); border-left-color: #f4c542; }
.thread-row img.avatar {
  width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.thread-row .meta { flex: 1; min-width: 0; }
.thread-row .meta-top {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
}
.thread-row .meta-top strong {
  font-size: 15px; font-weight: 700; color: var(--xn-fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-row .meta-top .time { font-size: 12px; color: var(--xn-muted); flex-shrink: 0; }
.thread-row .meta-preview {
  font-size: 14px; color: var(--xn-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.thread-row .unread-dot {
  flex-shrink: 0;
  background: #f4c542; color: #fff;
  border-radius: 9999px; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
}

.msg-skel .row {
  height: 60px; margin: 8px 16px; border-radius: 12px;
  background: linear-gradient(90deg, var(--xn-skeleton-base), var(--xn-skeleton-hi), var(--xn-skeleton-base));
  background-size: 200% 100%;
  animation: xnShimmer 1.4s ease-in-out infinite;
}
@keyframes xnShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
}
.skel-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  flex: 0 0 auto;
  background: linear-gradient(90deg, var(--xn-skeleton-base, #2a2f33), var(--xn-skeleton-hi, #3a4046), var(--xn-skeleton-base, #2a2f33));
  background-size: 200% 100%;
  animation: xnShimmer 1.4s ease-in-out infinite;
}
.skel-lines { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.skel-line {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--xn-skeleton-base, #2a2f33), var(--xn-skeleton-hi, #3a4046), var(--xn-skeleton-base, #2a2f33));
  background-size: 200% 100%;
  animation: xnShimmer 1.4s ease-in-out infinite;
}
.skel-line.short { width: 40%; height: 10px; }
.skel-line.medium { width: 70%; }
.skel-line.long { width: 90%; }

.msg-fab {
  position: absolute; bottom: 20px; right: 20px;
  width: 52px; height: 52px; border-radius: 50%;
  background: #f4c542; color: #fff; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(244,197,66,.4);
}
.msg-fab:hover { background: #d9a91f; }

/* ───── Thread pane ───── */
.msg-thread-pane {
  display: flex; flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--xn-border);
  background: var(--xn-bg);
  min-width: 0;
}

.msg-thread-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 32px;
}
.msg-thread-empty-inner { max-width: 320px; text-align: center; }
.msg-thread-empty h2 { font-size: 28px; font-weight: 800; margin: 0 0 8px; }
.msg-thread-empty p { color: var(--xn-muted); margin: 0 0 20px; }

.primary-pill {
  background: #f4c542; color: #fff; border: 0; cursor: pointer;
  padding: 12px 24px; border-radius: 9999px; font-weight: 700; font-size: 15px;
}
.primary-pill:hover { background: #d9a91f; }

/* HTML `hidden` must beat the display rules below */
.msg-page [hidden] { display: none !important; }

.msg-thread { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.msg-thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--xn-border);
  background: var(--xn-bg);
}
.msg-thread-back {
  display: none;
  background: transparent; border: 0; color: var(--xn-fg);
  padding: 6px; border-radius: 50%; cursor: pointer;
}
@media (max-width: 1024px) { .msg-thread-back { display: inline-flex; } }
.msg-thread-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.msg-thread-meta { flex: 1; min-width: 0; }
.msg-thread-meta strong { display: block; font-size: 16px; font-weight: 700; }
.msg-thread-meta span { display: block; font-size: 12px; color: var(--xn-muted); }

.msg-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 12px 0; display: flex; flex-direction: column; gap: 10px;
}
.msg-body::-webkit-scrollbar { width: 6px; }
.msg-body::-webkit-scrollbar-thumb { background: var(--xn-border); border-radius: 6px; }

.day-divider {
  align-self: center;
  font-size: 12px; color: var(--xn-muted);
  margin: 14px 0 8px;
}

.bubble-row { display: flex; align-items: flex-end; gap: 6px; max-width: 92%; }
.bubble-row.out { align-self: flex-end; flex-direction: row-reverse; padding-right: 6px; }
.bubble-row.in  { align-self: flex-start; padding-left: 6px; }
.bubble-column { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: 100%; }
.bubble-row.out .bubble-column { align-items: flex-end; }
.bubble-row.in  .bubble-column { align-items: flex-start; }

/* Group sender avatar (WhatsApp style) */
.bubble-avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  align-self: flex-end;
}
.bubble-row.out .bubble-avatar { display: none; }
.group-sender {
  font-size: 12.5px; font-weight: 700; color: #f4c542;
  padding: 0 4px; display: inline-flex; align-items: center; gap: 4px;
}

/* Verified badge */
.verified-badge { display: inline-flex; align-items: center; vertical-align: -2px; margin-left: 3px; }
.verified-badge svg { display: block; }

/* Google Material old-style spinner */
.msg-loading { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 0; }
.google-spinner { width: 44px; height: 44px; animation: gs-rotate 1.6s linear infinite; }
.google-spinner svg { width: 100%; height: 100%; }
.google-spinner .gs-path {
  stroke: #f4c542;
  stroke-linecap: round;
  animation: gs-dash 1.4s ease-in-out infinite;
}
@keyframes gs-rotate { 100% { transform: rotate(360deg); } }
@keyframes gs-dash {
  0%   { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
  50%  { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
  100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}
.bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: 15px; line-height: 1.4;
  word-wrap: break-word; white-space: pre-wrap;
  display: inline-flex; align-items: baseline; gap: 8px; position: relative;
}
.bubble-row.out .bubble {
  background: #f4c542; color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-row.in .bubble {
  background: var(--xn-card); color: var(--xn-fg);
  border-bottom-left-radius: 4px;
}
.bubble .bubble-time {
  font-size: 11px; opacity: .75; flex-shrink: 0;
}
.bubble-row.out .bubble .bubble-time { color: rgba(255,255,255,.85); }
.bubble img.bubble-media, .bubble video.bubble-media {
  max-width: 100%; border-radius: 12px; display: block;
}
/* Media-only bubbles: no card background, no padding, media floats free */
.bubble.media-only {
  padding: 0 !important;
  background: transparent !important;
  border-radius: 14px;
  overflow: hidden;
  display: block;
  min-width: 200px;
  max-width: min(360px, 78vw);
}
.bubble.media-only .bubble-media,
.bubble.media-only .video-player,
.bubble.media-only img {
  width: 100%; height: auto; border-radius: 14px; display: block;
}
.bubble.media-only .media-meta {
  position: absolute; right: 8px; bottom: 6px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,.55); color: #fff;
  font-size: 11px;
}
.bubble.media-only .media-meta .bubble-time { color: #fff; opacity: .95; }
.bubble.media-only .media-meta .bubble-ticks { filter: brightness(1.6); }
.bubble-status {
  font-size: 11px; color: var(--xn-muted); padding: 2px 6px;
}
.bubble-status.failed { color: #ef4444; cursor: pointer; }
.bubble-status.failed::before { content: "↻ "; }

.msg-typing {
  align-self: flex-start; display: inline-flex; gap: 4px; padding: 8px 16px;
}
.msg-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--xn-muted);
  animation: bounce 1.2s infinite;
}
.msg-typing span:nth-child(2) { animation-delay: .15s; }
.msg-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity:.5 } 40% { transform: translateY(-4px); opacity:1 } }

.msg-composer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--xn-border);
  background: var(--xn-bg);
}
.composer-btn {
  background: transparent; border: 0; color: #f4c542;
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.composer-btn:hover { background: rgba(244,197,66,.1); }
.composer-btn.recording { background: #ef4444; color:#fff; box-shadow: 0 0 0 4px rgba(239,68,68,.25); animation: micPulse 1s ease-in-out infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 4px rgba(239,68,68,.25);} 50% { box-shadow: 0 0 0 8px rgba(239,68,68,.15);} }
.composer-input {
  flex: 1; background: var(--xn-card); color: var(--xn-fg);
  border: 1px solid transparent; border-radius: 9999px;
  padding: 10px 16px; font: inherit; outline: none;
}
.composer-input:focus { border-color: #f4c542; background: var(--xn-bg); }
.composer-send {
  background: #f4c542; color: #fff; border: 0;
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.composer-send:disabled { opacity: .5; cursor: not-allowed; }
.composer-send:hover:not(:disabled) { background: #d9a91f; }

/* ───── Right rail (Groups) ───── */
.msg-rightrail {
  display: none;
  height: 100vh; overflow-y: auto;
  padding: 16px;
  border-left: 1px solid var(--xn-border);
  background: var(--xn-bg);
}
@media (min-width: 1280px) { .msg-rightrail { display: block; } }
.rr-card {
  background: var(--xn-card); border-radius: 16px; padding: 12px 16px; margin-bottom: 16px;
}
.rr-card-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.rr-card-head h3 { margin: 0; font-size: 18px; font-weight: 800; }
.link-btn {
  background: transparent; border: 0; color: #f4c542;
  font-weight: 600; cursor: pointer; padding: 4px 8px; border-radius: 9999px;
}
.link-btn:hover { background: rgba(244,197,66,.1); }
.rr-groups { display: flex; flex-direction: column; gap: 4px; }
.rr-group {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px; border-radius: 12px; cursor: pointer;
}
.rr-group:hover { background: var(--xn-hover); }
.rr-group img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.rr-group .gmeta strong { display: block; font-size: 14px; font-weight: 700; }
.rr-group .gmeta span { display: block; font-size: 12px; color: var(--xn-muted); }
.rr-empty { color: var(--xn-muted); font-size: 14px; padding: 6px; }

/* ───── Mobile (≤1024px): single-pane navigation ───── */
@media (max-width: 1024px) {
  body.thread-open { overflow: hidden; }
  .x-layout.msg-layout { display: block; }
  .msg-rightrail { display: none; }
  .msg-list-pane { height: calc(100vh - 0px); border-right: none; }
  .msg-thread-pane {
    position: fixed; inset: 0; z-index: 80; height: 100vh; height: 100dvh;
    transform: translateX(100%); transition: transform .2s ease;
  }
  body.thread-open .msg-thread-pane { transform: translateX(0); }
  body.thread-open .msg-list-pane,
  body.thread-open .xn-sidebar { display: none; }

  /* Pin composer to the bottom of the viewport on phones */
  .msg-thread { height: 100%; }
  .msg-composer {
    position: sticky;
    bottom: 0;
    flex: 0 0 auto;
    z-index: 10;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--xn-bg);
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
    flex-wrap: nowrap;
  }
  .msg-composer .composer-input {
    min-width: 0;
    flex: 1 1 auto;
    padding: 9px 14px;
  }
  .msg-composer .composer-btn,
  .msg-composer .composer-send {
    width: 38px; height: 38px;
  }
  .msg-body { padding-bottom: 16px; }
}

/* very small phones */
@media (max-width: 380px) {
  .msg-composer { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .msg-composer .composer-input { padding: 8px 12px; font-size: 14px; }
  .msg-composer .composer-btn,
  .msg-composer .composer-send { width: 34px; height: 34px; }
  .msg-composer .composer-btn svg,
  .msg-composer .composer-send svg { width: 18px; height: 18px; }
}

/* ───── Swipe-to-reply feedback ───── */
.bubble-row { transition: transform .12s ease; position: relative; }
.bubble-row .reply-hint {
  position: absolute; top: 50%; transform: translateY(-50%);
  opacity: 0; transition: opacity .12s ease;
  color: #f4c542; font-size: 18px; pointer-events: none;
}
.bubble-row.in .reply-hint  { left: -22px; }
.bubble-row.out .reply-hint { right: -22px; }
.bubble-row.reply-armed .reply-hint { opacity: 1; }

/* ───── Reply quote inside bubble ───── */
.reply-quote {
  align-self: stretch;
  max-width: 320px;
  background: var(--xn-card);
  border-left: 3px solid #f4c542;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--xn-fg);
  opacity: .9;
}
.bubble-row.out .reply-quote { background: rgba(244,197,66,.18); border-left-color: #fff; color: var(--xn-fg); }
.reply-quote strong { display: block; color: #f4c542; font-size: 12px; margin-bottom: 2px; }
.reply-quote span   { display: block; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* legacy nested reply-quote inside bubble (kept safe if it ever renders) */
.bubble .reply-quote-legacy {
  display: block;
  border-left: 3px solid #f4c542;
  background: rgba(244,197,66,.12);
  padding: 6px 8px; margin-bottom: 4px;
  border-radius: 6px;
  font-size: 12px; line-height: 1.3;
  max-width: 100%;
}

/* ───── Reply preview above composer ───── */
.reply-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--xn-card);
  border-top: 1px solid var(--xn-border);
}
.reply-preview .rp-bar { width: 3px; align-self: stretch; background: #f4c542; border-radius: 2px; }
.reply-preview .rp-meta { flex: 1; min-width: 0; }
.reply-preview .rp-meta strong { display: block; color: #f4c542; font-size: 12px; }
.reply-preview .rp-meta span { display: block; font-size: 13px; color: var(--xn-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview .rp-close {
  background: transparent; border: 0; color: var(--xn-muted); cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; font-size: 14px;
}
.reply-preview .rp-close:hover { background: var(--xn-hover); color: var(--xn-fg); }

/* ───── Action sheet (long-press menu) ───── */
.msg-action-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 240; backdrop-filter: blur(2px);
  animation: fadeIn .15s ease;
}
.msg-action-sheet {
  position: fixed; left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(420px, 100%);
  background: var(--xn-bg);
  border: 1px solid var(--xn-border);
  border-bottom: 0;
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
  z-index: 250;
  display: flex; flex-direction: column; gap: 4px;
  animation: sheetUp .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.asheet-reactions {
  display: flex; justify-content: space-between; gap: 4px;
  padding: 8px 4px 12px;
  border-bottom: 1px solid var(--xn-border);
  margin-bottom: 6px;
  overflow-x: auto;
}
.asheet-reactions button {
  background: transparent; border: 0; cursor: pointer;
  font-size: 24px; padding: 4px 6px; border-radius: 50%;
  flex: 0 0 auto;
  transition: transform .12s ease;
}
.asheet-reactions button:hover { transform: scale(1.25); }
.asheet-item {
  background: transparent; border: 0; cursor: pointer;
  color: var(--xn-fg); text-align: left;
  padding: 12px 14px; border-radius: 10px;
  font-size: 15px;
}
.asheet-item:hover { background: var(--xn-hover); }
.asheet-item.danger { color: #ef4444; }
@media (min-width: 700px) {
  .msg-action-sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 16px; border-bottom: 1px solid var(--xn-border); }
  @keyframes sheetUp { from { transform: translate(-50%, -46%); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
}

/* ───── Modals ───── */
.msg-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 20, 25, .5); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.msg-modal[hidden] { display: none; }
.msg-modal-card {
  background: var(--xn-bg); color: var(--xn-fg);
  width: min(420px, 100%); max-height: 80vh;
  border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg-modal-card header {
  display: flex; align-items: center; justify-content: space-between;
}
.msg-modal-card header h3 { margin: 0; font-size: 18px; }
.msg-search-input {
  width: 100%; background: var(--xn-card); color: var(--xn-fg);
  border: 1px solid var(--xn-border); border-radius: 9999px;
  padding: 10px 14px; font: inherit; outline: none;
}
.msg-user-results { overflow-y: auto; flex: 1; max-height: 50vh; }
.msg-user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px; border-radius: 10px; cursor: pointer;
}
.msg-user-row:hover { background: var(--xn-hover); }
.msg-user-row img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.msg-user-row .u-meta strong { display: block; font-size: 14px; }
.msg-user-row .u-meta { flex: 1; min-width: 0; }
.msg-user-row .u-meta span { display: block; font-size: 12px; color: var(--xn-muted); }
.msg-user-row.picked { background: color-mix(in srgb, var(--xn-accent, #f4c542) 14%, transparent); }
.msg-user-row .pick-mark {
  width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--xn-card); border: 1px solid var(--xn-border);
  font-size: 14px; line-height: 1; color: var(--xn-fg); flex: 0 0 auto;
}
.msg-user-row.picked .pick-mark { background: var(--xn-accent, #f4c542); color: #fff; border-color: transparent; }
#groupChosen { min-height: 28px; margin-top: 8px; }

.msg-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.msg-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--xn-card); border-radius: 9999px; padding: 4px 10px;
  font-size: 13px;
}
.msg-chip .x { cursor: pointer; opacity: .7; }

/* ───── Toast ───── */
.msg-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(15, 20, 25, .9); color: #fff;
  padding: 10px 16px; border-radius: 9999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 300;
  max-width: min(92vw, 680px);
  white-space: normal;
  overflow-wrap: anywhere;
}
.msg-toast.show { opacity: 1; }

/* ───── Custom voice player (waveform) ───── */
.voice-player {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 6px;
  min-width: 180px;
}
.voice-play {
  background: rgba(255,255,255,.2); color: inherit;
  border: 0; cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.bubble-row.in .voice-play { background: rgba(244,197,66,.15); color: #f4c542; }
.voice-play svg { width: 14px; height: 14px; }
.voice-wave {
  flex: 1 1 auto;
  height: 32px;
  display: block;
  cursor: pointer;
  min-width: 100px;
}
.voice-time { font-size: 11px; opacity: .8; flex: 0 0 auto; }

/* ───── Reaction picker ───── */
.reaction-picker {
  position: absolute;
  display: flex; gap: 4px;
  padding: 6px 8px;
  background: var(--xn-card, #16181c);
  border: 1px solid var(--xn-border, #2f3336);
  border-radius: 9999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  z-index: 150;
  animation: reactionPop .15s ease-out;
}
@keyframes reactionPop {
  from { transform: translateY(6px) scale(.85); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.reaction-picker button {
  background: transparent; border: 0; cursor: pointer;
  font-size: 22px; padding: 4px 6px; border-radius: 50%;
  transition: transform .12s ease;
}
.reaction-picker button:hover { transform: scale(1.3); }
.bubble-reactions {
  display: inline-flex; gap: 4px; margin-top: 4px; flex-wrap: wrap;
}
.bubble-row.out .bubble-reactions { justify-content: flex-end; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--xn-card, #16181c);
  border: 1px solid var(--xn-border, #2f3336);
  border-radius: 9999px;
  padding: 2px 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ───── Mic recording UI (slide-to-cancel / lock) ───── */
.mic-overlay {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--xn-bg);
  border-top: 1px solid var(--xn-border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px;
  z-index: 120;
  font-size: 14px;
}
.mic-overlay .mic-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #ef4444;
  animation: micBlink 1s ease-in-out infinite;
}
@keyframes micBlink { 50% { opacity: .3; } }
.mic-overlay .mic-timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.mic-overlay .mic-hint { flex: 1; color: var(--xn-muted); text-align: center; }
.mic-overlay .mic-cancel,
.mic-overlay .mic-send {
  background: transparent; border: 0; cursor: pointer;
  color: var(--xn-fg); font-weight: 600; padding: 6px 12px; border-radius: 9999px;
}
.mic-overlay .mic-cancel { color: #ef4444; }
.mic-overlay .mic-send { background: #f4c542; color: #fff; }

.mic-lock-indicator {
  position: absolute;
  bottom: 60px; right: 16px;
  background: var(--xn-card);
  border: 1px solid var(--xn-border);
  border-radius: 9999px;
  padding: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  z-index: 110;
  color: var(--xn-muted);
  font-size: 11px;
}
.mic-lock-indicator.armed { color: #f4c542; border-color: #f4c542; }

/* ── presence + delivery ticks (Phase 1 realtime) ─────────────── */
.peer-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  margin-right: 6px;
  vertical-align: middle;
}
.peer-dot.online { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.15); }
.peer-recording { color: #f4c542; font-weight: 500; }

.bubble-ticks {
  display: inline-block;
  width: 16px; height: 11px;
  margin-left: 4px;
  vertical-align: middle;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 11px;
  flex-shrink: 0;
}
.bubble-ticks.tick-sent {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 11' fill='none' stroke='%23cbd5e1' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='3,6 7,10 14,2'/></svg>");
}
.bubble-ticks.tick-delivered {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 11' fill='none' stroke='%23cbd5e1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='1,6 4,9 10,2'/><polyline points='6,9 13,2'/></svg>");
}
.bubble-ticks.tick-read {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 11' fill='none' stroke='%2334b7f1' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='1,6 4,9 10,2'/><polyline points='6,9 13,2'/></svg>");
}
.bubble-ticks.tick-sending {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23cbd5e1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='8' cy='8' r='6'/><polyline points='8,4.5 8,8 11,10'/></svg>");
  background-size: 12px 12px;
}

/* ── Custom video player ── */
.video-player { position: relative; background: #000; border-radius: 14px; overflow: hidden; }
.video-player > video { width: 100%; display: block; background: #000; }
.video-player .vp-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,0));
  color: #fff; opacity: 0; transition: opacity .2s;
}
.video-player:hover .vp-controls,
.video-player.paused .vp-controls,
.video-player:focus-within .vp-controls { opacity: 1; }
.video-player .vp-btn {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  padding: 4px; display: inline-flex; align-items: center; justify-content: center;
}
.video-player .vp-btn svg { width: 18px; height: 18px; }
.video-player .vp-seek {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 3px; background: rgba(255,255,255,.35); border-radius: 3px; outline: none;
}
.video-player .vp-seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%;
  background: #f4c542; cursor: pointer; border: 0;
}
.video-player .vp-seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #f4c542; cursor: pointer; border: 0; }
.video-player .vp-time { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .95; }
.video-player .vp-bigplay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.15); color: #fff; border: 0; cursor: pointer;
}
.video-player.playing .vp-bigplay { display: none; }
.video-player .vp-bigplay svg { width: 48px; height: 48px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }

/* ── Group info: online dot on members + share row ── */
.chat-info-dialog .ci-member { position: relative; }
.chat-info-dialog .ci-member .online-dot {
  position: absolute; left: 30px; bottom: 8px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--xn-card, #fff);
}
.chat-info-dialog .ci-invite {
  display: flex; gap: 6px; margin: 8px 0;
}
.chat-info-dialog .ci-invite input {
  flex: 1; background: var(--xn-hover); border: 1px solid var(--xn-border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; color: var(--xn-fg);
}
.chat-info-dialog .ci-invite button {
  background: #f4c542; color: #000; border: 0; border-radius: 8px;
  padding: 8px 12px; font-weight: 700; cursor: pointer; font-size: 12.5px;
}
/* In light mode: use darker grey for readability on light bubbles (only outgoing ticks show, but keep flexibility) */
.bubble-row.in .bubble-ticks.tick-sent,
.bubble-row.in .bubble-ticks.tick-delivered,
.bubble-row.in .bubble-ticks.tick-sending {
  filter: brightness(.6);
}

/* ═════════ Phase 2/3/4 additions ═════════ */

/* Phase 3 — tighter voice bubble */
.bubble .voice-player { min-width: 160px; max-width: 220px; padding: 2px 4px; }
.bubble-row .voice-player + .bubble-time { margin-left: 4px; }
@media (max-width: 640px) {
  .bubble-row { max-width: 88%; }
  .bubble .voice-player { min-width: 140px; max-width: min(220px, 60vw); }
  .voice-wave { min-width: 70px; }
  .bubble { padding: 8px 12px; font-size: 14.5px; }
}

/* Phase 2 — Link preview card (WhatsApp style: full-width inside bubble column) */
.link-preview {
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: var(--xn-card);
  border: 1px solid var(--xn-border);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  min-width: 240px;
  max-width: 320px;
  align-self: stretch;
}
.bubble-row.out .link-preview { background: rgba(0,0,0,.18); border-color: rgba(255,255,255,.15); color: inherit; }
.link-preview .lp-img { width: 100%; height: 150px; object-fit: cover; flex: 0 0 auto; background: var(--xn-hover); display: block; }
.link-preview .lp-body { padding: 8px 12px; min-width: 0; }
.link-preview .lp-site { font-size: 11px; opacity: .7; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 2px; }
.link-preview .lp-title { font-size: 13.5px; font-weight: 700; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-preview .lp-desc { font-size: 12px; opacity: .75; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-preview.lp-loading, .link-preview.lp-pending { display: none; }

/* Phase 4 — Chat info dialog */
.chat-info-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 400; animation: fadeIn .15s ease-out;
}
.chat-info-dialog {
  position: fixed;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(420px, 94vw);
  max-height: 88vh; overflow-y: auto;
  background: var(--xn-bg);
  border: 1px solid var(--xn-border);
  border-radius: 18px;
  z-index: 401;
  padding: 18px 18px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: pop .15s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -46%) scale(.96); opacity: 0; } to { transform: translate(-50%,-50%) scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.chat-info-dialog .ci-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: 0; color: var(--xn-fg);
  font-size: 18px; width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
}
.chat-info-dialog .ci-close:hover { background: var(--xn-hover); }
.chat-info-dialog .ci-hero { text-align: center; padding: 6px 0 12px; }
.chat-info-dialog .ci-hero img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; }
.chat-info-dialog .ci-hero h3 { margin: 10px 0 2px; font-size: 20px; font-weight: 800; }
.chat-info-dialog .ci-hero p  { margin: 0; color: var(--xn-muted); font-size: 13px; }
.chat-info-dialog .ci-actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  padding: 8px 4px 16px; border-bottom: 1px solid var(--xn-border);
}
.chat-info-dialog .ci-actions button {
  background: transparent; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--xn-fg); font-size: 12px;
}
.chat-info-dialog .ci-actions button svg {
  background: var(--xn-card); border: 1px solid var(--xn-border);
  border-radius: 50%; padding: 10px; width: 42px; height: 42px;
  color: #f4c542;
}
.chat-info-dialog .ci-actions button:hover svg { background: rgba(244,197,66,.12); }
.chat-info-dialog .ci-rows { display: flex; flex-direction: column; padding-top: 10px; }
.chat-info-dialog .ci-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 6px; border-bottom: 1px solid var(--xn-border);
  background: transparent; border-left: 0; border-right: 0; border-top: 0;
  color: var(--xn-fg); font-size: 14.5px; cursor: pointer; text-align: left; width: 100%;
}
.chat-info-dialog .ci-row.danger { color: #ef4444; }
.chat-info-dialog .ci-row .ci-val { color: var(--xn-muted); font-size: 13px; }
.chat-info-dialog .ci-section-title { padding: 12px 6px 6px; font-size: 12px; text-transform: uppercase; color: var(--xn-muted); letter-spacing: .4px; }
.chat-info-dialog .ci-members { display: flex; flex-direction: column; }
.chat-info-dialog .ci-member {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px; border-bottom: 1px solid var(--xn-border);
}
.chat-info-dialog .ci-member img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.chat-info-dialog .ci-mmeta { flex: 1; min-width: 0; }
.chat-info-dialog .ci-mmeta strong { display: block; font-size: 14px; }
.chat-info-dialog .ci-mmeta span { display: block; font-size: 12px; color: var(--xn-muted); }
.chat-info-dialog .ci-mact {
  background: transparent; border: 1px solid var(--xn-border);
  border-radius: 9999px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--xn-fg);
}
.chat-info-dialog .ci-mact.danger { color: #ef4444; border-color: rgba(239,68,68,.4); }
.chat-info-dialog .ci-loading { padding: 40px 0; text-align: center; color: var(--xn-muted); }

/* threadAvatar clickable */
.msg-thread-avatar { cursor: pointer; }

/* ── chat gift modal ── */
.chat-gift-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; max-height:340px; overflow-y:auto; padding:8px 4px; }
.chat-gift-item { display:flex; flex-direction:column; align-items:center; gap:2px; padding:10px 6px; border:1px solid rgba(0,0,0,.08); border-radius:12px; cursor:pointer; background:#fff; transition:all .15s; }
.chat-gift-item:hover { border-color:#f4c542; transform:translateY(-1px); }
.chat-gift-item.selected { border-color:#f4c542; background:#fff8e1; }
.chat-gift-item .cg-emoji { font-size:26px; }
.chat-gift-item .cg-name { font-size:11px; color:#555; text-align:center; }
.chat-gift-item .cg-cost { font-size:11px; color:#b8860b; font-weight:600; }
.cg-balance { text-align:center; font-size:14px; margin:8px 0; color:#333; }
.cg-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:12px; }

/* group photo picker */
.group-photo-picker { display:flex; justify-content:center; margin:8px 0 12px; }
.gp-avatar { position:relative; width:84px; height:84px; border-radius:50%; overflow:hidden; cursor:pointer; display:block; border:2px solid #f4c542; }
.gp-avatar img { width:100%; height:100%; object-fit:cover; display:block; }
.gp-cam { position:absolute; right:0; bottom:0; background:#f4c542; color:#000; width:26px; height:26px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:13px; border:2px solid #fff; }

.edited-tag { font-size:11px; opacity:.6; margin-left:4px; font-style:italic; }
#threadName { cursor:pointer; }
.bubble-avatar, .group-sender { cursor:pointer; }

/* ── System message pill (e.g. "admin changed the group icon") ── */
.sys-msg { display:flex; justify-content:center; margin: 10px 0; }
.sys-msg-pill {
  background: rgba(120,120,120,.18);
  color: var(--xn-muted, #8b98a5);
  padding: 6px 14px; border-radius: 9999px;
  font-size: 12.5px; font-weight: 500;
  max-width: 80%; text-align: center;
}

/* ── Premium gift bubble ── */
.bubble-gift {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  min-width: 220px; max-width: 320px;
  padding: 14px 16px; border-radius: 20px;
  background: linear-gradient(135deg, #b8860b 0%, #f4c542 45%, #ffd97a 100%);
  color: #1a1300;
  box-shadow: 0 6px 22px rgba(180,130,20,.35), inset 0 0 0 1px rgba(255,255,255,.35);
}
.bubble-gift.in  { border-bottom-left-radius: 6px; }
.bubble-gift.out { border-bottom-right-radius: 6px; }
.bubble-gift .gift-shine {
  position:absolute; inset:0;
  background: radial-gradient(120% 60% at 20% 0%, rgba(255,255,255,.55), transparent 60%);
  pointer-events:none;
}
.bubble-gift .gift-emoji {
  font-size: 40px; line-height:1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.25));
}
.bubble-gift .gift-meta { display:flex; flex-direction:column; gap:2px; min-width:0; }
.bubble-gift .gift-title { font-size: 11px; text-transform: uppercase; letter-spacing:.6px; opacity:.75; font-weight:700; }
.bubble-gift .gift-name  { font-size: 16px; font-weight: 800; }
.bubble-gift .gift-stars { font-size: 13px; font-weight: 700; color:#4a2f00; }
.bubble-gift .gift-time  { font-size: 11px; align-self:flex-end; opacity:.7; font-weight:600; }

/* ── Gift-modal recipient picker ── */
.cg-recipient-wrap { display:flex; flex-direction:column; gap:8px; margin: 4px 0 10px; }
.cg-recipient-label { font-size:12px; font-weight:700; color:var(--xn-muted, #8b98a5); text-transform:uppercase; letter-spacing:.4px; }
.cg-member-row { display:flex; gap:10px; overflow-x:auto; padding-bottom:4px; }
.cg-member {
  flex:0 0 auto; display:flex; flex-direction:column; align-items:center; gap:6px;
  padding:6px; border-radius:12px; background:transparent; border:2px solid transparent; cursor:pointer;
  min-width:64px;
}
.cg-member img { width:44px; height:44px; border-radius:50%; object-fit:cover; }
.cg-member span { font-size:11px; color:var(--xn-fg); max-width:64px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cg-member.selected { border-color:#f4c542; background:rgba(244,197,66,.12); }
.cg-empty { color:var(--xn-muted); font-size:13px; }

/* ── Save button spinner ── */
.btn-spinner {
  display:inline-block; width:14px; height:14px; margin-right:6px;
  border:2px solid rgba(255,255,255,.4); border-top-color:#fff;
  border-radius:50%; animation: btnspin .8s linear infinite; vertical-align:-2px;
}
@keyframes btnspin { to { transform: rotate(360deg); } }

/* ── Group info description block ── */
.ci-desc-block { padding: 10px 16px; border-bottom:1px solid var(--xn-border); }
.ci-desc-label { font-size:11px; font-weight:700; color:var(--xn-muted,#8b98a5); text-transform:uppercase; letter-spacing:.5px; margin-bottom:4px; }
.ci-desc-text  { font-size:14px; color:var(--xn-fg); white-space:pre-wrap; word-wrap:break-word; }
.ci-desc-text.empty { color:var(--xn-muted,#8b98a5); font-style:italic; }