/* =============================================
   GROUPED CHAT LAYOUT (Slack-style)
   ============================================= */

/* Chat Group Layout - default (assistant/other on left) */
.chat-group {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
  margin-left: 16px;
  margin-right: 16px;
}

/* User messages on right */
.chat-group.user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.chat-group-messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: min(900px, calc(100% - 60px));
}

/* User messages align content right */
.chat-group.user .chat-group-messages {
  align-items: flex-end;
}

.chat-group.user .chat-group-footer {
  justify-content: flex-end;
}

/* Footer at bottom of message group (role + time) */
.chat-group-footer {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-top: 6px;
}

.chat-sender-name {
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.chat-group-timestamp {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
}

/* Avatar Styles */
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--panel-strong);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  align-self: flex-end; /* Align with last message in group */
  margin-bottom: 4px; /* Optical alignment */
}

.chat-avatar.user {
  background: rgba(245, 159, 74, 0.2);
  color: rgba(245, 159, 74, 1);
}

.chat-avatar.assistant {
  background: rgba(52, 199, 183, 0.2);
  color: rgba(52, 199, 183, 1);
}

.chat-avatar.other {
  background: rgba(150, 150, 150, 0.2);
  color: rgba(150, 150, 150, 1);
}

.chat-avatar.tool {
  background: rgba(134, 142, 150, 0.2);
  color: rgba(134, 142, 150, 1);
}

/* Image avatar support */
img.chat-avatar {
  display: block;
  object-fit: cover;
  object-position: center;
}

/* Minimal Bubble Design - dynamic width based on content */
.chat-bubble {
  position: relative;
  display: inline-block;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: none;
  transition: background 150ms ease-out, border-color 150ms ease-out;
  max-width: 100%;
  word-wrap: break-word;
}

.chat-bubble.has-copy {
  padding-right: 36px;
}

.chat-copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out, background 120ms ease-out;
}

.chat-copy-btn__icon {
  display: inline-block;
  width: 1em;
  text-align: center;
}

.chat-bubble:hover .chat-copy-btn {
  opacity: 1;
  pointer-events: auto;
}

.chat-copy-btn:hover {
  background: rgba(0, 0, 0, 0.3);
}

.chat-copy-btn[data-copying="1"] {
  opacity: 0;
  pointer-events: none;
}

.chat-copy-btn[data-error="1"] {
  opacity: 1;
  pointer-events: auto;
  border-color: rgba(255, 69, 58, 0.8);
  background: rgba(255, 69, 58, 0.18);
  color: rgba(255, 69, 58, 1);
}

.chat-copy-btn[data-copied="1"] {
  opacity: 1;
  pointer-events: auto;
  border-color: rgba(52, 199, 183, 0.8);
  background: rgba(52, 199, 183, 0.18);
  color: rgba(52, 199, 183, 1);
}

.chat-copy-btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: none) {
  .chat-copy-btn {
    opacity: 1;
    pointer-events: auto;
  }
}

.chat-bubble:hover {
  background: rgba(0, 0, 0, 0.18);
}

/* User bubbles have different styling */
.chat-group.user .chat-bubble {
  background: rgba(245, 159, 74, 0.15);
  border-color: rgba(245, 159, 74, 0.3);
}

.chat-group.user .chat-bubble:hover {
  background: rgba(245, 159, 74, 0.22);
}

/* Streaming animation */
.chat-bubble.streaming {
  animation: pulsing-border 1.5s ease-out infinite;
}

@keyframes pulsing-border {
  0%, 100% {
    border-color: var(--border);
  }
  50% {
    border-color: var(--accent);
  }
}

/* Fade-in animation for new messages */
.chat-bubble.fade-in {
  animation: fade-in 200ms ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
