*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a56db;
  --primary-hover: #1648c0;
  --primary-light: #eff4ff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --bg-page: #f9fafb;
  --bg-white: #ffffff;
  --bg-sidebar: #1e2535;
  --bg-sidebar-hover: #2a3245;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --success: #059669;
  --warning: #d97706;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

html, body { height: 100%; overscroll-behavior: none; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif; }

/* ─── Layout ─────────────────────────────── */
.layout {
  display: flex;
  height: 100dvh;
  background: var(--bg-page);
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}

.sidebar-header {
  padding: 24px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo span {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.sidebar-subtitle {
  font-size: 12px;
  color: var(--sidebar-muted);
  padding-left: 38px;
}

.sidebar-section {
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-muted);
  margin-bottom: 10px;
}

.progress-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--sidebar-muted);
  white-space: nowrap;
}

.fields-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.field-empty {
  font-size: 12px;
  color: var(--sidebar-muted);
  padding: 6px 0;
  line-height: 1.5;
}

.field-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.field-item:hover { background: var(--bg-sidebar-hover); }

.field-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.field-dot.filled { background: #34d399; }
.field-dot.empty { background: rgba(255,255,255,0.15); }

.field-label {
  font-size: 11.5px;
  color: var(--sidebar-text);
  line-height: 1.5;
}

.field-value {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 170px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-export {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  width: 100%;
}

.btn-export:hover:not(:disabled) { background: var(--primary-hover); }
.btn-export:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}

.btn-new:hover { background: rgba(255,255,255,0.1); }

/* ─── Chat Area ─────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-white);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-white);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-info h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-badge {
  font-size: 11px;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 999px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lang-select {
  font-size: 12.5px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  background: var(--bg-page);
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.lang-select:focus { border-color: var(--primary); }

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d1d5db;
  transition: background 0.3s;
}

.status-dot.ready { background: #34d399; }
.status-dot.typing {
  background: #fbbf24;
  animation: pulse 1.2s infinite;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ─── Messages ─────────────────────────────── */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeUp 0.22s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.message.assistant .avatar {
  background: var(--primary);
  color: white;
  font-size: 11px;
}

.message.user .avatar {
  background: #f3f4f6;
  color: var(--text-secondary);
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-top-left-radius: 3px;
}

.message.user .bubble {
  background: var(--primary);
  color: white;
  border-top-right-radius: 3px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ─── Input Area ─────────────────────────────── */
.input-area {
  border-top: 1px solid var(--border);
  padding: 14px 28px 16px;
  background: var(--bg-white);
  flex-shrink: 0;
}

.export-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 10px;
}

.btn-export-inline {
  margin-left: auto;
  background: var(--success);
  color: white;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-export-inline:hover { background: #047857; }

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  resize: none;
  line-height: 1.6;
  max-height: 140px;
  overflow-y: auto;
  background: var(--bg-page);
  transition: border-color 0.2s, box-shadow 0.2s;
  scrollbar-width: thin;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
  background: var(--bg-white);
}

textarea::placeholder { color: var(--text-muted); }
textarea:disabled { opacity: 0.5; }

.btn-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-send:hover:not(:disabled) { background: var(--primary-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 6px;
  padding-left: 2px;
}

/* ─── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

/* ─── 快速選項按鈕 ─────────────────────────────
   讓客戶做選擇題而不是填空題 —— 這是提高回覆率最直接的機制。 */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.suggestions:empty { display: none; }

.suggestion-chip {
  padding: 8px 14px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  line-height: 1.3;
}
.suggestion-chip:hover { background: var(--primary); color: #fff; }
.suggestion-chip:active { transform: scale(.97); }

/* ─── 原生表單元件（日期選擇器／多選框）───────
   結構化欄位改用原生元件收集，不再靠 AI 猜文字——
   同一套視覺語言（--primary、--radius、--border），跟快速選項按鈕一致。 */
.form-request:empty { display: none; }

.form-request-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
}

.form-date-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-page);
}
.form-date-input:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }

.form-checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.form-checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s;
}
.form-checkbox-item:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}
.form-checkbox-item input { accent-color: var(--primary); }

.form-submit-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.form-submit-btn:hover { background: var(--primary-hover); }
.form-submit-btn:active { transform: scale(.97); }

/* ─── 匯出結果卡片 ───────────────────────────── */
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-white);
  margin-top: 8px;
}
.result-card a {
  color: var(--primary);
  font-weight: 600;
  word-break: break-all;
}
.result-warn {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  color: var(--warning);
  font-size: 13px;
}

/* ─── 行動版抽屜按鈕（桌機隱藏）───────────────── */
.btn-drawer {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-white);
  color: var(--text-primary);
  cursor: pointer;
  margin-right: 10px;
}
.drawer-badge { font-size: 12px; font-weight: 600; color: var(--primary); }

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 40;
}
.backdrop.open { display: block; }

/* ─── 行動版 / LIFF ───────────────────────────
   舊版整份 CSS 沒有任何 media query，280px 固定 sidebar
   在 375px 的手機上直接吃掉四分之三畫面。 */
@media (max-width: 768px) {
  .layout { position: relative; }

  /* sidebar 改為由左滑出的抽屜 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86vw;
    max-width: 320px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { transform: translateX(0); }

  .btn-drawer { display: inline-flex; }

  .chat-area { width: 100%; }

  .chat-header {
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .chat-header h1 { font-size: 15px; }
  .header-badge { display: none; }
  .chat-status { display: none; }

  .messages { padding: 14px 12px; }
  .bubble { max-width: 88%; }

  .input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  /* iOS 在 font-size < 16px 的輸入框聚焦時會自動放大整頁 */
  #userInput { font-size: 16px; }

  .input-hint { display: none; }
  .suggestion-chip { font-size: 15px; padding: 9px 14px; }
}

/* 極窄螢幕（LIFF compact） */
@media (max-width: 380px) {
  .lang-select { max-width: 74px; }
  .bubble { max-width: 92%; }
}
