:root {
  --ui-font-scale: 1;
  --ui-layout-height-vh: 100vh;
  --ui-layout-height-dvh: 100dvh;
  --ink: #17322a;
  --muted: #64766f;
  --line: #dfe8e2;
  --paper: #fffefa;
  --canvas: #f2f6f1;
  --green: #1f6b4f;
  --green-dark: #164b39;
  --green-soft: #e4f1e9;
  --gold: #d49738;
  --danger: #b64236;
  --shadow: 0 18px 50px rgba(30, 66, 52, .1);
  --radius: 20px;
  --document-panel-width: 620px;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7f0eb;
  --muted: #a7bbb1;
  --line: #30443a;
  --paper: #18231e;
  --canvas: #101713;
  --green: #52b789;
  --green-dark: #9ad6ba;
  --green-soft: #203a2f;
  --gold: #e0a84f;
  --danger: #f07b70;
  --shadow: 0 18px 50px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: var(--ui-layout-height-vh); min-height: var(--ui-layout-height-dvh); overflow-x: clip; background: radial-gradient(circle at 90% 0, #e3efe3 0, transparent 30%), var(--canvas); zoom: var(--ui-font-scale); }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(31, 107, 79, .22); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

:root[data-theme="dark"] body { background: radial-gradient(circle at 90% 0, rgba(46, 91, 68, .42) 0, transparent 30%), var(--canvas); }
:root[data-theme="dark"] .topbar { border-bottom-color: rgba(126, 180, 153, .18); background: rgba(18, 28, 23, .9); }
:root[data-theme="dark"] .sidebar { background: rgba(18, 28, 23, .92); }
:root[data-theme="dark"] :is(.status-chip, .icon-button, .new-conversation-button, .history-toggle, .upload-button, .secondary-button, .select-label select, .answer-feedback-actions button, .negative-feedback-actions button, .vision-feedback button, .vision-crop-field input, .vision-citations a, .vision-citations button, .document-toolbar button, .document-pane-toggle, .login-card input) { color: var(--ink); border-color: var(--line); background: #1d2b24; }
:root[data-theme="dark"] :is(.integration-card, .suggestion, .message.is-user .message-body, .citation, .evidence-figure, .negative-feedback-form, .vision-decision, .vision-recommendation, .login-card, .login-copy li) { color: var(--ink); border-color: var(--line); background: rgba(24, 35, 30, .96); }
:root[data-theme="dark"] :is(.welcome-card, .portal-card, .portal-card-chat) { border-color: var(--line); background: linear-gradient(145deg, rgba(29, 43, 36, .98), rgba(20, 31, 26, .96)); }
:root[data-theme="dark"] .composer { border-color: var(--line); background: rgba(24, 35, 30, .97); box-shadow: 0 22px 60px rgba(0, 0, 0, .36); }
:root[data-theme="dark"] .composer-toolbar, :root[data-theme="dark"] .composer-note { border-color: var(--line); }
:root[data-theme="dark"] .question-field textarea::placeholder { color: #879b91; }
:root[data-theme="dark"] .citation:hover { border-color: #547965; background: #1d2b24; }
:root[data-theme="dark"] .citation blockquote { color: #bfd0c7; border-left-color: #5f8b74; background: #14201a; }
:root[data-theme="dark"] .answer-warnings { color: #f2cd93; border-color: #755a32; background: #3b2c19; }
:root[data-theme="dark"] .cancel-button { color: var(--danger); border-color: #754742; background: #35201e; }
:root[data-theme="dark"] .negative-feedback-form { border-color: #68433f; background: #2b1d1b; }
:root[data-theme="dark"] :is(.vision-stage, .preview) { background: #17231d; }
:root[data-theme="dark"] :is(.vision-decision.is-classified, .vision-recommendation.is-grounded) { border-color: #547965; background: #193126; }
:root[data-theme="dark"] .portal-panel { background: radial-gradient(circle at 12% 15%, rgba(43, 91, 66, .42), transparent 32%), linear-gradient(145deg, #111a16, #18231e 58%); }
:root[data-theme="dark"] .document-divider { border-color: #3a5045; background: #26372e; }
:root[data-theme="dark"] .document-viewer { background: #111a16; }
:root[data-theme="dark"] .document-viewer-header { border-bottom-color: var(--line); background: rgba(24, 35, 30, .98); }
:root[data-theme="dark"] .document-preview-loading { background: linear-gradient(100deg, #1a2821 30%, #25372e 45%, #1a2821 60%); background-size: 220% 100%; }
:root[data-theme="dark"] .document-preview-status { border-color: var(--line); background: rgba(24, 35, 30, .88); }
:root[data-theme="dark"] .evidence-figure img { background: #17231d; }
:root[data-theme="dark"] .evidence-figure.is-loading img { background: linear-gradient(100deg, #17231d 30%, #25372e 45%, #17231d 60%); background-size: 220% 100%; }
.public-only, .auth-only, .portal-only, .session-only { display: none; }
body[data-auth="guest"] .public-only { display: grid; }
body[data-auth="authenticated"][data-view="chat"] .auth-only { display: flex; }
body[data-auth="authenticated"][data-view="portal"] .portal-only { display: grid; }
body[data-auth="authenticated"] .session-only { display: flex; }
body[data-auth="authenticated"][data-view="chat"] { height: var(--ui-layout-height-vh); height: var(--ui-layout-height-dvh); overflow: hidden; }
body[data-auth="authenticated"][data-view="chat"] .app-shell { height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 76px minmax(0, 1fr); overflow: hidden; }
body[data-auth="authenticated"][data-view="chat"] .topbar { position: relative; top: auto; }
body[data-auth="authenticated"][data-view="chat"] .workspace { height: 100%; min-height: 0; overflow: hidden; }

.app-shell { min-height: var(--ui-layout-height-vh); min-height: var(--ui-layout-height-dvh); overflow-x: clip; }
.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; border-bottom: 1px solid rgba(31, 107, 79, .12); background: rgba(255, 254, 250, .88); backdrop-filter: blur(16px); position: sticky; top: 0; z-index: 20; }
.brand { display: inline-flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 16px; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; color: white; font-weight: 800; border-radius: 12px 12px 12px 4px; background: linear-gradient(145deg, #2b7f5f, #164c39); box-shadow: 0 8px 20px rgba(31, 107, 79, .24); }
.brand-mark.large { width: 54px; height: 54px; font-size: 22px; border-radius: 17px 17px 17px 6px; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.topbar > .status-chip { margin-left: auto; margin-right: 16px; }
.status-short { display: none; }
.status-chip { display: inline-flex; flex-shrink: 0; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 999px; color: var(--muted); background: #f4f7f4; font-size: 12px; }
.status-chip i { flex: 0 0 7px; width: 7px; height: 7px; border-radius: 50%; background: #96a69f; }
.status-chip.is-ready { color: var(--green-dark); background: var(--green-soft); }
.status-chip.is-ready i { background: #35a36f; box-shadow: 0 0 0 4px rgba(53, 163, 111, .12); }
.status-chip.is-error { color: var(--danger); background: #faece9; }
.status-chip.is-error i { background: var(--danger); }
.text-button, .icon-button, .secondary-button { border: 0; color: var(--green-dark); background: transparent; }
/* Topbar controls are flex items. min-width keeps them from shrinking under the
   44px touch target on 320-360px phones, and nowrap stops a squeezed label from
   wrapping into a tall, thin control that still fails the check. */
.text-button { min-height: 44px; min-width: 44px; white-space: nowrap; font-weight: 700; padding: 8px; }
.new-conversation-button, .history-toggle { min-height: 44px; min-width: 44px; align-items: center; white-space: nowrap; padding: 7px 11px; border: 1px solid #bcd5c7; border-radius: 10px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 800; }
.new-conversation-button i { display: none; font-style: normal; }
.new-conversation-button:hover { border-color: #8fb9a4; background: #d9ebdf; }
.new-conversation-button:disabled { opacity: .5; cursor: wait; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; background: #edf3ee; font-size: 15px; }
body[data-auth="authenticated"] .history-toggle, .history-close { display: none; }

.workspace { min-height: calc(var(--ui-layout-height-vh) - 76px); min-height: calc(var(--ui-layout-height-dvh) - 76px); display: grid; grid-template-columns: 270px minmax(0, 1fr); }
body[data-view="portal"] .workspace { grid-template-columns: minmax(0, 1fr); }
body.document-viewer-open .workspace { grid-template-columns: 270px minmax(0, 1fr) 16px var(--document-panel-width); }
body.document-viewer-collapsed .workspace { grid-template-columns: 270px minmax(0, 1fr) 16px 0; }
.sidebar { flex-direction: column; min-height: calc(var(--ui-layout-height-vh) - 76px); min-height: calc(var(--ui-layout-height-dvh) - 76px); padding: 28px 20px; border-right: 1px solid var(--line); background: rgba(247, 250, 246, .7); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.sidebar-heading h2 { margin: 3px 0 0; font-size: 17px; }
.sidebar-actions { display: flex; gap: 6px; }
.history-backdrop { position: fixed; inset: 76px 0 0; z-index: 49; padding: 0; border: 0; background: rgba(15, 35, 28, .42); }
.history-status { min-height: 20px; margin: -8px 0 10px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.history-status:empty { display: none; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
.history-list { min-height: 0; flex: 1 1 auto; display: grid; align-content: start; gap: 7px; overflow: auto; overscroll-behavior: contain; }
.history-empty { color: var(--muted); font-size: 13px; padding: 14px 4px; line-height: 1.6; }
.history-entry { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 4px; align-items: stretch; }
.history-item { min-height: 50px; border: 1px solid transparent; border-radius: 12px; padding: 11px 12px; background: transparent; text-align: left; color: var(--ink); }
.history-item:hover { border-color: var(--line); background: var(--paper); }
.history-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.history-item small { color: var(--muted); font-size: 10px; }
.history-delete { width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 10px; color: var(--danger); background: transparent; }
.history-delete:hover { background: #faece9; }
.history-entry-actions { display: flex; flex-direction: column; }
.history-copy { display: grid; place-items: center; width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 10px; color: var(--muted); background: transparent; }
.history-copy:hover { color: var(--green-dark); background: var(--green-soft); }
.history-copy:disabled { opacity: .5; cursor: wait; }
.integration-card { margin-top: auto; padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 255, 255, .72); }
.integration-row { display: flex; justify-content: space-between; gap: 10px; padding-top: 11px; font-size: 12px; }
.integration-row b { color: var(--muted); font-weight: 700; }
.integration-row b.is-ready { color: var(--green); }

.conversation { min-width: 0; min-height: calc(var(--ui-layout-height-vh) - 76px); min-height: calc(var(--ui-layout-height-dvh) - 76px); flex-direction: column; position: relative; }
.chat-risk-notice { flex: 0 0 auto; margin: 12px 16px 0; padding: 10px 14px; border-left: 4px solid var(--green); background: var(--paper); color: var(--ink); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.chat-risk-notice { position: relative; padding-right: 44px; }
.chat-risk-notice[hidden] { display: none; }
.chat-risk-notice-close { position: absolute; top: 4px; right: 8px; padding: 0 8px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 22px; line-height: 1.5; cursor: pointer; opacity: .6; }
.chat-risk-notice-close:hover, .chat-risk-notice-close:focus-visible { opacity: 1; }
body[data-auth="authenticated"][data-view="chat"] .conversation { height: 100%; min-height: 0; overflow: hidden; }
.message-scroll { min-width: 0; min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
/* 送出後仍可用鍵盤捲動對話，不描繪整個閱讀區的瀏覽器焦點外框。 */
.message-scroll:focus { outline: none; }
.messages { min-width: 0; grid-template-columns: minmax(0, 1fr); width: min(920px, calc(100% - 48px)); margin: 0 auto; padding: 52px 0 48px; display: grid; gap: 24px; }
.welcome-card { padding: 34px; border: 1px solid rgba(31, 107, 79, .13); border-radius: 26px; background: linear-gradient(145deg, rgba(255,255,255,.95), rgba(240,247,239,.92)); box-shadow: var(--shadow); }
.welcome-card h1 { max-width: 650px; margin: 10px 0 12px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(30px, 4vw, 50px); line-height: 1.08; letter-spacing: -.035em; }
.welcome-card > p { max-width: 680px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.75; }
.suggestion-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 26px; }
.suggestion { min-height: 86px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: rgba(255,255,255,.82); text-align: left; font-weight: 700; line-height: 1.4; }
.suggestion:hover { border-color: #aac8b8; transform: translateY(-1px); box-shadow: 0 8px 20px rgba(31,107,79,.08); }
.suggestion span { display: block; margin-bottom: 7px; color: var(--green); font-size: 10px; letter-spacing: .1em; }

.message { display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: start; }
.message-avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; color: white; background: var(--green); font-size: 12px; font-weight: 800; }
.message.is-user .message-avatar { color: var(--green-dark); background: var(--green-soft); }
.message-content { min-width: 0; padding-top: 2px; }
.message-meta { color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.message-body { line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-body.is-markdown { white-space: normal; }
.message-body.is-markdown > :first-child { margin-top: 0; }
.message-body.is-markdown > :last-child { margin-bottom: 0; }
.message-body.is-markdown :is(p, ul, ol, pre, blockquote) { margin: 0 0 .55em; }
.message-body.is-markdown :is(h3, h4, h5, h6) { margin: .9em 0 .35em; font-size: 1.05em; line-height: 1.4; }
.message-body.is-markdown :is(ul, ol) { padding-left: 1.5em; }
.message-body.is-markdown li { margin: .15em 0; }
.message-body.is-markdown code { padding: .1em .35em; border-radius: 4px; background: rgba(127, 127, 127, .16); font-size: .92em; }
.message-body.is-markdown pre { overflow-x: auto; padding: 10px 12px; border-radius: 6px; background: rgba(127, 127, 127, .14); white-space: pre; }
.message-body.is-markdown pre code { padding: 0; background: none; }
.message-body.is-markdown hr { margin: .9em 0; border: 0; border-top: 1px solid var(--line); }
.message-body.is-markdown blockquote { padding: 6px 12px; border-left: 3px solid var(--green); border-radius: 0 6px 6px 0; background: rgba(127, 127, 127, .09); color: inherit; }
.message.is-user .message-body { display: inline-block; padding: 12px 15px; border-radius: 6px 16px 16px 16px; background: white; border: 1px solid var(--line); }
.message.is-loading .message-body::after { content: ""; display: inline-block; width: 18px; height: 5px; margin-left: 8px; border-radius: 999px; background: linear-gradient(90deg, var(--green) 30%, transparent 30% 60%, var(--green) 60%); background-size: 15px; animation: pulse 1s infinite linear; }
.message.is-streaming .message-body::after { content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 4px; vertical-align: -0.15em; background: var(--green); animation: pulse .8s infinite alternate; }
.answer-warnings { display: grid; gap: 6px; margin-top: 12px; padding: 11px 13px; border: 1px solid #e7c9a3; border-radius: 11px; color: #704719; background: #fff8eb; font-size: 12px; line-height: 1.6; }
.answer-warnings p { margin: 0; }
@keyframes pulse { to { background-position: 15px 0; } }
.citation-list { display: grid; gap: 10px; margin-top: 15px; }
.citation { min-width: 0; padding: 14px 15px; border: 1px solid var(--line); border-radius: 14px; color: inherit; background: rgba(255,255,255,.76); }
.citation:hover { border-color: #9fc4b1; background: white; }
.citation-header { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; align-items: start; }
.citation-header span { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 7px; color: white; background: var(--green); font-size: 11px; font-weight: 800; }
.citation-title { padding: 0; border: 0; color: var(--ink); background: transparent; font-size: 13px; font-weight: 800; line-height: 1.45; text-align: left; }
.citation-title:hover, .citation-open:hover { text-decoration: underline; }
.citation-location { margin: 9px 0 0 32px; color: var(--green-dark); font-size: 11px; font-weight: 750; }
.citation blockquote { margin: 9px 0 0 32px; padding: 9px 11px; border-left: 3px solid #a9cbb9; border-radius: 0 9px 9px 0; color: #40584f; background: #f4f8f4; font-size: 12px; line-height: 1.65; }
.citation-open { display: inline-block; margin: 9px 0 0 32px; padding: 0; border: 0; color: var(--green); background: transparent; font-size: 11px; font-weight: 800; text-decoration: none; }
.passage-preview { margin: 8px 0 0; padding: 12px 14px; max-height: 60vh; overflow: auto; word-break: break-word; font: inherit; font-size: 14px; line-height: 1.7; border: 1px solid var(--line, #d7e2da); border-radius: 8px; background: var(--paper); color: var(--ink); text-align: left; }
.passage-preview > :first-child { margin-top: 0; }
.passage-paragraph { margin: 0 0 10px; white-space: pre-wrap; }
.passage-heading { margin: 14px 0 6px; color: var(--ink); font-weight: 800; line-height: 1.5; }
.passage-heading-1 { font-size: 16px; }
.passage-heading-2 { font-size: 15px; }
.passage-heading-3 { font-size: 14px; }
.passage-table-wrap { margin: 6px 0 12px; overflow-x: auto; }
.passage-table { border-collapse: collapse; font-size: 13px; line-height: 1.5; }
.passage-table th, .passage-table td { padding: 5px 9px; border: 1px solid var(--line, #d7e2da); text-align: left; vertical-align: top; }
.passage-table th { background: var(--green-soft, #e8f2ed); font-weight: 750; }

.document-divider { min-width: 16px; height: calc(var(--ui-layout-height-vh) - 76px); height: calc(var(--ui-layout-height-dvh) - 76px); position: sticky; top: 76px; z-index: 12; align-items: center; justify-content: center; touch-action: none; cursor: col-resize; background: #dce6df; border-inline: 1px solid #ccd9d1; }
.document-divider::before { content: ""; position: absolute; inset: 0 -5px; }
.document-divider-grip { width: 3px; height: 38px; border-radius: 99px; background: repeating-linear-gradient(to bottom, #789087 0 3px, transparent 3px 7px); opacity: .75; }
.document-pane-toggle { width: 44px; height: 44px; position: absolute; top: 50%; left: 50%; z-index: 2; display: grid; place-items: center; padding: 0; border: 1px solid #b8cbc0; border-radius: 999px; color: var(--green-dark); background: #fffefa; box-shadow: 0 4px 12px rgba(23, 50, 42, .14); font-size: 20px; line-height: 1; transform: translate(-50%, -50%); cursor: pointer; }
.document-pane-toggle:hover { border-color: #75a48d; background: var(--green-soft); }
body.document-viewer-collapsed .document-pane-toggle { transform: translate(-50%, -50%) rotate(180deg); }
.document-viewer { min-width: 0; height: calc(var(--ui-layout-height-vh) - 76px); height: calc(var(--ui-layout-height-dvh) - 76px); position: sticky; top: 76px; flex-direction: column; overflow: hidden; background: #e9eeea; }
body.document-viewer-collapsed .document-viewer { display: none !important; }
.document-viewer-header { min-height: 84px; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 16px 12px 20px; border-bottom: 1px solid #cfdad3; background: rgba(255, 254, 250, .97); }
.document-viewer-heading { min-width: 0; }
.document-viewer-header h2 { max-width: 390px; overflow: hidden; margin: 3px 0 1px; font-size: 14px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.document-viewer-header small { display: block; color: var(--muted); font-size: 10px; }
.document-toolbar { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; }
.document-toolbar span { min-width: 54px; color: var(--muted); font-size: 10px; text-align: center; }
.document-toolbar button { height: 44px; min-width: 44px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--green-dark); background: white; font-size: 11px; font-weight: 750; }
.document-toolbar button:hover { border-color: #9fc4b1; background: var(--green-soft); }
.document-viewer-scroll { min-height: 0; position: relative; flex: 1; overflow: auto; padding: 24px clamp(16px, 2vw, 30px) 54px; scroll-behavior: smooth; }
.pdf-pages { display: grid; justify-items: center; gap: 24px; }
.pdf-page { position: relative; flex: 0 0 auto; overflow: hidden; border: 1px solid #d0d5d1; border-radius: 3px; background: white; box-shadow: 0 12px 30px rgba(23, 50, 42, .12); }
.pdf-page::after { content: attr(data-page-label); position: absolute; right: 8px; bottom: 6px; padding: 2px 5px; border-radius: 5px; color: #66776f; background: rgba(255,255,255,.82); font-size: 9px; pointer-events: none; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; user-select: text; }
.pdf-text-item { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; cursor: text; }
.pdf-text-item.is-cited:not(.has-cited-ranges), .pdf-cited-range { background: rgba(255, 220, 45, .58); border-radius: 2px; box-shadow: 0 0 0 1px rgba(237, 187, 0, .18); mix-blend-mode: multiply; }
.citation-claim { margin: 10px 0 0 32px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.citation-evidence blockquote { white-space: pre-line; }
.pdf-page.is-cited { animation: cited-page-emphasis 1.2s ease-out; scroll-margin-top: 20px; }
@keyframes cited-page-emphasis { 0% { box-shadow: 0 0 0 6px rgba(245, 196, 24, .5), 0 12px 30px rgba(23, 50, 42, .12); } 100% { box-shadow: 0 0 0 0 rgba(245, 196, 24, 0), 0 12px 30px rgba(23, 50, 42, .12); } }
.document-preview-loading { min-height: 190px; display: grid; place-items: center; color: var(--muted); border-radius: 8px; background: linear-gradient(100deg, #e3e9e5 30%, #f5f8f6 45%, #e3e9e5 60%); background-size: 220% 100%; animation: evidence-loading 1.4s infinite linear; font-size: 12px; }
.document-preview-status { max-width: 420px; margin: 60px auto; padding: 24px; color: var(--muted); border: 1px solid #d7e0da; border-radius: 12px; background: rgba(255,255,255,.7); font-size: 13px; line-height: 1.7; text-align: center; }
.visual-evidence { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.visual-evidence h4 { margin: 0; font-size: 13px; }
.visual-evidence-group + .visual-evidence-group { margin-top: 16px; }
.visual-evidence-group > p { margin: 5px 0 10px; color: var(--muted); font-size: 10px; }
.evidence-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.evidence-figure { min-width: 0; overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 13px; background: white; }
.evidence-figure img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #edf2ed; }
.evidence-figure.is-loading img { min-height: 180px; background: linear-gradient(100deg, #edf2ed 30%, #f8faf8 45%, #edf2ed 60%); background-size: 220% 100%; animation: evidence-loading 1.4s infinite linear; }
.evidence-figure.is-error img { display: none; }
.evidence-figure figcaption { display: grid; gap: 3px; padding: 10px 11px; }
.evidence-figure figcaption a, .evidence-figure figcaption strong { overflow: hidden; color: var(--ink); font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.evidence-figure figcaption a:hover { text-decoration: underline; }
.evidence-figure figcaption small { color: var(--muted); font-size: 10px; }
@keyframes evidence-loading { to { background-position: -220% 0; } }
.message-error { color: var(--danger); }
.answer-feedback { margin-top: 14px; padding-top: 11px; border-top: 1px solid var(--line); }
.answer-feedback-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.answer-feedback-status { color: var(--muted); font-size: 11px; }
.answer-feedback-actions { display: flex; gap: 6px; }
.answer-feedback-actions button, .negative-feedback-actions button { padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font-size: 11px; }
.answer-feedback-actions button:hover, .negative-feedback-actions button:hover { border-color: #9fc4b1; }
.answer-feedback-actions .feedback-negative { color: var(--danger); }
.negative-feedback-form { max-width: 560px; margin-top: 10px; padding: 12px; border: 1px solid #efd8d4; border-radius: 12px; background: #fffafa; }
.negative-feedback-form label { display: grid; gap: 7px; color: var(--ink); font-size: 11px; font-weight: 750; }
.negative-feedback-form textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; resize: vertical; line-height: 1.5; }
.negative-feedback-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 9px; }
.negative-feedback-actions .feedback-submit { border-color: var(--danger); color: white; background: var(--danger); }
.answer-feedback.is-sent .answer-feedback-actions, .answer-feedback.is-sent .negative-feedback-form { display: none; }
.answer-feedback.is-sent .answer-feedback-status { color: var(--green); font-weight: 750; }

.composer { position: relative; flex: 0 0 auto; align-self: center; width: min(860px, calc(100% - 48px)); margin: 0 auto max(22px, env(safe-area-inset-bottom)); z-index: 10; padding: 12px; border: 1px solid rgba(31, 107, 79, .18); border-radius: 20px; background: rgba(255, 254, 250, .96); backdrop-filter: blur(18px); box-shadow: 0 22px 60px rgba(27, 60, 47, .2); }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.question-field { flex: 1 0 100%; min-width: 0; }
.composer-footer { display: flex; flex: 0 0 auto; align-items: start; gap: 6px; width: min(860px, calc(100% - 28px)); margin: 0 auto max(8px, env(safe-area-inset-bottom)); }
.composer.is-busy #submit-button { display: none; }
.composer.is-collapsed .question-field { flex: 1 1 100px; }
.composer.is-collapsed .question-field textarea { height: 44px; min-height: 44px; max-height: 44px; resize: none; }
.question-field textarea { width: 100%; min-height: 68px; max-height: 180px; padding: 10px 10px 4px; border: 0; resize: vertical; color: var(--ink); background: transparent; line-height: 1.55; }
.question-field textarea::placeholder { color: #82928b; }
.composer-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding-top: 9px; border-top: 1px solid #edf1ed; }
.toolbar-group { display: flex; flex-wrap: wrap; min-width: 0; align-items: center; gap: 7px; }
.toolbar-group.right { justify-content: flex-end; margin-left: auto; }
#image-input { position: absolute; opacity: 0; pointer-events: none; }
.upload-button, .secondary-button { flex-shrink: 0; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; color: var(--green-dark); background: #f5f8f5; font-size: 12px; font-weight: 750; }
.secondary-button:disabled { opacity: .45; cursor: not-allowed; }
.select-label { display: flex; flex-shrink: 0; white-space: nowrap; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.select-label select { height: 44px; padding: 0 24px 0 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font-size: 12px; }
.primary-button { flex-shrink: 0; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 0 15px; border: 0; border-radius: 11px; color: white; background: linear-gradient(135deg, #267858, #17503c); box-shadow: 0 8px 18px rgba(31,107,79,.2); font-weight: 800; text-decoration: none; }
.primary-button i { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 7px; background: rgba(255,255,255,.18); font-style: normal; }
.primary-button:disabled { opacity: .58; cursor: wait; }
.primary-button.wide { width: 100%; }
.composer-note { flex: 1 1 auto; min-width: 0; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.composer-note summary { min-height: 44px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; cursor: pointer; }
.composer-note p { margin: 0 0 8px; }
.composer-note[open] { max-height: var(--composer-notice-max-height, 120px); overflow-y: auto; }
.composer-note strong { color: var(--danger); }
.composer-service-summary { display: none; }
.cancel-button { color: var(--danger); border-color: #e8c5c0; background: #fffafa; }
.image-input-status { margin: 8px 7px 0; color: var(--green); font-size: 11px; font-weight: 750; text-align: center; }
.image-input-status:empty { display: none; }
.composer.is-collapsed .image-input-status[data-tone="success"] { display: none; }
.image-input-status[data-tone="error"] { color: var(--danger); }
.preview-list { display: flex; gap: 8px; overflow-x: auto; }
.preview-list:not(:empty) { padding: 4px 2px 10px; }
.preview { flex: 0 0 68px; height: 58px; position: relative; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: #edf2ed; }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview button { position: absolute; top: 0; right: 0; width: 44px; height: 44px; padding: 0 0 15px 15px; border: 0; border-radius: 0 0 0 34px; color: white; background: rgba(20,40,32,.78); }

.vision-panel { position: fixed; top: 96px; right: 24px; z-index: 15; width: min(390px, calc(100vw - 48px)); max-height: calc(var(--ui-layout-height-vh) - 130px); max-height: calc(var(--ui-layout-height-dvh) - 130px); overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow); }
.vision-heading { display: flex; justify-content: space-between; align-items: center; }
.vision-heading h3 { margin: 3px 0 0; }
.vision-stage { position: relative; overflow: hidden; margin-top: 14px; border-radius: 14px; background: #ecf1ed; }
.vision-stage img { display: block; width: 100%; height: auto; }
.vision-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.vision-stage rect { fill: rgba(240, 78, 62, .08); stroke: #f04e3e; stroke-width: 4; vector-effect: non-scaling-stroke; }
.vision-count { margin: 12px 0 4px; font-weight: 800; }
.vision-disclaimer { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.vision-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); }
.vision-feedback span { color: var(--muted); font-size: 11px; margin-right: 3px; }
.vision-feedback button { padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font-size: 11px; }
.vision-feedback button:hover { border-color: #9fc4b1; }
.vision-feedback.is-sent button { display: none; }
.vision-feedback.is-sent span { color: var(--green); font-weight: 750; }
.vision-crop-field { display: inline-flex; flex-shrink: 0; white-space: nowrap; align-items: center; gap: 7px; min-height: 44px; color: var(--muted); font-size: 11px; }
.vision-crop-field input { width: 132px; min-height: 38px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--ink); }
.vision-decision, .vision-recommendation { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8faf8; }
.vision-decision h4, .vision-recommendation h4 { margin: 0 0 5px; font-size: 13px; }
.vision-decision p, .vision-recommendation p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.vision-decision.is-classified, .vision-recommendation.is-grounded { border-color: #9fc4b1; background: #f2f8f4; }
.vision-citations { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.vision-citations a, .vision-citations button { padding: 7px 9px; border: 1px solid #9fc4b1; border-radius: 9px; background: white; color: var(--green); font-size: 11px; text-decoration: none; }

.portal-panel { grid-column: 1 / -1; min-height: calc(var(--ui-layout-height-vh) - 76px); min-height: calc(var(--ui-layout-height-dvh) - 76px); align-content: center; gap: 34px; padding: 56px max(5vw, 24px) 44px; background: radial-gradient(circle at 12% 15%, rgba(207, 231, 215, .72), transparent 32%), linear-gradient(145deg, #f8faf6, #fffefa 58%); }
.portal-heading { width: min(1080px, 100%); margin: 0 auto; }
.portal-heading h1 { margin: 9px 0 10px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(38px, 5vw, 62px); line-height: 1.08; letter-spacing: -.045em; }
.portal-heading p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.portal-heading p span { color: var(--green-dark); font-weight: 800; }
.portal-grid { width: min(1080px, 100%); margin: 0 auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.portal-card { min-height: 310px; position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 24px; padding: 34px; overflow: hidden; border: 1px solid rgba(31, 107, 79, .15); border-radius: 28px; color: var(--ink); background: rgba(255, 255, 255, .9); box-shadow: 0 22px 55px rgba(25, 67, 50, .11); text-decoration: none; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.portal-card::after { content: ""; width: 180px; height: 180px; position: absolute; right: -80px; bottom: -90px; border-radius: 50%; background: rgba(31, 107, 79, .07); }
.portal-card:hover { border-color: rgba(31, 107, 79, .35); box-shadow: 0 28px 65px rgba(25, 67, 50, .17); transform: translateY(-4px); }
.portal-card:focus-visible { outline-offset: 5px; }
.portal-card-chat { background: linear-gradient(145deg, rgba(255, 255, 255, .96), rgba(234, 244, 237, .96)); }
.portal-icon { width: 88px; height: 88px; display: grid; place-items: center; border-radius: 25px; color: white; background: linear-gradient(145deg, #2f8362, #174f3c); box-shadow: 0 16px 28px rgba(31, 107, 79, .22); }
.portal-card-chat .portal-icon { background: linear-gradient(145deg, #447d68, #225344); }
.portal-icon svg { width: 54px; height: 54px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.portal-card-copy { display: grid; gap: 9px; }
.portal-card-copy small { color: var(--green); font-size: 12px; font-weight: 850; letter-spacing: .12em; }
.portal-card-copy strong { max-width: 430px; font-size: clamp(22px, 2.2vw, 30px); line-height: 1.25; letter-spacing: -.02em; }
.portal-card-copy > span { max-width: 430px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.portal-arrow { width: 44px; height: 44px; position: absolute; right: 28px; top: 30px; display: grid; place-items: center; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font-size: 22px; font-weight: 800; }
.portal-session-note { width: min(1080px, 100%); margin: -12px auto 0; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }

.login-panel { grid-column: 1 / -1; min-height: calc(var(--ui-layout-height-vh) - 76px); min-height: calc(var(--ui-layout-height-dvh) - 76px); grid-template-columns: minmax(0, 1.1fr) minmax(360px, 460px); gap: 60px; align-items: center; padding: 64px max(6vw, 28px); }
.login-copy { max-width: 700px; }
.login-copy h1 { margin: 12px 0 18px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(44px, 7vw, 82px); line-height: .98; letter-spacing: -.055em; }
.login-copy > p { max-width: 640px; color: var(--muted); font-size: 16px; line-height: 1.8; }
.login-copy ul { display: flex; flex-wrap: wrap; gap: 9px; padding: 0; margin: 26px 0 0; list-style: none; }
.login-copy li { padding: 9px 13px; border: 1px solid rgba(31,107,79,.16); border-radius: 999px; background: rgba(255,255,255,.6); font-size: 12px; }
.login-card { padding: 30px; border: 1px solid rgba(31,107,79,.16); border-radius: 24px; background: rgba(255,254,250,.94); box-shadow: var(--shadow); }
.login-card h2 { margin: 20px 0 6px; }
.login-card > p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.dev-token-login > p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.login-card label { display: grid; gap: 7px; margin: 24px 0 16px; font-size: 12px; font-weight: 750; }
.login-card input { height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 11px; background: white; }
.login-card small { display: block; margin-top: 15px; color: var(--muted); font-size: 10px; line-height: 1.55; }
.login-card .cookie-note { margin-top: 9px; color: var(--green-dark); }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 20px 0 12px; color: var(--muted); font-size: 10px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.dev-token-login { width: 100%; }
.sso-status { min-height: 16px; }
.dev-login { width: 100%; }
.form-error { min-height: 20px; margin: 0 0 8px !important; color: var(--danger) !important; }

@media (max-width: 1199px) {
  body[data-auth="authenticated"][data-view="chat"] .app-shell { grid-template-rows: auto minmax(0, 1fr); }
  .topbar { min-width: 0; height: auto; min-height: 76px; flex-wrap: wrap; gap: 8px 12px; padding-block: 8px; }
  .brand { min-width: 0; max-width: 100%; }
  .topbar-actions { min-width: 0; max-width: 100%; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
  body[data-auth="authenticated"][data-view="chat"] .app-shell { grid-template-rows: auto minmax(0, 1fr); }
  .composer { max-height: 45%; overflow-y: auto; margin-bottom: 0; padding: 6px; }
  .composer-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(2, calc(45px / var(--ui-font-scale))); gap: 6px; }
  .question-field { grid-column: 1 / -1; }
  .composer.is-collapsed .question-field { grid-column: 1; }
  .composer.is-collapsed .question-field textarea { height: calc(45px / var(--ui-font-scale)); min-height: calc(45px / var(--ui-font-scale)); max-height: calc(45px / var(--ui-font-scale)); padding-block: 6px; line-height: 1.2; }
  .composer-note summary { min-height: calc(45px / var(--ui-font-scale)); }
  /* Share the existing footer row without clipping the reason or next step.
     Full service text remains a live status and in the keyboard disclosure. */
  .image-input-status.is-footer-notice { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .composer-note.has-service-notice #composer-risk-summary { display: none; }
  .composer-note.has-service-notice .composer-service-summary { display: inline; }
  .composer-row .upload-button { grid-column: 2; }
  .composer-row .primary-button, .composer-row .cancel-button { grid-column: 3; }
  .composer-row > button { width: calc(45px / var(--ui-font-scale)); min-width: calc(45px / var(--ui-font-scale)); height: calc(45px / var(--ui-font-scale)); min-height: calc(45px / var(--ui-font-scale)); padding: 0; gap: 0; position: relative; }
  .composer-action-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  #selected-image-count { position: absolute; right: 2px; top: 1px; font-size: 10px; }
  .workspace { grid-template-columns: 1fr; }
  body.document-viewer-open .workspace, body.document-viewer-collapsed .workspace { grid-template-columns: 1fr; }
  body[data-auth="authenticated"][data-view="chat"] .history-toggle { display: inline-flex; }
  .sidebar { width: min(360px, calc(100vw / var(--ui-font-scale) - 32px)); min-height: 0; position: fixed; inset: 76px auto 0 0; z-index: 50; visibility: hidden; padding-bottom: max(28px, env(safe-area-inset-bottom)); background: #f7faf6; box-shadow: 16px 0 42px rgba(23, 50, 42, .2); transform: translateX(-105%); transition: transform .2s ease, visibility .2s linear; }
  .history-close { display: grid; }
  body.history-drawer-open { overflow: hidden; }
  body.history-drawer-open .sidebar { visibility: visible; transform: translateX(0); }
  body.history-drawer-open .history-backdrop { display: block; }
  .composer { width: calc(100% - 28px); margin-bottom: 0; }
  .messages { width: min(100% - 30px, 760px); padding-top: 30px; }
  .login-panel { grid-template-columns: 1fr; gap: 34px; }
  .portal-panel { align-content: start; padding-top: 46px; }
  .portal-grid { grid-template-columns: 1fr; }
  .portal-card { min-height: 250px; }
  .login-copy h1 { font-size: clamp(42px, 11vw, 70px); }
  .document-divider { display: none !important; }
  .document-viewer { width: calc(100vw / var(--ui-font-scale)); height: calc(var(--ui-layout-height-vh) - 76px); height: calc(var(--ui-layout-height-dvh) - 76px); position: fixed; inset: 76px 0 0; z-index: 60; background: #e9eeea; }
  body.document-viewer-open { overflow: hidden; }
  body.document-viewer-collapsed .document-viewer { display: flex !important; }
}

@media (max-width: 640px) {
  body[data-auth="authenticated"][data-view="chat"] .app-shell { grid-template-rows: auto minmax(0, 1fr); }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; height: auto; min-height: 66px; padding: 4px 12px; gap: 4px 8px; }
  .brand { gap: 8px; }
  .brand small { display: none; }
  .brand strong { font-size: 12px; }
  .topbar-actions { grid-column: 1 / -1; width: 100%; gap: 6px; }
  .topbar > .status-chip { width: auto; max-width: 110px; margin: 0; gap: 8px; white-space: normal; overflow-wrap: anywhere; }
  body[data-view="chat"] .status-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  body[data-view="chat"] .status-short { display: inline; }
  .status-chip.is-ready .status-short::after { content: "已就緒"; }
  .status-chip.is-error .status-short::after { content: "無法連線"; }
  .status-chip.is-checking .status-short::after { content: "載入中"; }
  .new-conversation-button { padding: 7px 8px; }
  .history-toggle { padding: 7px 9px; }
  .workspace { min-height: calc(var(--ui-layout-height-vh) - 66px); min-height: calc(var(--ui-layout-height-dvh) - 66px); }
  .messages { width: calc(100% - 24px); padding: 18px 0 28px; }
  .welcome-card { padding: 24px 20px; border-radius: 20px; }
  .welcome-card h1 { font-size: 34px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .citation-list { grid-template-columns: 1fr; }
  .evidence-gallery { grid-template-columns: 1fr; }
  .composer { padding: 6px; border-radius: 16px; }
  .composer-toolbar { flex-direction: column; align-items: stretch; }
  .composer-toolbar > .toolbar-group:not(.right) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .composer-toolbar > .toolbar-group:not(.right) > .upload-button,
  .composer-toolbar > .toolbar-group:not(.right) > .secondary-button { width: 100%; min-width: 44px; }
  .vision-crop-field { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr); width: 100%; }
  .vision-crop-field input { width: 100%; min-width: 0; min-height: 44px; }
  .toolbar-group.right { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .toolbar-group.right > * { min-width: 0; }
  .toolbar-group.right .secondary-button, .toolbar-group.right .primary-button { width: 100%; min-width: 44px; }
  .primary-button span { display: inline; }
  .composer-note { font-size: 10px; }
  .login-panel { padding: 34px 18px; }
  .login-copy h1 { font-size: 46px; }
  .login-copy > p { font-size: 14px; }
  .login-card { padding: 24px 20px; }
  .portal-panel { min-height: calc(var(--ui-layout-height-vh) - 66px); min-height: calc(var(--ui-layout-height-dvh) - 66px); gap: 24px; padding: 34px 18px 28px; }
  .portal-heading h1 { font-size: 38px; }
  .portal-card { min-height: 230px; padding: 24px; border-radius: 22px; }
  .portal-icon { width: 72px; height: 72px; border-radius: 21px; }
  .portal-icon svg { width: 44px; height: 44px; }
  .portal-card-copy strong { padding-right: 10px; font-size: 22px; }
  .portal-arrow { width: 40px; height: 40px; top: 22px; right: 20px; }
  .history-backdrop { inset-block-start: 66px; }
  .sidebar { inset-block-start: 66px; }
  .document-viewer { top: 66px; height: calc(var(--ui-layout-height-vh) - 66px); height: calc(var(--ui-layout-height-dvh) - 66px); }
  .document-viewer-header { min-height: 76px; flex-wrap: wrap; gap: 8px; padding: 10px 10px 9px 13px; }
  .document-viewer-heading { width: 100%; }
  .document-toolbar { min-width: 0; width: 100%; flex-wrap: wrap; }
  .document-viewer-heading .eyebrow, .document-viewer-header small { display: none; }
  .document-toolbar button { padding: 0 5px; }
  .document-viewer-scroll { padding: 14px 10px 36px; }
}

/* On short screens keep the homepage, status and session controls on one row.
   Touch targets stay above 44px after account text zoom. */
@media (max-width: 1199px) and (max-height: 520px) {
  body[data-auth="authenticated"][data-view="chat"] .topbar { display: flex; flex-wrap: nowrap; min-height: 0; padding: 4px; gap: 4px; }
  body[data-view="chat"] .brand { flex-shrink: 0; gap: 0; }
  body[data-view="chat"] .brand > span:last-child { display: none; }
  body[data-view="chat"] .brand-mark { width: calc(45px / var(--ui-font-scale)); height: calc(45px / var(--ui-font-scale)); }
  body[data-view="chat"] .topbar > .status-chip { margin: 0; padding: 4px; gap: 4px; }
  body[data-view="chat"] .status-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  body[data-view="chat"] .status-short { display: inline; }
  body[data-view="chat"] .status-chip.is-ready .status-short::after { content: "已就緒"; }
  body[data-view="chat"] .status-chip.is-error .status-short::after { content: "無法連線"; }
  body[data-view="chat"] .status-chip.is-checking .status-short::after { content: "載入中"; }
  body[data-view="chat"] .topbar-actions { width: auto; flex-wrap: nowrap; gap: 4px; }
  body[data-view="chat"] .topbar-actions > button, body[data-view="chat"] .topbar-actions > .account-control > .account-trigger { width: calc(45px / var(--ui-font-scale)); min-width: calc(45px / var(--ui-font-scale)); height: calc(45px / var(--ui-font-scale)); min-height: calc(45px / var(--ui-font-scale)); padding: 0; align-items: center; justify-content: center; }
  body[data-view="chat"] .new-conversation-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  body[data-view="chat"] .new-conversation-button i { display: inline; font-size: 20px; }
}

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

/* Keep each label and its select together at the narrowest widths, including
   the largest account font preference; native selects otherwise impose their
   longest option's minimum width on a half-width column. */
@media (max-width: 400px) {
  .toolbar-group.right .select-label { flex-direction: column; align-items: stretch; gap: 4px; }
  .toolbar-group.right .select-label select { min-width: 0; width: 100%; }
}

.memory-panel { margin: 1rem 0; padding: 1rem; flex-shrink: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); overflow-wrap: anywhere; }
.sidebar:has(.memory-panel[open]) { overflow-y: auto; }
.sidebar:has(.memory-panel[open]) .history-list { flex: 0 0 auto; min-height: 60px; max-height: 250px; }
.sidebar:has(.memory-panel[open]) .sidebar-heading, .sidebar:has(.memory-panel[open]) .integration-card { flex-shrink: 0; }
.memory-panel summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.memory-panel p { font-size: .82rem; line-height: 1.6; }
.memory-panel label { display: block; font-size: .86rem; margin: .6rem 0; }
.memory-panel select, .memory-panel textarea, .memory-panel input[type=date] { display: block; width: 100%; min-height: 44px; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; box-sizing: border-box; background: var(--paper); color: var(--ink); }
.memory-panel .memory-opt-in { display: flex; align-items: center; min-height: 44px; gap: .6rem; }
.memory-panel button { min-height: 44px; padding: .4rem .65rem; margin: .2rem; border: 1px solid var(--line); border-radius: 6px; background: var(--canvas); color: var(--ink); font: inherit; font-size: .82rem; cursor: pointer; }
.memory-panel button:disabled { opacity: .5; cursor: default; }
.memory-panel ul { padding: 0; list-style: none; }
.memory-panel li { border-top: 1px solid var(--line); padding: .5rem 0; }
.memory-panel small { display: block; font-size: .75rem; }
.memory-actions { display: flex; flex-wrap: wrap; }
.memory-panel .memory-retention { color: var(--muted); }

/* Inline source numbers open the same verified source card/document. */
.citation-inline { display: inline; padding: 0 2px; border: 0; color: var(--accent-dark, #14654f); background: transparent; font: inherit; font-size: .86em; font-weight: 700; line-height: inherit; cursor: pointer; text-decoration: none; }
.citation-inline:hover, .citation-inline:focus-visible { text-decoration: underline; }

/* R26：田區選擇在桌機與手機均保持可見、可操作。 */
.garden-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 0;
  font-size: 13px;
}
.garden-controls[hidden] { display: none; }
.garden-controls select { max-width: min(280px, 60vw); }
.garden-controls [data-garden-status] { color: var(--text-muted, #64748b); }
/* 田區下拉取代原「更多設定」鈕的位置；選了田區就代表本次問答要結合該田區。 */
.composer-garden { flex: 0 1 auto; min-width: 0; flex-wrap: nowrap; gap: 0; padding: 0; }
.composer-garden .select-label { min-width: 0; }
.composer-garden select { width: 100%; max-width: min(120px, 40vw); text-overflow: ellipsis; }
.composer-garden[data-selected="true"] select { border-color: var(--green, #1f6b4f); font-weight: 600; }
.vision-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 6px 2px 0; }
.vision-tools[hidden] { display: none; }
.vision-tools .vision-crop-field { flex: 1 1 200px; }
.vision-tools .vision-crop-field input { flex: 1; min-width: 0; }

/* Unified reading column and independent, content-sized question composer. */
body[data-view="chat"] { --chat-header-height: 56px; --history-sidebar-width: 240px; }
body[data-view="chat"].history-sidebar-collapsed { --history-sidebar-width: 0px; }
body[data-auth="authenticated"][data-view="chat"] .app-shell { grid-template-rows: auto minmax(0, 1fr); }
body[data-view="chat"] .topbar { height: 56px; min-height: 56px; padding: 0 20px; }
body[data-view="chat"] .brand-mark { width: 32px; height: 32px; box-shadow: none; }
body[data-view="chat"] .topbar-actions { gap: 8px; }
body[data-view="chat"] .topbar > .status-chip.is-ready { display: none; }
body[data-view="chat"] .workspace { min-height: 0; grid-template-columns: var(--history-sidebar-width) minmax(0, 1fr); }
body[data-view="chat"].document-viewer-open .workspace { grid-template-columns: var(--history-sidebar-width) minmax(0, 1fr) 16px var(--document-panel-width); }
body[data-view="chat"].document-viewer-collapsed .workspace { grid-template-columns: var(--history-sidebar-width) minmax(0, 1fr) 16px 0; }
body[data-view="chat"] .sidebar { min-height: 0; padding: 16px 12px; }
body[data-view="chat"] .sidebar-heading { margin-bottom: 12px; }
body[data-view="chat"] .sidebar-heading .eyebrow { display: none; }
body[data-view="chat"] .history-close { display: grid; }
body[data-auth="authenticated"][data-view="chat"] .history-toggle { display: inline-flex; }
body[data-view="chat"].history-sidebar-collapsed .sidebar { display: none; }
body[data-view="chat"] .memory-panel { margin: 12px 0 8px; padding: 8px 12px; border-radius: 10px; }
body[data-view="chat"] .memory-panel summary { font-size: 13px; }
body[data-view="chat"] .integration-card { flex-shrink: 0; margin-top: 0; padding: 8px 12px; border-radius: 10px; }
body[data-view="chat"] .integration-card summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-size: 13px; font-weight: 700; }
body[data-view="chat"] .messages { width: calc(100% - 48px); margin: 0 24px; padding: 24px 0 20px; gap: 20px; }
body[data-view="chat"] .welcome-card { padding: 24px; border-radius: 16px; box-shadow: none; }
body[data-view="chat"] .welcome-card h1 { font-size: clamp(24px, 2.5vw, 34px); line-height: 1.3; }
body[data-view="chat"] .suggestion-grid { margin-top: 16px; }
body[data-view="chat"] .suggestion { min-height: 64px; padding: 10px 12px; }
body[data-view="chat"] .message { display: block; }
body[data-view="chat"] .message-avatar { display: none; }
body[data-view="chat"] .message-content { padding: 0; }
body[data-view="chat"] .message-meta { margin-bottom: 8px; font-size: 12px; }
body[data-view="chat"] .message.is-assistant .message-meta > .message-avatar { display: inline-grid; vertical-align: middle; width: 28px; height: 28px; margin-right: 8px; border-radius: 8px; color: var(--paper); background: var(--green); font-weight: 800; }
body[data-view="chat"] .message-body { font-size: 18px; line-height: 1.65; }
body[data-view="chat"] .message.is-user { padding: 12px 16px; border-radius: 12px; background: var(--green-soft); }
body[data-view="chat"] .message.is-user .message-body { display: block; padding: 0; border: 0; border-radius: 0; background: transparent; }
body[data-view="chat"] .citation-list { gap: 8px; margin-top: 12px; }
body[data-view="chat"] .citation { padding: 10px 12px; }
body[data-view="chat"] .composer { width: min(calc(800px / var(--ui-font-scale)), calc(100% - 48px)); max-height: none; overflow: visible; padding: 12px; margin: 0 auto 4px; border-radius: 24px; background: var(--paper); box-shadow: 0 4px 18px rgba(27, 60, 47, .08); }
body[data-view="chat"] .question-field { display: block; width: 100%; min-width: 0; }
body[data-view="chat"] .question-field textarea { display: block; box-sizing: border-box; min-height: 0; max-height: none; height: 96px; padding: 8px 10px; border: 0; resize: none; font-size: 18px; line-height: 1.5; background: transparent; }
body[data-view="chat"] .composer-row { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; margin-top: 6px; }
body[data-view="chat"] .composer-row > button { width: auto; height: 44px; min-height: 44px; padding: 0 10px; gap: 6px; }
body[data-view="chat"] .composer-action-label { position: static; width: auto; height: auto; clip: auto; overflow: visible; }
body[data-view="chat"] .composer-row .upload-button { position: relative; min-width: 44px; background: transparent; border-color: var(--line); }
body[data-view="chat"] .composer-mode { min-width: 0; }
body[data-view="chat"] .composer-mode select { min-width: 0; width: 100%; background: transparent; }
body[data-view="chat"] .composer-send-actions { display: flex; margin-left: auto; flex-shrink: 0; }
body[data-view="chat"] .composer-send-actions button { position: relative; width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; box-shadow: none; }
body[data-view="chat"] .composer-send-actions .composer-action-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
body[data-view="chat"] .composer-send-actions i { font-size: 22px; background: transparent; font-style: normal; }
body[data-view="chat"] #selected-image-count { position: static; font-size: 11px; }
body[data-view="chat"] .preview-list:not(:empty) { padding: 6px 2px; max-height: 76px; }
body[data-view="chat"] .composer-footer { width: min(calc(800px / var(--ui-font-scale)), calc(100% - 48px)); margin: 0 auto max(4px, env(safe-area-inset-bottom)); }
body[data-view="chat"] .composer-note summary { min-height: 28px; }
body[data-view="chat"] .composer-note[open] { max-height: 96px; overflow-y: auto; }
body[data-view="chat"] .document-viewer { top: var(--chat-header-height); height: calc(var(--ui-layout-height-dvh) - var(--chat-header-height)); }
body[data-view="chat"] .history-backdrop { inset-block-start: var(--chat-header-height); }
@media (max-width: 1199px) {
  body[data-view="chat"] .workspace, body[data-view="chat"].document-viewer-open .workspace, body[data-view="chat"].document-viewer-collapsed .workspace { grid-template-columns: minmax(0, 1fr); }
  body[data-view="chat"] .sidebar, body[data-view="chat"].history-sidebar-collapsed .sidebar { display: flex; inset-block-start: var(--chat-header-height); }
  body[data-view="chat"] .sidebar { visibility: hidden; }
  body[data-view="chat"].history-drawer-open .sidebar { visibility: visible; }
  body[data-view="chat"] .topbar { height: auto; padding: 4px 12px; }
  body[data-view="chat"] .document-viewer { top: var(--chat-header-height); }
}
@media (max-width: 640px) {
  body[data-view="chat"] .topbar { grid-template-columns: minmax(0, 1fr) auto; min-height: 56px; gap: 8px; }
  body[data-view="chat"] .brand { min-width: 0; }
  body[data-view="chat"] .brand-mark { flex-shrink: 0; }
  body[data-view="chat"] .brand > span:last-child { min-width: 0; }
  body[data-view="chat"] .brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body[data-view="chat"] .topbar-actions { grid-column: 2; width: auto; max-width: none; flex-wrap: nowrap; gap: 4px; }
  body[data-view="chat"] .topbar > .status-chip { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  body[data-view="chat"] .messages { width: calc(100% - 24px); margin: 0 12px; padding: 16px 0; gap: 16px; }
  body[data-view="chat"] .message-body { font-size: 16px; }
  body[data-view="chat"] .composer, body[data-view="chat"] .composer-footer { width: calc(100% - 24px); }
  body[data-view="chat"] .composer { padding: 8px; border-radius: 20px; }
  body[data-view="chat"] .question-field textarea { font-size: 16px; padding: 6px; }
  body[data-view="chat"] .composer-row { gap: 6px; }
  body[data-view="chat"] .composer-row > button { padding: 0; min-width: 44px; }
  body[data-view="chat"] .upload-button .composer-action-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  body[data-view="chat"] .composer-mode { flex: 0 1 auto; }
  body[data-view="chat"] .composer-mode select { padding-right: 20px; }
}
@media (max-width: 380px) {
  body[data-view="chat"] .topbar { padding-inline: 8px; }
  body[data-view="chat"] .new-conversation-button { justify-content: center; width: 44px; padding: 0; }
  body[data-view="chat"] .new-conversation-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  body[data-view="chat"] .new-conversation-button i { display: inline; font-size: 20px; }
}
@media (max-width: 1199px) and (max-height: 520px) {
  body[data-view="chat"] .topbar { min-height: 0; padding: 4px; }
  body[data-view="chat"] .composer-note summary { min-height: 24px; }
}
/* Keep the main area in its own grid column when the sidebar is removed. */
@media (min-width: 1200px) {
  body[data-view="chat"] .sidebar { grid-column: 1; }
  body[data-view="chat"] .conversation { grid-column: 2; }
  body[data-view="chat"] .document-divider { grid-column: 3; }
  body[data-view="chat"] .document-viewer { grid-column: 4; }
}
@media (max-width: 1199px) and (max-height: 520px) {
  body[data-view="chat"] .composer { padding: 6px; }
  body[data-view="chat"] .composer-row > button,
  body[data-view="chat"] .composer-send-actions button,
  body[data-view="chat"] .composer-mode select { height: calc(44px / var(--ui-font-scale)); min-height: calc(44px / var(--ui-font-scale)); }
  body[data-view="chat"] .composer-row > button,
  body[data-view="chat"] .composer-send-actions button { width: calc(44px / var(--ui-font-scale)); min-width: calc(44px / var(--ui-font-scale)); }
  body[data-view="chat"] .composer-note summary { min-height: calc(24px / var(--ui-font-scale)); }
}
/* Autosize measures immediately; even the reduced-motion 0.01ms global
   transition would otherwise report the previous height during measurement. */
body[data-view="chat"] .question-field textarea { transition: none !important; }

/* Desktop history remains reachable at the left edge after folding. */
body[data-auth="authenticated"][data-view="chat"] .history-rail { display: none; }
@media (min-width: 1200px) {
  body[data-view="chat"].history-sidebar-collapsed { --history-sidebar-width: 56px; }
  body[data-auth="authenticated"][data-view="chat"].history-sidebar-collapsed .history-rail {
    display: flex; grid-column: 1; grid-row: 1; align-items: flex-start; justify-content: center;
    padding: 16px 6px; border-right: 1px solid var(--line); background: var(--canvas);
  }
  body[data-view="chat"] #history-expand { flex-shrink: 0; min-width: 44px; font-size: 24px; }
  body[data-auth="authenticated"][data-view="chat"] #history-toggle { display: none; }
}

/* Compact answer and source presentation; details open only on request. */
body[data-view="chat"] .message.is-user { align-self: flex-end; margin-left: auto; width: fit-content; max-width: 90%; }
body[data-view="chat"] .message.is-user .message-meta { display: none; }
body[data-view="chat"] .message.is-assistant { background: transparent; border: 0; }
body[data-view="chat"] .answer-warnings { border: 0; border-left: 3px solid #e9ac35; border-radius: 0 10px 10px 0; padding: 10px 14px; }
body[data-view="chat"] .source-disclosure { margin-top: 14px; }
body[data-view="chat"] .source-disclosure > summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 650; list-style: none; }
body[data-view="chat"] .source-disclosure > summary::-webkit-details-marker { display: none; }
body[data-view="chat"] .source-disclosure > summary::after { content: "›"; margin-left: auto; font-size: 22px; }
body[data-view="chat"] .source-disclosure[open] > summary::after { content: "⌄"; }
body[data-view="chat"] .source-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
body[data-view="chat"] .source-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: inherit; font-size: 12px; text-decoration: none; cursor: pointer; }
body[data-view="chat"] .source-chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body[data-view="chat"] .source-chip:hover, body[data-view="chat"] .source-disclosure > summary:hover { border-color: var(--green); }
body[data-view="chat"] .source-chip:focus-visible, body[data-view="chat"] .source-disclosure > summary:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
/* Q-80：來源詳情的長標題與摘要須在手機寬度內換行。 */
body[data-view="chat"] .citation-title,
body[data-view="chat"] .citation blockquote { overflow-wrap: anywhere; }
body[data-view="chat"] .citation-list:empty { display: none; }
body[data-view="chat"] .source-disclosure .citation-list { margin-top: 8px; }
body[data-view="chat"] .citation blockquote { max-height: 240px; overflow: auto; }
body[data-view="chat"] .citation-evidence.has-source-display blockquote { max-height: none; overflow: visible; }
body[data-view="chat"] .citation-evidence.has-source-display blockquote.citation-table-source { white-space: pre; overflow-x: auto; overflow-y: visible; overflow-wrap: normal; max-width: calc(100% - 32px); box-sizing: border-box; font-family: ui-monospace, monospace; tab-size: 8; }
body[data-view="chat"] .answer-feedback { border-top: 0; padding-top: 0; margin-top: 10px; }
body[data-view="chat"] .answer-feedback-status:empty { display: none; }
body[data-view="chat"] .answer-feedback-actions button, body[data-view="chat"] .answer-copy { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
body[data-view="chat"] .answer-feedback-actions button:hover, body[data-view="chat"] .answer-copy:hover { background: var(--green-soft); }
.answer-action-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.answer-copy-control { position: relative; display: inline-block; vertical-align: top; }
.answer-copy-status { position: absolute; top: calc(100% + 4px); left: 0; z-index: 10; width: max-content; max-width: 220px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: 0 3px 12px rgba(0, 0, 0, .12); font-size: 12px; line-height: 1.5; pointer-events: none; }
.answer-copy-status:empty { display: none; }
.answer-copy-status.is-manual, .conversation-share-status.is-manual { pointer-events: auto; max-width: min(280px, 80vw); }
.share-link-manual { display: block; width: 100%; min-width: 200px; margin-top: 4px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; }

body[data-view="chat"] .answer-feedback:not([hidden]) { display: inline-block; vertical-align: top; margin-top: 0; }

/* Refined composer: compact actions and an adjacent risk disclosure. */
body[data-view="chat"] .composer-row > button { height: 44px; min-height: 44px; padding: 0 12px; border-radius: 9px; font-size: 13px; font-weight: 600; gap: 7px; }
body[data-view="chat"] .composer-mode select { height: 44px; min-height: 44px; padding-left: 12px; font-size: 13px; }
body[data-view="chat"] .composer-icon { display: block; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
body[data-view="chat"] .composer-send-actions button { width: 44px; min-width: 44px; height: 44px; min-height: 44px; background: var(--green); }
body[data-view="chat"] .composer-send-actions i { width: 18px; height: 18px; }
body[data-view="chat"] .composer-send-actions .composer-icon { width: 18px; height: 18px; stroke-width: 1.9; }
body[data-view="chat"] .composer-row .composer-footer { flex: 1 1 auto; min-width: 0; width: auto; margin: 0 0 0 16px; align-items: center; }
body[data-view="chat"] .composer-note { font-size: 11px; }
body[data-view="chat"] .composer-note summary { min-height: 32px; justify-content: flex-start; line-height: 1.5; }
body[data-view="chat"] .composer-note strong { font-weight: 600; }
body[data-view="chat"] .composer-note[open] { max-height: none; overflow: visible; }
body[data-view="chat"] .composer-risk-details { position: absolute; z-index: 26; bottom: calc(100% + 8px); left: 12px; width: min(420px, calc(100% - 24px)); max-height: min(160px, 30dvh); overflow-y: auto; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--paper); box-shadow: var(--shadow); }
body[data-view="chat"] .composer-risk-details p { margin: 0; }
body[data-view="chat"] .composer-risk-details p + p { margin-top: 8px; }
@media (max-width: 640px) {
  body[data-view="chat"] .composer-row { flex-wrap: wrap; }
  body[data-view="chat"] .composer-row > button,
  body[data-view="chat"] .composer-row .upload-button,
  body[data-view="chat"] .composer-send-actions button { width: calc(44px / var(--ui-font-scale)); min-width: calc(44px / var(--ui-font-scale)); height: calc(44px / var(--ui-font-scale)); min-height: calc(44px / var(--ui-font-scale)); padding: 0; }
  body[data-view="chat"] .composer-mode select { height: calc(44px / var(--ui-font-scale)); min-height: calc(44px / var(--ui-font-scale)); padding-left: 8px; font-size: 12px; }
  body[data-view="chat"] .composer-row .composer-footer { order: 5; flex-basis: 100%; margin: 2px 0 0; }
  body[data-view="chat"] .composer-note { font-size: 10px; }
  body[data-view="chat"] .composer-note summary { min-height: calc(24px / var(--ui-font-scale)); }
}

body[data-view="chat"] .composer-mode { position: relative; }
body[data-view="chat"] .composer-mode select { appearance: none; padding-right: 28px; }
body[data-view="chat"] .composer-mode::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); transform: translateY(-4px) rotate(45deg); pointer-events: none; }

/* 處理中的送出位置顯示三點；仍可點擊取消回答。 */
body[data-view="chat"] .composer-send-actions .cancel-button { color: white; border-color: var(--green); }
.composer-processing circle { fill: currentColor; stroke: none; animation: composer-processing-dot 1.2s ease-in-out infinite; }
.composer-processing circle:nth-child(2) { animation-delay: .16s; }
.composer-processing circle:nth-child(3) { animation-delay: .32s; }
@keyframes composer-processing-dot { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .composer-processing circle { animation: none; opacity: 1; }
}

/* 首頁與問答共用帳號選單，沿用管理端偏好。 */
.account-control { position: relative; flex: 0 0 auto; }
.account-trigger {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--green-dark);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
}
.account-trigger svg, .account-avatar svg { width: 21px; height: 21px; fill: currentColor; }
.account-trigger[aria-expanded="true"] { color: #fff; background: var(--green); border-color: var(--green); }
.account-menu {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 50;
  width: min(360px, calc((100vw - 24px) / var(--ui-font-scale)));
  max-height: calc((100dvh - 96px) / var(--ui-font-scale));
  overflow-y: auto;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 46px rgba(17, 48, 36, .2);
}
.account-summary { min-height: 68px; display: flex; align-items: center; gap: 11px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.account-summary strong, .account-summary small { display: block; }
.account-summary strong { font-size: 13px; }
.account-summary small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.account-avatar { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; background: var(--green); border-radius: 11px; }
.account-preference { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.account-preference:last-child { border-bottom: 0; }
.account-preference strong, .account-preference small { display: block; }
.account-preference strong { font-size: 12px; }
.account-preference small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.theme-options { display: inline-flex; gap: 3px; padding: 3px; background: var(--canvas); border: 1px solid var(--line); border-radius: 9px; }
.theme-options button { min-height: 30px; padding: 4px 8px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-size: 11px; white-space: nowrap; }
.theme-options button[aria-pressed="true"] { color: #fff; background: var(--green); }
.account-preferences .account-preference:nth-child(n+3) { grid-column: 1 / -1; }
.preference-select { min-height: 32px; max-width: 100%; padding: 0 24px 0 8px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink); background: var(--paper); font-size: 12px; }
.font-size-stepper { display: inline-grid; grid-template-columns: 30px 34px 30px; align-items: center; min-height: 32px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 8px; }
.font-size-stepper button { min-height: 30px; padding: 0; border: 0; border-radius: 0; background: var(--paper); font-size: 16px; }
.font-size-stepper output { min-height: 30px; display: grid; place-items: center; border-inline: 1px solid var(--line); font-size: 12px; font-weight: 750; }

.account-identity { min-width: 0; }
.account-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.account-email { min-width: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.account-menu-footer { padding: 10px 15px; border-top: 1px solid var(--line); }
.account-logout { display: block; width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--danger); background: var(--paper); font-weight: 700; cursor: pointer; }
.account-logout:hover { background: var(--canvas); }

.portal-user-email { margin-left: 8px; overflow-wrap: anywhere; }

.account-menu { overflow-x: hidden; overflow-y: auto; }

/* 緊湊帳號卡片：主題與字級同列，控制項尺寸不受頂列按鈕樣式影響。 */
.account-menu { width: min(300px, calc((100vw - 24px) / var(--ui-font-scale))); max-height: calc((100dvh - 150px) / var(--ui-font-scale)); overflow-x: hidden; overflow-y: auto; border-radius: 12px; box-shadow: 0 12px 32px rgba(17, 48, 36, .16); }
.account-summary { min-height: 62px; gap: 10px; padding: 12px 14px; }
.account-avatar { width: 32px; height: 32px; border-radius: 9px; }
.account-avatar svg { width: 18px; height: 18px; }
.account-identity { min-width: 0; }
.account-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.account-heading .account-email { min-width: 0; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.account-summary strong { font-size: 12px; }
.account-summary small { font-size: 10px; }
.account-preferences { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; padding: 12px 14px; }
.account-preferences .account-preference { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 7px; min-width: 0; padding: 0; border: 0; }
.account-preferences .account-preference + .account-preference { border-left: 1px solid var(--line); padding-left: 14px; }
.account-preferences .account-preference strong { font-size: 10px; font-weight: 600; color: var(--muted); }
.account-menu .theme-options { gap: 2px; padding: 2px; border-radius: 8px; }
.account-menu .theme-options button { display: grid; place-items: center; width: 32px; min-width: 0; height: 32px; min-height: 32px; padding: 0; }
.account-menu .font-size-stepper { grid-template-columns: 30px 34px 30px; min-height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--canvas); }
.account-menu .font-size-stepper button { display: grid; place-items: center; width: 30px; min-width: 0; height: 34px; min-height: 34px; padding: 0; color: var(--ink); background: transparent; border: 0; }
.account-menu .font-size-stepper output { min-height: 34px; color: var(--ink); font-size: 12px; }
.account-menu .font-size-stepper button:disabled { opacity: .4; cursor: default; }
.account-menu .font-size-stepper button:hover:not(:disabled) { background: var(--green-soft); }
.account-menu .preference-icon { display: block; width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.account-menu-footer { padding: 6px 10px; border-top: 1px solid var(--line); }
.account-menu .account-logout { display: flex; align-items: center; justify-content: flex-start; gap: 9px; width: 100%; min-height: 36px; padding: 8px 10px; border: 0; border-radius: 7px; color: var(--danger); background: transparent; font-size: 12px; font-weight: 600; cursor: pointer; }
.account-menu .account-logout:hover { background: var(--canvas); }
@media (max-width: 480px) {
  .account-preferences { gap: 8px; padding: 10px 12px; }
  .account-preferences .account-preference + .account-preference { padding-left: 8px; }
  .account-menu .theme-options button { width: calc(44px / var(--ui-font-scale)); min-height: calc(44px / var(--ui-font-scale)); height: calc(44px / var(--ui-font-scale)); }
  .account-menu .font-size-stepper { grid-template-columns: calc(44px / var(--ui-font-scale)) 30px calc(44px / var(--ui-font-scale)); }
  .account-menu .font-size-stepper button { width: calc(44px / var(--ui-font-scale)); min-height: calc(44px / var(--ui-font-scale)); height: calc(44px / var(--ui-font-scale)); }
  .account-menu .account-logout { min-height: calc(44px / var(--ui-font-scale)); }
}

/* 田區下拉較寬，縮小內距讓風險提示與下拉之間保有空隙。 */
body[data-view="chat"] .composer-garden select { padding-left: 8px; padding-right: 18px; }
/* 平板寬度（含放大文字）一列放不下圖片、模式、田區與風險提示：風險提示換到下一列，與手機版一致。 */
@media (min-width: 641px) and (max-width: 1000px) {
  body[data-view="chat"] .composer-row { flex-wrap: wrap; }
  body[data-view="chat"] .composer-row .composer-footer { order: 5; flex-basis: 100%; margin: 2px 0 0; }
}
/* 手機：田區下拉吃掉圖片、模式與送出之外的剩餘寬度，維持同一列。 */
@media (max-width: 640px) {
  body[data-view="chat"] .composer-garden { flex: 1 1 0; min-width: 0; }
  body[data-view="chat"] .composer-garden .select-label { width: 100%; }
  body[data-view="chat"] .composer-garden select { width: 100%; max-width: none; }
}
.retrieval-progress { font-size: .875rem; color: #40594c; border-left: 3px solid #7da991; padding: .4rem .75rem; margin: .5rem 0 .85rem; }

.retrieval-results { margin: 12px 0 20px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.retrieval-results summary { cursor: pointer; font-weight: 700; color: var(--green-dark); }
.retrieval-results-note { margin: 8px 0; color: var(--muted); font-size: .88em; }
.retrieval-results ul { padding-left: 1.3em; margin: 10px 0 0; }
.retrieval-results li { margin: 10px 0; overflow-wrap: anywhere; }
.retrieval-results li p { margin: 3px 0 0; font-size: .9em; color: var(--muted); }

/* 回答圖示的對話連結與公開唯讀頁 */
button.conversation-share-button { border: 0; cursor: pointer; padding: 0; font-family: inherit; }
button.conversation-share-button:hover { filter: brightness(1.15); }
button.conversation-share-button:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
button.conversation-share-button:disabled { cursor: progress; opacity: .65; }
.conversation-share-status { color: var(--green-dark); font-size: 12px; margin-right: 8px; }
body[data-view="chat"] .message.is-assistant .message-meta > button.conversation-share-button { width: 36px; height: 36px; }
.share-page { max-width: 960px; margin: 0 auto; padding: 24px 20px 64px; }
.share-page header { border-bottom: 1px solid var(--line); margin-bottom: 24px; padding-bottom: 16px; }
.share-page h1 { font-size: 24px; }
.share-page .share-question { white-space: pre-wrap; overflow-wrap: anywhere; padding: 16px; background: var(--green-soft); border-radius: 12px; }
.share-page .share-turn { border-bottom: 1px solid var(--line); padding: 8px 0 24px; margin-bottom: 24px; overflow-wrap: anywhere; }
.share-page .message-body { font-size: 16px; line-height: 1.8; }
.share-page .share-meta { color: var(--muted); font-size: 13px; }
.share-page .share-citation { padding: 12px; margin: 8px 0; border: 1px solid var(--line); border-radius: 10px; }
.share-page blockquote { margin: 8px 0; white-space: pre-wrap; }
.share-page .share-error { color: #b42318; }
.share-page pre { overflow-x: auto; }
