.chat-container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  pointer-events: none;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 20px;
  height: auto;
}

.chat-messages {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 16px;
  right: 16px;

  max-height: 75svh;
  padding: 16px;

  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: flex-start;

  width: auto;
  overflow-y: auto;

  opacity: 1;
  background: transparent;
  pointer-events: none;

  transition: all 0.3s ease;
  z-index: 1;

  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

.chat-container.has-history .chat-messages:hover {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  pointer-events: auto;
  z-index: 4;
}

.chat-messages .message:not(:last-child) {
  display: none;
}

/* Live STT 辨識結果：永遠顯示，不受 :not(:last-child) 隱藏影響 */
.chat-messages .message.live-input {
  display: flex;
}

.chat-container.has-history .chat-messages:hover .message:not(:last-child) {
  display: flex;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: messageSlideIn 0.3s ease-out;
  pointer-events: auto;
  flex-shrink: 0;
  width: 100%;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

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

.message.user {
  flex-direction: row-reverse;
}

.message-bubble {
  max-width: 85%;
  min-height: min-content;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 20px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #0095f6 0%, #00376b 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 149, 246, 0.3);
}

.message.bot .message-bubble {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  color: #262626;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.bot-answer.streaming {
  white-space: pre-wrap;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  pointer-events: auto;
  transition: all 0.3s ease;
  position: relative;
  z-index: 2;
  margin: 0 16px;
}

.chat-input input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.8);
  border: none;
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s;
}

.chat-input input::placeholder {
  color: #8e8e8e;
  font-style: normal;
}

.chat-input input:focus {
  outline: none;
  background: rgba(255, 255, 255, 1);
}

.chat-input button {
  background: #0095f6;
  border: none;
  color: white;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.chat-input button:hover {
  background: #0081d8;
  transform: scale(1.05);
}

.chat-input button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: scale(1);
}

.source-tooltip {
  margin-top: 6px;
  font-size: 0.85em;
  color: #1e88e5;
  cursor: pointer;
  user-select: none;
}

.source-popup {
  display: none;
  margin-top: 6px;
  padding: 8px;
  background: #f9f9f9;
  border: 1px solid #ccc;
  border-radius: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.source-item {
  margin-bottom: 8px;
}

.source-header {
  font-weight: bold;
  font-size: 0.85em;
  display: flex;
  justify-content: space-between;
}

.source-score {
  color: #666;
  font-size: 0.8em;
}

.source-content {
  font-size: 0.8em;
  color: #444;
  margin-top: 2px;
}
