/* ==========================================================================
   WeKnora Mobile —— 手机优先样式
   设计原则：
   1. 一切用 dvh/svh，不用 100vh —— iOS 地址栏收放会让 100vh 抖动，这是最常见的坑
   2. 安全区全用 env(safe-area-inset-*) —— 刘海屏和底部小黑条不遮挡内容
   3. 输入框吸底 + 键盘弹起不遮挡（用 visualViewport 配合）
   4. 字号不小于 16px —— 小于这个 iOS Safari 会自动放大页面
   5. 横向零溢出：所有容器 min-width:0，长文强制换行
   ========================================================================== */

:root {
  --green: #0d3b2a;
  --green-2: #159c6e;
  --green-3: #07c05f;

  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #f0f1f2;
  --text: #14181b;
  --text-2: #5b6470;
  --text-3: #8b95a1;
  --border: #e3e6e9;
  --accent: var(--green-2);

  --bubble-user: #0d3b2a;
  --bubble-user-text: #ffffff;
  --bubble-ai: #ffffff;

  --tabbar-h: 54px;
  --topbar-h: 50px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 4px 14px rgba(16, 24, 32, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1113;
    --surface: #181c1f;
    --surface-2: #212629;
    --text: #e8ecef;
    --text-2: #9aa5b1;
    --text-3: #6b7580;
    --border: #272d32;
    --bubble-ai: #1c2126;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 必须放在所有 display 声明之前生效：
   display:grid/flex 会覆盖 [hidden] 的默认 display:none，导致「隐藏」失效 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
               "Helvetica Neue", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  /* 关键：用 dvh 而非 100vh，规避 iOS 地址栏导致的底部截断 */
  height: 100dvh;
  max-height: 100dvh;
}

/* ── 顶栏 ─────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  display: flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-title { flex: 1; min-width: 0; padding-left: 6px; }
.topbar-title h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: -2px;
}

.topbar-back, .topbar-act {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.topbar-back:active, .topbar-act:active { background: var(--surface-2); }

/* ── 屏幕容器 ─────────────────────────────────────── */
.screens { flex: 1; min-height: 0; position: relative; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-width: 0;
}
.screen.is-active { display: flex; }

/* 底部预留 tabbar 高度 + 安全区 */
.page-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px calc(14px + var(--safe-r))
           calc(var(--tabbar-h) + var(--safe-b) + 22px)
           calc(14px + var(--safe-l));
}

/* ── 问答页 ───────────────────────────────────────── */
.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.chat-inner {
  padding: 16px calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l));
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.empty {
  margin: auto;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-2);
  max-width: 420px;
}
.empty-logo {
  width: 60px; height: 60px;
  margin: 0 auto 16px;
  border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--green), var(--green-2));
  color: #fff;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.03em;
  box-shadow: 0 8px 22px rgba(13, 59, 42, .26);
}
.empty h2 { margin: 0 0 8px; font-size: 20px; color: var(--text); font-weight: 650; }
.empty p { margin: 0 0 22px; font-size: 14px; color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
}
.chip:active { background: var(--surface-2); transform: scale(.97); }

/* 消息气泡 */
.msg { display: flex; gap: 9px; min-width: 0; }
.msg-avatar {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12.5px;
  font-weight: 700;
  margin-top: 2px;
}
.msg-user .msg-avatar { background: var(--surface-2); color: var(--text-2); }
.msg-ai .msg-avatar { background: linear-gradient(150deg, var(--green), var(--green-2)); color: #fff; }

.msg-body { flex: 1; min-width: 0; }

.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 15.5px;
  line-height: 1.68;
  overflow-wrap: break-word;
  word-break: break-word;      /* 长串英文/URL 不撑破容器 */
  min-width: 0;
}
.msg-user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-top-right-radius: 5px;
}
.msg-ai .bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-top-left-radius: 5px;
  box-shadow: var(--shadow);
}

