/* ===== style.css - 聊天介面樣式 ===== */
/* 深色主題、置中對話框的聊天介面 */

/* ===== 全域重置與基本設定 ===== */
/* 清除瀏覽器預設的 margin 和 padding，設定深色背景 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  /* 深色背景色 */
  background-color: #1a1a2e;
  /* 使用系統預設的無襯線字體 */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* 讓 body 佔滿整個視窗高度 */
  height: 100vh;
  /* 使用 Flexbox 將聊天容器置中 */
  display: flex;
  justify-content: center;
  align-items: center;
  /* 文字顏色設為白色 */
  color: #e0e0e0;
}

/* ===== 聊天主容器 ===== */
/* 整個聊天介面的外框，置中顯示 */
.chat-container {
  width: 100%;
  max-width: 700px;
  height: 90vh;
  background-color: #16213e;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  /* 陰影效果，讓容器有浮起來的感覺 */
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* ===== 頂部標題列 ===== */
.chat-header {
  background-color: #0f3460;
  padding: 20px 24px;
  text-align: center;
  /* 底部加一條微妙的分隔線 */
  border-bottom: 1px solid #1a1a4e;
}

.chat-header h1 {
  font-size: 1.4rem;
  color: #e94560;
  margin-bottom: 4px;
}

.chat-header p {
  font-size: 0.85rem;
  color: #8892b0;
}

/* ===== 對話訊息區域 ===== */
/* 中間的訊息顯示區，可以捲動 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 自訂捲動條樣式（Webkit 瀏覽器） */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background-color: #333;
  border-radius: 3px;
}

/* ===== 訊息泡泡共用樣式 ===== */
.message {
  display: flex;
  /* 預設靠左（AI 訊息） */
  align-items: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 12px 18px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  /* 保留文字中的換行 */
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== AI 訊息樣式（靠左） ===== */
.ai-message {
  justify-content: flex-start;
}

.ai-message .message-bubble {
  background-color: #1a1a4e;
  color: #e0e0e0;
  /* 左上角是直角，其他三個角是圓角 */
  border-radius: 4px 16px 16px 16px;
}

/* ===== 使用者訊息樣式（靠右） ===== */
.user-message {
  justify-content: flex-end;
}

.user-message .message-bubble {
  /* 使用者的訊息用強調色 */
  background-color: #e94560;
  color: #ffffff;
  /* 右上角是直角 */
  border-radius: 16px 4px 16px 16px;
}

/* ===== Loading 動畫（AI 思考中） ===== */
.loading .message-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 三個跳動的圓點動畫 */
.loading-dot {
  width: 8px;
  height: 8px;
  background-color: #8892b0;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }
.loading-dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ===== 底部輸入區域 ===== */
.chat-input-area {
  padding: 16px 20px;
  background-color: #0f3460;
  border-top: 1px solid #1a1a4e;
}

.input-wrapper {
  display: flex;
  gap: 10px;
}

/* 文字輸入框 */
#messageInput {
  flex: 1;
  padding: 12px 18px;
  border: 1px solid #333;
  border-radius: 24px;
  background-color: #1a1a2e;
  color: #e0e0e0;
  font-size: 0.95rem;
  outline: none;
  /* 輸入框獲得焦點時的過渡效果 */
  transition: border-color 0.3s;
}

#messageInput:focus {
  border-color: #e94560;
}

/* placeholder 文字顏色 */
#messageInput::placeholder {
  color: #555;
}

/* 送出按鈕 */
#sendButton {
  padding: 12px 24px;
  border: none;
  border-radius: 24px;
  background-color: #e94560;
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.1s;
}

#sendButton:hover {
  background-color: #c73652;
}

#sendButton:active {
  transform: scale(0.96);
}

/* 按鈕禁用狀態（送出中） */
#sendButton:disabled {
  background-color: #555;
  cursor: not-allowed;
}

/* ===== 響應式設計 ===== */
/* 在手機等小螢幕上，聊天容器佔滿整個畫面 */
@media (max-width: 768px) {
  .chat-container {
    height: 100vh;
    max-width: 100%;
    border-radius: 0;
  }

  body {
    align-items: stretch;
  }
}
