/* =========================================================================
   MENSAGENS — densidade WhatsApp-mobile (compacto de verdade)

   Estratégia:
   - Container .chat-messages com padding mínimo
   - Bolha com padding pequeno (5/9/4) e fonte 13.5px
   - Tempo INLINE no final do texto via float, sem espaço extra reservado
   - Linhas adjacentes da mesma direção colam (margem 1px)
   - Mudança de direção dá um respiro pequeno (4px)
   ========================================================================= */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
  /* Em telas largas, limita a largura mas alinha à ESQUERDA pra não criar
     gap entre a lista de leads e o conteúdo. */
  max-width: 1000px;
  width: 100%;
  margin: 0 auto 0 0;
}

.msg-row {
  display: flex;
  margin: 0;
}
.msg-row.out { justify-content: flex-end; }
.msg-row.in  { justify-content: flex-start; }

/* Respiro pequeno quando muda a direção da conversa */
.msg-row.in + .msg-row.out,
.msg-row.out + .msg-row.in,
.msg-row + .msg-row.system,
.msg-row.system + .msg-row {
  margin-top: 4px;
}

/* === A BOLHA ===
   Padding: 4px topo, 8px laterais, 4px embaixo. Padding-right grande
   pra reservar espaço para o timestamp absolutamente posicionado. */
.msg-bubble {
  position: relative;
  max-width: 68%;
  padding: 4px 48px 4px 8px;
  border-radius: 7.5px;
  font-size: 13.5px;
  line-height: 1.3;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 1px .5px rgba(0, 0, 0, .13);
  min-height: 0;
}

.msg-row.out .msg-bubble {
  background: var(--bubble-out, #005c4b);
  color: #e9edef;
  border-bottom-right-radius: 2px;
}
.msg-row.in .msg-bubble {
  background: var(--bubble-in, #202c33);
  color: var(--text);
  border-bottom-left-radius: 2px;
}

/* === TIMESTAMP — absoluto no canto inferior direito === */
.msg-row .msg-bubble .msg-time {
  position: absolute;
  right: 7px;
  bottom: 3px;
  font-size: 10px;
  color: rgba(233, 237, 239, .55);
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

/* Float não precisa mais ser contido */
.msg-bubble::after { content: none; }

/* === Variante "system" === */
.msg-row.system { justify-content: center; margin: 8px 0; }
.msg-row.system .msg-bubble {
  background: rgba(255, 181, 71, .12);
  color: var(--warning, #ffb547);
  font-size: 11.5px;
  text-align: center;
  border-radius: 8px;
  padding: 4px 11px;
  max-width: none;
  box-shadow: none;
}
.msg-row.system .msg-bubble .msg-time { display: none; }

/* === Cauda (tail) na última bolha do grupo === */
.msg-row.out:last-child .msg-bubble::before,
.msg-row.out:has(+ .msg-row.in) .msg-bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: -6px;
  width: 8px;
  height: 12px;
  background: var(--bubble-out, #005c4b);
  clip-path: polygon(0 0, 0 100%, 100% 100%);
}
.msg-row.in:last-child .msg-bubble::before,
.msg-row.in:has(+ .msg-row.out) .msg-bubble::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -6px;
  width: 8px;
  height: 12px;
  background: var(--bubble-in, #202c33);
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
}

/* === Anexos === */
.msg-bubble .msg-attachment-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  margin: -1px -3px 4px;
}
.msg-bubble .msg-attachment-audio,
.msg-bubble .msg-attachment-video {
  display: block;
  max-width: 100%;
  margin-bottom: 4px;
}
.msg-bubble .msg-attachment-file {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(255, 255, 255, .06);
  padding: 7px 10px;
  border-radius: 6px;
  color: inherit;
  margin-bottom: 4px;
}
.msg-bubble .msg-attachment-file i { font-size: 22px; flex-shrink: 0; }
.msg-bubble .msg-attachment-file .att-name {
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}
.msg-bubble .msg-attachment-file .att-size {
  font-size: 11px;
  color: rgba(233, 237, 239, .55);
}
.msg-bubble .att-caption {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}

/* Quando bolha tem imagem, tempo fica em chip sobre a foto */
.msg-bubble:has(.msg-attachment-image) .msg-time {
  position: absolute;
  bottom: 6px;
  right: 8px;
  float: none;
  margin: 0;
  background: rgba(0, 0, 0, .4);
  color: rgba(255, 255, 255, .9);
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1;
}

/* === MOBILE === */
@media (max-width: 640px) {
  .chat-messages {
    padding: 6px 8px 10px;
  }
  .msg-bubble {
    max-width: 82%;
  }
}

@media (min-width: 641px) and (max-width: 1100px) {
  .msg-bubble { max-width: 72%; }
}
