:root {
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
  color: #293d34;
  background: #faf9f5;
  font-size: 14px;
  --paper: #faf9f5;
  --green: #315e49;
  --muted: #6f7c72;
  --line: #dfe4dc;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid #50785e; outline-offset: 3px; }
.hidden { display: none !important; }
.mobile-menu { display: none; }
.web .desktop-only { display: none; }
.web-only { display: none; }
.web .web-only { display: block; }
.download-client { margin-top: 20px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 9px; color: var(--green); text-decoration: none; text-align: center; font-size: 13px; }
.download-client:hover { background: #eef1ea; }
.download-client span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.download-side { text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: .15em; color: var(--muted); }
.primary { border: 1px solid var(--green); background: var(--green); color: #fff; border-radius: 9px; padding: 11px 20px; font-weight: 700; }
.primary:hover:not(:disabled) { background: #234c38; }
.error { color: #a34135; margin: 10px 0; line-height: 1.6; overflow-wrap: anywhere; }
.error:empty { display: none; }
.text-button { border: 0; background: transparent; color: var(--green); padding: 6px 0; }
.text-button:hover { text-decoration: underline; }

/* Login: book-like typography and a solid accent panel. */
.auth-view { min-height: 100vh; display: grid; grid-template-columns: minmax(430px, 1fr) minmax(280px, 40%); }
.auth-card { width: min(380px, 80%); margin: auto; padding: 36px 0; }
.mark, .mini-mark { display: grid; place-items: center; background: var(--green); color: #fff; font-family: "SimSun", serif; }
.mark { width: 52px; height: 56px; border-radius: 10px 10px 20px 10px; font-size: 29px; margin-bottom: 27px; }
.auth-card h1 { font-family: "SimSun", serif; font-size: 38px; letter-spacing: .12em; margin: 12px 0; }
.subtitle { color: var(--muted); margin: 0 0 28px; line-height: 1.8; }
.auth-switch { border-bottom: 1px solid var(--line); display: flex; gap: 30px; margin-bottom: 23px; }
.auth-switch button { border: 0; border-bottom: 2px solid transparent; background: none; padding: 10px 3px; color: var(--muted); }
.auth-switch button.active { color: var(--green); border-color: var(--green); font-weight: 700; }
.auth-card label, #settings-form label { display: block; font-size: 13px; font-weight: 700; margin: 17px 0 8px; }
.auth-card input, #settings-form input { width: 100%; padding: 12px 14px; border: 1px solid #d2dacf; background: #fff; border-radius: 8px; outline: none; }
input::placeholder, textarea::placeholder { color: #879087; }
.auth-card input:focus, #settings-form input:focus { border-color: #50785e; box-shadow: 0 0 0 3px #50785e15; }
.auth-card .primary { width: 100%; margin: 24px 0 12px; }
.auth-tools { position: absolute; left: 28px; bottom: 18px; display: flex; gap: 24px; font-size: 12px; }
.auth-view { position: relative; padding-bottom: 48px; }
.auth-aside { margin-bottom: -48px; }
.auth-aside { background: #294f3f; color: #f4f1e7; display: flex; flex-direction: column; justify-content: center; padding: 60px 12%; }
.aside-label { font-size: 11px; letter-spacing: .24em; color: #c1cdbb; margin: 0 0 42px; }
.aside-title { font-family: "SimSun", serif; font-size: clamp(40px, 4.8vw, 66px); line-height: 1.5; letter-spacing: .14em; }
.aside-description { color: #c7d3c7; line-height: 2; margin: 26px 0 64px; }
.aside-note { border-top: 1px solid #ffffff29; padding-top: 24px; }
.aside-note span { font-size: 14px; letter-spacing: .12em; }
.aside-note p { color: #c7d3c7; font-size: 11px; line-height: 1.7; }

/* Stable sidebar, bounded reading column, fixed composer. */
.app-view { height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar { background: #eef1ea; border-right: 1px solid var(--line); padding: 27px 16px 18px; display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 9px 30px; }
.mini-mark { width: 37px; height: 40px; border-radius: 8px 8px 14px 8px; font-size: 22px; flex: none; }
.brand strong { display: block; font-family: "SimSun", serif; font-size: 19px; letter-spacing: .08em; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 5px; }
.new-chat { background: var(--green); color: #fff; border: 0; border-radius: 8px; padding: 12px 15px; text-align: left; }
.new-chat:hover:not(:disabled) { background: #234c38; }
.side-label { color: var(--muted); font-size: 11px; letter-spacing: .1em; margin: 29px 10px 10px; }
.sidebar nav { overflow-y: auto; flex: 1; min-height: 0; }
.history-empty { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 12px 10px; }
.conversation { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; color: #526356; border-radius: 7px; padding: 11px 12px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation:hover:not(:disabled) { background: #e3e9df; }
.conversation.active { background: #dce6d8; border-color: #d0dccb; color: #254d36; font-weight: 700; }
.side-bottom { border-top: 1px solid #d8dfd3; padding-top: 15px; margin-top: 15px; }
.knowledge-status { font-size: 11px; color: var(--muted); line-height: 1.8; padding: 0 9px 12px; }
.side-action { border: 0; background: transparent; color: #526356; width: 100%; text-align: left; padding: 9px; border-radius: 6px; font-size: 12px; }
.side-action:hover:not(:disabled) { background: #e0e7db; }
.main { --gutter: max(32px, calc((100% - 780px) / 2)); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { min-height: 85px; border-bottom: 1px solid #e6e8df; display: flex; gap: 20px; align-items: center; justify-content: space-between; padding: 18px 32px; flex: none; }
.topbar > div { min-width: 0; }
.topbar h2 { font-size: 17px; font-weight: 600; margin: 7px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-badge { background: #edf0e7; border: 1px solid #e1e6da; color: #49634e; padding: 7px 12px; border-radius: 6px; font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 32px var(--gutter) 16px; scrollbar-gutter: stable; }
.welcome { max-width: 560px; margin: 0 auto; padding: clamp(20px, 7vh, 70px) 0 24px; }
.welcome-label { display: inline-block; font-size: 11px; letter-spacing: .16em; color: var(--green); border-left: 3px solid #8b9e71; padding-left: 10px; }
.welcome h2 { font-family: "SimSun", serif; font-size: 32px; letter-spacing: .04em; margin: 20px 0 16px; }
.welcome > p { line-height: 1.95; color: var(--muted); margin-bottom: 28px; }
.welcome-example { border: 1px solid var(--line); background: #fffefa; border-radius: 10px; padding: 17px 20px; }
.welcome-example > span { color: var(--muted); font-size: 11px; }
.welcome-example p { font-size: 14px; margin: 9px 0 0; line-height: 1.8; }
.welcome-steps { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; margin-top: 23px; }
.message { margin: 0 0 30px; min-width: 0; }
.message-heading { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 10px; letter-spacing: .06em; }
.message.user { display: flex; flex-direction: column; align-items: flex-end; }
.message.user .message-content { background: #eaf0e4; border: 1px solid #e0e7da; border-radius: 12px 12px 3px 12px; padding: 12px 17px; max-width: 90%; white-space: pre-wrap; line-height: 1.8; }
.message.assistant .message-heading { color: var(--green); display: flex; align-items: center; gap: 8px; }
.message.assistant .message-heading::before { content: "草"; font-family: "SimSun", serif; font-size: 12px; background: #e8eee1; padding: 3px 5px; border-radius: 4px; }
.message-content { overflow-wrap: anywhere; line-height: 1.9; font-size: 14px; }
.message.pending .message-content { color: var(--muted); font-size: 13px; }
.sources { margin-top: 20px; border: 1px solid var(--line); background: #f2f4ed; border-radius: 9px; padding: 12px 16px; }
.sources summary { color: #47674d; font-size: 12px; cursor: pointer; line-height: 1.6; }
.source { padding: 15px 0 0; border-top: 1px solid var(--line); margin-top: 13px; }
.source strong { font-size: 12px; color: #49614b; line-height: 1.8; overflow-wrap: anywhere; }
.source p { margin: 9px 0 0; color: #64715f; font-size: 13px; line-height: 1.9; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Original questions and excerpts remain plain text. */
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 14px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { color: #2a4e38; line-height: 1.5; margin: 25px 0 12px; font-weight: 700; }
.markdown h1 { font-size: 23px; }
.markdown h2 { font-size: 20px; }
.markdown h3 { font-size: 17px; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 14px; }
.markdown ul, .markdown ol { padding-left: 25px; margin: 12px 0 17px; }
.markdown li { padding-left: 3px; margin: 5px 0; }
.markdown li > p { margin-bottom: 6px; }
.markdown li ul, .markdown li ol { margin: 4px 0; }
.markdown li::marker { color: #628167; }
.markdown strong { color: #254b34; font-weight: 700; }
.markdown blockquote { margin: 16px 0; padding: 12px 17px; border-left: 3px solid #9cad8b; background: #f0f3e9; color: #607059; }
.markdown blockquote > :last-child { margin-bottom: 0; }
.markdown code { font-family: Consolas, "Cascadia Code", monospace; font-size: .9em; background: #ecefe6; border-radius: 4px; padding: 2px 5px; }
.markdown pre { background: #f0f2eb; border: 1px solid var(--line); border-radius: 8px; padding: 15px 17px; overflow-x: auto; max-width: 100%; line-height: 1.65; }
.markdown pre code { background: none; padding: 0; border-radius: 0; white-space: pre; overflow-wrap: normal; }
.markdown table { display: block; max-width: 100%; width: max-content; overflow-x: auto; border-collapse: collapse; margin: 17px 0; font-size: 13px; }
.markdown th, .markdown td { border: 1px solid #d7dfd2; padding: 9px 13px; text-align: left; min-width: 96px; }
.markdown th { background: #eaf0e2; color: #34553c; font-weight: 700; }
.markdown tr:nth-child(even) { background: #f3f5ee; }
.markdown a { color: #326d50; text-underline-offset: 3px; }
.markdown a:hover { color: #204a34; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 23px 0; }

.composer-wrap { padding: 10px var(--gutter) 16px; flex: none; background: var(--paper); }
.composer { display: flex; align-items: flex-end; gap: 10px; background: #fffefa; border: 1px solid #cfd8c8; border-radius: 12px; padding: 9px; box-shadow: 0 3px 12px #293d3406; }
.composer:focus-within { border-color: #72906c; box-shadow: 0 0 0 3px #72906c10; }
.composer textarea { resize: none; min-width: 0; min-height: 58px; max-height: 160px; flex: 1; border: 0; outline: none; padding: 9px; background: transparent; line-height: 1.65; }
.composer .primary { white-space: nowrap; padding: 10px 17px; }
.composer-hint { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 10px; margin: 9px 3px 0; }
.footnote { text-align: center; color: var(--muted); font-size: 10px; margin: 13px 0 0; line-height: 1.6; }

dialog { color: #293d34; background: var(--paper); border: 1px solid #d3e0d2; border-radius: 13px; box-shadow: 0 20px 60px #1b39272b; width: min(480px, calc(100% - 40px)); padding: 28px; }
dialog::backdrop { background: #13251c66; }
dialog h2 { margin: 0; color: #284a33; font-size: 20px; }
dialog p { line-height: 1.8; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
dialog .error { color: #a34135; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 23px; }
.dialog-actions button:not(.primary) { border: 1px solid #d2ded1; border-radius: 8px; background: #fff; padding: 10px 20px; color: #536b59; }
#settings-form .debug-toggle { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 24px; padding: 16px 0; border-top: 1px solid var(--line); }
#settings-form #local-debug { appearance: none; width: 40px; height: 24px; padding: 3px; border: 1px solid #9aa997; border-radius: 20px; background: #dfe5da; cursor: pointer; flex-shrink: 0; }
#local-debug::before { content: ''; display: block; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px #0002; }
#settings-form #local-debug:checked { background: var(--green); border-color: var(--green); }
#local-debug:checked::before { transform: translateX(16px); }
#settings-form .settings-help { font-size: 12px; margin: 0 0 12px; }
#debug-fields { padding: 0 16px 4px; margin: 8px 0 0; border: 1px solid var(--line); border-radius: 9px; background: #f0f3eb; }
.endpoint-fields { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 12px; margin-bottom: 14px; }
@media (max-width: 1000px) {
  .app-view { grid-template-columns: 212px minmax(0, 1fr); }
  .main { --gutter: 25px; }
  .topbar { padding: 17px 25px; }
  .sidebar { padding-inline: 12px; }
}
@media (max-width: 760px) {
  .auth-view { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .app-view { grid-template-columns: 176px minmax(0, 1fr); }
  .main { --gutter: 18px; }
  .topbar { padding: 15px 18px; gap: 10px; }
  .welcome h2 { font-size: 26px; }
  .welcome-steps, .composer-hint { flex-wrap: wrap; }
}
.web .app-view { height: 100dvh; }
@media (max-width: 640px) {
  .web .app-view { display: flex; flex-direction: column; }
  .web .main { flex: 1; --gutter: 16px; }
  .web .sidebar { display: none; max-height: 40dvh; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }
  .web .menu-open .sidebar { display: flex; }
  .web .sidebar .brand, .web .side-label, .web .knowledge-status { display: none; }
  .web .sidebar nav { margin-top: 8px; }
  .web .side-bottom { margin-top: 8px; padding-top: 4px; }
  .web .mobile-menu { display: block; flex-shrink: 0; border: 1px solid var(--line); border-radius: 7px; background: #eef1ea; color: var(--green); padding: 9px; }
  .web .topbar { min-height: 72px; padding: 12px 16px; }
  .web .topbar > div:nth-child(2) { flex: 1; }
  .web .topbar h2 { font-size: 15px; }
  .web .user-badge { max-width: 78px; }
  .web .messages { padding-top: 20px; }
  .web .welcome { padding-top: 18px; }
  .web .auth-card input, .web .composer textarea { font-size: 16px; }
}
