/* 使用全域 box-sizing，讓寬高計算更直覺，避免 padding 撐破版面。 */
* {
  box-sizing: border-box;
}

/* 設定整個頁面的基本字體、深色背景與文字顏色。 */
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  color: #f8fafc;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.22), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(168, 85, 247, 0.18), transparent 30rem),
    #020617;
}

/* app 負責把聊天卡片水平、垂直置中，並在小螢幕保留安全間距。 */
.app {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

/* chat-card 是主要視覺容器，使用半透明背景與陰影營造深色玻璃感。 */
.chat-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(920px, 100%);
  height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 28px;
  background: rgba(15, 23, 42, 0.82);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

/* header 區塊呈現產品名稱與簡介。 */
.chat-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

/* eyebrow 是小型標籤文字，用來增加介面層次。 */
.eyebrow {
  margin: 0 0 8px;
  color: #38bdf8;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

/* 副標題使用較淡的顏色，避免搶走主標題焦點。 */
.subtitle {
  margin: 10px 0 0;
  color: #cbd5e1;
}

/* 對話紀錄區可垂直捲動，訊息太多時不會撐破整個頁面。 */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 24px 32px;
  scroll-behavior: smooth;
}

/* 每一則訊息都是一個 row，依照角色靠左或靠右。 */
.message {
  display: flex;
  width: 100%;
}

/* 使用者訊息靠右顯示。 */
.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: 18px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* 使用者訊息使用亮色漸層，方便與 AI 訊息區分。 */
.message-user .message-bubble {
  color: #082f49;
  background: linear-gradient(135deg, #7dd3fc, #c4b5fd);
}

/* AI 訊息使用深色背景，和整體主題一致。 */
.message-ai .message-bubble {
  color: #e2e8f0;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

/* loading 訊息使用較淡的顏色，提示 AI 正在處理。 */
.message-loading .message-bubble {
  color: #93c5fd;
  font-style: italic;
}

/* 輸入表單固定在卡片底部。 */
.chat-form {
  display: flex;
  gap: 12px;
  padding: 20px 32px 28px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.36);
}

/* 輸入框樣式。 */
.message-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 999px;
  padding: 14px 18px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.9);
  font-size: 1rem;
  outline: none;
}

/* 使用 focus-visible 提供鍵盤操作時的清楚焦點狀態。 */
.message-input:focus-visible {
  border-color: #38bdf8;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.18);
}

/* 送出按鈕使用醒目的藍紫漸層。 */
.send-button {
  border: 0;
  border-radius: 999px;
  padding: 0 24px;
  color: #020617;
  background: linear-gradient(135deg, #38bdf8, #a78bfa);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 160ms ease,
    opacity 160ms ease;
}

/* 滑鼠移到按鈕上時，提供輕微互動回饋。 */
.send-button:hover {
  transform: translateY(-1px);
}

/* 送出期間停用按鈕，避免使用者重複送出。 */
.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

/* 手機版調整卡片高度、間距與表單排列，讓小螢幕也好操作。 */
@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  .chat-card {
    height: calc(100vh - 24px);
    border-radius: 22px;
  }

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

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

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

  .message-bubble {
    max-width: 92%;
  }
}
