/* 全域變數：集中管理顏色、陰影與圓角，讓深色主題更容易調整。 */
:root {
  --bg: #0f172a;
  --bg-soft: #111827;
  --card: rgba(15, 23, 42, 0.88);
  --card-border: rgba(148, 163, 184, 0.18);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #8b5cf6;
  --primary-strong: #7c3aed;
  --ai-bubble: #1f2937;
  --user-bubble: linear-gradient(135deg, #8b5cf6, #06b6d4);
  --danger: #fca5a5;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius-lg: 28px;
  --radius-md: 18px;
}

/* 使用 border-box 可以讓 padding 與 border 不會額外撐大元素寬度。 */
* {
  box-sizing: border-box;
}

/* body 設定整體字型、背景與基本排版。 */
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(139, 92, 246, 0.34), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(6, 182, 212, 0.24), transparent 30rem),
    var(--bg);
}

/* 讓主畫面置中，並在小螢幕保留適當邊距。 */
.app-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 32px 16px;
}

/* 聊天卡片是整個 UI 的主要容器。 */
.chat-card {
  display: flex;
  width: min(920px, 100%);
  height: min(760px, calc(100vh - 64px));
  overflow: hidden;
  flex-direction: column;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

/* 頁首區塊使用漸層背景，讓畫面更有層次。 */
.chat-header {
  padding: 32px 32px 24px;
  border-bottom: 1px solid var(--card-border);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(6, 182, 212, 0.08));
}

/* 小標籤用來呈現品牌感或功能提示。 */
.eyebrow {
  margin: 0 0 8px;
  color: #c4b5fd;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* 主標題。 */
h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

/* 副標題。 */
.subtitle {
  margin: 12px 0 0;
  color: var(--muted);
}

/* 對話紀錄區域會自動捲動，因此設定 overflow-y。 */
.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 28px 32px;
  scroll-behavior: smooth;
}

/* 每則訊息的外層，用來控制靠左或靠右。 */
.message {
  display: flex;
}

/* 使用者訊息靠右顯示。 */
.message-user {
  justify-content: flex-end;
}

/* AI 訊息靠左顯示。 */
.message-ai {
  justify-content: flex-start;
}

/* 訊息氣泡基本樣式。 */
.message-bubble {
  max-width: min(680px, 82%);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  color: var(--text);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI 訊息使用較低調的深色氣泡。 */
.message-ai .message-bubble {
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: var(--ai-bubble);
}

/* 使用者訊息使用亮色漸層，方便與 AI 回覆區分。 */
.message-user .message-bubble {
  background: var(--user-bubble);
  box-shadow: 0 12px 28px rgba(6, 182, 212, 0.18);
}

/* loading 狀態讓使用者知道請求正在等待回覆。 */
.message-loading .message-bubble {
  color: var(--muted);
  font-style: italic;
}

/* 錯誤訊息使用柔和紅色，提示有問題但不造成視覺壓力。 */
.message-error .message-bubble {
  color: var(--danger);
}

/* 輸入列固定在底部，讓使用者隨時可以輸入下一句。 */
.chat-form {
  display: flex;
  gap: 12px;
  padding: 20px 32px 28px;
  border-top: 1px solid var(--card-border);
  background: rgba(15, 23, 42, 0.86);
}

/* 文字輸入框樣式。 */
.chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 999px;
  outline: none;
  padding: 14px 18px;
  color: var(--text);
  background: var(--bg-soft);
  font-size: 1rem;
}

/* focus 狀態讓鍵盤使用者知道目前正在輸入。 */
.chat-input:focus {
  border-color: rgba(139, 92, 246, 0.8);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.16);
}

/* 送出按鈕樣式。 */
.send-button {
  border: 0;
  border-radius: 999px;
  padding: 0 24px;
  color: white;
  background: var(--primary);
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

/* hover 時提供輕微互動回饋。 */
.send-button:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

/* disabled 狀態用於等待 AI 回覆時，避免重複送出。 */
.send-button:disabled,
.chat-input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

/* 小螢幕調整，避免輸入欄太擠。 */
@media (max-width: 640px) {
  .chat-card {
    height: calc(100vh - 32px);
  }

  .chat-header,
  .chat-messages,
  .chat-form {
    padding-right: 18px;
    padding-left: 18px;
  }

  .chat-form {
    flex-direction: column;
  }

  .send-button {
    min-height: 48px;
  }
}
