/* ---------- 基础变量 ---------- */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-elev: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-soft: #4b5563;
  --text-mute: #9ca3af;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-grad: #2563eb;
  --user-bubble: #eef2ff;
  --shadow-sm: none;
  --shadow-md: none;
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #181a20;
    --bg-elev: #1c1f26;
    --border: #2a2e38;
    --border-strong: #3a3f4b;
    --text: #e6e7ea;
    --text-soft: #b8bcc6;
    --text-mute: #7a7f8b;
    --primary: #818cf8;
    --primary-soft: #1f2230;
    --user-bubble: #232633;
    --shadow-sm: none;
    --shadow-md: none;
  }
}

/* ---------- reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--text-soft); text-decoration: none; }
a:hover { color: var(--primary); }
.hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 14px; text-decoration: none; color: inherit; cursor: pointer; }
.brand:hover .brand-name { opacity: 0.85; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary-grad);
}
.brand-name { font-weight: 600; letter-spacing: 0.2px; }
.brand-divider {
  width: 1px; height: 16px; background: var(--border-strong);
}
.brand-sub { color: var(--text-mute); font-size: 13px; }
.topnav { display: flex; gap: 18px; font-size: 13px; }

/* ---------- main ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

/* ---------- welcome ---------- */
.welcome {
  min-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 40px 0;
}
.title {
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.15;
  font-weight: 600;
  margin: 0 0 14px;
  letter-spacing: -0.5px;
}
.title-grad {
  background: var(--primary-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  color: var(--text-mute);
  font-size: 15px;
  margin: 0 0 36px;
}

/* ---------- composer ---------- */
/* (see styles.css for composer styles) */

/* ---------- conversation ---------- */
.conversation {
  padding-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: msgIn 0.25s ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  background: var(--user-bubble);
  padding: 12px 16px;
  border-radius: 16px 16px 4px 16px;
  max-width: 80%;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.avatar-mini {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary-grad);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.4px;
}
.msg-body { flex: 1; min-width: 0; }

/* ---------- thinking stream ---------- */
.thinking-stream {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 13px;
}
.thinking-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  padding: 2px 0;
}
.thinking-step .spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.thinking-step.done .spinner {
  border: 0;
  background: var(--primary);
  width: 12px; height: 12px;
  border-radius: 50%;
  position: relative;
}
.thinking-step.done .spinner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--primary);
  border-radius: 50%;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='white' d='M9 16.2L4.8 12l-1.4 1.4L9 19l11-11-1.4-1.4z'/></svg>") center/10px no-repeat;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='white' d='M9 16.2L4.8 12l-1.4 1.4L9 19l11-11-1.4-1.4z'/></svg>") center/10px no-repeat;
}
.thinking-step .label { font-weight: 500; color: var(--text-soft); }
.thinking-step .detail { color: var(--text-mute); font-size: 12px; }

/* 占位:首条 thinking 事件到达前显示,避免用户感到"按了按钮但屏幕没反应" */
.thinking-placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  font-size: 13px;
  padding: 4px 0;
  animation: fadeIn 0.3s ease-out;
}
.thinking-placeholder .spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.thinking-placeholder .ph-text { color: var(--text-soft); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- answer stream ---------- */
.answer-stream {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}
.answer-stream h1, .answer-stream h2, .answer-stream h3 {
  margin: 18px 0 8px;
  font-weight: 600;
  line-height: 1.3;
}
.answer-stream h1 { font-size: 20px; }
.answer-stream h2 { font-size: 17px; }
.answer-stream h3 { font-size: 15px; color: var(--text-soft); }
.answer-stream p { margin: 0 0 12px; }
.answer-stream ul, .answer-stream ol {
  margin: 0 0 12px;
  padding-left: 22px;
}
.answer-stream li { margin: 4px 0; }
.answer-stream code {
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
}
.answer-stream pre {
  background: var(--bg-soft);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  margin: 0 0 12px;
}
.answer-stream blockquote {
  border-left: 3px solid var(--primary);
  margin: 8px 0;
  padding: 4px 12px;
  background: var(--primary-soft);
  color: var(--text-soft);
  border-radius: 0 6px 6px 0;
}
.answer-stream table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
  font-size: 13px;
}
.answer-stream th, .answer-stream td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.answer-stream th { background: var(--bg-soft); font-weight: 600; }
.answer-stream a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--primary) 40%, transparent);
}
.cursor-blink::after {
  content: "▍";
  color: var(--primary);
  animation: blink 1s steps(2) infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- followups ---------- */
.followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.followup-chip {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  transition: all 0.15s;
}
.followup-chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

/* ---------- sources ---------- */
.sources {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-mute);
}
.sources-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-soft);
}
.sources ul { padding-left: 18px; margin: 0; }
.sources li { margin: 3px 0; line-height: 1.5; }
.sources a { color: var(--text-soft); }
.sources a:hover { color: var(--primary); }

