/* Chat Bubble Styling */

/* Message container items */
.message-item {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  position: relative;
  clear: both;
}

.user-message-item {
  text-align: right;
}

.ai-message-item {
  text-align: left;
}

.message {
  padding: 12px 16px;
  border-radius: 8px;
  max-width: 70%;
  font-size: 0.8em;
  /* backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px); */
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0px 3px 0px rgb(4, 3, 71);
  opacity: 0;
  /* Initially hidden for animation */
  animation: fadeIn .3s forwards;
  user-select: text;
  z-index: 1;
  transition: opacity 0.5s ease-in-out; /* Shortened transition for more responsive fade */
}

.user-message-item .user-message {
  display: inline-block;
  text-align: right;
  background: #fbf0dd;
  color: #5c5301;
  position: relative;
  box-shadow: 0px 3px 0px rgb(255, 204, 0);
  float: right;
  margin-right: 20px;
}

.user-message::after {
  content: '';
  position: absolute;
  bottom: -10px;
  right: 15px;
  width: 20px;
  height: 10px;
  border-radius: 0 0 10px 10px;
  background: #fbf0dd;
  box-shadow: 0px 2px 0px rgb(255, 204, 0);
}

.ai-message-item .ai-message {
  display: inline-block;
  text-align: left;
  background: #dcf3fd;
  color: #0c1022;
  position: relative;
  float: left;
  margin-left: 20px;
}

.ai-message::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 15px;
  width: 20px;
  height: 10px;
  border-radius: 0 0 10px 10px;
  background: #dcf3fd;
  box-shadow: 0px 3px 0px rgb(4, 3, 71);
}

/* Keyframe for initial fade-in (used by .message) */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Make sure all messages clear floats */
.message-item::after {
  content: "";
  display: table;
  clear: both;
}

/* Ensure the messages container maintains proper flow */
.messages-container {
  display: flex;
  flex-direction: column;
  /* justify-content: flex-end; */ /* Removed - interferes with scrolling */
  width: 100%;
}

/* Add a pseudo-element spacer that pushes messages to the bottom */
.messages-container::before {
  content: "";
  flex-grow: 1; /* Takes up available space, pushing messages down */
  min-height: 0; /* Helps ensure proper sizing when scrolling */
}

@media (min-width: 1000px) and (orientation: portrait) {
  .message {
    padding: 20px 24px;
    max-width: 85%;
    font-size: 1.4em;
    border-radius: 16px;
  }
  
  .user-message-item .user-message {
    margin-right: 35px;
  }
  
  .ai-message-item .ai-message {
    margin-left: 35px;
  }
  
  .user-message::after, .ai-message::after {
    width: 32px;
    height: 16px;
    bottom: -16px;
  }
  
  .message-item {
    margin-bottom: 30px;
  }
}
