/* ═══════════════════════════════════════════════════════════════════
   TiME 2026 — MASTER FIXES v1.0
   Loaded LAST — This is the single source of truth for all layout.
   DO NOT ADD BUBBLE/MSG RULES TO ANY OTHER FILE.
   ═══════════════════════════════════════════════════════════════════ */


/* ══════════════════════════════════════════
   1. MESSAGE ROW — Full-width flex row
   ══════════════════════════════════════════ */

.msg {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-end !important;
  gap: 8px !important;
  margin-bottom: 3px !important;
  width: 100% !important;
  max-width: 100% !important;
  position: relative !important;
  box-sizing: border-box !important;
  /* No width:fit-content here — we want the row to be full-width */
  /* so that justify-content can push bubbles left/right properly */
}

/* Outgoing: bubble hugs RIGHT side */
.msg.out {
  justify-content: flex-end !important;
}

/* Incoming: bubble hugs LEFT side */
.msg.in {
  justify-content: flex-start !important;
}

/* Avatar only shows for incoming */
.msg.out > .msg-av {
  display: none !important;
}


/* ══════════════════════════════════════════
   2. BUBBLE — Shrink-wraps its content
   ══════════════════════════════════════════ */

.bubble {
  /* Width: grow to fit text, never squish it */
  display: inline-block !important;
  width: auto !important;
  min-width: 60px !important;
  max-width: min(82%, 480px) !important;

  /* Prevent text compression */
  flex: 0 1 auto !important;
  flex-shrink: 0 !important;

  /* Layout */
  padding: 8px 13px 6px !important;
  border-radius: 18px !important;
  box-sizing: border-box !important;
  position: relative !important;
  transition: transform .15s ease, box-shadow .15s ease !important;
}

/* Mobile: slightly more width */
@media (max-width: 600px) {
  .bubble {
    max-width: min(88%, 340px) !important;
  }
}

/* Large desktop: cap width */
@media (min-width: 1200px) {
  .bubble {
    max-width: min(60%, 580px) !important;
  }
}

/* Emoji-only bubbles */
.msg.emoji-only .bubble {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 2.6rem !important;
  padding: 2px 4px !important;
  min-width: 0 !important;
}

/* Deleted messages */
.msg.msg-deleted .bubble {
  background: transparent !important;
  border: 1px dashed rgba(255,255,255,0.2) !important;
  color: rgba(255,255,255,0.4) !important;
  font-style: italic !important;
}


/* ══════════════════════════════════════════
   3. MSG-TEXT — Text rendering, never break words mid-character
   ══════════════════════════════════════════ */

.msg-text {
  display: block !important;
  font-size: .95rem !important;
  line-height: 1.6 !important;

  /* Arabic + English safe wrapping */
  white-space: pre-wrap !important;
  word-break: normal !important;          /* Never break inside words */
  overflow-wrap: break-word !important;   /* Break only very long URLs */

  /* Bidirectional text (Arabic RTL, English LTR, mixed = auto) */
  direction: auto !important;
  text-align: start !important;
  unicode-bidi: plaintext !important;

  margin: 0 !important;
  padding: 0 !important;
}

@media (max-width: 600px) {
  .msg-text {
    font-size: .9rem !important;
  }
}


/* ══════════════════════════════════════════
   4. MSG FOOTER — Time + tick, always at bottom-right
   ══════════════════════════════════════════ */

.msg-foot {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 3px !important;
  margin-top: 4px !important;
  direction: ltr !important;
  opacity: 0.75 !important;
}

.msg-time {
  font-size: .66rem !important;
  white-space: nowrap !important;
  letter-spacing: 0.2px !important;
}


/* ══════════════════════════════════════════
   5. BUBBLE COLORS — Dark mode
   ══════════════════════════════════════════ */

.msg.out .bubble {
  background: linear-gradient(135deg, rgba(183,33,255,0.95), rgba(100,0,200,0.9)) !important;
  color: #fff !important;
  border-bottom-right-radius: 4px !important;
  box-shadow: 0 2px 10px rgba(183,33,255,0.25) !important;
  border: none !important;
}

.msg.in .bubble {
  background: rgba(28,18,48,0.88) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
  color: #f0eaff !important;
  border: 1px solid rgba(183,33,255,0.09) !important;
  border-bottom-left-radius: 4px !important;
}

