:root {
  --navy: #102a43; --blue: #1665d8; --blue-dark: #0f53b7; --text: #1f2d3d;
  --muted: #66788a; --line: #dce5ef; --background: #eef3f8;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
  color: var(--text); background: var(--background);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.chat {
  display: flex; flex-direction: column; width: min(100% - 48px, 1040px);
  height: calc(100vh - 48px); height: calc(100dvh - 48px); margin: 24px auto;
  background: #fff; border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  box-shadow: 0 14px 35px rgba(25,51,78,.08);
}
.chat-header { display: flex; flex-shrink: 0; gap: 12px; align-items: center; padding: 19px 28px; border-bottom: 1px solid var(--line); }
.brand-mark, .welcome-mark, .mini-avatar {
  display: grid; place-items: center; flex-shrink: 0; color: #fff;
  background: linear-gradient(145deg, #1769d9, #0c4a9f); border-radius: 12px;
}
.brand-mark { width: 42px; height: 42px; font-size: 21px; }
h1 { font-size: 20px; line-height: 1.4; color: var(--navy); margin: 0; }
.chat-header p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; background: linear-gradient(180deg, #fbfdff, #fff 180px); }
.messages-inner { max-width: 900px; height: 100%; margin: 0 auto; padding: 28px 28px 40px; }
.welcome { display: flex; flex-direction: column; justify-content: center; min-height: 100%; padding: 24px 0; }
.welcome-mark { width: 56px; height: 56px; margin-bottom: 22px; border-radius: 16px; font-size: 28px; box-shadow: 0 13px 30px rgba(22,101,216,.16); }
.welcome h2 { font-size: clamp(26px, 4vw, 36px); margin: 0 0 12px; color: var(--navy); }
.welcome p { margin: 0; color: var(--muted); font-size: 18px; line-height: 1.8; }
.message { margin: 0 0 25px; }
.message-label { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; color: #52677c; font-size: 14px; font-weight: 700; }
.mini-avatar { height: 26px; width: 26px; border-radius: 8px; font-size: 14px; }
.user .message-label { justify-content: flex-end; }
.user-bubble { max-width: 85%; width: fit-content; margin-left: auto; padding: 12px 17px; color: #fff; background: #1d5faa; border-radius: 16px 16px 4px 16px; font-size: 18px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.assistant-card { border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 7px 22px rgba(30,60,90,.04); overflow: hidden; }
.assistant-content { padding: 22px 24px; font-size: 18px; line-height: 1.9; overflow-wrap: anywhere; }
.assistant-content p { margin: 0 0 12px; white-space: pre-wrap; }
.assistant-content p:last-child { margin-bottom: 0; }
.assistant-content h2, .assistant-content h3 { color: var(--navy); line-height: 1.4; margin: 22px 0 10px; }
.assistant-content h2 { font-size: 23px; }
.assistant-content h3 { font-size: 20px; }
.assistant-content > :first-child { margin-top: 0; }
.assistant-content h2:first-child + p { padding: 14px 17px; border-left: 3px solid #357bbd; border-radius: 0 9px 9px 0; background: #f1f6fc; }
.assistant-content ul, .assistant-content ol { padding-left: 26px; margin: 10px 0 16px; }
.assistant-content li { margin: 5px 0; }
.assistant-content strong { color: #173d61; }
.assistant-content a { color: var(--blue-dark); text-decoration: none; border-bottom: 1px dashed currentColor; }
.sources { border-top: 1px solid var(--line); padding: 16px 24px; background: #f8fafc; }
.sources summary { cursor: pointer; color: #42617e; font-size: 15px; font-weight: 700; }
.source { padding: 14px 0 4px; font-size: 15px; line-height: 1.7; scroll-margin-top: 16px; }
.source a { display: block; color: var(--blue-dark); font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.source a:hover { text-decoration: underline; }
.source p { color: var(--muted); margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer-wrap { flex-shrink: 0; padding: 12px 24px 16px; border-top: 1px solid var(--line); background: #fff; }
.composer { max-width: 844px; margin: auto; }
.status { min-height: 22px; margin: 0 4px 9px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.status.error { color: #a23540; }
.composer-box { display: flex; align-items: flex-end; gap: 12px; padding: 12px 12px 12px 17px; border: 1px solid #cfdbe7; border-radius: 15px; background: #fff; box-shadow: 0 8px 24px rgba(28,55,83,.06); }
.composer-box:focus-within { border-color: #75a9eb; box-shadow: 0 0 0 3px rgba(22,101,216,.1); }
textarea { flex: 1; width: 0; min-height: 34px; max-height: 150px; border: 0; outline: none; padding: 4px 0; background: transparent; color: var(--text); resize: none; font-size: 18px; line-height: 1.5; }
textarea::placeholder { color: #8292a4; }
textarea:disabled { opacity: .65; }
#sendButton { flex-shrink: 0; min-height: 42px; border: 0; border-radius: 10px; padding: 8px 17px; background: var(--blue); color: #fff; font-size: 16px; font-weight: 700; }
#sendButton:hover { background: var(--blue-dark); }
#sendButton.stop { background: #a9404b; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #75a9eb; outline-offset: 3px; }
.composer-note { margin: 10px 4px 0; color: #7a8b9c; font-size: 12px; line-height: 1.6; text-align: center; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.loading::before { content: ""; width: 16px; height: 16px; border: 2px solid #dce5ef; border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation: none; } }
@media (max-width: 600px) {
  .chat { width: 100%; height: 100vh; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .chat-header { padding: 16px 18px; }
  h1 { font-size: 18px; }
  .chat-header p { font-size: 12px; }
  .messages-inner { padding: 24px 18px 32px; }
  .welcome p { font-size: 16px; }
  .assistant-content { padding: 18px; font-size: 17px; }
  .user-bubble { max-width: 94%; font-size: 17px; }
  .sources { padding: 14px 18px; }
  .composer-wrap { padding: 10px 14px max(14px, env(safe-area-inset-bottom)); }
  .status { font-size: 12px; }
  .composer-note { font-size: 11px; }
}
