* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e7e9ee;
  --text: #1a1d24;
  --muted: #8a909c;
  --accent: #2f6df6;
  --accent-soft: #eaf1ff;
  --user-bubble: #2f6df6;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
}

.app { display: flex; height: calc(var(--vh, 1vh) * 100 - var(--nav-h, 60px) - env(safe-area-inset-bottom)); }

/* 侧边栏 */
.sidebar {
  width: 264px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.logo { width: 38px; height: 38px; display: grid; place-items: center; }
.logo img { width: 100%; height: 100%; display: block; }
.brand-title { font-size: 15px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--muted); }

.new-chat {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 14px;
  transition: .15s;
}
.new-chat:hover { background: var(--accent-soft); border-color: var(--accent); }

/* 历史对话 */
.history-head { font-size: 12px; color: var(--muted); margin: 18px 4px 8px; }
.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 0 -4px; padding: 0 4px; }
.history-empty { font-size: 12px; color: var(--muted); padding: 8px 6px; line-height: 1.5; }
.history-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px;
  font-size: 13px; cursor: pointer; color: #4a4f5a; border: 1px solid transparent;
}
.history-item:hover { background: var(--bg); }
.history-item.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.history-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-del {
  flex-shrink: 0; width: 18px; height: 18px; line-height: 16px; text-align: center;
  border: none; background: transparent; color: var(--muted); cursor: pointer; border-radius: 4px;
  font-size: 15px; opacity: 0;
}
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { background: rgba(0,0,0,.08); color: #e04848; }

/* 主区域 */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; border-bottom: 1px solid var(--border); background: var(--panel);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
}
.greeting { font-size: 15px; font-weight: 600; }
.status { font-size: 12px; color: var(--muted); margin-top: 2px; }
.topbar-left { display: flex; flex-direction: column; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-name { color: #4a4f5a; }
.logout-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px;
  padding: 5px 12px; font-size: 12px; cursor: pointer; color: #4a4f5a; font-family: inherit;
}
.logout-btn:hover { border-color: var(--accent); color: var(--accent); }

.chat { flex: 1; overflow-y: auto; padding: 26px 22px; }
.empty { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.empty-icon { width: 82px; height: 82px; margin: 0 auto; }
.empty-icon img { width: 100%; height: 100%; display: block; }
.empty-title { font-size: 20px; font-weight: 600; margin-top: 10px; }
.empty-sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.suggest { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
.chip {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; cursor: pointer; color: #4a4f5a;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* 消息气泡 */
.msg { max-width: 760px; margin: 0 auto 18px; display: flex; gap: 12px; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 14px; color: #fff;
}
.msg.bot .avatar { background: linear-gradient(135deg, #2f6df6, #5b8cff); }
.avatar img { width: 100%; height: 100%; display: block; }
.msg.user .avatar { background: #5a6270; }
.bubble { padding: 12px 15px; border-radius: 12px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--border); white-space: normal; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; }

/* Markdown 结构化排版 */
.bubble .md-h { margin: 14px 0 6px; line-height: 1.4; font-weight: 600; color: var(--text); font-size: 15px; }
.bubble .md-h:first-child { margin-top: 2px; }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 600; }
.bubble em { color: #4a4f5a; }
.bubble code { background: var(--bg); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-size: 13px; font-family: Consolas, "Courier New", monospace; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; padding-left: 2px; }

/* 引用溯源（文档级卡片 + 可展开的段级明细） */
.cite-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.cite-card.cite-focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,109,246,.12); }
.cite-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  font-size: 12px; color: #4a4f5a; cursor: pointer; flex-wrap: wrap;
}
.cite-head:hover { background: var(--bg); }
.cite-head .idx {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 16px; height: 16px; display: grid; place-items: center; font-size: 10px; flex-shrink: 0;
}
.cite-name { font-weight: 500; color: var(--text); }
.cite-meta { color: var(--muted); }
.cite-toggle { margin-left: auto; color: var(--accent); font-size: 11px; white-space: nowrap; }
.cite-card.open .cite-toggle { color: var(--muted); }
.cite-segs { display: none; border-top: 1px dashed var(--border); padding: 6px 12px 8px; }
.cite-card.open .cite-segs { display: block; }
.cite-seg { padding: 7px 6px; border-radius: 6px; border-bottom: 1px dashed var(--border); }
.cite-seg:last-child { border-bottom: none; }
.cite-seg-head { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.cite-seg-no { color: var(--accent); font-weight: 600; }
.cite-seg-score { margin-left: auto; }
.cite-seg-text { font-size: 12.5px; line-height: 1.65; color: #4a4f5a; white-space: pre-wrap; word-break: break-word; }
.cite-seg.cite-flash {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(47,109,246,.35);
  transition: background .3s;
}
.cite-flash { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); transition: background .3s; }

/* 消息主体占满剩余宽度，保证流式长文打字时不跳动 */
.msg-main { flex: 1; min-width: 0; }

/* ---------- 思考过程（流式展示；完成后自动收起）---------- */
.process:empty { display: none; }
.think {
  margin: 0 0 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); overflow: hidden;
}
.think-head {
  display: flex; align-items: center; gap: 7px; padding: 7px 11px;
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.think-head:hover { color: #4a4f5a; }
.think-title { flex: 1; }
.think-arrow { font-size: 10px; transition: transform .15s; }
.think.open .think-arrow { transform: rotate(180deg); }
.think-body {
  display: none; max-height: 260px; overflow-y: auto;
  padding: 0 12px 10px; font-size: 12.5px; line-height: 1.7;
  color: #6b7280; white-space: pre-wrap; word-break: break-word;
  border-top: 1px dashed var(--border);
}
.think.open .think-body { display: block; padding-top: 8px; }
.think[data-state="done"] { border-color: transparent; background: transparent; margin-bottom: 2px; }
.think[data-state="done"] .think-head { padding: 2px 0; }

/* ---------- 参考资料：整体折叠、样式弱化，默认不占版面 ---------- */
.srcs { max-width: 760px; margin: 0 auto 20px; padding-left: 44px; }
.srcs-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; background: transparent; cursor: pointer; font-family: inherit;
  font-size: 12px; color: var(--muted); padding: 4px 2px;
}
.srcs-toggle:hover { color: var(--accent); }
.srcs-arrow { font-size: 10px; transition: transform .15s; }
.srcs.open .srcs-arrow { transform: rotate(180deg); }
.srcs-body { display: none; flex-direction: column; gap: 6px; margin-top: 6px; }
.srcs.open .srcs-body { display: flex; }

/* 引用卡片内的折叠箭头 */
.cite-toggle { transition: transform .15s; }
.cite-card.open .cite-toggle { transform: rotate(180deg); }

.srcs-tip { max-width: 760px; margin: -6px auto 18px; padding-left: 44px; font-size: 12px; color: #b06a00; }
.bubble .err { color: #c0392b; font-size: 13px; margin-top: 8px; }

/* 回答正文里的 [n] 引用编号：可点击跳转 */
.bubble .cite-ref {
  color: var(--accent); text-decoration: none; cursor: pointer; font-weight: 600;
  padding: 0 2px; border-bottom: 1px solid rgba(47,109,246,.35);
}
.bubble .cite-ref:hover { background: var(--accent-soft); border-radius: 3px; }

/* 输入区 */
.composer {
  border-top: 1px solid var(--border); background: var(--panel);
  padding: 14px 22px; display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
}
.composer-top { width: 100%; display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mode-switch { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.mode-switch .mode {
  border: none; background: transparent; cursor: pointer; font-size: 13px; color: #5a6270;
  padding: 6px 14px; border-radius: 999px; transition: .15s; font-family: inherit;
}
.mode-switch .mode.active { background: var(--accent); color: #fff; box-shadow: 0 1px 4px rgba(47,109,246,.3); }
#input {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 14px; line-height: 1.6; max-height: 140px;
  font-family: inherit; outline: none;
}
#input:focus { border-color: var(--accent); }
.send {
  padding: 11px 22px; border: none; border-radius: 12px; background: var(--accent);
  color: #fff; font-size: 14px; cursor: pointer;
}
.send:disabled { opacity: .5; cursor: not-allowed; }

.loader-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); margin-right: 4px; animation: blink 1.2s infinite;
}
@keyframes blink { 0%,100%{opacity:.2} 50%{opacity:1} }

/* 登录/注册弹窗 */
.auth-overlay {
  position: fixed; inset: 0; background: rgba(20,24,33,.5);
  display: grid; place-items: center; z-index: 50; backdrop-filter: blur(2px);
}
.auth-overlay.hidden { display: none; }
.auth-card {
  width: 340px; background: var(--panel); border-radius: 16px; padding: 30px 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18); text-align: center;
}
.auth-logo { width: 48px; height: 48px; margin: 0 auto 12px; display: grid; place-items: center; }
.auth-logo img { width: 100%; height: 100%; display: block; }
.auth-title { font-size: 18px; font-weight: 600; margin-bottom: 18px; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px;
  cursor: pointer; font-size: 14px; color: #5a6270; font-family: inherit;
}
.auth-tab.active { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); font-weight: 600; }
.auth-input {
  width: 100%; padding: 11px 13px; margin-bottom: 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; outline: none; font-family: inherit;
}
.auth-input:focus { border-color: var(--accent); }
.auth-submit {
  width: 100%; padding: 11px; border: none; border-radius: 10px; background: var(--accent);
  color: #fff; font-size: 15px; cursor: pointer; font-family: inherit;
}
.auth-submit:hover { filter: brightness(1.05); }
.auth-msg { font-size: 12px; min-height: 18px; margin-top: 10px; color: #d23b3b; }
.auth-msg.ok { color: #2a9d4a; }

/* 移动端抽屉相关（桌面默认隐藏菜单按钮） */
.menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px; margin-right: 10px;
  border: none; background: transparent; border-radius: 8px;
  font-size: 22px; line-height: 1; color: var(--text); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.menu-btn:active { background: var(--bg); }
.topbar-titles { display: flex; flex-direction: column; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,33,.45);
  z-index: 55; display: none;
}
.sidebar-backdrop.open { display: block; }

/* 平板：保留紧凑侧栏 */
@media (max-width: 720px) and (min-width: 601px) {
  .sidebar { width: 200px; padding: 16px 12px; }
  .brand-text, .new-chat { display: block; }
  .srcs, .msg, .empty { padding-left: 0; }
}

/* 手机：侧栏改为抽屉，主区占满，输入区避让底部导航 */
@media (max-width: 600px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 84%; max-width: 320px; z-index: 60;
    background: var(--panel); border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .brand-text, .new-chat { display: block; }
  .topbar { height: 52px; padding: 0 12px; }
  .topbar-left { flex-direction: row; align-items: center; }
  .topbar-left .status { display: none; }
  .menu-btn { display: inline-flex; }
  .chat { padding: 16px 12px; }
  .msg { max-width: 100%; }
  .empty { margin: 3vh auto 0; }
  .empty-title { font-size: 18px; }
  .composer { padding: 10px 12px; gap: 8px; }
  .composer-top { margin-bottom: 6px; }
  #input { padding: 11px 12px; font-size: 16px; max-height: 120px; }
  .send { padding: 11px 16px; }
  .srcs, .srcs-tip { padding-left: 0; }
  .suggest { gap: 8px; }
  .chip { padding: 8px 12px; font-size: 13px; }
}

/* ==================== 分享（消息操作栏 / 动作面板 / 海报 / 轻提示） ==================== */
/* 注意：站点底部导航 nav.css 的 z-index 是 99990，所有模态浮层必须高于它，
   否则面板会被导航条压在下面。 */
/* 与 .srcs 同一套对齐规则：左右限宽 760px、左侧缩进 44px（= 头像 32 + 间距 12）对齐气泡主体 */
.msg-actions { max-width: 760px; margin: -2px auto 16px; padding-left: 44px; display: flex; gap: 8px; }
.act-btn {
  display: inline-flex; align-items: center; gap: 6px; font-family: inherit;
  padding: 5px 13px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); color: #6b7280; font-size: 12.5px; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.act-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.act-btn:active { transform: translateY(1px); }
.act-btn svg { display: block; }

/* ---------- 底部动作面板 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 100001; background: rgba(20,24,33,.46);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s; backdrop-filter: blur(2px);
}
.sheet-mask.show { opacity: 1; }
.sheet-panel {
  width: 100%; max-width: 460px; background: var(--panel);
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(14px); transition: transform .22s;
}
.sheet-mask.show .sheet-panel { transform: translateY(0); }
.sheet-title { font-size: 15px; font-weight: 600; text-align: center; }
.sheet-note { font-size: 12px; color: var(--muted); text-align: center; margin: 6px 0 16px; line-height: 1.6; }
.sheet-acts { display: flex; flex-direction: column; gap: 8px; }
.sheet-act {
  display: flex; align-items: center; gap: 12px; width: 100%; font-family: inherit;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); cursor: pointer; text-align: left; transition: .15s;
}
.sheet-act:hover { border-color: var(--accent); background: var(--accent-soft); }
.sheet-act .act-ic { font-size: 20px; line-height: 1; }
.sheet-act .act-tx { display: flex; flex-direction: column; gap: 2px; }
.sheet-act .act-tx b { font-size: 14px; font-weight: 600; color: var(--text); }
.sheet-act .act-tx i { font-style: normal; font-size: 12px; color: var(--muted); }
.sheet-cancel {
  width: 100%; margin-top: 12px; padding: 12px; font-family: inherit; font-size: 14px;
  border: none; border-radius: 12px; background: var(--bg); color: #4a4f5a; cursor: pointer;
}
.sheet-panel.busy { pointer-events: none; opacity: .7; }

/* ---------- 微信内引导：普通网页唤不起分享菜单，只能指向右上角 ---------- */
.wx-guide {
  position: fixed; inset: 0; z-index: 100004; background: rgba(0,0,0,.74);
  color: #fff; opacity: 0; transition: opacity .2s;
}
.wx-guide.show { opacity: 1; }
.wx-arrow { position: absolute; top: 6px; right: 20px; font-size: 48px; line-height: 1; }
.wx-tip { position: absolute; top: 76px; right: 14px; text-align: right; max-width: 78%; }
.wx-tip b { display: block; font-size: 17px; }
.wx-tip span { display: block; font-size: 13.5px; opacity: .85; margin-top: 8px; line-height: 1.7; }

/* ---------- 海报 ---------- */
.poster-mask {
  position: fixed; inset: 0; z-index: 100002; background: rgba(12,16,26,.88);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  opacity: 0; transition: opacity .2s;
}
.poster-mask.show { opacity: 1; }
.poster-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; max-height: 100%; }
.poster-tip { color: rgba(255,255,255,.82); font-size: 12.5px; }
.poster-holder { max-height: 74vh; overflow: auto; border-radius: 14px; }
.poster-loading {
  color: rgba(255,255,255,.72); font-size: 13px; padding: 60px 40px;
  background: rgba(255,255,255,.06); border-radius: 14px;
}
.poster-img { display: block; width: 100%; max-width: 332px; border-radius: 14px; }
.poster-close {
  padding: 8px 26px; border: 1px solid rgba(255,255,255,.32); border-radius: 999px;
  background: transparent; color: #fff; font-size: 13px; font-family: inherit; cursor: pointer;
}

/* ---------- 轻提示 ---------- */
.qa-toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 8px);
  z-index: 100005; max-width: 76vw; padding: 10px 18px; border-radius: 999px;
  background: rgba(20,24,33,.92); color: #fff; font-size: 13px; line-height: 1.5;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.qa-toast.show { opacity: 1; transform: translate(-50%, 0); }
