/* =====================================================================
   style.css
   ---------------------------------------------------------------------
   深色主題的 AI 聊天介面樣式。
   重點：
     - 整個畫面置中、最大寬度限制，桌機 / 手機都好看
     - 訊息泡泡分「使用者 / Bot」兩種顏色
     - 輸入區固定在底部，textarea 會隨內容長高
   ===================================================================== */

/* 基本重置 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC',
    'Microsoft JhengHei', 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #e5e7eb;
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
}

/* ---------------------------------------------------------------------
   App 外層
   --------------------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: 100vh;
  background: #111827;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* ---------------------------------------------------------------------
   標題列
   --------------------------------------------------------------------- */
.app__header {
  padding: 16px 20px;
  border-bottom: 1px solid #1f2937;
  background: #0b1220;
  text-align: center;
}

.app__title {
  font-size: 18px;
  font-weight: 600;
  color: #f9fafb;
}

.app__subtitle {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
}

/* ---------------------------------------------------------------------
   聊天訊息區
   --------------------------------------------------------------------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 單一訊息 */
.msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 85%;
}

/* 使用者訊息靠右 */
.msg--user {
  flex-direction: row-reverse;
  margin-left: auto;
}

/* 頭像圓圈 */
.msg__avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #1f2937;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.msg--user .msg__avatar {
  background: #2563eb;
}

/* 訊息泡泡 */
.msg__bubble {
  background: #1f2937;
  color: #e5e7eb;
  padding: 10px 14px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 15px;
}

.msg--user .msg__bubble {
  background: #2563eb;
  color: #ffffff;
  border-top-left-radius: 14px;
  border-top-right-radius: 4px;
}

/* 「AI 思考中」的 loading 訊息樣式 */
.msg--loading .msg__bubble {
  color: #9ca3af;
  font-style: italic;
}

/* 錯誤訊息 */
.msg--error .msg__bubble {
  background: #7f1d1d;
  color: #fecaca;
}

/* ---------------------------------------------------------------------
   輸入區
   --------------------------------------------------------------------- */
.composer {
  border-top: 1px solid #1f2937;
  padding: 12px 16px 14px;
  background: #0b1220;
}

.composer__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer__input {
  flex: 1;
  resize: none;
  max-height: 160px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #374151;
  background: #111827;
  color: #f9fafb;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s ease;
}

.composer__input:focus {
  border-color: #2563eb;
}

.composer__send {
  height: 42px;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.composer__send:hover:not(:disabled) {
  background: #1d4ed8;
}

.composer__send:disabled {
  background: #374151;
  color: #9ca3af;
  cursor: not-allowed;
}

.composer__hint {
  margin-top: 8px;
  font-size: 11px;
  color: #6b7280;
  text-align: center;
}

/* ---------------------------------------------------------------------
   小螢幕（手機）微調
   --------------------------------------------------------------------- */
@media (max-width: 480px) {
  .chat {
    padding: 14px;
  }
  .msg {
    max-width: 92%;
  }
  .msg__bubble {
    font-size: 14.5px;
  }
}
