:root {
  color-scheme: light;
  --ink: #0d0d0d;
  --ink-soft: #5d5d5d;
  --canvas: #ffffff;
  --surface: #ffffff;
  --sidebar: #f9f9f9;
  --line: #ececec;
  --line-strong: #d9d9d9;
  /* 小字對比：#8f8f8f 在白底只有 3.23:1、#10a37f 在 --ok-soft 上只有 2.8:1，
     都低於 WCAG AA 對小字的 4.5:1。這幾個 token 幾乎只用在 12~14px 的說明字與
     徽章上，是整個介面最看不清楚的地方。壓深之後分別是 5.1:1 與 4.7:1。 */
  --muted: #6e6e6e;
  --hover: #ececec;
  --bubble: #f4f4f4;
  --ok: #0b7a5f;
  --ok-soft: #e6f4ef;
  --warning: #c4281c;
  --warning-soft: #fdecea;
  --caution: #b54708;
  --caution-soft: #fff3e0;
  --focus: #2f6fca;
  --sidebar-width: 288px;
  --admin-content: 1120px;
  /* 空白頁三段式排版：標題 → 輸入框 → 建議題目。三者都從同一組變數推算，
     不要讓標題用 vh、輸入框用 % 各算各的——視窗一矮兩者就會疊在一起。 */
  --topbar-h: 66px;
  --welcome-top: min(24vh, 250px);
  --welcome-title-h: 44px;
  --welcome-gap: 40px;
  --welcome-composer-h: 58px;
  --drawer-width: 420px;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
}

* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
/* touch-action: manipulation 關掉「連點兩下放大」；捏合由 app.js 擋（iOS
   Safari 的瀏覽器分頁不理 viewport 的 user-scalable=no）。 */
body { overflow: hidden; background: var(--canvas); overscroll-behavior-y: none; touch-action: manipulation; }
/* 安裝成 App 後畫面會延伸到瀏海與底部，這兩塊要跟內容同色。 */
@supports (padding: env(safe-area-inset-top)) {
  html { background: var(--canvas); }
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent); outline-offset: 2px; }
/* row 一定要寫死成一列 minmax(0,1fr)：留成隱含的 auto 時，側欄對話一多就會把
   整個 grid 撐超過視窗，<html> 開始整頁捲動，position:relative 的 topbar 會被捲掉。 */
.app-shell { min-height: 0; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; }
.app-shell:has(.sidebar.desktop-hidden) { grid-template-columns: 0 minmax(0, 1fr); }

.sidebar { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 10px 8px 8px; color: var(--ink); background: var(--sidebar); border-right: 1px solid var(--line); z-index: 30; transition: margin-left 180ms ease; }
.sidebar.desktop-hidden { margin-left: calc(var(--sidebar-width) * -1); }
.brand-row { min-height: 48px; display: flex; align-items: center; gap: 4px; padding: 0 4px 0 7px; }
.brand-logo { display: block; width: 74px; height: 22px; object-fit: contain; object-position: left center; }
.brand-row .brand-logo { margin-right: auto; }
.sidebar-close { display: none; }
.sidebar-search, .sidebar-panel { flex: 0 0 34px; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; color: var(--ink); background: transparent; border: 0; border-radius: 10px; cursor: pointer; text-decoration: none; }
.icon-button svg { width: 19px; height: 19px; stroke-width: 1.8; }
.sidebar-close { display: none; }
.conversation-search { height: 40px; display: flex; align-items: center; gap: 8px; margin: 4px 4px 7px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); }
.conversation-search svg { width: 16px; color: var(--muted); }
.conversation-search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; }
.primary-nav { display: grid; gap: 2px; margin: 12px 0 25px; }
.primary-nav-item { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 12px; padding: 8px 10px; color: var(--ink); background: transparent; border: 0; border-radius: 10px; text-decoration: none; text-align: left; cursor: pointer; font-size: 16px; }
.primary-nav-item.active { background: var(--hover); }
.primary-nav-item svg { width: 20px; height: 20px; flex: 0 0 20px; stroke-width: 1.8; }
.sidebar-label { margin: 0 10px 8px; color: var(--muted); font-size: 14px; font-weight: 500; }
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
/* 下拉更新：手指往下拉時把提示推出來，放開就跟伺服器對一次。 */
.pull-refresh { height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); font-size: 14px; transition: height 160ms ease; }
.pull-refresh.dragging { transition: none; }
/* 換字用 ::before：span 本身縮成 0，但 ::before 要自己把字級補回來，
   否則會繼承 0 變成看不見。 */
.pull-refresh.ready span, .pull-refresh.loading span { font-size: 0; }
.pull-refresh.ready span::before, .pull-refresh.loading span::before { font-size: 14px; }
.pull-refresh.ready span::before { content: "放開更新"; }
.pull-refresh.loading span::before { content: "更新中"; }
.conversation-item { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; margin-bottom: 2px; color: var(--ink); background: transparent; border: 0; border-radius: 10px; text-align: left; cursor: pointer; font-size: 17px; }
.conversation-item.active { background: var(--hover); }
/* 編號要跟標題同一列（不是夾在標題與時間中間），而且靠左。固定寬度讓兩位數
   也不會把標題推歪；`align-self: flex-start` ＋ 跟標題一樣的行高才對得齊。 */
