:root {
  --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;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 90% 0, #e3efe3 0, transparent 30%), var(--canvas); }
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; }
.public-only, .auth-only { display: none; }
body[data-auth="guest"] .public-only { display: grid; }
body[data-auth="authenticated"] .auth-only { display: flex; }

.app-shell { min-height: 100vh; }
.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; }
.text-button { font-weight: 700; padding: 8px; }
.new-conversation-button { align-items: center; 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: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: #edf3ee; font-size: 13px; }

.workspace { min-height: calc(100vh - 76px); display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sidebar { flex-direction: column; min-height: calc(100vh - 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; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
.history-list { display: grid; gap: 7px; overflow: auto; }
.history-empty { color: var(--muted); font-size: 13px; padding: 14px 4px; line-height: 1.6; }
.history-item { 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; }
.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(100vh - 76px); flex-direction: column; position: relative; }
.messages { width: min(920px, calc(100% - 48px)); margin: 0 auto; padding: 52px 0 calc(var(--composer-height, 182px) + 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; }
@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-header a { color: var(--ink); font-size: 13px; font-weight: 800; line-height: 1.45; text-decoration: none; }
.citation-header a: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; color: var(--green); font-size: 11px; font-weight: 800; text-decoration: none; }
.visual-evidence { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.visual-evidence h4 { margin: 0; font-size: 13px; }
.visual-evidence > 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: fixed; left: calc(270px + (100vw - 270px) / 2); bottom: 22px; width: min(860px, calc(100vw - 318px)); transform: translateX(-50%); 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 { height: 36px; display: inline-flex; align-items: 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: 34px; padding: 0 24px 0 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font-size: 12px; }
.primary-button { height: 38px; 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; }
.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; color: #788981; font-size: 10px; text-align: center; }
.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: 3px; right: 3px; width: 19px; height: 19px; padding: 0; border: 0; border-radius: 50%; color: white; background: rgba(20,40,32,.75); }

.vision-panel { position: fixed; top: 96px; right: 24px; z-index: 15; width: min(390px, calc(100vw - 48px)); max-height: calc(100vh - 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; }

.login-panel { grid-column: 1 / -1; min-height: calc(100vh - 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; }
.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; }
.form-error { min-height: 20px; margin: 0 0 8px !important; color: var(--danger) !important; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: none !important; }
  .composer { left: 50%; width: calc(100vw - 28px); bottom: 12px; }
  .messages { width: min(100% - 30px, 760px); padding-top: 30px; }
  .login-panel { grid-template-columns: 1fr; gap: 34px; }
  .login-copy h1 { font-size: clamp(42px, 11vw, 70px); }
}

@media (max-width: 640px) {
  .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; }
  .workspace { min-height: calc(100vh - 66px); }
  .messages { width: calc(100% - 24px); padding: 18px 0 calc(var(--composer-height, 214px) + 48px); }
  .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 { align-items: flex-end; }
  .toolbar-group.right { display: grid; grid-template-columns: repeat(2, auto); }
  .primary-button { grid-column: 1 / -1; }
  .primary-button span { display: inline; }
  .composer-note { display: none; }
  .login-panel { padding: 34px 18px; }
  .login-copy h1 { font-size: 46px; }
  .login-copy > p { font-size: 14px; }
  .login-card { padding: 24px 20px; }
}

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