.bubble.error { color: #c0392b; border-color: rgba(192,57,43,.3); }
@media (prefers-color-scheme: dark) { .bubble.error { color: #ff8a7a; } }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.3s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity:.25; transform: translateY(0); } 30% { opacity:1; transform: translateY(-3px); } }

/* Markdown 渲染 */
.md-p { margin: 0 0 9px; }
.md-p:last-child { margin-bottom: 0; }
.md-h { margin: 14px 0 7px; font-weight: 650; line-height: 1.35; }
.md-h1 { font-size: 18px; } .md-h2 { font-size: 16.5px; } .md-h3 { font-size: 15.5px; }
.md-ul, .md-ol { margin: 7px 0; padding-left: 21px; }
.md-ul li, .md-ol li { margin: 3px 0; }
.md-quote {
  margin: 8px 0; padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--text-2);
  font-size: 14.5px;
}
.md-hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md-pre {
  margin: 9px 0;
  padding: 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 13px;
  line-height: 1.55;
}
.md-pre code { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; white-space: pre; }
.md-ic {
  padding: 2px 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg-user .md-ic { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.2); color: inherit; }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg-user .bubble a { color: #a8e6c8; }
.md-img { max-width: 100%; height: auto; border-radius: 9px; margin: 6px 0; display: block; }

/* 输入区 */
.composer {
  flex: 0 0 auto;
  padding: 8px calc(12px + var(--safe-r))
           calc(var(--safe-b) + 8px)
           calc(12px + var(--safe-l));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  transition: padding-bottom .18s ease;
}
.composer-kb {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; margin-bottom: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }

#input {
  flex: 1;
  min-width: 0;                 /* 关键：允许 flex 子项收缩，防溢出 */
  max-height: 132px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 21px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;              /* <16px 会触发 iOS 自动放大 */
  line-height: 1.45;
  resize: none;
  outline: none;
}
#input:focus { border-color: var(--accent); }

.send-btn, .stop-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bubble-user);
  color: #fff;
  cursor: pointer;
  transition: opacity .16s, transform .12s;
}
.send-btn:disabled { opacity: .45; background: var(--text-3); }
.send-btn:not(:disabled):active, .stop-btn:active { transform: scale(.9); }
.stop-btn { background: var(--text-2); }

/* ── 知识库卡片 ───────────────────────────────────── */
.kb-list { display: flex; flex-direction: column; gap: 11px; }

.kb-card {
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  min-width: 0;
}
.kb-card:active { transform: scale(.985); background: var(--surface-2); }
.kb-name {
  font-size: 16px; font-weight: 620;
  margin-bottom: 5px;
  overflow-wrap: break-word;
}
.kb-desc {
  font-size: 13.5px; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word;
}
.kb-meta {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 7px;
  font-size: 11.5px; color: var(--text-3);
}
.kb-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
}
.kb-badge.on { background: rgba(21,156,110,.14); color: var(--green-2); }

/* ── 文档列表 ─────────────────────────────────────── */
.files-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 13px; flex-wrap: wrap;
}
.files-title { font-size: 17px; font-weight: 650; }
.files-count { font-size: 12.5px; color: var(--text-3); }

.file-list { display: flex; flex-direction: column; gap: 9px; }
.file-item {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  min-width: 0;
}
.file-icon {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--text-2);
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 14.5px; font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.file-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.dot-done { background: var(--green-3); }
.dot-proc { background: #f5a623; }
.dot-err  { background: #e74c3c; }
.dot-unk  { background: var(--text-3); }

/* ── 我的 ─────────────────────────────────────────── */
.me-card {
  display: flex; align-items: center; gap: 13px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.avatar {
  width: 46px; height: 46px;
  border-radius: 15px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--green), var(--green-2));
  color: #fff; font-size: 19px; font-weight: 700;
}
.me-name { font-size: 16.5px; font-weight: 620; }
.me-mail { font-size: 13px; color: var(--text-3); }

.me-stats { display: flex; gap: 9px; margin-bottom: 12px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 100px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}
.stat-num { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

.me-tip {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 12px;
  font-size: 13.5px;
}
.me-tip strong { display: block; margin-bottom: 6px; font-size: 14.5px; }
.me-tip p { margin: 0; color: var(--text-2); line-height: 1.65; }

.me-actions { display: flex; flex-direction: column; gap: 9px; }
.me-btn {
  display: block;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  font-size: 14.5px; font-weight: 550;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.me-btn:active { background: var(--surface-2); }
.me-ver { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 18px; }

/* ── 底部 tabbar ──────────────────────────────────── */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  z-index: 20;
}
.tab {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  color: var(--text-3);
  cursor: pointer;
  padding: 0;
}
.tab span { font-size: 10.5px; letter-spacing: .01em; }
.tab.is-active { color: var(--accent); }
.tab:active { opacity: .6; }

/* ── 详情抽屉 ─────────────────────────────────────── */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.sheet-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.42);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  animation: slideUp .26s cubic-bezier(.2,.8,.3,1);
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 10px 8px;
  border-bottom: 1px solid var(--border);
}
.sheet-title {
  flex: 1; min-width: 0;
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.sheet-close, .sheet-spacer { flex: 0 0 auto; width: 38px; height: 38px; }
.sheet-close {
  border: 0; background: transparent; color: var(--text);
  display: grid; place-items: center; border-radius: 10px; cursor: pointer;
}
.sheet-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-b));
}

