:root {
  --ink: #111316;
  --muted: #6d737a;
  --border: #d8dce1;
  --soft: #f2f2f2;
  --white: #ffffff;
  --green: #164b3c;
  --gutter: clamp(22px, 4.5vw, 72px);
  --header-height: 80px;
  font-family: Inter, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--white);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-width: 320px; background: var(--white); }
body { -webkit-font-smoothing: antialiased; }
button, textarea { font: inherit; }
button { color: inherit; }

.tool-header {
  min-height: var(--header-height);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  position: relative;
  z-index: 20;
}

.tool-header__brand,
.tool-header__project { color: var(--ink); font-size: 18px; font-weight: 600; }
.tool-header__brand { flex: 0 0 auto; text-decoration: none; }
.tool-header__project { min-width: 0; overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

.app-shell { min-height: calc(100vh - var(--header-height)); display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.scope-panel { border-right: 1px solid var(--border); padding: 30px 24px 22px; display: flex; flex-direction: column; min-height: calc(100vh - var(--header-height)); }
.scope-panel h2 { margin: 0 0 9px; font-size: 18px; }
.scope-copy p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.scope-copy p { margin: 0; }
.document-list { margin-top: 30px; }
.list-label { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.document-list ul { padding: 0; margin: 0; list-style: none; }
.document-list li { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.document-list small { color: var(--muted); }
.mobile-scope { display: none; }

.conversation { min-width: 0; min-height: calc(100vh - var(--header-height)); display: flex; flex-direction: column; position: relative; }
.welcome { width: min(720px, calc(100% - 64px)); margin: auto; padding: 72px 0; text-align: center; }
.welcome h1 { margin: 0; font-size: clamp(30px, 3vw, 44px); line-height: 1.2; letter-spacing: -.035em; }
.welcome > p { width: min(620px, 100%); margin: 20px auto 38px; color: var(--muted); font-size: 15px; line-height: 1.8; }
.examples { display: grid; gap: 9px; width: min(610px, 100%); margin: 0 auto; }
.examples button { display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 0 17px; border: 1px solid var(--border); border-radius: 9px; background: var(--white); cursor: pointer; text-align: left; font-size: 14px; transition: border-color .18s ease, background .18s ease; }
.examples button:hover { border-color: var(--ink); background: #fafafa; }

.answer-view { width: min(920px, calc(100% - 64px)); margin: 0 auto; padding: 54px 0 72px; }
.question-row, .answer-row { display: grid; grid-template-columns: 40px 1fr; gap: 16px; align-items: start; padding: 20px 0; border-bottom: 1px solid var(--border); }
.question-row p, .answer-text { margin: 5px 0 0; line-height: 1.75; }
.message-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--soft); font-weight: 650; }
.answer-mark { color: var(--white); background: var(--green); }
.answer-text { white-space: pre-wrap; font-size: 16px; }
.answer-meta { margin: 14px 0 0; color: var(--muted); font-size: 12px; }
.sources { padding-top: 28px; }
.sources h2 { margin: 0 0 12px; font-size: 15px; }
.source-item { display: grid; grid-template-columns: 210px 82px 1fr; border: 1px solid var(--border); border-bottom: 0; }
.source-item:last-child { border-bottom: 1px solid var(--border); }
.source-item > * { padding: 14px; margin: 0; font-size: 12px; line-height: 1.65; }
.source-item .source-page { border-left: 1px solid var(--border); border-right: 1px solid var(--border); color: var(--muted); }
.source-quote { color: #363a3e; }

.loading { margin: auto; text-align: center; color: var(--muted); font-size: 13px; }
.error-message { width: min(720px, calc(100% - 64px)); margin: 56px auto; padding: 16px; border: 1px solid #a23b32; color: #7a2923; background: #fffafa; font-size: 14px; }

.composer-area { position: sticky; z-index: 10; bottom: 0; margin-top: auto; padding: 12px 24px 20px; border-top: 1px solid var(--border); background: rgba(255,255,255,.98); }
.trace-note { width: min(920px, 100%); margin: 0 auto 9px; color: var(--muted); font-size: 11px; }
.composer { width: min(920px, 100%); margin: 0 auto; display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.composer textarea { min-height: 58px; max-height: 150px; resize: none; padding: 18px 16px; border: 1px solid var(--border); border-radius: 9px; outline: none; line-height: 1.45; }
.composer textarea:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(22,75,60,.12); }
.composer button { min-width: 116px; border: 1px solid var(--ink); border-radius: 9px; background: var(--ink); color: var(--white); font-size: 14px; font-weight: 650; cursor: pointer; }
.composer button:hover { background: #292c30; }
.composer button:disabled { border-color: var(--border); background: #e4e7e9; color: #858a90; cursor: not-allowed; opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.site-footer { min-height: 112px; padding: 0 var(--gutter); display: flex; align-items: center; justify-content: flex-end; border-top: 1px solid var(--border); background: var(--white); }
.site-footer small { color: var(--muted); }

@media (max-width: 800px) {
  :root { --header-height: 68px; }
  .tool-header { min-height: 68px; gap: 12px; }
  .tool-header__brand { font-size: 14px; }
  .tool-header__project { font-size: 12px; }
  .app-shell { display: block; }
  .scope-panel { display: none; }
  .conversation { min-height: calc(100dvh - var(--header-height)); }
  .mobile-scope { display: block; margin: 20px 20px 0; padding-bottom: 14px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 13px; }
  .mobile-scope summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; color: var(--ink); cursor: pointer; list-style: none; }
  .mobile-scope summary::after { content: "+"; color: var(--green); font-size: 18px; }
  .mobile-scope[open] summary::after { content: "−"; }
  .mobile-scope summary::-webkit-details-marker { display: none; }
  .mobile-scope ul { margin: 8px 0 0; padding: 0; list-style: none; }
  .mobile-scope li { padding: 9px 0; border-top: 1px solid var(--border); }
  .welcome { width: calc(100% - 40px); padding: 52px 0; text-align: left; }
  .welcome h1 { font-size: 31px; }
  .welcome > p { margin: 16px 0 30px; font-size: 14px; }
  .examples button { min-height: 56px; }
  .answer-view { width: calc(100% - 40px); padding: 20px 0 48px; }
  .question-row, .answer-row { grid-template-columns: 38px 1fr; gap: 12px; padding: 18px 0; }
  .answer-text { font-size: 15px; }
  .source-item { display: block; padding: 14px 0; border-left: 0; border-right: 0; }
  .source-item > * { padding: 3px 0; }
  .source-item .source-page { border: 0; }
  .source-quote { margin-top: 8px; padding: 13px !important; border: 1px solid var(--border); }
  .composer-area { padding: 10px 14px max(14px, env(safe-area-inset-bottom)); }
  .trace-note { font-size: 10px; }
  .composer { gap: 8px; }
  .composer textarea { min-height: 54px; padding: 16px 13px; }
  .composer button { min-width: 76px; }
  .error-message { width: calc(100% - 40px); }
  .site-footer { min-height: 96px; }
}

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