/* 月圓 r16：歡迎首頁與專業報告（29号）。
   設計原則：使用者說的話是畫面上唯一的內容主角；工具收進窄欄；破壞性動作再收一層。
   顏色有職責 —— 藍紫＝使用者自己，暖月黃＝月圓，警示紅＝即時幫助與真實故障。 */

:root {
  --bg: #F7F8FD;
  --surface: #FFFFFF;
  --ink: #292B40;
  --ink-soft: #555B70;      /* 次文；在 #F7F8FD 上約 6.3:1 */
  --line: #DFE2EF;
  --accent: #655AC8;
  --accent-hover: #5145AD;
  --accent-ink: #FFFFFF;
  --accent-soft: #EFEDFC;
  --moon: #FFF1D8;
  --danger: #A33846;
  --danger-soft: #F7E6E2;
  --warn: #8a6d1f;
  --warn-soft: #FFF1D8;
  --ok: #2F5E7A;
  --ok-soft: #E3ECF3;
  --info: #3F5E7A;
  --info-soft: #E3ECF3;
  --radius: 14px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI", system-ui, -apple-system, sans-serif;

  /* 版面尺度 */
  --frame: 1140px;        /* 桌面外框；≥1200 1280，≥2200 1600 */
  --sidebar-w: 240px;     /* 左側工具欄；≥2200 260 */
  --chat-gap: 24px;
  --chat-fs: 1.15rem;     /* 對話正文 18.4px（≥1200 為 20.1px） */
  --measure: 36em;        /* 單條消息可讀行寬（約 36 個漢字） */
}

* { box-sizing: border-box; }

/* 確保 hidden 屬性永遠生效，避免被 display:flex 覆蓋 */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
}
body { min-height: 100vh; display: flex; flex-direction: column; }