/* ---------- meta line ---------- */
.meta-line {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-mute);
}

/* ---------- bottom composer ---------- */
.bottom-composer {
  position: sticky;
  bottom: 0;
  padding: 12px 0 18px;
  background: var(--bg);
}
.composer-mini {
  padding: 10px 14px;
  border-radius: 22px;
}

/* ---------- error ---------- */
.error-banner {
  background: color-mix(in srgb, #ef4444 12%, var(--bg-soft));
  border: 1px solid color-mix(in srgb, #ef4444 30%, transparent);
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
}

/* ---------- mode toggle ---------- */
.mode-toggle {
  display: flex;
  gap: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 28px;
}
.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: all 0.18s;
  white-space: nowrap;
}
.mode-btn.active {
  background: var(--bg-elev);
  color: var(--primary);
}
.mode-btn:hover:not(.active) {
  color: var(--text-soft);
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}

/* ---------- qa / synthesis panels ---------- */
#qaPanel, #synthesisPanel { width: 100%; }

/* ---------- synthesis ---------- */
.synth-intro {
  margin-bottom: 20px;
  text-align: left;
}
.synth-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.synth-desc {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.composer-synth { padding: 14px 14px 10px; }
.composer-synth textarea { min-height: 52px; max-height: 120px; }

.synth-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.depth-selector, .lang-selector {
  display: flex;
  align-items: center;
  gap: 6px;
}
.depth-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.depth-btns {
  display: flex;
  gap: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.depth-btn {
  padding: 4px 10px;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: all 0.15s;
}
.depth-btn.active {
  background: var(--bg-elev);
  color: var(--primary);
}
.depth-btn:hover:not(.active) { color: var(--text-soft); }

.synth-submit {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 8px 18px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.synth-submit:hover { background: #4338ca; }
.synth-submit:active { transform: scale(0.97); }
.synth-submit:disabled { background: var(--border-strong); cursor: not-allowed; }

/* ---------- synthesis output ---------- */
.synth-output {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 28px;
  animation: msgIn 0.25s ease-out;
}
.synth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex-wrap: wrap;
  gap: 8px;
}
.synth-badge-row { display: flex; align-items: center; gap: 10px; }
.synth-meta-info {
  font-size: 12px;
  color: var(--text-muted);
}
.synth-actions { display: flex; gap: 6px; }
.synth-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--bg-elev);
  transition: all 0.15s;
}
.synth-action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}
.download-btn:hover { color: var(--primary); }
.new-synth-btn:hover { color: var(--text-soft); }

.synth-article {
  padding: 20px 24px 28px;
  font-size: 15px;
  line-height: 1.75;
}
.synth-article h2:first-child { margin-top: 0; }

/* ---------- voice button ---------- */
.voice-btn {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  cursor: pointer;
}
.voice-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}
.voice-btn.recording {
  color: #fff;
  background: #ef4444;
  border-color: #ef4444;
  animation: voicePulse 1s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

/* ---------- file upload ---------- */
.upload-zone {
  width: 100%;
  padding: 20px;
  margin-bottom: 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-soft);
}
.upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.01);
}
.upload-zone-mini {
  padding: 10px 16px;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}
.upload-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.7;
}
.upload-icon-sm {
  font-size: 18px;
}
.upload-text {
  font-size: 14px;
  color: var(--text-soft);
  margin: 0 0 4px;
}
.upload-text-sm {
  font-size: 13px;
  color: var(--text-muted);
}
.upload-link {
  color: var(--primary);
  text-decoration: underline;
}
.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* Uploaded files list */
.uploaded-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 0;
}
.uploaded-files-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0;
  min-height: 0;
}

