: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-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; }
.status-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 999px; color: var(--muted); background: #f4f7f4; font-size: 12px; }
.status-chip i { 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: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; }
.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; }
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; }
.messages { 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.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; }

.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 { background: rgba(255, 220, 45, .58); border-radius: 2px; box-shadow: 0 0 0 1px rgba(237, 187, 0, .18); mix-blend-mode: multiply; }
.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); }
.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; align-items: center; justify-content: space-between; gap: 10px; padding-top: 9px; border-top: 1px solid #edf1ed; }
.toolbar-group { display: flex; align-items: center; gap: 7px; }
.toolbar-group.right { justify-content: flex-end; }
#image-input { position: absolute; opacity: 0; pointer-events: none; }
.upload-button, .secondary-button { 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; 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 { 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 { margin: 9px 7px 0; padding-top: 8px; border-top: 1px solid #e7ece8; color: #53675f; font-size: 11px; line-height: 1.55; text-align: center; }
.composer-note strong { color: var(--danger); }
.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; }
.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; 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) {
  .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 - 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: max(12px, env(safe-area-inset-bottom)); }
  .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: 100vw; 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: 66px minmax(0, 1fr); }
  .topbar { height: 66px; padding: 0 15px; }
  .brand small { display: none; }
  .brand strong { font-size: 14px; }
  .topbar-actions { gap: 6px; }
  .status-chip { width: 30px; padding: 8px; gap: 0; overflow: hidden; white-space: nowrap; }
  .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: 10px; 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; }
  .cancel-button, .primary-button { grid-column: auto; }
  .primary-button span { display: inline; }
  .composer-note { margin-inline: 2px; font-size: 10px; text-align: left; }
  .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; padding: 10px 10px 9px 13px; }
  .document-viewer-heading .eyebrow, .document-viewer-header small { display: none; }
  .document-toolbar button { padding: 0 5px; }
  .document-viewer-scroll { padding: 14px 10px 36px; }
}

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