.conversation-order { flex: 0 0 28px; align-self: flex-start; color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 15px; line-height: 24px; text-align: left; }
.conversation-item.active .conversation-order { color: var(--ink-soft); }
.conversation-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conversation-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 每個對話記錄最後活動的日期時間 */
.conversation-time { color: var(--muted); font-size: 14px; font-family: "SFMono-Regular", Consolas, monospace; }
.conversation-delete { width: 28px; height: 28px; flex: 0 0 28px; display: inline-grid; place-items: center; padding: 0; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity 120ms ease; }
.conversation-delete svg { width: 15px; height: 15px; }
.conversation-item:focus-within .conversation-delete { opacity: 1; }
/* 刪除不用瀏覽器原生視窗：第一下變成「確定刪除」，再按一下才刪 */
.conversation-delete.confirming { width: auto; flex-basis: auto; padding: 0 8px; opacity: 1; color: var(--warning); background: var(--warning-soft); }
.confirm-delete { font-size: 13px; font-weight: 600; white-space: nowrap; }
@media (hover: none) {
  .conversation-delete { opacity: 1; }
}
.sidebar-footer { position: relative; display: grid; gap: 12px; padding: 14px 7px 5px; border-top: 1px solid var(--line); }
/* 帳號彈窗卡片：置中、二分欄——左邊導覽（設定／用量）、右邊內容 */
.account-modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; }
.account-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.3); border: 0; cursor: default; }
.account-card { position: relative; z-index: 1; width: min(560px, 100%); min-height: 300px; display: grid; grid-template-columns: 132px minmax(0, 1fr); overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14); }
.account-side { display: flex; flex-direction: column; gap: 4px; padding: 14px 10px; background: var(--sidebar); border-right: 1px solid var(--line); }
.account-tab { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 8px 10px; color: var(--ink-soft); background: transparent; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 600; text-align: left; }
.account-tab.active { color: var(--ink); background: var(--surface); border-color: var(--line); }
.account-tab svg { width: 15px; height: 15px; flex: 0 0 15px; }
.account-content { position: relative; padding: 18px 20px; }
.account-close { position: absolute; top: 10px; right: 10px; }
.account-heading { margin: 2px 0 14px; font-size: 17px; font-weight: 650; }
.account-hint { margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.account-panel .tone-toggle { display: inline-flex; }
.account-content .usage-panel { border: 0; padding: 0; }
.usage-panel { min-width: 0; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.usage-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.usage-heading strong { color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.usage-track { height: 6px; margin: 8px 0; overflow: hidden; background: #e7e7e7; border-radius: 3px; }
.usage-track span { display: block; width: 0; height: 100%; background: var(--ink); border-radius: inherit; transition: width 220ms ease; }
.usage-spend, .usage-tokens { display: block; }
.usage-spend { font-size: 13px; font-weight: 650; }
.usage-tokens { margin-top: 3px; color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
/* 帳號列分三區 hover：名字（開彈窗）、設定、登出各自獨立 */
.user-account { min-width: 0; display: flex; align-items: center; gap: 4px; }
.account-trigger { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 4px 6px; color: inherit; background: transparent; border: 0; border-radius: 10px; cursor: pointer; text-align: left; }
.user-account .icon-button { flex: 0 0 30px; width: 30px; height: 30px; color: var(--muted); }
.profile-avatar { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; color: #fff; background: var(--ink); border-radius: 50%; font-size: 15px; font-weight: 700; }
.profile-copy { min-width: 0; flex: 1; }
.profile-copy strong, .profile-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy strong { font-size: 14px; }
.profile-copy span { margin-top: 3px; color: var(--muted); font-size: 12px; }

.login-gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--canvas); }
.login-panel { width: min(380px, 100%); padding: 8px; background: transparent; border: 0; }
.login-logo { display: block; width: 104px; height: 31px; margin: 0 auto; object-fit: contain; object-position: center; }
.login-heading { margin: 26px 0 30px; text-align: center; }
.login-tagline { margin: 0; color: var(--muted); font-size: 17px; font-weight: 500; letter-spacing: .04em; }
.login-panel > label { display: block; margin: 14px 0 6px; color: var(--ink-soft); font-size: 14px; font-weight: 500; }
.login-field { height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.login-field:focus-within { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.login-field svg { width: 16px; color: var(--muted); }
.login-field input { min-width: 0; width: 100%; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; }
.login-button { width: 100%; margin-top: 20px; min-height: 48px; border-radius: var(--radius-pill); font-size: 16px; }
.login-status { min-height: 18px; margin: 12px 0 0; color: var(--warning); text-align: center; font-size: 14px; }

.chat-main { position: relative; min-width: 0; min-height: 0; height: 100%; display: grid; grid-template-rows: 66px minmax(0, 1fr) auto; overflow: hidden; background: var(--surface); }
.topbar { position: relative; min-height: 66px; display: flex; align-items: center; justify-content: space-between; padding: 8px 18px; }
.topbar h1 { max-width: min(32vw, 420px); margin: 0; overflow: hidden; color: var(--ink); font-size: 17px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; opacity: 1; }
.is-empty .topbar-title { opacity: 0; pointer-events: none; }
/* 右上角常駐的回覆模式標示（點擊跳出切換確認） */
.tone-indicator { margin-left: auto; min-height: 28px; padding: 4px 13px; color: var(--ink-soft); background: var(--bubble); border: 0; border-radius: var(--radius-pill); cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap; }
.tone-confirm { position: absolute; top: calc(100% - 4px); right: 13px; z-index: 70; width: 208px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.10); }
.tone-confirm p { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.tone-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* 兩顆按鈕同形狀同尺寸（都是藥丸），只有填色不同：切換是黑底、取消是白底黑框。
   選擇器要比 .command-button 更明確，否則會被它的圓角與高度蓋過去。 */
.tone-confirm-actions .tone-cancel,
.tone-confirm-actions .tone-ok { min-height: 34px; padding: 0 14px; border-radius: var(--radius-pill); font-size: 14px; font-weight: 600; }
.tone-confirm-actions .tone-cancel { color: var(--ink); background: var(--surface); border: 1px solid var(--ink); cursor: pointer; }
.topbar-title { min-width: 0; display: flex; align-items: center; gap: 2px; margin-right: auto; }
.rename-button { width: 30px; height: 30px; color: var(--muted); flex: 0 0 30px; }
.rename-button svg { width: 15px; height: 15px; }
.title-input { width: min(320px, 52vw); height: 34px; padding: 0 10px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; outline: 0; font-size: 17px; font-weight: 600; }
.title-input:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.menu-button { display: none; }
.sidebar.desktop-hidden + .chat-main .menu-button { display: inline-grid; }
.mode-switch { position: absolute; left: 50%; top: 10px; display: grid; grid-template-columns: repeat(2, 108px); padding: 3px; background: var(--bubble); border-radius: var(--radius-pill); transform: translateX(-50%); }
.mode-option { height: 42px; display: grid; place-items: center; color: var(--ink-soft); background: transparent; border: 0; border-radius: var(--radius-pill); text-decoration: none; cursor: pointer; font-size: 16px; }
.mode-option.active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.12); font-weight: 600; }

.messages {
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 24px 42px;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-thumb { background: #d7d7d7; border: 2px solid transparent; border-radius: 4px; background-clip: padding-box; }
.welcome { width: min(760px, 100%); margin: 0 auto; padding-top: var(--welcome-top); }
.welcome h2 { height: var(--welcome-title-h); margin: 0; color: var(--ink); font-size: 32px; line-height: var(--welcome-title-h); text-align: center; font-weight: 500; }
/* 上緣留出「間距＋輸入框＋間距」，輸入框正好浮在標題與建議題目中間。 */
.prompt-list { width: min(680px, 100%); display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: calc(var(--welcome-gap) * 2 + var(--welcome-composer-h)) auto 0; }
.prompt-suggestion { min-height: 42px; display: inline-flex; align-items: center; gap: 9px; padding: 8px 16px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); text-align: left; cursor: pointer; font-size: 15px; }
.prompt-suggestion svg { width: 16px; height: 16px; flex: 0 0 16px; color: var(--ink); fill: none; stroke-width: 1.8; }

.message-row { width: min(760px, 100%); display: flex; margin: 26px auto 0; }
.message-row:last-child { animation: message-in 180ms ease both; }
@keyframes message-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message-avatar { display: none; }
.message-role { display: none; }
.message-content { min-width: 0; flex: 1; }
.message-row.user { justify-content: flex-end; }
.message-row.user .message-content { flex: 0 1 auto; max-width: min(78%, 560px); }
.message-row.user .message-text { padding: 11px 18px; color: var(--ink); background: var(--bubble); border-radius: 24px; }
.message-text { color: var(--ink); font-size: 17px; line-height: 1.8; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-text strong { font-weight: 700; }
.message-text code { padding: 1px 6px; background: var(--bubble); border-radius: 5px; font-family: "SFMono-Regular", Consolas, monospace; font-size: .9em; }
.message-text.rich { white-space: normal; }
.message-text.rich > * { margin: 0; }
.message-text.rich > * + * { margin-top: 10px; }
.message-text.rich ul, .message-text.rich ol { padding-left: 20px; }
.message-text.rich li + li { margin-top: 6px; }
.message-text.rich li::marker { color: var(--muted); }
.message-text .md-heading { font-weight: 700; font-size: 18px; }
.cite-ref { display: inline-grid; place-items: center; min-width: 22px; height: 22px; margin: 0 1px; padding: 0 4px; color: var(--ink-soft); background: var(--bubble); border: 0; border-radius: 50%; cursor: pointer; vertical-align: 2px; font-size: 13px; font-weight: 700; }
.message-status { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; margin-top: 13px; padding: 4px 10px; color: var(--ok); background: var(--ok-soft); border: 0; border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.message-status.escalated { color: var(--warning); background: var(--warning-soft); }
.message-status svg { width: 13px; height: 13px; }
/* 連線失敗後的重送按鈕 */
.retry-button { margin-top: 10px; }

/* 回答評分：👍👎 回饋，供之後加強知識 */
.feedback-row { display: flex; gap: 2px; margin-top: 8px; }
.feedback-button { width: 28px; height: 28px; display: inline-grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; }
.feedback-button.selected[data-rating="up"] { color: var(--ok); background: var(--ok-soft); }
.feedback-button.selected[data-rating="down"] { color: var(--warning); background: var(--warning-soft); }
.feedback-button.copied { color: var(--ok); background: var(--ok-soft); }
.feedback-button svg { width: 15px; height: 15px; }

.citation-list { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.citation-label { color: var(--muted); font-size: 13px; }
.citation-button { min-height: 25px; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); cursor: pointer; font-size: 13px; }
.citation-number { display: grid; place-items: center; width: 18px; height: 18px; color: #fff; background: var(--ink); border-radius: 50%; font-size: 12px; font-weight: 700; }
.typing { display: flex; gap: 5px; padding: 8px 0; }
.typing span { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: pulse 900ms ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: 150ms; }
.typing span:nth-child(3) { animation-delay: 300ms; }
@keyframes pulse { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }
.wait-hint { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.composer-shell { position: relative; z-index: 5; padding: 12px 24px 16px; background: rgba(255, 255, 255, 0.97); border-top: 1px solid transparent; }
.is-empty .composer-shell { position: absolute; top: calc(var(--topbar-h) + var(--welcome-top) + var(--welcome-title-h) + var(--welcome-gap)); left: 0; right: 0; bottom: auto; padding: 0 40px; background: transparent; }
.composer { width: min(820px, 100%); min-height: 58px; display: flex; align-items: center; gap: 8px; margin: 0 auto; padding: 7px 8px 7px 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 28px; }
.is-empty .composer { width: min(640px, 100%); }
/* 輸入列永遠不加陰影（含 focus），只用邊框變深提示 */
.composer:focus-within { border-color: #c8c8c8; }
.composer textarea { min-width: 0; max-height: 160px; flex: 1; resize: none; padding: 9px 4px; color: var(--ink); background: transparent; border: 0; outline: 0; line-height: 1.5; }
.composer textarea::placeholder { color: var(--muted); }
.composer-tool, .composer-action { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; cursor: pointer; }
.composer-tool { color: var(--ink-soft); background: transparent; }
.composer-tool svg { width: 23px; height: 23px; }
.composer-action svg { width: 17px; height: 17px; }
.message-status.degraded { color: var(--caution); background: var(--caution-soft); }
.message-status.boundary { color: var(--ink-soft); background: var(--bubble); }
/* 「查不到資料」不是錯誤也不是警告，用紅色會讓一句「謝謝」看起來像出事了。 */
.message-status.escalated.soft { color: var(--caution); background: var(--caution-soft); }
/* 客服模式的來源收成一顆小鈕，不要把聊天畫面變成報表。 */
.citation-list.compact { margin-top: 8px; }
.citation-list.compact .citation-button { color: var(--muted); border-color: var(--line); padding: 3px 10px; }
.citation-list.compact .citation-button svg { width: 13px; height: 13px; }

/* 觸控裝置的點擊目標要夠大：圓形引用鈕、評分鈕、追問 chip 原本都不到 44px，
   手指按下去常常按到旁邊。只加大可點範圍，視覺尺寸不變。 */
@media (hover: none) {
  .cite-ref { position: relative; }
  .cite-ref::after { content: ""; position: absolute; inset: -11px; }
  .feedback-button { position: relative; }
  .feedback-button::after { content: ""; position: absolute; inset: -8px; }
  .citation-button { min-height: 34px; }
  .followup-button { min-height: 44px; }
  .prompt-suggestion { min-height: 44px; }
}
.retrieval-mode { color: var(--muted); font-size: 14px; white-space: nowrap; }
.send-action { color: #fff; background: var(--ink); }
.send-action:disabled { color: #a5a5a5; background: #e6e6e6; cursor: default; }
.stop-action { color: #fff; background: var(--ink); }

/* 語氣設定：專家（條列講深）／客服（真人聊天一句一句回） */
.tone-toggle { display: inline-flex; gap: 2px; padding: 2px; background: var(--bubble); border-radius: var(--radius-pill); }
.tone-option { min-height: 24px; padding: 2px 12px; color: var(--ink-soft); background: transparent; border: 0; border-radius: var(--radius-pill); cursor: pointer; font-size: 13px; font-weight: 600; }
.tone-option.active { color: #fff; background: var(--ink); }

/* 客服模式的回答：每行畫成一顆獨立訊息泡泡 */
.message-text.bubbles { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.message-text.bubbles .chat-line { max-width: 92%; margin: 0; padding: 9px 15px; background: var(--bubble); border-radius: 18px; line-height: 1.6; }

.source-drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(var(--drawer-width), 92vw); padding: 22px; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--line); box-shadow: -18px 0 50px rgba(0, 0, 0, 0.12); transform: translateX(104%); transition: transform 180ms ease; }
.source-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.drawer-header h2 { margin: 4px 0 0; font-size: 24px; font-weight: 650; }
.source-block { padding: 18px 0; border-bottom: 1px solid var(--line); }
.source-block:last-child { border-bottom: 0; }
.source-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.source-index { color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; font-weight: 700; }
.source-score { color: var(--muted); font-size: 13px; }
.source-block h3 { margin: 10px 0 5px; font-size: 16px; }
.source-locator { color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.source-excerpt { margin: 14px 0 0; padding-left: 13px; color: var(--ink-soft); border-left: 3px solid var(--line-strong); font-size: 15px; line-height: 1.75; white-space: pre-wrap; }
.drawer-overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .3); border: 0; }
/* 手機版選單用：接住選單旁 20% 區域的點擊，但不壓暗畫面 */
/* 推開式選單：遮罩只蓋「被推到右邊的那張頁面」，選單本身還要點得到。 */
.drawer-overlay.clear { background: transparent; }
@media (max-width: 760px) {
  .drawer-overlay.clear { left: 75%; z-index: 30; }
}

/* Administration */
.admin-body { overflow: auto; }
.admin-shell { min-height: 100%; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.admin-nav { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 12px 10px 14px; color: var(--ink); background: var(--sidebar); border-right: 1px solid var(--line); }
.admin-brand { min-height: 52px; padding: 0 7px; color: var(--ink); text-decoration: none; }
.admin-brand .brand-logo { width: 74px; }
.admin-nav-label { margin: 16px 10px 8px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.admin-nav-links { display: grid; gap: 2px; margin-top: 0; }
.admin-nav-links a { min-height: 40px; display: flex; align-items: center; gap: 12px; padding: 8px 10px; color: var(--ink); border-radius: 10px; text-decoration: none; font-size: 15px; }
.admin-nav-links a.active { font-weight: 600; }
.admin-nav-links a.active { background: var(--hover); }
.admin-nav-links svg { width: 17px; }
/* 底部返回鍵：分隔線用 ::before 畫在項目上方 18px 處，項目本身維持 10px 圓角的
   hover。直接在項目上加 border-top 會讓線緊貼文字，下緣也頂到視窗，看起來很擠。 */
.admin-chat-link { position: relative; min-height: 42px; display: flex; align-items: center; gap: 12px; margin-top: auto; padding: 10px; color: var(--ink-soft); border-radius: 10px; text-decoration: none; font-size: 15px; }
.admin-chat-link::before { content: ""; position: absolute; top: -18px; right: 0; left: 0; height: 1px; background: var(--line); }
/* 後台內容給寬度上限並置中：放到 1440px 以上滿版時，健康檢查右側的數值會被
   推到離標籤一千多 px 遠，讀不起來。 */
.admin-main { min-width: 0; padding: 0 32px 72px; }
.admin-section { width: min(var(--admin-content), 100%); margin: 0 auto; padding: 34px 0 40px; scroll-margin-top: 10px; }
.admin-section[hidden] { display: none; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.section-heading h2 { margin: 0; font-size: 24px; font-weight: 600; }
.section-heading p { margin: 6px 0 0; color: var(--ink-soft); font-size: 15px; }
.heading-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

/* 上傳分析彈窗：拖檔進來 → 進度條 → 一塊一塊確認 → 一次存檔。
   卡片高度用 min() 夾住，內容再多也不會把彈窗撐出畫面；捲動交給
   .upload-scroll，標題列與按鈕列才會固定在上下不跟著捲走。 */
.upload-modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; }
.upload-panel { position: relative; z-index: 1; width: min(760px, 100%); max-height: min(84vh, 900px); display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14); }
.upload-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 20px 14px; border-bottom: 1px solid var(--line); }
.upload-head h3 { margin: 0; font-size: 20px; font-weight: 650; }
.upload-head p { margin: 6px 0 0; }
.upload-scroll { display: grid; gap: 16px; align-content: start; padding: 20px; overflow-y: auto; }
/* 彈窗裡的表單欄位：標籤在上、輸入在下，寬度一律滿版。 */
.modal-field { display: grid; gap: 7px; color: var(--ink-soft); font-size: 15px; font-weight: 500; }
.modal-field input, .modal-field select { width: 100%; min-height: 44px; padding: 11px 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; font: inherit; font-size: 15px; }
.modal-field input:focus, .modal-field select:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
/* 下拉會被 enhanceSelects() 換成自訂元件，原生的 select 被藏起來——
   所以樣式要套在看得見的那個（.select-field / .select-button）上。 */
.modal-field .select-field { width: 100%; }
.modal-field .select-button { width: 100%; min-width: 0; min-height: 44px; }
.upload-drop { display: grid; justify-items: center; gap: 8px; padding: 34px 20px; color: var(--ink-soft); background: var(--sidebar); border: 2px dashed var(--line-strong); border-radius: var(--radius-sm); text-align: center; cursor: pointer; transition: border-color 140ms ease, background 140ms ease; }
.upload-drop:focus-visible { border-color: var(--ink); }
/* 拖到上面時要看得出來放開會生效，不然使用者不知道能不能放。 */
.upload-drop.dragging { color: var(--ink); background: var(--bubble); border-color: var(--ink); border-style: solid; }
.upload-drop strong { font-size: 17px; }
.upload-drop span { font-size: 14px; color: var(--muted); }
.upload-drop i { width: 26px; height: 26px; }
.upload-progress { display: grid; gap: 8px; }
.upload-bar { height: 6px; overflow: hidden; background: var(--bubble); border-radius: var(--radius-pill); }
.upload-bar span { display: block; width: 0; height: 100%; background: var(--ink); border-radius: var(--radius-pill); transition: width 220ms ease; }
/* 分析一份檔案要幾十秒又問不到進度，所以跑不定量的動畫；用百分比的話單檔會
   整段停在 0%，看起來像當掉。 */
.upload-bar.working span { width: 40%; animation: upload-sweep 1.1s ease-in-out infinite; transition: none; }
@keyframes upload-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
.upload-results { display: grid; gap: 12px; }
.upload-file { color: var(--muted); font-size: 14px; }
.upload-card { display: grid; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.upload-card.dropped { opacity: .45; }
.upload-card-head { display: flex; align-items: center; gap: 10px; }
.upload-card-head input[type="text"] { flex: 1; min-width: 0; height: 38px; padding: 0 12px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; font: inherit; font-weight: 600; }
.upload-card-meta { display: flex; flex-wrap: wrap; gap: 10px; }
.upload-card-meta input, .upload-card-meta select { height: 36px; padding: 0 10px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; font: inherit; font-size: 14px; }
.upload-card textarea { width: 100%; min-height: 120px; padding: 12px 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; resize: vertical; font: inherit; font-size: 15px; line-height: 1.8; }
.upload-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
/* 候選很多時會捲很長，按鈕列黏在底部才不用捲到最下面才能存。 */
.upload-scroll .editor-actions { position: sticky; bottom: -20px; margin: 0 -20px -20px; padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--line); }
@media (max-width: 760px) {
  /* 手機上做成整頁的 sheet；標題與按鈕列要避開瀏海與底部手勢條。 */
  .upload-modal { padding: 0; }
  .upload-panel { width: 100%; max-height: 100%; height: 100%; border: 0; border-radius: 0; }
  .upload-head { padding-top: max(20px, env(safe-area-inset-top)); }
  .upload-scroll .editor-actions { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}
.command-button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 18px; color: #fff; background: var(--ink); border: 0; border-radius: var(--radius-pill); cursor: pointer; font-weight: 600; font-size: 15px; }
.command-button svg { width: 16px; height: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
/* 回覆品質有五個數字：用 auto-fit 讓它們填滿一列，不要留一格孤零零掉到第二行。 */
#reply-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat-card { min-width: 0; padding: 18px 20px; background: var(--surface); border-right: 1px solid var(--line); }
.stat-card:last-child { border-right: 0; }
.stat-card { }
.stat-card span { display: block; color: var(--muted); font-size: 14px; }
.stat-card strong { display: block; margin-top: 10px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 32px; line-height: 1.1; }
/* 只有真的有待整理的知識才標紅：0 也塗紅會讓人以為出事了。 */
.alert-stat[data-alert="true"] strong { color: var(--warning); }
.pipeline-heading { margin: 30px 0 12px; }
.pipeline-heading h3 { margin: 0; font-size: 17px; font-weight: 600; }
.pipeline-heading p { margin: 5px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.health-overview { display: grid; grid-template-columns: minmax(250px, 1fr) auto; align-items: stretch; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.health-overall-panel { min-height: 82px; display: flex; align-items: center; gap: 13px; padding: 16px 18px; }
.health-state-icon { width: 36px; height: 36px; display: grid; place-items: center; color: var(--muted); background: var(--bubble); border-radius: 50%; }
.health-state-icon svg { width: 19px; height: 19px; }
.health-overall-panel > div > span { display: block; color: var(--muted); font-size: 14px; }
.health-overall-panel strong { display: block; margin-top: 4px; font-size: 20px; }
.health-overview[data-status="ok"] .health-state-icon { color: var(--ok); background: var(--ok-soft); }
.health-overview[data-status="warning"] .health-state-icon { color: var(--caution); background: var(--caution-soft); }
.health-overview[data-status="error"] .health-state-icon { color: var(--warning); background: var(--warning-soft); }
.health-summary { display: grid; grid-template-columns: repeat(3, minmax(76px, 1fr)); border-left: 1px solid var(--line); }
.health-summary span { min-width: 84px; display: grid; place-items: center; align-content: center; gap: 4px; padding: 14px; color: var(--muted); border-left: 1px solid var(--line); font-size: 14px; }
.health-summary span:first-child { border-left: 0; }
.health-summary strong { color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; font-size: 24px; }
.health-grid { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
/* 兩欄：左邊狀態與說明、右邊數值。原本三欄會把數值推到列的最右端，
   在寬螢幕上跟它的標籤距離超過 1000px，等於看不懂。 */
.health-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) minmax(0, auto); align-items: center; gap: 14px; min-height: 84px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.health-item:last-child { border-bottom: 0; }
.health-item-icon { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); background: var(--bubble); border-radius: 8px; }
.health-item-icon svg { width: 17px; height: 17px; }
.health-item[data-status="ok"] .health-item-icon { color: var(--ok); background: var(--ok-soft); }
.health-item[data-status="warning"] .health-item-icon { color: var(--caution); background: var(--caution-soft); }
.health-item[data-status="error"] .health-item-icon { color: var(--warning); background: var(--warning-soft); }
.health-item-copy > div { display: flex; align-items: center; gap: 8px; }
.health-item-copy strong { font-size: 15px; }
.health-item-copy p { margin: 6px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.health-badge { padding: 3px 9px; color: var(--muted); background: var(--bubble); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.health-item[data-status="ok"] .health-badge { color: var(--ok); background: var(--ok-soft); }
.health-item[data-status="warning"] .health-badge { color: var(--caution); background: var(--caution-soft); }
.health-item[data-status="error"] .health-badge { color: var(--warning); background: var(--warning-soft); }
.health-item-meta { min-width: 0; max-width: 460px; display: grid; justify-items: end; }
.health-item-meta > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px 14px; }
.health-item-meta > div span { color: var(--ink-soft); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.health-item-meta b { margin-right: 5px; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 500; }
/* 延遲時間跟狀態徽章放一起，才看得出來是誰的耗時。 */
.health-latency { color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.command-button.is-loading svg { animation: health-spin 800ms linear infinite; }
@keyframes health-spin { to { transform: rotate(360deg); } }
.admin-search-form { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-search-form input { min-width: 0; height: 42px; flex: 1; padding: 0 14px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; }
.admin-search-form input:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.admin-search-form select { height: 42px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; color: var(--ink); font-size: 15px; cursor: pointer; }
.admin-search-form select:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.compact-search { max-width: 640px; margin-bottom: 4px; }
.user-form { max-width: 840px; margin-bottom: 14px; }
.user-form select { flex: 0 0 132px; }
.role-badge { display: inline-block; padding: 3px 10px; color: var(--muted); background: var(--bubble); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.role-badge.is-admin { color: var(--ok); background: var(--ok-soft); }
.bordered-icon { color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); }
.result-list { display: grid; gap: 8px; margin-top: 14px; }
.result-row { padding: 14px 0; border-top: 1px solid var(--line); }
.result-row:first-child { border-top: 0; }
.result-row h3 { margin: 0; font-size: 15px; }
.result-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.result-row p { margin: 9px 0 0; color: var(--ink-soft); font-size: 15px; line-height: 1.7; }
.table-shell { max-width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table th { padding: 12px 16px; color: var(--muted); background: var(--sidebar); border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; font-weight: 600; white-space: nowrap; }
.data-table td { max-width: 460px; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.data-table tr:last-child td { border-bottom: 0; }
.table-status { display: inline-flex; padding: 3px 9px; color: var(--ok); background: var(--ok-soft); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.table-status.escalated { color: var(--warning); background: var(--warning-soft); }
.empty-state { padding: 28px; color: var(--muted); text-align: center; font-size: 15px; }

/* 載入中：一條跑不定量的進度條。單純寫「載入中」看不出來系統還活著，也不知道
   要不要繼續等；請求逾時是 20 秒，動畫一停就代表出事了。
   整個元件只靠一個 class：文字與進度條都用虛擬元素畫，這樣 HTML 的初始狀態與
   JS 重新填的那一份不會各寫一份而走鐘。 */
.loading-state { display: grid; gap: 12px; justify-items: center; padding: 28px 20px; }
.loading-state::before {
  content: "";
  width: min(240px, 70%);
  height: 4px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--bubble) 0 38%, var(--ink) 44% 56%, var(--bubble) 62% 100%);
  background-size: 260% 100%;
  animation: loading-sweep 1.2s ease-in-out infinite;
}
.loading-state::after { content: "載入中"; color: var(--muted); font-size: 14px; }
@keyframes loading-sweep { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* 載入失敗要停下來講清楚，不能繼續假裝在載入——toast 消失之後畫面上只剩
   「載入中」，使用者會一直等一個永遠不會來的東西。 */
.load-failed { display: grid; gap: 12px; justify-items: center; padding: 28px 20px; color: var(--muted); font-size: 15px; text-align: center; }
.knowledge-count { margin: 12px 2px 0; color: var(--muted); font-size: 15px; }
/* 知識卡內文照原結構條列呈現 */
.knowledge-text { color: var(--ink-soft); font-size: 15px; line-height: 1.7; }
.knowledge-text p { margin: 0 0 6px; }
.knowledge-text ul, .knowledge-text ol { margin: 0 0 6px; padding-left: 20px; }
.knowledge-text li { margin: 3px 0; }
.knowledge-text li::marker { color: var(--muted); }
.knowledge-text .knowledge-more { color: var(--muted); }
/* AI 模型校調：左側分組選單、右側該組的規則。51 條排成一長串會看不完。 */
.tuning-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); gap: 26px; align-items: start; }
.tuning-menu { position: sticky; top: 16px; display: grid; gap: 2px; }
.tuning-menu button { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 8px 12px; color: var(--ink-soft); background: transparent; border: 0; border-radius: 10px; cursor: pointer; text-align: left; font-size: 15px; }
.tuning-menu button.active { color: var(--ink); background: var(--bubble); font-weight: 600; }
.tuning-menu em { flex: 0 0 auto; color: var(--muted); font-style: normal; font-size: 13px; }
.tuning-menu button.active em { color: var(--ink-soft); }
.tuning-groups { display: grid; gap: 8px; }
.tuning-groups .pipeline-heading { margin-top: 0; }
.tuning-rules { display: grid; gap: 10px; }
.tuning-rule { display: grid; gap: 12px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tuning-rule.is-custom { border-color: var(--ink); }
.tuning-rule-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tuning-rule-head strong { margin-right: 8px; font-size: 15px; }
.tuning-rule-head p { margin: 6px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.tuning-rule textarea { width: 100%; padding: 12px 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; resize: vertical; font: inherit; font-size: 15px; line-height: 1.8; }
.tuning-rule textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.tuning-rule-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.tuning-rule-actions .command-button { min-height: 34px; padding: 0 16px; font-size: 14px; }

/* 「看實際指令」：顯示組好之後真正送給模型的整段文字。 */
.preview-panel { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: rgba(13, 13, 13, .32); }
.preview-card { width: min(880px, 100%); max-height: min(80vh, 760px); display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.preview-head { display: flex; align-items: center; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.preview-head h3 { margin: 0; font-size: 17px; }
.preview-head p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.preview-tabs { display: flex; gap: 6px; margin-left: auto; }
.preview-tab { min-height: 32px; padding: 0 14px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); cursor: pointer; font-size: 14px; }
.preview-tab.active { color: #fff; background: var(--ink); border-color: var(--ink); font-weight: 600; }
.preview-body { margin: 0; padding: 20px; overflow: auto; color: var(--ink-soft); font-family: "SFMono-Regular", Consolas, monospace; font-size: 14px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(360px, calc(100vw - 44px)); padding: 11px 16px; color: #fff; background: var(--ink); border-radius: var(--radius-sm); box-shadow: 0 10px 30px rgba(0, 0, 0, .2); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 140ms ease, transform 140ms ease; font-size: 15px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--warning); }

@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card:nth-child(2) { border-right: 0; }
  .stat-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  /* Inputs below 16px trigger focus-zoom on iOS Safari. */
  input, select, textarea { font-size: 18px; }
  .icon-button { width: 40px; height: 40px; }
  .app-shell { display: block; }
  /* 手機版選單是「把主畫面往右推」，不是蓋在上面（比照 ChatGPT App）：
     選單一直在底下不動，動的是 .chat-main——往右推 75%、縮一點、帶圓角與陰影，
     看起來像整張頁面被推到旁邊。
     兩個關鍵：
     (1) `transform-origin: left center`——用預設的 center 時，縮放會讓左緣再往右
         移一段，蓋不準的那條縫會露出選單，透明遮罩也對不齊。
     (2) .chat-main 要有自己的底色，不然推開後會透出下面的選單。 */
  .sidebar, .sidebar.desktop-hidden { position: fixed; inset: 0; right: auto; z-index: 10; width: 75%; margin-left: 0; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--surface); border-right: 0; transform: none; transition: none; }
  .chat-main { position: relative; z-index: 20; background: var(--canvas); transform-origin: left center; transition: transform 260ms cubic-bezier(.32, .72, 0, 1), border-radius 260ms ease, box-shadow 260ms ease; }
  .sidebar.open + .chat-main { overflow: hidden; border-radius: 20px; box-shadow: -2px 0 24px rgba(0, 0, 0, .18); transform: translateX(75%) scale(.92); }
  .sidebar-close, .menu-button, .sidebar.desktop-hidden + .chat-main .menu-button { display: inline-grid; }
  .sidebar-panel { display: none; }
  /* 手機版 topbar 是 auto row，高度含安全區，所以變數要跟著算。 */
  :root {
    --topbar-h: max(58px, calc(max(8px, env(safe-area-inset-top)) + 42px));
    --welcome-top: 20vh;
    --welcome-title-h: 37px;
    --welcome-gap: 34px;
    --welcome-composer-h: 52px;
  }
  .chat-main { height: 100svh; height: 100dvh; grid-template-rows: auto minmax(0, 1fr) auto; }
  .topbar { min-height: 58px; padding: max(8px, env(safe-area-inset-top)) 13px 8px; }
  .topbar h1 { max-width: 52vw; font-size: 17px; }
  .rename-button { width: 34px; height: 34px; flex-basis: 34px; }
  .title-input { font-size: 18px; }
  .mode-switch { top: 8px; grid-template-columns: repeat(2, 84px); }
  .mode-option { height: 36px; font-size: 15px; }
  .messages { padding: 0 14px 26px; }
  .welcome h2 { font-size: 26px; }
  .prompt-suggestion { font-size: 15px; }
  .message-row { margin-top: 22px; }
  .message-row.user .message-content { max-width: 86%; }
  .message-text { font-size: 18px; line-height: 1.75; }
  .composer-shell { padding: 9px 11px max(10px, env(safe-area-inset-bottom)); }
  .is-empty .composer-shell { padding: 0 24px; }
  .composer { min-height: 52px; padding: 5px 6px 5px 10px; }
  /* 手機版空白頁輸入框不要滿版 */
  .is-empty .composer { width: min(400px, 100%); }
  .account-card { grid-template-columns: 96px minmax(0, 1fr); min-height: 260px; }
  .account-content { padding: 16px 14px; }
  .composer-tool, .composer-action { width: 38px; height: 38px; flex-basis: 38px; }
  .retrieval-mode { display: none; }
  /* 手機版後台＝App 的形狀：分頁列固定在底部（拇指按得到），左上角是返回前台。
     原本兩者都擠在頂端，光導覽就吃掉快 400px 的高度。 */
  .admin-shell { display: block; }
  /* flex-direction 要明寫成 row：桌機版是 column，只設 align-items: center
     的話在直向排列裡等於「水平置中」，返回鍵會跑到正中間。 */
  .admin-nav { position: sticky; top: 0; z-index: 20; display: flex; flex-direction: row; align-items: center; width: 100%; height: auto; padding: max(8px, env(safe-area-inset-top)) 12px 8px; background: var(--canvas); border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-brand, .admin-nav-label { display: none; }
  /* 返回鍵放左上角，是這一列唯一的東西。 */
  .admin-chat-link { min-height: 38px; margin: 0; padding: 6px 8px 6px 4px; color: var(--ink); border-radius: 10px; font-weight: 600; }
  .admin-chat-link::before { display: none; }
  /* 底部分頁列：六格等寬，圖示上、短標籤下。 */
  .admin-nav-links { position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; margin: 0; padding: 6px 4px max(6px, env(safe-area-inset-bottom)); background: var(--canvas); border-top: 1px solid var(--line); }
  .admin-nav-links a { min-height: 46px; flex-direction: column; justify-content: center; gap: 3px; padding: 4px 2px; color: var(--muted); border-radius: 10px; font-size: 11px; }
  .admin-nav-links a.active { color: var(--ink); background: transparent; }
  .admin-nav-links svg { width: 20px; height: 20px; }
  /* 完整名稱在手機上放不下（「AI 模型校調」六個字），改用 data-short。 */
  .admin-nav-links span { display: none; }
  .admin-nav-links a::after { content: attr(data-short); }
  /* 內容不能被底部分頁列蓋住。 */
  .admin-main { padding: 0 16px calc(64px + max(6px, env(safe-area-inset-bottom))); }
  .admin-section { padding: 22px 0 30px; }
  .section-heading { flex-direction: column; align-items: flex-start; gap: 12px; }
  .section-heading h2 { font-size: 20px; }
  .health-item { grid-template-columns: 30px minmax(0, 1fr); row-gap: 10px; }
  .health-item-meta { grid-column: 1 / -1; max-width: none; justify-items: start; }
  .health-item-meta > div { justify-content: flex-start; }
  .editor-row.even-row { grid-template-columns: 1fr; }
  .section-heading { flex-wrap: wrap; }
  .section-heading { align-items: flex-start; }
  .pipeline-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .health-overview { grid-template-columns: 1fr; }
  .health-summary { border-top: 1px solid var(--line); border-left: 0; }
  .health-item { grid-template-columns: 30px minmax(0, 1fr); }
  .health-item-meta { grid-column: 2; flex-direction: column; gap: 7px; }
  .health-item-meta > div { justify-content: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tuning-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  /* 手機版選單改成可橫向捲的一排。 */
  .tuning-menu { position: static; grid-auto-flow: column; grid-auto-columns: max-content; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .tuning-menu button { border: 1px solid var(--line-strong); border-radius: var(--radius-pill); }
  .tuning-menu button.active { border-color: var(--ink); }
  /* 維持橫排：改成直排的話還原鍵會被撐成一個滿版的空盒子。 */
  .tuning-rule-head { flex-direction: row; align-items: flex-start; }
  .preview-panel { padding: 12px; }
  .preview-head { flex-wrap: wrap; }
  .preview-tabs { margin-left: 0; }
  .admin-search-form { align-items: stretch; }
  /* Narrow screens: search on its own row, filters underneath. */
  .compact-search input[type="search"] { flex: 1 0 100%; }
  .compact-search .select-field { flex: 1 1 auto; }
  .compact-search .select-button { min-width: 0; width: 100%; }
  /* 帳號表格：帳號與狀態不要斷字（原本「jason」被拆成兩行）。 */
  .data-table th, .data-table td { padding: 10px 12px; }
  .data-table td:first-child, .data-table td:nth-child(3) { white-space: nowrap; }
  .role-badge { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.followup-list { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; margin-top: 14px; }
.followup-button { min-height: 36px; display: inline-flex; align-items: center; gap: 8px; padding: 7px 15px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); cursor: pointer; text-align: left; font-size: 15px; }
.followup-button svg { width: 14px; height: 14px; flex: 0 0 14px; color: var(--muted); }

/* Knowledge curation views */
.heading-actions { display: flex; align-items: center; gap: 8px; }
.ghost-button { color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); text-decoration: none; }
.domain-grid { display: grid; gap: 14px; }
.domain-block { padding: 18px 20px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.domain-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.domain-head h4 { margin: 0; font-size: 17px; font-weight: 600; }
.domain-head span { color: var(--muted); font-size: 14px; }
.domain-badge { padding: 2px 8px; color: var(--ink-soft); background: var(--bubble); border: 1px solid var(--line); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
/* 分類卡改用淡底而不是每格都描一條框：一頁 40 幾格時框線比內容還搶眼。 */
.category-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; color: var(--ink-soft); background: var(--bubble); border: 0; border-radius: var(--radius-sm); font-size: 15px; }
.category-card strong { color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; font-size: 17px; }
.knowledge-list { display: grid; gap: 10px; margin-top: 16px; }
/* 知識庫＝QA 式收合清單：一列一則、彼此靠在一起，點標題才展開。
   278 則攤開來是看不完的，收起來才掃得動。
   **不要外框**：`#knowledge-results` 本身就是 `.knowledge-list`，再包一層或
   再描一個框就會變成框裡有框。列與列之間只用一條分隔線。 */
.knowledge-list { display: grid; }
.knowledge-row { border-top: 1px solid var(--line); }
.knowledge-row:first-of-type { border-top: 0; }
.knowledge-row.open { background: var(--sidebar); border-radius: var(--radius-sm); }
/* 一列式：標題、主題、來源、分類、定位點、字數全部排在同一行。
   標題吃掉剩下的空間並截斷（`flex: 1` ＋ `min-width: 0`，少了 min-width
   長標題會把後面的東西擠出去），字數靠最右邊，278 列的右緣才會對齊。 */
.knowledge-summary { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px; color: var(--ink); background: transparent; border: 0; cursor: pointer; text-align: left; font: inherit; }
.knowledge-summary-title { flex: 1 1 auto; min-width: 0; overflow: hidden; font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.knowledge-summary > .domain-badge, .knowledge-summary > .origin-badge { flex: 0 0 auto; }
.knowledge-category { flex: 0 0 auto; color: var(--muted); font-size: 14px; white-space: nowrap; }
.knowledge-summary > .source-locator { flex: 0 0 auto; }
/* 收合時箭頭朝右，展開轉成朝下。 */
.knowledge-chevron { flex: 0 0 16px; width: 16px; height: 16px; color: var(--muted); transition: transform 140ms ease; }
.knowledge-row.open .knowledge-chevron { transform: rotate(90deg); }
.knowledge-length { flex: 0 0 62px; color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; text-align: right; }
.knowledge-detail { padding: 0 10px 14px 36px; }
.knowledge-detail .knowledge-actions { margin-top: 12px; }

/* 知識庫的手機版。**這個 media query 一定要放在上面那些規則後面**：
   media query 不加權重，同分時是後者勝——寫在檔案前段的話會被桌機規則蓋掉
   （實測標題被擠成「第…」還往右溢出）。
   390px 放不下一列六個欄位，所以改成兩行：標題與字數一行、次要資訊一行。 */
@media (max-width: 760px) {
  .knowledge-summary { flex-wrap: wrap; row-gap: 4px; padding: 12px 8px; }
  .knowledge-summary-title { flex: 1 1 auto; overflow: visible; white-space: normal; }
  /* 主題、來源、分類在手機上資訊量最低，收起來換版面。 */
  .knowledge-summary > .domain-badge, .knowledge-summary > .origin-badge,
  .knowledge-summary > .knowledge-category { display: none; }
  /* 字數靠右收在第一行；定位點自己一行。兩個細節少一個就會歪：
     - `flex-basis: 100%` 才會真的換行（光給 order 只改順序，不會換行）；
     - 定位點在 DOM 裡排在字數前面，所以要用 order 把它推到最後，
       不然它先換行、字數就被擠到第三行去了。
     縮排用 padding 不用 margin：margin 會加在 100% 之外，右緣會溢出。 */
  .knowledge-length { order: 2; margin-left: auto; }
  .knowledge-summary > .source-locator { order: 3; flex: 0 0 100%; padding-left: 26px; }
  .knowledge-detail { padding: 0 8px 12px 26px; }
}
.knowledge-card { padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.knowledge-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.knowledge-card h3 { margin: 0; font-size: 17px; font-weight: 600; }
.knowledge-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 6px; color: var(--muted); font-size: 14px; }
.knowledge-actions { display: flex; flex: 0 0 auto; gap: 4px; }
.knowledge-card p { margin: 12px 0 0; color: var(--ink-soft); font-size: 15px; line-height: 1.75; }
.knowledge-note { color: var(--muted); font-size: 14px; white-space: nowrap; }
.origin-badge { padding: 2px 8px; color: var(--muted); background: var(--bubble); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; }
.origin-badge.is-custom { color: var(--ok); background: var(--ok-soft); }
.issue-chip { display: inline-block; padding: 3px 9px; color: var(--caution); background: var(--caution-soft); border-radius: var(--radius-pill); font-size: 14px; font-weight: 600; }
.issue-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.knowledge-editor { display: grid; gap: 16px; margin-bottom: 16px; padding: 22px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.editor-row { display: grid; grid-template-columns: 2fr 1.2fr 1fr; gap: 14px; }
/* 整列都是同類欄位時要等寬——LINE 設定的三個下拉原本 2:1.2:1，看起來像沒對齊。 */
.editor-row.even-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.knowledge-editor label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 15px; font-weight: 500; }
.knowledge-editor input, .knowledge-editor select, .knowledge-editor textarea { min-height: 44px; padding: 11px 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: 0; font-size: 16px; }
.knowledge-editor textarea { resize: vertical; line-height: 1.7; }
.knowledge-editor input:focus, .knowledge-editor select:focus, .knowledge-editor textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.editor-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.editor-hint { margin-right: auto; color: var(--muted); font-size: 14px; }

@media (max-width: 760px) {
  .heading-actions { width: 100%; }
  .heading-actions .command-button { flex: 1; justify-content: center; }
  .editor-row { grid-template-columns: 1fr; }
  .category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-row { grid-template-columns: 1fr; }
  .knowledge-head { flex-direction: column; }
}

/* In-page dropdown: the native <select> opens an OS picker that covers the
   page, so it stays hidden and this renders in its place. */
.select-field { position: relative; display: inline-flex; }
.select-field > select { display: none; }
.select-button { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 148px; height: 42px; padding: 0 12px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: inherit; font-size: 15px; cursor: pointer; }
.select-field.is-open .select-button { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.select-button i { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }
.select-field.is-open .select-button i { transform: rotate(180deg); }
.select-menu { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 100%; padding: 6px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: 0 12px 32px rgba(15, 15, 15, 0.12); display: grid; gap: 2px; }
.select-menu button { padding: 9px 10px; color: var(--ink); background: none; border: 0; border-radius: 6px; font: inherit; font-size: 15px; text-align: left; white-space: nowrap; cursor: pointer; }
.select-menu button.is-selected { background: var(--bubble); font-weight: 600; }
.knowledge-editor .select-field, .knowledge-editor .select-button { width: 100%; }

/* Search row controls share one height so the icon button lines up. */
.admin-search-form .bordered-icon { width: 42px; height: 42px; flex: 0 0 42px; border-radius: var(--radius-sm); }
.compact-search { align-items: center; }

/* 觸控裝置沒有滑鼠，但點過之後 `:hover` 會黏在最後點到的那個元素上——側欄會
   同時出現兩個灰底（一個是真的選中的，一個是上次點過的殘留）。所以 hover 的
   視覺一律關在 `hover: hover` 裡，只有真的有滑鼠時才生效。
   `.active` 與 `:focus-visible`／`:focus-within` 不在這裡，它們代表真的狀態，
   在觸控裝置上也要看得到。 */
@media (hover: hover) {
  .icon-button:hover { background: var(--hover); }
  .primary-nav-item:hover { background: var(--hover); }
  .conversation-item:hover { background: var(--hover); }
  .conversation-item:hover .conversation-delete { opacity: 1; }
  .conversation-delete:hover { color: var(--warning); background: #e4e4e4; }
  .account-tab:hover { background: var(--hover); }
  .account-trigger:hover { background: var(--hover); }
  .tone-indicator:hover { color: var(--ink); background: var(--hover); }
  .tone-confirm-actions .tone-cancel:hover { background: var(--bubble); }
  .prompt-suggestion:hover { color: var(--ink); background: var(--bubble); }
  .cite-ref:hover { color: #fff; background: var(--ink); }
  .feedback-button:hover { color: var(--ink); background: var(--hover); }
  .citation-button:hover { color: var(--ink); background: var(--bubble); }
  .composer-tool:hover { background: var(--hover); }
  .send-action:hover { background: #3d3d3d; }
  .admin-nav-links a:hover { background: var(--hover); }
  .admin-chat-link:hover { color: var(--ink); background: var(--hover); }
  .upload-drop:hover { border-color: var(--ink); }
  .command-button:hover { background: #3d3d3d; }
  .tuning-menu button:hover { background: var(--hover); }
  .followup-button:hover { color: var(--ink); background: var(--bubble); }
  .ghost-button:hover { background: var(--bubble); }
  .select-button:hover { border-color: var(--ink-soft); }
  .select-menu button:hover { background: var(--bubble); }
}