/* Individual uploaded file item */
.uploaded-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  transition: all 0.15s;
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
.uploaded-file-item:hover {
  border-color: var(--primary);
}
.uploaded-file-item.uploading {
  opacity: 0.85;
}
.uploaded-file-item.ready {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.uploaded-file-item.error {
  border-color: #ef4444;
  background: #fef2f2;
}

.file-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.file-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.file-name {
  font-weight: 500;
  color: var(--text);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size {
  font-size: 11px;
  color: var(--text-muted);
}

.upload-progress {
  flex: 1;
  min-width: 60px;
  max-width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  width: 0;
  transition: width 0.15s ease;
}

.upload-status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.upload-status.ready {
  color: #10b981;
}
.upload-status.error {
  color: #ef4444;
}

.file-remove {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.file-remove:hover {
  background: var(--border);
  color: var(--text);
}

/* Upload button in toolbar */
.upload-btn {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  cursor: pointer;
}
.upload-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  main { padding: 0 14px 40px; }
  .topbar { padding: 10px 16px; }
  .topnav { gap: 10px; font-size: 12px; }
  .brand-sub { display: none; }
  .composer textarea { font-size: 15px; }
  .msg-user .bubble { max-width: 90%; }
}

.cite-link { color: #2563eb; text-decoration: none; font-weight: 500; cursor: pointer; }
.cite-link:hover { color: #1d4ed8; text-decoration: underline; }

/* ---------- PubMed query blocks (NBK25497) ---------- */
.query-blocks-container { margin: 8px 0 4px 28px; display: flex; flex-direction: column; gap: 6px; }
.query-blocks-header {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qbh-icon::before { content: 'F50D'; margin-right: 4px; }
.qbh-syntax-doc { color: var(--primary); text-decoration: none; font-size: 12px; }
.qbh-syntax-doc:hover { text-decoration: underline; }

.query-block {
  background: var(--surface-2, #f9fafb);
  border: 1px solid var(--border-strong, #e5e7eb);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
  transition: border-color 0.18s;
}
.query-block:hover { border-color: var(--primary, #2563eb); }
.query-block.running { border-color: var(--primary, #2563eb); }
.query-block.done { border-color: #10b981; }
.query-block.done .qb-round { color: #10b981; }

.qb-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.qb-head:hover { background: rgba(0,0,0,0.02); }
.qb-round {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  color: var(--primary, #2563eb);
  font-size: 12px;
  min-width: 56px;
}
.qb-count { color: var(--text-muted, #6b7280); font-size: 12px; flex: 1; }
.qb-count b { color: #1f2937; font-weight: 600; }
.qb-toggle { font-size: 12px; color: var(--primary, #2563eb); font-weight: 500; }

.qb-query {
  background: #1f2937;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 10px 14px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: none;
}
.query-block.expanded .qb-query { display: block; }

.qb-pmids {
  padding: 8px 12px;
  max-height: 160px;
  overflow-y: auto;
}
.qb-pmid-list { display: flex; flex-wrap: wrap; gap: 6px; }
.qb-pmid-chip {
  display: inline-block;
  background: #eef2ff;
  color: #1d4ed8;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-decoration: none;
  border: 1px solid #dbeafe;
  transition: background 0.12s;
}
.qb-pmid-chip:hover { background: #dbeafe; }
.qb-empty { font-size: 12px; color: #dc2626; font-style: italic; }
.qb-foot { padding: 6px 12px 10px; border-top: 1px dashed var(--border-strong, #e5e7eb); }
.qb-pubmed-link {
  display: inline-block;
  font-size: 12px;
  color: var(--primary, #2563eb);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--primary, #2563eb);
  border-radius: 6px;
  transition: background 0.12s;
}
.qb-pubmed-link:hover { background: var(--primary, #2563eb); color: #fff; }

.hidden { display: none !important; }

/* spinner for running round */
.query-block.running .qb-round::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--primary, #2563eb);
  border-radius: 50%;
  margin-left: 6px;
  animation: qb-spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes qb-spin { to { transform: rotate(360deg); } }