/* ── 骨架屏 ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 10px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── 知识库选择器（问答页顶部） ─────────────────── */
.composer-kb {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; margin-bottom: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  max-width: 100%;
  cursor: pointer;
  user-select: none;
}
.composer-kb:active { background: var(--border); }
.composer-kb.is-set { background: rgba(21,156,110,.13); color: var(--green-2); }
.composer-kb span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 62vw;
}
.kb-caret { flex: 0 0 auto; opacity: .6; }

.pick-hint {
  font-size: 13px; color: var(--text-2);
  line-height: 1.6; margin-bottom: 14px;
}
.pick-list { display: flex; flex-direction: column; gap: 9px; }
.pick-item {
  display: flex; align-items: center; gap: 11px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
}
.pick-item:active { background: var(--surface-2); }
.pick-item.is-on { border-color: var(--accent); background: rgba(21,156,110,.07); }
.pick-radio {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
}
.pick-item.is-on .pick-radio { border-color: var(--accent); }
.pick-item.is-on .pick-radio::after {
  content: ''; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent);
}
.pick-name { font-size: 15px; font-weight: 570; }
.pick-desc {
  font-size: 12px; color: var(--text-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 表格：容器横向滚动，绝不撑破页面宽度 */
.md-tablewrap {
  margin: 10px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
  font-size: 13.5px;
}
.md-table th, .md-table td {
  padding: 8px 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.md-table th {
  background: var(--surface-2);
  font-weight: 620;
  color: var(--text);
  position: sticky;
  left: 0;
}
.md-table td { color: var(--text-2); }
.md-table tr:last-child td { border-bottom: 0; }

/* 后端引用标签还原出的来源角标 */
.kb-ref {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 5px;
  background: rgba(21,156,110,.13);
  color: var(--green-2);
  font-size: 11.5px;
  font-weight: 550;
  white-space: nowrap;
  vertical-align: baseline;
}
.msg-user .kb-ref { background: rgba(255,255,255,.2); color: #fff; }

/* ── 引用来源 ───────────────────────────────────── */
.refs { margin-top: 11px; border-top: 1px solid var(--border); padding-top: 9px; }
.refs-head {
  font-size: 11.5px; color: var(--text-3);
  margin-bottom: 7px; display: flex; align-items: center; gap: 5px;
}
.refs-list { display: flex; flex-direction: column; gap: 6px; }
.ref-item {
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 9px;
  border-left: 2.5px solid var(--accent);
  cursor: pointer;
}
.ref-item:active { background: var(--border); }
.ref-title {
  font-size: 12.5px; font-weight: 560;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.ref-score {
  font-size: 10.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums; flex: 0 0 auto;
}
.ref-text {
  font-size: 11.5px; color: var(--text-2);
  margin-top: 3px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 检索中提示 */
.tooling {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-3);
  margin-bottom: 6px;
}
.tooling i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}

/* ── 添加资料按钮条 ─────────────────────────────── */
.add-bar { display: flex; gap: 9px; margin-bottom: 13px; }
.add-btn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 8px;
  border: 1px dashed var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  font-family: inherit;
}
.add-btn:active { background: var(--surface-2); transform: scale(.985); }
.add-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.field-label {
  display: block;
  font-size: 12.5px; color: var(--text-2);
  margin-bottom: 6px;
}
.field-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  /* 16px 以下 iOS 会自动缩放页面 */
  font-size: 16px;
  outline: none;
  margin-bottom: 12px;
}
.field-input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 11px;
  background: var(--bubble-user);
  color: #fff;
  font-size: 15px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary:disabled { opacity: .5; }
.btn-primary:active:not(:disabled) { transform: scale(.99); }

.url-target {
  font-size: 12.5px; color: var(--text-2);
  padding: 9px 12px;
  background: var(--surface-2);
  border-radius: 9px;
  margin-bottom: 14px;
}
.url-hint {
  font-size: 12px; color: var(--text-3);
  line-height: 1.6; margin-top: 14px;
}

.sheet-pick { max-height: 80dvh; }

/* 上传进度 */
.upload-bar {
  height: 3px; border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden; margin-top: 8px;
}
.upload-bar i {
  display: block; height: 100%;
  background: var(--accent);
  transition: width .2s;
}

.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-3);
  font-size: 14px;
}

