/* ============================================================
 *  Peerly — Bulles de message + réactions + réponses + typing
 *  v7.4.0 — fix taille de la bulle "écrit…"
 * ============================================================ */

/* ---- Wrapper ---- */
.chat-bubble-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 76%;
  position: relative;
  gap: 2px;
  animation: bubbleIn var(--duration-base) var(--ease-out);
}
.chat-bubble-wrapper.sent { align-self: flex-end; }
.chat-bubble-wrapper.received { align-self: flex-start; }

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
 *  Bulle
 * ============================================================ */
.chat-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  font-size: var(--text-md);
  line-height: var(--leading-md);
  word-break: break-word;
  position: relative;
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

.chat-bubble.sent {
  background: var(--md-primary);
  color: var(--md-on-primary);
  border-bottom-right-radius: var(--radius-xs);
}
.chat-bubble.sent:hover {
  box-shadow: 0 2px 12px var(--md-primary-soft);
}

.chat-bubble.received {
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
  border-bottom-left-radius: var(--radius-xs);
}
.chat-bubble.received:hover {
  background: var(--md-surface-container-highest);
}

/* ---- Contenu + footer ---- */
.bubble-content {
  position: relative;
}
.chat-bubble .bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-top: 3px;
  font-size: var(--text-2xs);
  line-height: var(--leading-2xs);
  opacity: 0.7;
}
.chat-bubble .bubble-time {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  font-variant-numeric: tabular-nums;
}
.chat-bubble .bubble-edited {
  font-style: italic;
  opacity: 0.9;
}
.chat-bubble .bubble-lock {
  font-size: 10px;
  opacity: 0.5;
  margin-right: 4px;
}

/* ============================================================
 *  Statut de message (⏱ ✓ ✓✓ ⚠️)
 * ============================================================ */
.bubble-status {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  line-height: 1;
  transition: color var(--duration-base) var(--ease-out);
}
.bubble-status i { line-height: 1; }

.bubble-status.pending { opacity: 0.6; }
.bubble-status.pending i {
  animation: statusPulse 1.8s var(--ease-in-out) infinite;
}
@keyframes statusPulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

.bubble-status.sent { opacity: 0.75; }

.bubble-status.read {
  color: #7DB9FF;
  opacity: 1;
}
.bubble-status.read i {
  animation: statusPop var(--duration-slow) var(--ease-spring);
}
@keyframes statusPop {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.bubble-status.failed {
  color: var(--md-error);
  cursor: pointer;
}
.bubble-status.failed:hover { opacity: 1; }

/* ============================================================
 *  Citation
 * ============================================================ */
.bubble-reply-context {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background var(--duration-fast) var(--ease-out);
}
.chat-bubble.sent .bubble-reply-context {
  background: rgba(0, 0, 0, 0.14);
}
.chat-bubble.received .bubble-reply-context {
  background: var(--md-surface-container);
}
.bubble-reply-context:hover {
  background: rgba(0, 0, 0, 0.22);
}

.bubble-reply-accent {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}
.chat-bubble.sent .bubble-reply-accent {
  background: var(--md-on-primary);
  opacity: 0.7;
}
.chat-bubble.received .bubble-reply-accent {
  background: var(--md-primary);
}

.bubble-reply-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.bubble-reply-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.bubble-reply-text {
  font-size: var(--text-xs);
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
 *  Actions sur message
 * ============================================================ */
.bubble-actions {
  position: absolute;
  top: 0;
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
  z-index: 2;
  padding-top: 4px;
}
.chat-bubble-wrapper:hover .bubble-actions { opacity: 1; }
.chat-bubble-wrapper.sent .bubble-actions { right: calc(100% + 6px); }
.chat-bubble-wrapper.received .bubble-actions { left: calc(100% + 6px); }

@media (hover: none) {
  .bubble-actions { opacity: 1; }
}

.bubble-action-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--md-outline-variant);
  transition: all var(--duration-fast) var(--ease-out);
  padding: 0;
}
.bubble-action-btn i { font-size: 13px; line-height: 1; }
.bubble-action-btn:hover {
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface);
}
.bubble-delete-btn:hover {
  background: var(--md-error-soft);
  color: var(--md-error);
  border-color: var(--md-error);
}

/* ============================================================
 *  Édition
 * ============================================================ */
.chat-bubble.editing {
  box-shadow: inset 0 0 0 1px var(--md-primary);
}

.bubble-edit-input {
  width: 100%;
  min-width: 180px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  resize: none;
  outline: none;
}
.bubble-edit-input:focus {
  border-color: var(--md-primary);
}

.bubble-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-top: var(--space-2);
}
.bubble-edit-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: all var(--duration-fast) var(--ease-out);
}
.bubble-edit-btn i { font-size: 12px; line-height: 1; }
.bubble-edit-save {
  background: var(--md-primary);
  color: var(--md-on-primary);
}
.bubble-edit-cancel {
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
}

/* ============================================================
 *  Réactions
 * ============================================================ */
.bubble-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.chat-bubble-wrapper.sent .bubble-reactions { justify-content: flex-end; }
.chat-bubble-wrapper.received .bubble-reactions { justify-content: flex-start; }

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2) 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--md-surface-container-high);
  border: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.reaction-pill:hover {
  background: var(--md-surface-container-highest);
  border-color: var(--md-outline);
}
.reaction-pill.mine {
  background: var(--md-primary-soft);
  border-color: var(--md-primary);
  color: var(--md-primary);
}
.reaction-emoji { font-size: 12px; line-height: 1; }
.reaction-count {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--weight-semibold);
}

/* ============================================================
 *  Emoji picker
 * ============================================================ */
.emoji-picker {
  position: fixed;
  z-index: 5000;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
  padding: var(--space-2);
  background: var(--md-surface-container-high);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pickerIn var(--duration-base) var(--ease-spring);
}
@keyframes pickerIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.emoji-picker-item {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}
.emoji-picker-item:hover {
  background: var(--md-surface-container-highest);
}

/* ============================================================
 *  Indicateur de frappe "écrit…"
 *  Utilise un wrapper (comme un vrai message) pour un sizing fiable
 * ============================================================ */

.chat-bubble-wrapper.typing-wrapper {
  /* Force le wrapper à ne prendre que la place de son contenu */
  width: auto;
  max-width: fit-content;
  flex: 0 0 auto;
  align-self: flex-start;
  animation: typingWrapperIn 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes typingWrapperIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-bubble.typing-bubble {
  /* Largeur minimale du contenu, pas d'étirement */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: fit-content;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-xl);
  border-bottom-left-radius: var(--radius-xs);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 16px;
}

.typing-dot {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--md-on-surface-variant);
  opacity: 0.5;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Mobile : un peu plus compact */
@media (max-width: 599px) {
  .chat-bubble.typing-bubble {
    padding: var(--space-2) var(--space-4);
  }
  .typing-dot {
    width: 6px;
    height: 6px;
  }
}