:root {
  --ink: #102238;
  --ink-soft: #34485d;
  --paper: #f4f6f3;
  --surface: #ffffff;
  --surface-blue: #edf3f8;
  --line: #d9e0e2;
  --blue: #245786;
  --blue-dark: #174265;
  --gold: #b57a24;
  --green: #32715b;
  --danger: #a9413c;
  --shadow: 0 18px 50px rgba(16, 34, 56, 0.12);
  --radius: 18px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--paper); }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); font-size: 16px; line-height: 1.65; }
button, textarea, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid rgba(36, 87, 134, .28); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.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; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 2000; transform: translateY(-150%); padding: 10px 14px; color: white; background: var(--ink); border-radius: 8px; }
.skip-link:focus { transform: translateY(0); }

.topbar { height: 74px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: white; background: var(--ink); border-bottom: 1px solid rgba(255,255,255,.12); }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 12px; }
.brand-seal { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.38); border-radius: 12px 12px 12px 3px; font: 600 22px/1 var(--serif); }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 19px/1.2 var(--serif); letter-spacing: .16em; }
.brand small { margin-top: 4px; color: #b8c5d1; font-size: 11px; letter-spacing: .08em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.secure-state { margin-right: 8px; display: inline-flex; align-items: center; gap: 8px; color: #cbd6df; font-size: 13px; }
.secure-state i { width: 7px; height: 7px; background: #69b795; border-radius: 50%; box-shadow: 0 0 0 4px rgba(105,183,149,.12); }
.text-button, .icon-button { min-height: 44px; color: #e8eef3; background: transparent; border: 1px solid rgba(255,255,255,.16); border-radius: 10px; transition: background 180ms ease, border-color 180ms ease; }
.text-button { padding: 0 14px; }
.icon-button { width: 44px; display: grid; place-items: center; }
.text-button:hover, .icon-button:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.32); }

.app-shell { height: calc(100dvh - 74px); min-height: 620px; display: grid; grid-template-columns: 284px minmax(0, 1fr); }
.research-rail { padding: 38px 24px 28px 28px; background: #e9eeed; border-right: 1px solid var(--line); overflow-y: auto; }
.rail-heading span, .eyebrow { color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.rail-heading strong { display: block; margin-top: 12px; font: 600 25px/1.4 var(--serif); }
.prompt-list { margin-top: 34px; display: grid; gap: 8px; }
.prompt-list button { min-height: 54px; padding: 10px 10px; display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 8px; color: var(--ink-soft); text-align: left; background: transparent; border: 0; border-radius: 10px; transition: color 180ms ease, background 180ms ease; }
.prompt-list button:hover { color: var(--ink); background: rgba(255,255,255,.66); }
.prompt-list span { color: var(--gold); font: 600 12px/1 var(--serif); }
.rail-note { margin-top: 36px; padding-top: 22px; display: flex; gap: 12px; border-top: 1px solid #cbd5d5; }
.rail-note svg { flex: 0 0 auto; color: var(--green); }
.rail-note p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.rail-note strong { display: block; margin-bottom: 4px; color: var(--ink); }

.conversation { min-width: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: var(--paper); }
.conversation-scroll { min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.welcome { width: min(780px, calc(100% - 48px)); margin: 0 auto; padding: clamp(54px, 8vh, 94px) 0 36px; }
.welcome h1 { margin: 14px 0 22px; font: 600 clamp(38px, 5vw, 64px)/1.17 var(--serif); letter-spacing: -.035em; }
.welcome h1 em { color: var(--blue); font-style: normal; }
.welcome-copy { max-width: 620px; margin: 0; color: var(--ink-soft); font-size: 17px; }
.method-strip { margin-top: 40px; padding: 16px 18px; display: flex; align-items: center; gap: 12px; color: var(--ink-soft); background: rgba(255,255,255,.68); border: 1px solid var(--line); border-radius: 12px; font-size: 12px; }
.method-strip i { height: 1px; flex: 1; min-width: 12px; background: #bfcbd0; }

.messages { width: min(860px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 30px; display: grid; gap: 30px; }
.message { display: grid; gap: 10px; animation: message-in 260ms ease-out both; }
.message.user { justify-items: end; }
.message-label { color: var(--ink-soft); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.user-bubble { max-width: min(680px, 88%); padding: 13px 17px; color: white; white-space: pre-wrap; background: var(--blue); border-radius: 16px 16px 4px 16px; }
.assistant-card { width: 100%; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(16,34,56,.06); }
.answer-header { padding: 15px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink-soft); background: #f8faf9; border-bottom: 1px solid var(--line); font-size: 12px; }
.answer-header strong { color: var(--ink); font: 600 14px/1 var(--serif); }
.answer-body { padding: 22px 24px 20px; color: #1b3044; }
.answer-body p { max-width: 74ch; margin: 0 0 14px; }
.answer-body p:last-child { margin-bottom: 0; }
.answer-body h3 { margin: 22px 0 10px; font: 600 19px/1.4 var(--serif); }
.answer-body ul, .answer-body ol { margin: 8px 0 16px; padding-left: 22px; }
.citation-link { display: inline-grid; place-items: center; min-width: 25px; height: 25px; margin: 0 2px; padding: 0 6px; color: var(--blue-dark); vertical-align: baseline; background: var(--surface-blue); border: 1px solid #c5d6e3; border-radius: 7px; font-size: 12px; font-weight: 700; }
.sources { border-top: 1px solid var(--line); }
.sources > summary { min-height: 52px; padding: 13px 20px; display: flex; align-items: center; gap: 9px; color: var(--blue-dark); cursor: pointer; list-style: none; font-weight: 700; font-size: 14px; }
.sources > summary::-webkit-details-marker { display: none; }
.sources > summary svg { width: 18px; }
.source-list { padding: 0 20px 20px; display: grid; gap: 10px; }
.source-item { scroll-margin-top: 20px; padding: 14px 16px; background: #f7f9f8; border-left: 3px solid #9bb3c6; border-radius: 4px 10px 10px 4px; }
.source-item.flash { animation: evidence-flash 1.1s ease; }
.source-meta { display: flex; align-items: flex-start; gap: 10px; }
.source-index { flex: 0 0 auto; width: 27px; height: 27px; display: grid; place-items: center; color: white; background: var(--blue); border-radius: 8px; font-size: 12px; font-weight: 700; }
.source-title { margin: 0; font-weight: 700; line-height: 1.4; }
.source-anchor { color: #66798a; font-size: 12px; }
.source-item blockquote { margin: 11px 0 0 37px; color: var(--ink-soft); font-size: 14px; white-space: pre-wrap; }
.copy-row { padding: 0 20px 16px; display: flex; justify-content: flex-end; }
.copy-button { min-height: 40px; padding: 0 12px; color: var(--ink-soft); background: transparent; border: 0; border-radius: 8px; }
.copy-button:hover { background: var(--surface-blue); }

.thinking { width: min(860px, calc(100% - 40px)); margin: 0 auto 20px; padding: 18px 22px; display: flex; align-items: center; gap: 6px; color: var(--ink-soft); background: white; border: 1px solid var(--line); border-radius: var(--radius); }
.thinking[hidden] { display: none; }
.thinking span { width: 7px; height: 7px; background: var(--blue); border-radius: 50%; animation: pulse 1s infinite ease-in-out; }
.thinking span:nth-child(2) { animation-delay: 120ms; }
.thinking span:nth-child(3) { animation-delay: 240ms; }
.thinking p { margin: 0 0 0 8px; font-size: 14px; }

.composer-wrap { position: relative; z-index: 10; padding: 14px 28px 15px; background: linear-gradient(180deg, rgba(244,246,243,0), var(--paper) 18%); }
.composer { width: min(860px, 100%); margin: 0 auto; overflow: hidden; background: white; border: 1px solid #bfcbd0; border-radius: 17px; box-shadow: var(--shadow); transition: border-color 180ms ease, box-shadow 180ms ease; }
.composer:focus-within { border-color: var(--blue); box-shadow: 0 18px 55px rgba(30, 74, 111, .16); }
.mode-switch { padding: 10px 12px 0; display: flex; gap: 4px; }
.mode-switch label { cursor: pointer; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch span { min-height: 36px; padding: 7px 11px; display: block; color: #657687; border-radius: 8px; font-size: 12px; font-weight: 700; }
.mode-switch input:checked + span { color: var(--blue-dark); background: var(--surface-blue); }
.mode-switch input:focus-visible + span { outline: 3px solid rgba(36,87,134,.25); }
#question-input { width: 100%; max-height: 180px; min-height: 62px; padding: 14px 18px 8px; resize: none; color: var(--ink); background: transparent; border: 0; outline: none; font-size: 17px; line-height: 1.6; }
#question-input::placeholder { color: #8795a1; }
.composer-footer { padding: 0 10px 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.composer-footer > span { color: #82909b; font-size: 11px; }
.send-button { width: 44px; height: 44px; display: grid; place-items: center; color: white; background: var(--blue); border: 0; border-radius: 12px; transition: background 180ms ease, opacity 180ms ease; }
.send-button:hover { background: var(--blue-dark); }
.send-button:disabled { cursor: not-allowed; opacity: .46; }
.disclaimer { margin: 8px auto 0; color: #75838e; text-align: center; font-size: 11px; }

.auth-dialog { width: min(460px, calc(100% - 32px)); padding: 0; background: transparent; border: 0; }
.auth-dialog::backdrop { background: rgba(8, 22, 35, .66); backdrop-filter: blur(7px); }
.auth-card { padding: 32px; color: var(--ink); background: white; border-radius: 20px; box-shadow: 0 28px 90px rgba(0,0,0,.32); }
.auth-mark { width: 48px; height: 48px; margin-bottom: 22px; display: grid; place-items: center; color: white; background: var(--ink); border-radius: 14px 14px 14px 4px; }
.auth-card h2 { margin: 8px 0 10px; font: 600 30px/1.25 var(--serif); }
.auth-card > p:not(.eyebrow):not(.auth-error) { margin: 0 0 22px; color: var(--ink-soft); font-size: 14px; }
.field-label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
.password-field { display: grid; grid-template-columns: 1fr auto; border: 1px solid #aebcc6; border-radius: 11px; overflow: hidden; }
.password-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,87,134,.12); }
.password-field input { min-width: 0; min-height: 48px; padding: 0 13px; border: 0; outline: 0; }
.password-field button { min-width: 62px; color: var(--blue); background: transparent; border: 0; }
.remember-row { margin-top: 16px; padding: 12px; display: flex; gap: 11px; cursor: pointer; background: #f4f7f6; border-radius: 10px; }
.remember-row input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--blue); }
.remember-row strong, .remember-row small { display: block; }
.remember-row strong { font-size: 13px; }
.remember-row small { margin-top: 2px; color: #687985; font-size: 11px; }
.auth-error { min-height: 24px; margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.unlock-button { width: 100%; min-height: 50px; margin-top: 8px; color: white; background: var(--blue); border: 0; border-radius: 11px; font-weight: 700; }
.unlock-button:disabled { cursor: wait; opacity: .55; }
.toast { position: fixed; left: 50%; bottom: 22px; z-index: 1100; max-width: calc(100% - 32px); padding: 11px 16px; color: white; background: var(--ink); border-radius: 10px; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 18px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes message-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes pulse { 0%, 80%, 100% { opacity: .28; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
@keyframes evidence-flash { 0%, 100% { background: #f7f9f8; } 25% { background: #e4edf3; } }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .research-rail { padding-left: 18px; padding-right: 16px; }
  .rail-heading strong { font-size: 21px; }
}

@media (max-width: 720px) {
  .topbar { height: 64px; padding: 0 14px; }
  .brand small, .secure-state, .text-button { display: none; }
  .app-shell { height: calc(100dvh - 64px); min-height: 0; display: block; }
  .research-rail { display: none; }
  .conversation { height: 100%; }
  .welcome { width: calc(100% - 32px); padding: 38px 0 24px; }
  .welcome h1 { font-size: clamp(34px, 11vw, 46px); }
  .welcome-copy { font-size: 16px; }
  .method-strip { margin-top: 26px; padding: 12px; gap: 7px; overflow-x: auto; white-space: nowrap; }
  .messages, .thinking { width: calc(100% - 24px); }
  .messages { gap: 22px; padding-top: 18px; }
  .user-bubble { max-width: 94%; }
  .answer-body { padding: 18px 16px; }
  .source-list { padding: 0 12px 14px; }
  .source-item blockquote { margin-left: 0; }
  .composer-wrap { padding: 9px 10px max(10px, env(safe-area-inset-bottom)); }
  .composer-footer > span { display: none; }
  .disclaimer { font-size: 10px; }
  .auth-card { padding: 26px 22px; }
}

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