/* 扫描件 / 无文字文档的提示卡 */
.nofile {
  text-align: center;
  padding: 26px 18px 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.nofile-icon { font-size: 34px; line-height: 1; margin-bottom: 10px; }
.nofile-title {
  font-size: 15.5px; font-weight: 620; margin-bottom: 8px;
}
.nofile-desc {
  font-size: 13px; color: var(--text-2);
  line-height: 1.65; margin-bottom: 16px;
}
.nofile-btn {
  display: inline-block;
  padding: 11px 20px;
  border-radius: 10px;
  background: var(--bubble-user);
  color: #fff;
  font-size: 14.5px; font-weight: 600;
  text-decoration: none;
}
.nofile-btn:active { transform: scale(.98); opacity: .92; }
.nofile-hint { font-size: 12px; color: var(--text-3); margin-top: 9px; }

/* 内嵌 PDF：手机上是固定高度的滚动区，否则会撑破弹层 */
.pdf-embed {
  margin: 4px 0 14px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.pdf-frame {
  display: block;
  width: 100%;
  height: 62dvh;
  border: 0;
  background: #f3f4f6;
}
.pdf-fallback {
  padding: 26px 16px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-2);
}
.pdf-fallback p { margin-bottom: 12px; }

.nofile-btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  font-weight: 550;
  padding: 10px 18px;
  font-size: 13.5px;
}
.nofile-btn-ghost:active { background: var(--surface-2); }

/* 纯图片文档 */
.img-view {
  display: block;
  width: 100%;
  border-radius: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

/* 有引用但没正文时的提示 */
.answer-missing {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(217,119,6,.09);
  border-left: 2.5px solid #d97706;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
}

/* ── 文档阅读器 ─────────────────────────────────── */
.sheet-doc { max-height: 94dvh; }

.doc-meta {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.doc-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.doc-meta-row:last-child { border-bottom: 0; }
.doc-meta-k { color: var(--text-3); font-size: 12.5px; flex: 0 0 auto; }
.doc-meta-v {
  font-size: 13px; text-align: right;
  overflow-wrap: break-word; min-width: 0;
}

.doc-content {
  font-size: 15.5px;
  line-height: 1.72;
  overflow-wrap: break-word;
  word-break: break-word;
}
.doc-content .md-h1 { font-size: 21px; margin-top: 4px; }
.doc-content .md-h2 { font-size: 18px; }
.doc-content .md-h3 { font-size: 16.5px; }

.doc-loading { padding: 26px; text-align: center; color: var(--text-3); font-size: 13.5px; }
.doc-truncated {
  margin-top: 16px; padding: 9px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-3); font-size: 12.5px;
  text-align: center;
}

/* Obsidian 式双链 */
.wikilink {
  color: var(--accent) !important;
  text-decoration: none !important;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(21,156,110,.1);
  font-size: .95em;
}
.wikilink:active { background: rgba(21,156,110,.24); }

/* 标签 */
.md-tag {
  color: var(--green-2);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: .88em;
  font-weight: 550;
}

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px);
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20,24,27,.92);
  color: #fff;
  font-size: 13.5px;
  z-index: 90;
  max-width: 84vw;
  text-align: center;
  animation: toastIn .2s ease;
  pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* 小屏微调 */
@media (max-width: 360px) {
  .bubble { font-size: 15px; padding: 10px 12px; }
  .empty h2 { font-size: 18px; }
}

/* 键盘弹起时收紧输入区（配合 JS 设置的 --kb-inset） */
.composer.has-kb { padding-bottom: 8px; }