/* 進入對話後：整個視窗就是一個應用，只有指定區域捲動 */
body.is-chat {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 跳到主要內容 */
.skip-link {
  position: absolute;
  left: 10px;
  top: -70px;
  z-index: 100;
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.95rem;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 10px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------------- 頂欄 ---------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
body.is-chat .topbar-inner { max-width: var(--frame); }
.brand { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.brand-logo { width: 36px; height: 36px; object-fit: contain; flex: none; }
.brand-name { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { font-size: 0.9rem; color: var(--ink-soft); letter-spacing: 0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
  touch-action: manipulation;
  white-space: nowrap;   /* 連結不拆行，避免「使用與私隱／說明」斷開並留下孤字 */
}
.link-btn:hover { color: var(--accent-hover); }

/* 狀態膠囊 */
.status-pill {
  font-size: 1rem;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-unconfigured { background: #e9e6df; color: var(--ink-soft); }
.status-configured { background: var(--warn-soft); color: var(--warn); }
.status-connecting { background: var(--info-soft); color: var(--info); }
.status-verified { background: var(--ok-soft); color: var(--ok); }
.status-failed { background: var(--danger-soft); color: var(--danger); }
.status-offline { background: #e9e6df; color: var(--ink-soft); }
.status-mock { background: #e9e2f3; color: #6a4c93; }

/* ---------------- 主體 ---------------- */
.app { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 14px 40px; }
body.is-chat .app { max-width: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

/* ---------------- 歡迎首頁：開放的迎接頁，不用卡片包住全部內容 ---------------- */
.intro-screen { display: flex; justify-content: center; padding: 10vh 20px 48px; }
/* 700px：讓主標題在桌面能一行排完，不會把「自己」這類詞拆到兩行 */
.intro-inner { width: 100%; max-width: 700px; text-align: center; }
.intro-mark { display: block; width: 64px; height: 64px; margin: 0 auto 24px; object-fit: contain; }
.intro-headline {
  margin: 0 0 18px;
  font-size: 1.95rem;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-wrap: balance;
}
.intro-sub {
  margin: 0 0 36px;
  font-size: 1.15rem;
  line-height: 1.8;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.btn-confirm {
  display: block;
  width: min(100%, 300px);
  margin: 0 auto 28px;
  min-height: 56px;
  font-size: 1.08rem;
  border-radius: 999px;
}
.intro-note { margin: 0; font-size: 1rem; line-height: 1.7; color: var(--ink-soft); text-wrap: pretty; }
.intro-config {
  margin: 0 auto 24px;
  max-width: 520px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 1rem;
  text-align: left;
}
.intro-config.config-ok { background: var(--warn-soft); color: var(--warn); }
.intro-config.config-ready { background: var(--ok-soft); color: var(--ok); }
.intro-config.config-fail { background: var(--danger-soft); color: var(--danger); }

.intro-exit { animation: introFadeOut 0.32s ease forwards; }
.chat-enter { animation: chatFadeIn 0.36s ease; }
@keyframes introFadeOut { to { opacity: 0; transform: translateY(-8px); } }
/* 只用 opacity：transform 會讓後代 position:fixed（窄屏側欄抽屜）的定位基準跑掉 */
@keyframes chatFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawerIn { from { opacity: 0.4; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

/* ---------------- 對話應用外框 ---------------- */
body.is-chat #chat-screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: var(--frame);
  margin: 0 auto;
  padding: 16px 20px 0;
  display: flex;
  flex-direction: column;
}
.chat-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--chat-gap);
}

/* ---------------- 左側工具欄 ---------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding-right: var(--chat-gap);
  border-right: 1px solid var(--line);
}
.sidebar-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 10px; }
.sidebar-title { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: 0.02em; color: var(--ink); }
.sidebar-close { display: none; }
.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 2px 0 12px;
}
.side-group { display: flex; flex-direction: column; gap: 4px; }
.side-label { margin: 0 0 2px; font-size: 0.9rem; font-weight: 600; color: var(--ink-soft); }
.side-hint { margin: 2px 0 0; font-size: 0.95rem; line-height: 1.6; color: var(--ink-soft); }
.side-btn {
  font: inherit;
  font-size: 1rem;
  text-align: left;
  padding: 10px 10px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.side-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.side-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.side-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  padding: 10px 0;
  min-height: 46px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}
.side-toggle::after {
  content: '';
  box-sizing: border-box;
  width: 7px;
  height: 7px;
  /* 留 3px 餘裕：旋轉後的外接框會比原方框各多出約 1.5px，
     否則會在 overflow-y:auto 的側欄裡觸發橫向捲軸（橫向溢出用修的，不用隱藏掩蓋） */
  margin-left: auto;
  margin-right: 3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.side-toggle[aria-expanded="true"]::after { transform: rotate(-135deg); }
.side-toggle:hover { color: var(--accent); }
.sidebar-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0 calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.more-actions { padding: 0 0 4px; }
.sidebar-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(41,43,64,0.38); }

/* ---------------- 右側：對話 ---------------- */
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.chat-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-logo { width: 30px; height: 30px; flex: none; object-fit: contain; }
.chat-title { margin: 0; font-size: 1.1rem; font-weight: 600; letter-spacing: 0.02em; color: var(--ink); }

/* 偏好：緊湊分段控件 */
.pref-seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.pref-btn {
  font: inherit;
  font-size: 1rem;
  padding: 8px 14px;
  min-height: 40px;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.pref-btn:hover:not(:disabled):not(.is-active) { color: var(--accent); }
.pref-btn.is-active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgba(41,43,64,0.10); }
.pref-btn:disabled { opacity: 0.5; cursor: not-allowed; }
@media (pointer: coarse) { .pref-btn { min-height: 46px; } }
/* 偏好說明：使用者要看得清楚，桌面約 18.4px、窄屏不低於 16px */
.pref-desc { flex: none; margin: 10px 2px 0; font-size: 1.05rem; line-height: 1.6; color: var(--ink-soft); }

.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* ---------------- 訊息 ---------------- */
.messages-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 4px 12px;
}
.messages:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.msg { display: flex; gap: 10px; max-width: min(var(--measure), 100%); font-size: var(--chat-fs); line-height: 1.75; }
.msg-assistant { align-self: flex-start; color: var(--ink); }
.msg-user { align-self: flex-end; flex-direction: row-reverse; max-width: min(30em, 100%); color: var(--ink); }
.msg-avatar { width: 26px; height: 26px; flex: none; margin-top: 5px; object-fit: contain; }
.msg-body { min-width: 0; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg-assistant .msg-body { padding: 2px 0; }
.msg-user .msg-body { background: var(--accent-soft); border-radius: 14px; padding: 10px 14px; }
.msg-meta { font-size: 0.9rem; color: var(--ink-soft); margin-top: 6px; }
.msg-error {
  display: block;
  align-self: flex-start;
  max-width: min(var(--measure), 100%);
  padding: 10px 14px;
  border: 1px solid #eccfc8;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
}
.msg-error .retry-btn {
  margin-top: 8px;
  font: inherit;
  font-size: 0.95rem;
  min-height: 38px;
  border: 1px solid var(--danger);
  color: var(--danger);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}
.msg-system {
  display: block;
  align-self: center;
  max-width: 100%;
  padding: 2px 6px;
  background: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  text-align: center;
}
.typing { color: var(--ink-soft); }

/* 回到最新：使用者翻舊訊息時才出現 */
.jump-latest {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: 0.95rem;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 6px 18px rgba(41,43,64,0.14);
  cursor: pointer;
  touch-action: manipulation;
}

/* 上下文提示 */
.context-warning {
  flex: none;
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.95rem;
}

/* ---------------- 輸入區（固定在對話區底部） ---------------- */
.composer {
  flex: none;
  margin-top: 8px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: var(--chat-fs);
  line-height: 1.6;
  padding: 12px 16px;
  min-height: calc(2 * 1.6em + 26px);
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  resize: none;
}
.composer-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.composer-input:disabled { background: #F1F2F7; color: var(--ink-soft); }
.composer-hint { margin: 8px 2px 0; font-size: 0.9rem; color: var(--ink-soft); text-align: right; }

/* ---------------- 報告視圖 ---------------- */
.organize-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.organize-title { margin: 0; font-size: 1.1rem; font-weight: 600; color: var(--ink); }
.organize-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 4px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.organize-h3 { margin: 0 0 10px; font-size: 1.05rem; font-weight: 600; color: var(--ink); }

/* 同意面板：主流程只有這一次同意 */
.consent { max-width: 46em; }
.consent-list { margin: 0 0 22px; padding-left: 20px; }
.consent-list li { margin-bottom: 10px; font-size: 1.05rem; line-height: 1.8; color: var(--ink); }
.consent-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.report-note { margin: 12px 0 0; font-size: 1rem; line-height: 1.7; color: var(--ink-soft); }
.report-fail { color: var(--danger); }

/* 生成中／資訊不足 */
.report-state { max-width: 46em; }
.report-state-lead { margin: 0 0 18px; font-size: 1.05rem; line-height: 1.8; color: var(--ink); }

/* 報告文件：排版好的連續文件，不是一堆表單 */
.report-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.report-doc {
  max-width: 46em;
  padding: 32px 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.report-doc h1 { margin: 0 0 10px; font-size: 1.5rem; line-height: 1.4; }
.report-doc-lead { margin: 0 0 4px; font-size: 1.05rem; color: var(--ink-soft); }
.report-doc-limit { margin: 0 0 26px; font-size: 1rem; color: var(--ink-soft); }
.report-section { margin-top: 26px; }
.report-section h2 { margin: 0 0 10px; font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.report-section p { margin: 0 0 12px; font-size: var(--chat-fs); line-height: 1.85; }
.report-doc-edited { font-size: 0.95rem !important; color: var(--ink-soft); }

/* 依據：預設收起，只在需要核對時打開 */
.report-evidence { margin-top: 22px; max-width: 46em; }
.report-evidence summary {
  cursor: pointer;
  font-size: 1rem;
  color: var(--accent);
  padding: 8px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.report-evidence-body { padding: 6px 0 0; }
.report-evidence-list { margin: 0; padding-left: 20px; }
.report-evidence-list li { margin-bottom: 10px; font-size: 1rem; line-height: 1.75; color: var(--ink); }
.report-evidence-no { color: var(--ink-soft); margin-right: 8px; }
.report-evidence-text { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }

/* 修改內容：只在需要時展開 */
.report-edit { margin-top: 22px; max-width: 46em; }
.report-edit-field { margin-bottom: 16px; }
.report-edit-field label { display: block; font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.report-edit-field textarea {
  width: 100%;
  font: inherit;
  font-size: var(--chat-fs);
  line-height: 1.75;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
}

/* ---------------- 按鈕 ---------------- */
.btn {
  font: inherit;
  font-size: 1rem;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 46px;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-soft); }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink-soft); font-size: 0.95rem; }
.btn-quiet:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
/* 清除：外框線、不爭搶注意；實心警示色只留給即時幫助 */
.btn-quiet-danger { width: 100%; background: transparent; border-color: var(--line); color: var(--danger); font-size: 1rem; }
.btn-quiet-danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.btn-send { flex: none; min-width: 92px; min-height: 48px; padding: 0 20px; border-radius: 16px; }
.btn-help { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; min-height: 46px; padding: 10px 14px; }
.btn-help:hover:not(:disabled) { background: #8c2f39; border-color: #8c2f39; }
.sidebar-open { display: none; }

/* ---------------- 對話框 ---------------- */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.dialog::backdrop { background: rgba(0,0,0,0.4); }
.dialog-body { padding: 22px 20px; }
.dialog-body h2 { margin: 0 0 12px; font-size: 1.25rem; }
.dialog-body ul { padding-left: 18px; margin: 8px 0; }
.dialog-body li { margin-bottom: 8px; font-size: 1rem; line-height: 1.75; }
.help-lead { color: var(--ink-soft); margin: 0 0 8px; font-size: 1rem; }
.help-tier { margin: 14px 0; }
.help-tier h3 { margin: 0 0 8px; font-size: 1rem; font-weight: 600; color: var(--ink); }
.help-contact {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.help-number { font-size: 1.2rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.help-desc { flex: 1 1 auto; min-width: 0; font-size: 0.98rem; color: var(--ink-soft); }
.help-copy {
  font: inherit;
  font-size: 0.95rem;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.help-copy:hover { border-color: var(--accent); }
.help-sub { margin: 2px 0 0; font-size: 0.95rem; color: var(--ink-soft); }
.help-note { font-size: 0.95rem; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

/* ---------------- 列印區（匯出 PDF） ---------------- */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area { display: block; position: absolute; top: 0; left: 0; width: 100%; visibility: visible; }
  #print-area * { visibility: visible; }
  #print-area h1 { font-size: 1.4rem; }
  #print-area h2 { font-size: 1.05rem; margin-top: 16px; margin-bottom: 6px; }
  #print-area p { white-space: pre-wrap; font-size: 0.9rem; line-height: 1.7; }
  #print-area .print-src { color: #555; font-size: 0.8rem; }
}

/* ---------------- 大桌面 ---------------- */
@media (min-width: 1200px) {
  html { font-size: 17.5px; }
  :root { --frame: 1280px; --chat-fs: 1.2rem; }
  .app { max-width: 880px; }
  .topbar-inner { max-width: 960px; padding: 14px 18px; }
  body.is-chat .topbar-inner { max-width: var(--frame); }
  .intro-screen { padding-top: 12vh; }
  .intro-headline { font-size: 2.1rem; }
  .intro-sub { font-size: 1.2rem; }
  .btn-confirm { width: 320px; min-height: 58px; font-size: 1.1rem; }
  .btn { min-height: 48px; }
  .chat-frame { padding: 22px 26px 0; }
  .messages { gap: 24px; padding-top: 24px; }
}

/* ---------------- 超大桌面：外框與側欄一起放大 ---------------- */
@media (min-width: 2200px) {
  :root { --frame: 1600px; --sidebar-w: 260px; }
  .intro-headline { font-size: 2.3rem; }
  .intro-inner { max-width: 820px; }
  .report-doc { max-width: 52em; padding: 40px 44px; }
}

/* ---------------- 窄屏：工具欄收成「對話選項」抽屜 ---------------- */
@media (max-width: 900px) {
  :root { --chat-gap: 0px; }
  .chat-frame { padding: 12px 12px 0; }
  .chat-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    z-index: 60;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 0 40px rgba(41,43,64,0.18);
    overflow-y: auto;
  }
  .sidebar:not([hidden]) { animation: drawerIn 0.2s ease; }
  .sidebar-close {
    display: inline-flex;
    align-items: center;
    font: inherit;
    font-size: 0.95rem;
    min-height: 42px;
    padding: 8px 12px;
    color: var(--ink-soft);
    background: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
  }
  .sidebar-open { display: inline-flex; }
  .chat-head { gap: 10px; }
  .report-doc { padding: 22px 18px; }
}

/* ---------------- 手機 ---------------- */
@media (max-width: 520px) {
  .topbar-inner { padding: 8px 10px; }
  .brand-sub { display: none; }
  .app { padding: 10px 10px 56px; }
  body.is-chat .app { padding: 0; }
  .intro-screen { padding: 6vh 16px 40px; }
  .intro-headline { font-size: 1.7rem; }
  .intro-sub { font-size: 1.05rem; }
  .scenario-btn { flex: 1 1 100%; }
  .pref-seg { width: 100%; justify-content: space-between; }
  .pref-btn { flex: 1 1 auto; text-align: center; padding: 8px 6px; font-size: 0.95rem; }
  .msg { max-width: 100%; }
  .msg-user { max-width: 88%; }
  .btn-send { min-width: 76px; padding: 0 14px; }
  .organize-head { flex-wrap: wrap; }
  .consent-list { padding-left: 18px; }
  .consent-list li { font-size: 1rem; }
  .report-toolbar .btn { flex: 1 1 auto; }
}

/* ---------------- 矮視窗：把垂直空間還給對話 ---------------- */
@media (max-height: 620px) {
  .chat-frame { padding-top: 10px; }
  .messages { gap: 16px; padding-top: 14px; }
  .sidebar-foot { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}

/* ---------------- 減少動態 ---------------- */
@media (prefers-reduced-motion: reduce) {
  .intro-exit, .chat-enter, .sidebar:not([hidden]) { animation: none; }
  .skip-link, .side-toggle::after { transition: none; }
}

/* 月圓 · Quiet editorial system, 2026-10. Existing behavior hooks are preserved. */
:root {
  --bg: #F6F5F0; --surface: #FEFDF9; --ink: #273A47; --ink-soft: #626B70;
  --line: #D9DEDC; --accent: #354F65; --accent-hover: #243D52;
  --accent-soft: #ECEAF3; --moon: #EFE9DC; --danger: #963F48;
  --radius: 8px; --frame: 1480px; --sidebar-w: 228px; --chat-gap: 36px;
  --chat-fs: 1.0625rem; --measure: 37em;
}
html { font-size: 16px; }
body { background: var(--bg); font-weight: 400; -webkit-font-smoothing: antialiased; }
button, a, textarea { -webkit-tap-highlight-color: transparent; }
button { transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
:focus-visible { outline: 3px solid #6B6694; outline-offset: 4px; }
.topbar { background: var(--bg); border-bottom: 0; position: relative; }
.topbar-inner, body.is-chat .topbar-inner { max-width: var(--frame); padding: 24px 48px; gap: 16px; flex-wrap: nowrap; }
.brand { gap: 12px; }
.brand-logo { width: 35px; height: 35px; }
.brand-name { font-size: 1.35rem; font-weight: 550; letter-spacing: .15em; }
.brand-sub { margin-left: 16px; padding-left: 24px; border-left: 1px solid var(--line); font-size: .8125rem; letter-spacing: .1em; }
.topbar-actions { gap: 20px; justify-content: flex-end; }
.topbar-actions .link-btn { font-size: .8125rem; color: var(--ink-soft); padding: 10px 0; text-decoration: none; }
.btn-help { background: transparent; color: var(--danger); border-color: #D7BCBC; padding: 9px 13px; min-height: 42px; font-size: .8125rem; font-weight: 500; border-radius: 5px; }
.btn-help:hover:not(:disabled) { color: white; }
.status-pill { font-size: .75rem; padding: 6px 10px; border-radius: 4px; white-space: normal; max-width: 19em; }
.app { max-width: var(--frame); padding: 0 48px 28px; }
.intro-screen { padding: 44px 0 0; display: block; }
.intro-inner { max-width: none; text-align: left; display: grid; grid-template-columns: 1.17fr 1fr; column-gap: clamp(40px,7vw,112px); }
.intro-copy { padding: 27px 0 22px; }
.eyebrow { display: flex; align-items: center; gap: 14px; margin: 0 0 30px; font-size: .8125rem; letter-spacing: .14em; color: var(--ink-soft); }
.fine-rule { display: inline-block; width: 32px; height: 1px; background: #7D8F9B; }
.intro-headline { margin: 0 0 28px; font-size: clamp(2.75rem,4.8vw,4.6rem); line-height: 1.33; font-weight: 420; letter-spacing: -.045em; text-wrap: initial; }
.intro-headline span { color: #6B748A; }
.intro-sub { margin: 0 0 30px; font-size: 1rem; line-height: 1.95; color: var(--ink-soft); }
.btn { border-radius: 6px; min-height: 46px; font-size: .9375rem; }
.btn-confirm { display: flex; align-items: center; justify-content: space-between; width: 218px; min-height: 56px; border-radius: 5px; padding: 0 22px; margin: 0 0 20px; font-size: 1rem; letter-spacing: .06em; }
.btn-confirm > span:last-child { font-family: system-ui,sans-serif; font-size: 1.5rem; font-weight: 300; }
.intro-note { font-size: .75rem; line-height: 1.9; }
.intro-note .link-btn { font-size: inherit; padding: 4px 0; color: var(--ink-soft); text-underline-offset: 4px; }
.intro-config { margin: 0 0 22px; font-size: .875rem; border-radius: 5px; }
.intro-editorial { background: #E5EAF0; color: #3E5164; display: flex; flex-direction: column; min-height: 510px; padding: 26px 32px 24px; align-self: stretch; position: relative; }
.editorial-heading,.editorial-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: .6875rem; letter-spacing: .08em; }
.editorial-heading { padding-bottom: 20px; border-bottom: 1px solid #BCC8D3; }
.editorial-content { flex: 1; padding: 25px 12px 24px; }
.editorial-quote { display: block; height: 58px; font: 100px/.85 Georgia,serif; color: #8D9BAC; }
.editorial-content h2 { font-size: clamp(1.8rem,2.7vw,2.7rem); font-weight: 400; line-height: 1.65; letter-spacing: .04em; margin: 3px 0 20px; }
.editorial-rule { width: 46px; height: 1px; background: #899BAA; margin-bottom: 20px; }
.editorial-content p { font-size: .875rem; line-height: 1.9; margin: 0; color: #5E7080; }
.editorial-footer { border-top: 1px solid #BCC8D3; padding-top: 16px; }
.editorial-footer img { width: 33px; height: 33px; opacity: .8; }
.intro-bottom { grid-column: 1 / -1; display: grid; grid-template-columns: .8fr 1fr 1fr 1.25fr; align-items: start; gap: 26px; border-top: 1px solid #CAD1D3; margin-top: 52px; padding: 27px 0 12px; }
.intro-bottom-title { margin: 1px 0; font-size: .8125rem; letter-spacing: .06em; color: var(--ink-soft); }
.intro-promise { display: flex; gap: 14px; }
.promise-number { font: .7rem/1.8 system-ui,sans-serif; color: #747D88; padding-top: 3px; }
.intro-promise p { margin: 0; font-size: .9375rem; font-weight: 500; }
.intro-promise p span { display: block; font-size: .75rem; font-weight: 400; color: var(--ink-soft); margin-top: 7px; line-height: 1.8; }
/* Workspace: quiet rail + readable conversation, not nested dashboard cards. */
body.is-chat .topbar { flex: none; border-bottom: 1px solid var(--line); }
body.is-chat .topbar-inner { padding-top: 15px; padding-bottom: 15px; }
.chat-frame { max-width: var(--frame); padding: 28px 48px 0; }
.sidebar { padding-right: 28px; }
.sidebar-head { padding-bottom: 20px; }
.sidebar-title { font-size: .8125rem; letter-spacing: .09em; font-weight: 500; }
.sidebar-invitation { font-size: 1.4rem; font-weight: 400; line-height: 1.65; color: #697488; margin: 12px 0 12px; letter-spacing: .01em; }
.sidebar-scroll { gap: 27px; }
.side-label { font-size: .6875rem; font-weight: 400; letter-spacing: .12em; }
.side-btn { border: 1px solid var(--line); padding: 12px 10px; border-radius: 5px; font-size: .875rem; margin: 5px 0 6px; background: #FBFAF6; }
.side-hint { font-size: .75rem; line-height: 1.9; }
.side-toggle { font-size: .8125rem; }
.sidebar-foot .btn { font-size: .8125rem; }
.chat-main { max-width: 100%; }
.chat-head { padding: 0 0 18px; align-items: flex-end; border-bottom: 0; }
.chat-logo { display: none; }
.chat-kicker { margin: 0 0 7px; color: var(--ink-soft); font-size: .6875rem; letter-spacing: .08em; }
.chat-title { font-size: 1.625rem; font-weight: 450; letter-spacing: -.025em; }
.chat-identity { gap: 14px; }
.pref-seg { background: transparent; border: 1px solid #D0D6DC; border-radius: 5px; padding: 3px; gap: 0; }
.pref-btn { min-height: 40px; padding: 7px 10px; font-size: .8125rem; border-radius: 3px; }
.pref-btn.is-active { box-shadow: none; color: #33495C; background: #E2E7EB; font-weight: 500; }
.pref-desc { margin: 0; padding: 0 0 19px; border-bottom: 1px solid var(--line); font-size: .8125rem; }
.messages { padding: 32px max(4px,calc((100% - 750px)/2)) 20px; gap: 28px; scroll-padding-bottom: 20px; }
.msg { font-size: var(--chat-fs); line-height: 1.95; gap: 12px; }
.msg-avatar { width: 25px; height: 25px; margin-top: 7px; }
.msg-user { max-width: min(31em,88%); }
.msg-user .msg-body { background: #E8E7EF; border-radius: 9px 9px 2px 9px; padding: 12px 18px; }
.msg-assistant .msg-body { padding: 0; }
.msg-system { font-size: .75rem; line-height: 1.8; }
.msg-error { border-radius: 5px; font-size: .875rem; line-height: 1.8; }
.msg-error .retry-btn { min-height: 44px; border-radius: 4px; font-size: .8125rem; }
.composer { border-top: 0; margin-top: 0; padding-top: 12px; width: 100%; max-width: 790px; align-self: center; }
.composer-label { display: block; margin: 0 0 9px 2px; font-size: .75rem; color: var(--ink-soft); }
.composer-row { background: var(--surface); border: 1px solid #BDC8CD; border-radius: 8px; padding: 8px; gap: 8px; align-items: flex-end; }
.composer-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px #D8DDE7; }
.composer-input { background: transparent; border: 0; border-radius: 3px; padding: 7px 9px; min-height: 78px; font-size: 1rem; line-height: 1.8; max-height: min(200px,25dvh); }
.composer-input::placeholder { color: #7A838C; }
.composer-input:focus { outline: 0; border: 0; }
.btn-send { min-width: 68px; min-height: 44px; padding: 0 14px; border-radius: 5px; font-size: .875rem; }
.composer-hint { font-size: .6875rem; margin-top: 8px; }
.context-warning { font-size: .8125rem; border-radius: 4px; }
.jump-latest { font-size: .8125rem; border-radius: 5px; box-shadow: 0 3px 14px #273A4710; }
.organize-head { padding-bottom: 20px; gap: 18px; }
.organize-title { font-size: 1.45rem; font-weight: 450; }
.organize-body { padding: 28px 6px 32px; }
.consent { max-width: 45em; }
.organize-h3 { font-size: 1.125rem; font-weight: 500; }
.consent-list li { font-size: 1rem; line-height: 1.95; margin-bottom: 18px; }
.report-doc { border-radius: 2px; max-width: 48em; padding: 48px; border: 1px solid #DDDCD6; box-shadow: 0 8px 28px #273A4706; }
.report-doc h1 { font-size: 1.9rem; font-weight: 500; }
.report-doc-lead,.report-doc-limit,.report-note { font-size: .875rem; line-height: 1.85; }
.report-section { margin-top: 32px; padding-top: 22px; border-top: 1px solid var(--line); }
.report-section h2 { font-size: 1.0625rem; font-weight: 550; }
.report-section p { font-size: 1rem; line-height: 2; }
.report-evidence summary { font-size: .875rem; }
.dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); max-width: 620px; border-radius: 8px; max-height: calc(100dvh - 40px); }
.dialog::backdrop { background: #24344370; }
.dialog-body { padding: 32px; }
.dialog-body h2 { font-size: 1.5rem; font-weight: 500; margin-bottom: 22px; }
.dialog-body li { font-size: .9375rem; }
.help-contact { border-radius: 5px; }
@media (min-width: 1800px) {
  .intro-screen { padding-top: 8vh; }
  .intro-editorial { min-height: 580px; }
  .intro-bottom { margin-top: 64px; }
}
@media (max-width: 1100px) {
  .topbar-inner,body.is-chat .topbar-inner { padding-left: 32px; padding-right: 32px; }
  .app { padding-left: 32px; padding-right: 32px; }
  .intro-inner { column-gap: 40px; }
  .intro-editorial { padding: 24px; min-height: 500px; }
  .editorial-heading > span:last-child { display: none; }
  .intro-headline { font-size: 3.2rem; }
  .chat-frame { padding: 24px 28px 0; }
  :root { --sidebar-w: 198px; --chat-gap: 26px; }
  .chat-head { align-items: flex-start; }
  .pref-seg { margin-top: 7px; }
  .brand-sub { display: none; }
}
@media (max-width: 900px) {
  :root { --chat-gap: 0px; }
  .sidebar { padding: 24px; background: var(--bg); }
  .sidebar-close { border-radius: 5px; font-size: .8125rem; }
  .sidebar-open { border-color: var(--line); padding: 8px 10px; font-size: .75rem; }
  .chat-frame { padding: 20px 28px 0; }
  .chat-head { align-items: center; }
  .messages { padding-top: 24px; }
  .intro-screen { padding-top: 20px; }
  .intro-headline { font-size: 2.8rem; }
  .intro-inner { column-gap: 28px; }
  .intro-copy { padding-top: 20px; }
  .editorial-content { padding-left: 0; padding-right: 0; }
  .editorial-content h2 { font-size: 1.9rem; }
  .intro-sub { font-size: .9375rem; }
  .intro-bottom { grid-template-columns: repeat(3,1fr); gap: 22px; margin-top: 36px; }
  .intro-bottom-title { grid-column: 1/-1; }
}
@media (max-width: 640px) {
  .topbar-inner,body.is-chat .topbar-inner { padding: 18px 20px; gap: 8px; }
  .topbar-actions { gap: 12px; }
  .brand { gap: 7px; }
  .brand-logo { width: 28px; height: 28px; }
  .brand-name { font-size: 1.15rem; }
  .topbar-actions .link-btn { font-size: .6875rem; }
  .btn-help { font-size: .6875rem; padding: 7px 9px; min-height: 44px; }
  .status-pill { order: 3; width: 100%; max-width: none; }
  .topbar-actions:has(.status-pill:not([hidden])) { flex-wrap: wrap; }
  .app { padding: 0 24px 24px; }
  .intro-screen { padding-top: 14px; }
  .intro-inner { display: block; }
  .intro-copy { padding: 20px 0 32px; }
  .eyebrow { font-size: .75rem; margin-bottom: 25px; }
  .intro-headline { font-size: clamp(2.55rem,9.6vw,3.7rem); line-height: 1.38; margin-bottom: 23px; }
  .intro-sub { font-size: .9375rem; margin-bottom: 26px; line-height: 1.95; }
  .btn-confirm { width: 100%; max-width: 340px; }
  .intro-note { font-size: .6875rem; }
  .intro-editorial { min-height: 0; padding: 23px 25px 20px; }
  .editorial-heading > span:last-child { display: inline; }
  .editorial-content { padding: 24px 0; }
  .editorial-quote { height: 42px; font-size: 78px; }
  .editorial-content h2 { font-size: 1.8rem; line-height: 1.55; margin: 3px 0 18px; }
  .editorial-content p { font-size: .8125rem; }
  .editorial-footer img { width: 28px; height: 28px; }
  .intro-bottom { display: block; margin-top: 30px; padding-top: 22px; }
  .intro-bottom-title { margin-bottom: 22px; }
  .intro-promise { padding: 16px 0; border-bottom: 1px solid var(--line); gap: 22px; }
  .intro-promise p span { margin-top: 4px; }
  body.is-chat .topbar-inner { padding: 8px 16px; }
  .chat-frame { padding: 16px 16px 0; }
  .chat-head { gap: 13px; padding-bottom: 10px; }
  .chat-title { font-size: 1.3rem; }
  .chat-kicker { font-size: .625rem; margin-bottom: 4px; }
  .chat-identity { width: 100%; flex-direction: row-reverse; justify-content: space-between; }
  .pref-seg { width: 100%; margin: 0; }
  .pref-btn { flex: 1; font-size: .75rem; padding: 7px 5px; min-height: 44px; }
  .pref-desc { font-size: .75rem; padding-bottom: 12px; }
  .messages { padding: 22px 2px 16px; gap: 24px; }
  .msg { font-size: 1rem; line-height: 1.9; gap: 9px; }
  .msg-avatar { width: 22px; height: 22px; }
  .msg-user .msg-body { padding: 10px 14px; }
  .composer { padding: 9px 0 calc(8px + env(safe-area-inset-bottom)); }
  .composer-label { font-size: .6875rem; margin-bottom: 6px; }
  .composer-input { font-size: 1rem; min-height: 70px; padding: 5px; }
  .btn-send { min-width: 54px; padding: 0 10px; }
  .composer-hint { font-size: .625rem; margin-top: 5px; }
  .organize-title { font-size: 1.2rem; }
  .organize-body { padding: 20px 0; }
  .report-doc { padding: 24px 20px; }
  .report-doc h1 { font-size: 1.45rem; }
  .dialog-body { padding: 24px 20px; }
}
@media (max-width: 360px) {
  .topbar-inner,body.is-chat .topbar-inner { padding-left: 14px; padding-right: 14px; }
  .topbar-actions { gap: 7px; }
  .brand-name { font-size: 1rem; letter-spacing: .08em; }
  .brand-logo { width: 25px; height: 25px; }
  .app { padding-left: 20px; padding-right: 20px; }
  .editorial-heading { font-size: .625rem; }
  .pref-btn { font-size: .6875rem; }
  .chat-frame { padding-left: 12px; padding-right: 12px; }
}
@media (max-height: 620px) and (max-width: 900px) {
  .chat-kicker,.composer-label { display: none; }
  .chat-frame { padding-top: 10px; }
  .chat-head { padding-bottom: 6px; gap: 6px; }
  .pref-desc { padding-bottom: 7px; }
  .composer-input { min-height: 50px; }
  .messages { padding-top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
/* Readability review: secondary text is quiet through spacing, never faint/tiny. */
.composer-input::placeholder { color: #65717B; }
.editorial-content p { color: #536574; }
.report-section p, .report-doc-lead, .report-doc-limit { overflow-wrap: anywhere; }
.intro-note, .intro-note .link-btn, .intro-promise p span, .editorial-heading, .editorial-footer { font-size: .8125rem; }
.side-hint, .chat-kicker, .composer-label, .composer-hint { font-size: .8125rem; }
@media (max-width: 640px) {
 .topbar-actions .link-btn, .btn-help { font-size: .75rem; }
 .editorial-heading { font-size: .75rem; }
 .composer-hint { font-size: .75rem; }
 .chat-kicker { font-size: .75rem; }
}
/* The editorial invitation is carried by words and proportion, not ornaments. */
.editorial-content { display: flex; flex-direction: column; justify-content: center; }
/* Keep text links comfortable to tap without making their type shout. */
.link-btn { display: inline-flex; align-items: center; min-height: 44px; }

/* Explicit region choice; visible keyboard focus, no language-derived default. */
.help-region { display: block; width: 100%; min-height: 44px; margin: 8px 0; padding: 10px 12px; font: inherit; color: var(--ink); background: var(--paper, #faf8f3); border: 1px solid currentColor; border-radius: 8px; }
.help-region:focus-visible { outline: 3px solid var(--accent, #685478); outline-offset: 3px; }

.help-other-region { margin: 10px 0 18px; }
.help-other-region summary { cursor: pointer; padding: 10px 0; color: var(--ink); }
.help-other-region summary:focus-visible { outline: 3px solid var(--accent, #685478); outline-offset: 3px; }
