/* 基本排版與色彩 */
:root {
  --bg: #f7f7fb;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --bubble-user: #2563eb;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
  --bubble-bot-text: #111827;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang TC", "Noto Sans CJK TC", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  display: flex; flex-direction: column;
}

/* 公用 */
.hidden { display: none !important; }

/* 頂部列 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: 64px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
}
.logo { width: 36px; height: 36px; border-radius: 6px; }
.brand .title { font-weight: 600; }
.brand .subtitle { font-size: 12px; color: var(--muted); }

/* 主體與訊息清單 */
.main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 12px;
}
.messages {
  width: 100%; max-width: 820px;
  /* 兼容舊瀏覽器的 viewport 高度以及行動裝置動態視窗高度 */
  height: calc(100vh - 64px - 72px);
  height: calc(100dvh - 64px - 72px);
  overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

/* 單則訊息 */
.msg { display: flex; align-items: flex-start; gap: 10px; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 36px; height: 36px; border-radius: 999px;
  background: #fff; border: 1px solid var(--border); flex-shrink: 0;
}

/* 泡泡：修正播放鍵擠到下一行 + 正常換行 */
.bubble {
  max-width: 78%;
  border: 1px solid var(--border); border-radius: 16px;
  padding: 10px 12px;
  /* 預留右側空間給播放鍵，避免蓋到文字 */
  padding-right: 44px;
  background: var(--bubble-bot); color: var(--bubble-bot-text);
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  font-size: 14px; line-height: 1.5;
  position: relative;               /* 讓內部 .actions 可絕對定位 */
  white-space: pre-wrap;            /* 文字保留換行 */
  word-break: break-word;           /* 長字自動斷行 */
}
.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-color: transparent;
}

/* 動作列（播放鍵）固定在泡泡右下角 */
.actions {
  position: absolute; right: 8px; bottom: 8px;
  display: flex; align-items: center; gap: 4px;
}

/* 語音播放按鈕（圖示） */
.audio-btn {
  border: none; background: transparent; cursor: pointer;
  width: 28px; height: 28px; border-radius: 999px;
  display: inline-grid; place-items: center;
  color: var(--primary);
  transition: transform .12s ease, background-color .2s ease, opacity .2s ease;
}
.audio-btn:hover { transform: scale(1.06); background: rgba(37,99,235,.08); }
.audio-btn:active { transform: scale(.98); }
.audio-btn[disabled] { opacity: .5; cursor: not-allowed; }
.audio-btn .icon { width: 18px; height: 18px; fill: currentColor; }
.audio-btn .pause { display: none; }
.audio-btn[data-state="playing"] .play { display: none; }
.audio-btn[data-state="playing"] .pause { display: block; }

/* 使用者泡泡（藍底）時，讓播放鍵變白以提高對比 */
.user .actions .audio-btn { color: #fff; }
.user .actions .audio-btn:hover { background: rgba(255,255,255,.18); }

/* 思考中動畫 */
.thinking {
  width: 100%; max-width: 820px;
  display: flex; align-items: center; gap: .5rem;
  margin-top: 8px; padding: .6rem .8rem;
  border-radius: 12px; background: #f6f7fb; color: #4b5563;
  border: 1px dashed var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  font-size: 14px;
}
.thinking .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .35; display: inline-block;
  animation: dotBounce 1.05s infinite ease-in-out;
}
.thinking .dot:nth-child(1) { animation-delay: 0s; }
.thinking .dot:nth-child(2) { animation-delay: .15s; }
.thinking .dot:nth-child(3) { animation-delay: .3s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: .35; }
  40% { transform: scale(1); opacity: 1; }
}

/* 骨架（可選） */
.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f6f6f6 37%, #eee 63%);
  background-size: 400% 100%; animation: shimmer 1.25s infinite;
  border-radius: 10px; height: 1.1em; width: 60%;
}
@keyframes shimmer { 0% {background-position: 100% 0;} 100% {background-position: -100% 0;} }

/* 輸入列 */
/* ✅ 讓輸入列可隨 textarea 長高，不再固定 72px */
.composer {
  min-height: 72px;
  height: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;     /* 多行時從上緣對齊 */
  gap: 8px;
  padding: 8px 12px;          /* 上下加 padding，比較不擁擠 */
  justify-content: center;
}

.composer .input {
  width: 100%; max-width: 620px;
  min-height: 40px;            /* 初始高度 */
  max-height: 120px;           /* 最高長度 ≈ 3–4 行，可自行調整 */
  height: auto;
  padding: 8px 12px;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  overflow-y: auto;            /* 超過就顯示直向卷軸 */
  resize: none;                /* 禁止手動拖拉，靠自動長高 */
  white-space: pre-wrap;
  word-break: break-word;
}
.btn {
  height: 40px; padding: 0 14px; border-radius: 12px; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-outline { background: #f3f4f6; border-color: var(--border); }
.btn-outline:hover { background: #e9ecf1; }

/* 行動裝置微調 */
@media (max-width: 480px) {
  .bubble { max-width: 86%; padding-right: 40px; }
  .messages { padding: 12px; }
}


