/* ── 基础 ─────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --ink: #1F3B5C;          /* 学者深蓝 */
  --ink-light: #2d5385;
  --seal: #9E2B22;         /* 印泥红（全站唯一红色记忆点） */
  --paper: #F7F5F0;        /* 暖纸底 */
  --card: #FFFFFF;
  --accent: #B08D57;       /* 铜金点缀 */
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --bubble-user: #27486f;  /* user 气泡减重，长对话不压眼 */
  --bubble-ai: #FFFFFF;
  /* 字体两层体系：印章「杨」专用字 + 全站宋体（用户定稿） */
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", STSong, SimSun, "宋体", serif;
}
@font-face {
  font-family: SealChar;               /* 印章「杨」子集，1KB；换字体只换此文件 */
  src: url("assets/seal-char.woff2") format("woff2");
  font-display: swap;
}
/* 统一细滚动条 */
* { scrollbar-width: thin; scrollbar-color: #d5cfc0 transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: #d5cfc0; border-radius: 3px; }
*::-webkit-scrollbar-track { background: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--text);
}
.hidden { display: none !important; }

/* ── 落地页 ─────────────────────────────────────────────── */
.landing {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e8e2d5 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #dfe6ef 0%, transparent 55%),
    var(--paper);
}
.landing-card { text-align: center; padding: 40px 28px; max-width: 460px; width: 100%; }
.hero-avatar {
  width: 128px; height: 128px; margin: 0 auto 26px;
  animation: breathe 4.2s ease-in-out infinite;
  filter: drop-shadow(0 12px 28px rgba(31, 59, 92, .28));
}
@keyframes breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-6px) scale(1.02); }
}
.avatar-svg { width: 100%; height: 100%; }
.landing { transition: opacity .22s ease; }
.landing.leaving { opacity: 0; }
.landing h1 {
  font-family: var(--serif);
  font-size: 38px; color: var(--ink); letter-spacing: 4px; margin-bottom: 12px;
  font-weight: 600;
}
.tagline { color: var(--text); font-size: 15px; margin-bottom: 6px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 30px; letter-spacing: 1px; }
.gate { margin-bottom: 14px; }
.gate input {
  width: 240px; padding: 11px 16px; border: 1.5px solid #d8d2c4; border-radius: 10px;
  font-size: 14px; text-align: center; background: var(--card); outline: none;
}
.gate input:focus { border-color: var(--ink-light); }
.enter-btn {
  padding: 12px 52px; font-size: 16px; letter-spacing: 4px; cursor: pointer;
  color: #fff; background: var(--ink); border: none; border-radius: 12px;
  transition: transform .15s, box-shadow .15s;
}
.enter-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(31,59,92,.3); }
.gate-err { color: #b0342b; font-size: 13px; min-height: 20px; margin-top: 10px; }
.disclaimer { color: var(--muted); font-size: 12px; margin-top: 26px; }

/* ── 对话页布局 ─────────────────────────────────────────── */
.chat-view { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 210px; flex-shrink: 0; padding: 26px 18px;
  background: linear-gradient(180deg, #fbfaf7 0%, #f1eee6 100%);
  border-right: 1px solid #e5e0d3;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.side-avatar { position: relative; width: 92px; height: 92px; }
.state-ring {
  position: absolute; inset: -7px; border-radius: 30px;
  border: 2.5px solid transparent; pointer-events: none; transition: border-color .3s;
}
.side-avatar[data-state="thinking"] .state-ring {
  border-color: var(--accent);
  animation: spin-pulse 1.4s ease-in-out infinite;
}
.side-avatar[data-state="answering"] .state-ring {
  border-color: #4a8c5c;
  animation: ring-pulse 1.6s ease-in-out infinite;
}
@keyframes spin-pulse {
  0%, 100% { transform: scale(1); opacity: .55; }
  50%      { transform: scale(1.06); opacity: 1; }
}
@keyframes ring-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,140,92,.35); }
  50%      { box-shadow: 0 0 0 9px rgba(74,140,92,0); }
}
.side-avatar[data-state="thinking"] .avatar-svg { animation: tilt 2.2s ease-in-out infinite; }
@keyframes tilt {
  0%, 100% { transform: rotate(0deg); }
  30% { transform: rotate(-2.5deg); } 70% { transform: rotate(2.5deg); }
}
.side-name { font-family: var(--serif); font-size: 20px; color: var(--ink); font-weight: 600; letter-spacing: 2px; }
.side-name span { display: block; font-size: 11px; color: var(--muted); font-weight: 400; letter-spacing: 3px; margin-top: 2px; text-align: center; }
.side-status { font-size: 12px; color: #4a8c5c; }
.side-btn {
  margin-top: 8px; padding: 8px 22px; font-size: 13px; cursor: pointer;
  color: var(--ink); background: transparent; border: 1.5px solid var(--ink);
  border-radius: 9px; transition: background .15s, color .15s;
}
.side-btn:hover { background: var(--ink); color: #fff; }
/* 会话列表 */
.conv-list {
  width: 100%; margin-top: 12px; overflow-y: auto; max-height: 34vh;
  scrollbar-width: thin;
}
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 9px; margin-bottom: 4px; border-radius: 8px;
  font-size: 12.5px; color: var(--text); cursor: pointer;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.conv-item:hover { background: #fff; border-color: #eee8da; }
.conv-item.active { background: #fff; border-color: var(--accent); }
.conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 10.5px; color: #bab4a5; flex-shrink: 0; }
.conv-x {
  color: #cfc9ba; font-size: 15px; line-height: 1; padding: 1px 4px;
  border-radius: 5px; flex-shrink: 0;
}
.conv-x:hover { color: #b0342b; background: #f7ece9; }

.side-tips { margin-top: 14px; width: 100%; font-size: 12px; color: var(--muted); }
.side-tips .tip {
  margin-top: 8px; padding: 7px 10px; background: #fff; border-radius: 8px;
  cursor: pointer; color: var(--ink-light); border: 1px solid #eee8da;
  transition: border-color .15s;
  user-select: none;
}
.side-tips .tip:hover { border-color: var(--accent); }
.side-tips .tip:active { transform: scale(.97); }
.side-foot { margin-top: auto; font-size: 10.5px; color: #b5b0a3; text-align: center; line-height: 1.8; }

/* ── 消息区 ─────────────────────────────────────────────── */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 30px 6% 16px; scroll-behavior: smooth; }
.msg { display: flex; margin-bottom: 18px; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(76%, 44em); padding: 13px 17px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.85; word-break: break-word;
}
/* AI 消息旁的小印章头像 */
.mini-avatar { width: 28px; height: 28px; flex-shrink: 0; margin-right: 9px; margin-top: 3px; }
.mini-avatar svg { width: 100%; height: 100%; border-radius: 8px; }
.msg.user .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai .bubble {
  background: var(--bubble-ai); border: 1px solid #eae5d8;
  border-bottom-left-radius: 4px; box-shadow: 0 2px 10px rgba(31,59,92,.05);
}
.msg.ai .bubble.err { border-color: #e5b8b3; background: #fdf3f2; color: #8c3a32; }
.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--serif);
  color: var(--ink); margin: 12px 0 6px; line-height: 1.5;
}
.bubble h1 { font-size: 18px; } .bubble h2 { font-size: 16px; } .bubble h3 { font-size: 15px; }
.bubble ul { padding-left: 20px; margin: 6px 0; }
.bubble blockquote {
  margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent);
  background: #faf7f0; color: #6a6353; font-size: 13.5px;
}
.bubble hr { border: none; border-top: 1px solid #e8e2d3; margin: 12px 0; }
.typing { display: inline-flex; gap: 5px; align-items: center; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ink-light);
  animation: blink 1.2s infinite; opacity: .35;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 40% { opacity: 1; } }
.status-line { font-size: 12.5px; color: var(--muted); margin-top: 7px; }

/* 产物卡片 */
.artifact-card {
  margin-top: 12px; border: 1px solid #e2dccb; border-radius: 11px;
  background: #fffdf8; overflow: hidden;
}
.artifact-head {
  display: flex; align-items: center; gap: 9px; padding: 11px 15px;
  cursor: pointer; user-select: none; font-size: 13.5px; color: var(--ink); font-weight: 600;
}
.artifact-head:hover { background: #faf6ec; }
.artifact-head .caret { transition: transform .2s; font-size: 11px; color: var(--muted); }
.artifact-card.open .caret { transform: rotate(90deg); }
.artifact-body {
  display: none; max-height: 420px; overflow-y: auto;
  padding: 4px 18px 14px; border-top: 1px dashed #e8e2d3;
  font-size: 13.5px; line-height: 1.9;
}
.artifact-card.open .artifact-body { display: block; }
.artifact-foot { padding: 9px 15px; border-top: 1px solid #f0ebdd; display: flex; gap: 10px; }
.dl-btn {
  font-size: 12.5px; padding: 6px 15px; cursor: pointer; text-decoration: none;
  color: var(--ink); background: #fff; border: 1px solid var(--ink-light); border-radius: 7px;
}
.dl-btn:hover { background: var(--ink); color: #fff; }

/* ── 输入区 ─────────────────────────────────────────────── */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 6% 22px; background: linear-gradient(0deg, var(--paper) 75%, transparent);
}
.composer textarea {
  flex: 1; resize: none; max-height: 150px; padding: 13px 17px;
  font-size: 14.5px; font-family: inherit; line-height: 1.6;
  border: 1.5px solid #ddd6c5; border-radius: 13px; background: #fff; outline: none;
}
.composer textarea:focus { border-color: var(--ink-light); }
.composer button {
  width: 46px; height: 46px; border-radius: 12px; border: none; cursor: pointer;
  color: #fff; background: var(--ink); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
}
.composer button:hover { transform: scale(1.06); }
.composer button:disabled { background: #b8b3a6; cursor: not-allowed; transform: none; }
.send-spinner {
  display: none; width: 17px; height: 17px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.composer button.loading .send-icon { display: none; }
.composer button.loading .send-spinner { display: block; }

/* ── 移动端 ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  .chat-view { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 10px 14px 8px; border-right: none; border-bottom: 1px solid #e5e0d3;
  }
  .side-avatar { width: 44px; height: 44px; }
  .state-ring { inset: -4px; border-radius: 15px; }
  .side-name { font-size: 15px; }
  .side-name span { display: inline; margin-left: 5px; letter-spacing: 1px; }
  .side-status, .side-tips, .side-foot { display: none; }
  .side-btn { margin-top: 0; margin-left: auto; padding: 6px 14px; }
  /* 会话列表：横向滑动 chips，一行占满侧栏第二行 */
  .conv-list {
    display: flex; flex-direction: row; gap: 6px;
    flex-basis: 100%; max-height: none; margin-top: 2px;
    overflow-x: auto; overflow-y: hidden; padding-bottom: 4px;
  }
  .conv-item { flex: 0 0 auto; max-width: 46vw; margin-bottom: 0; padding: 5px 9px; }
  .conv-time { display: none; }
  .msgs { padding: 18px 4% 10px; }
  .bubble { max-width: 88%; }
  .mini-avatar { width: 24px; height: 24px; margin-right: 6px; }
  .composer { padding: 10px 4% calc(12px + env(safe-area-inset-bottom)); }
  /* iOS Safari：输入框 <16px 聚焦会强制放大页面 */
  .composer textarea { font-size: 16px; }
}

/* ── 批次1 新组件 ───────────────────────────────────────── */

/* 等待行：状态文案 + 取消 */
.status-line { display: flex; align-items: center; gap: 12px; }
.t-cancel {
  border: none; background: transparent; color: var(--muted);
  font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0;
}
.t-cancel:hover { color: var(--seal); }

/* 反馈条 */
.fb-bar { margin-top: 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fb-btn {
  border: 1px solid #e8e2d3; background: #fff; border-radius: 7px;
  padding: 2px 9px; font-size: 13px; cursor: pointer; opacity: .55;
  transition: opacity .12s, border-color .12s;
}
.fb-btn:hover { opacity: 1; border-color: var(--accent); }
.fb-done { font-size: 12px; color: var(--muted); }
.fb-panel {
  flex-basis: 100%; margin-top: 6px; padding: 9px 11px;
  background: #faf7f0; border: 1px solid #eee8da; border-radius: 9px;
  display: flex; flex-wrap: wrap; gap: 8px; font-size: 12.5px; color: var(--text);
}
.fb-panel label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.fb-panel textarea {
  flex-basis: 100%; resize: none; padding: 6px 9px; font-size: 12.5px;
  font-family: inherit; border: 1px solid #ddd6c5; border-radius: 7px; outline: none;
}
.fb-submit {
  border: none; background: var(--ink); color: #fff; border-radius: 7px;
  padding: 4px 16px; font-size: 12.5px; cursor: pointer;
}

/* 错误块与重试 */
.err-text { font-size: 12.5px; color: #a58f8c; margin-top: 6px; }
.err-actions { margin-top: 9px; display: flex; gap: 8px; }
.err-actions .dl-btn { border-color: #c99; color: #8c3a32; }
.err-actions .dl-btn:hover { background: var(--seal); border-color: var(--seal); color: #fff; }

/* 产物卡片补充 */
.artifact-head { font-family: var(--serif); }
.draft-tag {
  margin-left: auto;
  font-size: 10.5px; font-weight: 400; color: var(--seal);
  border: 1px solid #e5c4c0; border-radius: 5px; padding: 1px 6px; flex-shrink: 0;
}
.stripped-note { font-size: 12px; color: var(--muted); }
.artifact-foot .dl-btn { border: 1px solid var(--ink-light); background: #fff; cursor: pointer; font-family: inherit; }

/* 会话列表状态点 */
.unread-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--seal);
  flex-shrink: 0;
}
.conv-busy { color: var(--accent); font-weight: 700; flex-shrink: 0; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #2b2b2b; color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 10px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 99;
  animation: rise .2s ease;
}
.toast-action {
  border: none; background: transparent; color: #ffd28a; font-size: 13px;
  cursor: pointer; padding: 0; text-decoration: underline;
}

/* 动效偏好适配 */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── BYOK 模型配置 ─────────────────────────────────────── */
.llm-box {
  width: 300px; margin: 0 auto 14px; text-align: left;
  display: flex; flex-direction: column; gap: 8px;
}
.llm-title { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 2px; }
.llm-box input {
  width: 100%; padding: 10px 14px; border: 1.5px solid #d8d2c4; border-radius: 10px;
  font-size: 13px; background: var(--card); outline: none; font-family: inherit;
}
.llm-box input:focus { border-color: var(--ink-light); }
.side-llm {
  margin-top: 10px; padding: 6px 14px; font-size: 12px; cursor: pointer;
  color: var(--muted); background: transparent; border: 1px solid #ddd6c5;
  border-radius: 8px; transition: color .15s, border-color .15s;
}
.side-llm:hover { color: var(--ink); border-color: var(--ink-light); }

/* ── BYOK 入口优化：帮助行 / 高级折叠 / 回访快捷 / 按钮转圈 ── */
.llm-help {
  font-size: 11.5px; color: var(--muted); line-height: 1.7; margin-top: -2px;
}
.llm-help a { color: var(--ink-light); }
.llm-adv { margin-top: 2px; }
.llm-adv summary {
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
  padding: 4px 0; list-style-position: inside;
}
.llm-adv summary:hover { color: var(--ink); }
.llm-adv[open] summary { margin-bottom: 8px; }
.llm-adv input { margin-bottom: 8px; }
.llm-adv-hint { font-size: 11px; color: #b5b0a3; line-height: 1.6; }
#llmForm { display: flex; flex-direction: column; gap: 8px; }
#llmForm.hidden { display: none; }
.llm-quick { text-align: center; }
.llm-change { margin-top: 10px; font-size: 12px; }
.llm-change a { color: var(--muted); cursor: pointer; text-decoration: underline; }
.llm-change a:hover { color: var(--ink); }
.enter-btn.loading { pointer-events: none; opacity: .85; }
.enter-btn.loading::after {
  content: ""; display: inline-block; vertical-align: -2px; margin-left: 9px;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
