/* Message wrappers & bubbles
   - wrappers are full-width flex rows so we can justify bubbles left/right
   - bubbles are inline-block and will size to their content up to max-width */
.message-wrapper {
  display: flex;
  width: 100%;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeInMessage 0.3s ease-out forwards;
}

@keyframes fadeInMessage {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-wrapper.user {
  justify-content: flex-end; /* push user bubbles to the right */
}

.message-wrapper.bot {
  justify-content: flex-start; /* keep bot bubbles to the left */
}

.message {
  display: inline-block;
  max-width: 72%;
  padding: 12px 18px;
  border-radius: 18px;
  line-height: 1.6;
  word-wrap: break-word;
  /* smooth transitions for content/background/opacity changes */
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.message-wrapper.user .message {
  background: var(--user-message-bg);
  color: var(--user-message-text);
  border-bottom-right-radius: 6px;
}

.message-wrapper.bot .message {
  background: var(--bot-message-bg);
  color: var(--bot-message-text);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--bot-message-border);
  box-shadow: var(--bot-message-shadow);
  /* Allow bot bubbles to be slightly wider than general messages */
  max-width: calc(72% + 80px);
}

/* Thinking animation for bot */
.message.thinking {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  /* make the thinking indicator sit in a proper bubble similar to normal bot messages */
  padding: 8px 12px;
  min-width: 56px;
  min-height: 36px;
  border-radius: 16px;
  background: var(--bot-message-bg);
  color: var(--bot-message-text);
  border: 1px solid var(--bot-message-border);
  box-shadow: var(--bot-message-shadow);
  /* ensure the animated dots are centered horizontally */
  justify-content: center;
  position: relative;
  overflow: hidden; /* allow shimmer to be clipped to the bubble */
}
.message.thinking span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: rgba(247, 251, 255, 0.85);
  opacity: 0.85;
  /* slightly faster base animation so wave feels snappier */
  animation: dotPulse 1s infinite ease-in-out both;
}
.message.thinking span:nth-child(1) {
  /* left dot: earlier in the cycle so the wave starts here */
  animation-delay: -0.4s;
}
.message.thinking span:nth-child(2) {
  /* middle dot: follow the left dot with a noticeable offset */
  animation-delay: -0.2s;
}
.message.thinking span:nth-child(3) {
  /* right dot: arrives last to complete the wave */
  animation-delay: 0s;
}

@keyframes dotPulse {
  0%,
  60%,
  100% {
    transform: translateY(0) scale(0.9);
    opacity: 0.6;
  }
  30% {
    transform: translateY(-6px) scale(1.15);
    opacity: 1;
  }
}

/* subtle shimmer across the thinking bubble */
.message.thinking::before {
  content: '';
  position: absolute;
  left: -120%;
  top: 0;
  height: 100%;
  width: 220%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.035) 45%, rgba(255, 255, 255, 0) 100%);
  transform: translateX(0);
  pointer-events: none;
  opacity: 0.9;
  animation: shimmer 2.2s linear infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(0%);
  }
}

/* Make bubbles more permissive on small screens */
@media (max-width: 600px) {
  .message {
    max-width: 85%;
  }
}

/* Truncate table cell content with ellipsis */
table {
  table-layout: fixed;
  width: 100%;
}

td, th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#messages {
  flex: 1;
  padding: 24px;
  padding-bottom: calc(var(--input-height) + 16px);
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