.msg.out:hover .bubble {
  transform: translateY(-1px) !important;
  box-shadow: 0 5px 20px rgba(183,33,255,0.35) !important;
}
.msg.in:hover .bubble {
  transform: translateY(-1px) !important;
  box-shadow: 0 5px 20px rgba(0,0,0,0.4) !important;
}


/* ══════════════════════════════════════════
   6. BUBBLE COLORS — Light mode
   ══════════════════════════════════════════ */

body.light-mode .msg.out .bubble {
  background: linear-gradient(135deg, #b721ff, #8b13ff) !important;
  color: #fff !important;
  border: none !important;
  box-shadow: 0 3px 14px rgba(183,33,255,0.3) !important;
}

body.light-mode .msg.in .bubble {
  background: #ffffff !important;
  color: #111 !important;
  border: 1px solid rgba(0,0,0,0.08) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07) !important;
}

body.light-mode .msg.in .msg-time   { color: rgba(0,0,0,0.45) !important; }
body.light-mode .msg.out .msg-time  { color: rgba(255,255,255,0.8) !important; }
body.light-mode .tick-sent,
body.light-mode .tick-delivered     { color: rgba(255,255,255,0.75) !important; }
body.light-mode .tick-read          { color: #1a9bd4 !important; }


/* ══════════════════════════════════════════
   7. TICK (read receipts)
   ══════════════════════════════════════════ */

.msg-tick { font-size: .82rem !important; line-height: 1 !important; }
.tick-sent      { color: rgba(255,255,255,0.5) !important; }
.tick-delivered { color: rgba(255,255,255,0.5) !important; }
.tick-read      { color: #34b7f1 !important; text-shadow: 0 0 6px rgba(52,183,241,0.45) !important; }


/* ══════════════════════════════════════════
   8. CHAT BOX / SCROLL CONTAINER
   ══════════════════════════════════════════ */

/* The scrollable message area */
#msgs-box,
.msgs-box,
[id*="msgs"] {
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
  padding: 12px 14px 8px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  width: 100% !important;
}


/* ══════════════════════════════════════════
   9. REPLY QUOTE INSIDE BUBBLE
   ══════════════════════════════════════════ */

.reply-quote {
  background: rgba(255,255,255,0.08) !important;
  border-right: 3px solid rgba(183,33,255,0.6) !important;
  border-radius: 6px !important;
  padding: 4px 8px !important;
  margin-bottom: 6px !important;
  font-size: .78rem !important;
  opacity: 0.85 !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
  max-width: 100% !important;
}

body.light-mode .reply-quote {
  background: rgba(0,0,0,0.06) !important;
  border-right-color: #b721ff !important;
}


/* ══════════════════════════════════════════
   10. IMAGES & MEDIA IN BUBBLES
   ══════════════════════════════════════════ */

.msg-img {
  max-width: 220px !important;
  max-height: 300px !important;
  border-radius: 10px !important;
  cursor: pointer !important;
  display: block !important;
  object-fit: cover !important;
}

@media (max-width: 480px) {
  .msg-img {
    max-width: 180px !important;
  }
}


/* ══════════════════════════════════════════
   11. CONTEXT MENU ACTIONS (hover)
   ══════════════════════════════════════════ */

.msg-actions {
  display: none !important;
  position: absolute !important;
  top: -14px !important;
  gap: 3px !important;
  background: rgba(10,5,25,0.9) !important;
  backdrop-filter: blur(8px) !important;
  padding: 3px 7px !important;
  border-radius: 10px !important;
  z-index: 20 !important;
  border: 1px solid rgba(255,255,255,0.07) !important;
}

.msg:hover .msg-actions { display: flex !important; }
.msg.out .msg-actions   { right: 0 !important; left: auto !important; }
.msg.in  .msg-actions   { left: 0 !important;  right: auto !important; }


/* ══════════════════════════════════════════
   12. PENDING MESSAGE (sending state)
   ══════════════════════════════════════════ */

.msg.pending .bubble {
  opacity: 0.65 !important;
}


/* ══════════════════════════════════════════
   13. GROUP START (space before new sender)
   ══════════════════════════════════════════ */

.msg.group-start {
  margin-top: 10px !important;
}
