/* ==========================================================
   掌上知识库 - 档案图书馆风格
   米纸底 / 墨绿 / 琥珀 主色，衬线标题
   ========================================================== */

:root {
  --paper: #f3ede2;
  --paper-deep: #eae2d2;
  --ink: #22312b;
  --ink-soft: #4c5c54;
  --ink-faint: #7d8a83;
  --accent: #b7791f;
  --accent-deep: #945f12;
  --accent-soft: #f0e0ba;
  --card: #fffdf8;
  --line: #ddd2bc;
  --danger: #b3402f;
  --ok: #3c7a4f;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 46, 20, 0.08);
  --font-serif: "Songti SC", "STSong", "SimSun", Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 12% 8%, rgba(183, 121, 31, 0.06), transparent 38%),
    radial-gradient(circle at 88% 92%, rgba(34, 49, 43, 0.05), transparent 42%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: 86px;
  -webkit-font-smoothing: antialiased;
}

/* 桌面端居中容器感 */
@media (min-width: 640px) {
  body { background-position: center; }
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(160deg, #2a3d35, var(--ink));
  color: #f4ecd9;
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 2px 12px rgba(34, 49, 43, 0.25);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fffdf8;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  border-radius: 10px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}
.brand-title { font-family: var(--font-serif); font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 11px; opacity: 0.72; margin-top: 2px; }
.top-add {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #f4ecd9;
  background: rgba(255,255,255,0.08);
  transition: background 0.2s;
}
.top-add:active { background: rgba(255,255,255,0.2); }

/* ---------------- 视图 ---------------- */
.view { display: none; padding: 16px; max-width: 720px; margin: 0 auto; }
.view.active { display: block; animation: fadeUp 0.28s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 搜索区 ---------------- */
.search-area { padding-top: 6px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(183,121,31,0.15);
}
.search-ico { color: var(--ink-faint); flex: none; }
#search-input {
  flex: 1; min-width: 0;
  border: none; outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink);
  padding: 9px 0;
}
#search-input::placeholder { color: var(--ink-faint); }
.search-clear {
  font-size: 20px; color: var(--ink-faint);
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
}
.search-clear:active { background: var(--paper-deep); }
.search-btn {
  background: var(--accent);
  color: #fffdf8;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 11px;
  flex: none;
  transition: background 0.2s, transform 0.05s;
}
.search-btn:active { background: var(--accent-deep); transform: scale(0.97); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  font-size: 13px;
  color: var(--ink-soft);
  background: rgba(255, 253, 248, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 15px;
  transition: all 0.18s;
}
.chip:active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }

.ai-banner {
  margin-top: 12px;
  background: linear-gradient(135deg, #2a3d35, #31493f);
  color: #f4ecd9;
  border-radius: 14px;
  padding: 13px 15px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.ai-banner .ai-ico { flex: none; color: var(--accent-soft); }
.ai-banner .ai-btn {
  margin-left: auto; flex: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 9px;
  font-weight: 600;
}

/* ---------------- 区块标题 ---------------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 22px 2px 12px;
}
.section-head h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.5px;
}
.section-count { font-size: 12.5px; color: var(--ink-faint); }

/* ---------------- 文档卡片 ---------------- */
.doc-cards { display: flex; flex-direction: column; gap: 11px; }
.doc-card {
  display: flex; align-items: center; gap: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.2s;
}
.doc-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--kind-color, var(--ink-faint));
}
.doc-card:active { transform: scale(0.985); box-shadow: 0 1px 6px rgba(60,46,20,0.1); }

.doc-kind {
  flex: none;
  width: 44px; height: 52px;
  display: grid; place-items: center;
  border-radius: 8px;
  font-size: 11px; font-weight: 700;
  color: #fff;
  background: var(--kind-color, var(--ink-faint));
  letter-spacing: 0.5px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.15);
}
.doc-kind.pdf  { --kind-color: #b3402f; }
.doc-kind.word { --kind-color: #2f5fa8; }
.doc-kind.excel{ --kind-color: #2f7d4a; }
.doc-kind.image{ --kind-color: #8a5aa0; }
.doc-kind.text { --kind-color: #6b6f6a; }
.doc-kind.presentation { --kind-color: #d16a1f; }

.doc-main { flex: 1; min-width: 0; }
.doc-name {
  font-size: 15.5px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-meta {
  font-size: 12px; color: var(--ink-faint); margin-top: 5px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.doc-meta .tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper-deep);
  color: var(--ink-soft);
}
.doc-meta .tag.ocr { background: var(--accent-soft); color: var(--accent-deep); }
.doc-chev { flex: none; color: var(--ink-faint); }

/* 搜索结果卡片 */
.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 11px;
  overflow: hidden;
}
.result-head {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px dashed var(--line);
}
.result-body { padding: 10px 14px 13px; }
.snippet {
  font-size: 13.5px; line-height: 1.65;
  color: var(--ink-soft);
  padding: 8px 11px;
  background: #faf6ec;
  border-left: 3px solid var(--accent-soft);
  border-radius: 6px;
  margin-bottom: 8px;
}
.snippet mark {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
}
.snippet-more {
  font-size: 12.5px; color: var(--accent);
  font-weight: 600;
  padding: 3px 0;
}
.result-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 14px 12px;
  font-size: 12px; color: var(--ink-faint);
}
.result-score { color: var(--accent-deep); }

/* ---------------- 空状态 ---------------- */
.empty { text-align: center; padding: 52px 20px; }
.empty-ico { color: var(--ink-faint); opacity: 0.55; }
.empty-title { font-family: var(--font-serif); font-size: 17px; margin-top: 14px; font-weight: 700; }
.empty-sub { font-size: 13px; color: var(--ink-faint); margin-top: 7px; line-height: 1.6; }
.btn-primary {
  margin-top: 18px;
  background: var(--accent);
  color: #fffdf8;
  font-size: 15px; font-weight: 600;
  padding: 12px 26px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: background 0.2s;
}
.btn-primary:active { background: var(--accent-deep); }

.load-more {
  width: 100%; margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 14px;
}
.load-more:active { background: var(--paper-deep); }

/* ---------------- 上传 ---------------- */
.upload-hero { text-align: center; padding: 18px 4px 4px; }
.upload-title { font-family: var(--font-serif); font-size: 24px; font-weight: 700; letter-spacing: 1px; }
.upload-sub { font-size: 13px; color: var(--ink-soft); margin-top: 8px; line-height: 1.6; }
.upload-drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin-top: 22px;
  padding: 34px 16px;
  border: 2px dashed var(--line);
  border-radius: 18px;
  background: rgba(255,253,248,0.65);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.2s;
}
.upload-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.drop-title { font-size: 16px; font-weight: 600; color: var(--ink); margin-top: 6px; }
.drop-sub { font-size: 12.5px; color: var(--ink-faint); }
.upload-camera {
  margin-top: 13px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: #f4ecd9;
  border-radius: 14px;
  font-size: 15px; font-weight: 600;
  transition: background 0.2s;
}
.upload-camera:active { background: #2a3d35; }


.queue-list { display: flex; flex-direction: column; gap: 10px; }
.queue-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.queue-top { display: flex; align-items: center; gap: 10px; }
.queue-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-status { flex: none; font-size: 12px; color: var(--ink-faint); }
.queue-status.ok { color: var(--ok); font-weight: 600; }
.queue-status.err { color: var(--danger); font-weight: 600; }
.progress {
  margin-top: 9px;
  height: 6px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block; height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #d99b35);
  border-radius: 999px;
  transition: width 0.3s;
}
.queue-info { font-size: 12px; color: var(--ink-faint); margin-top: 7px; }

/* ---------------- 设置 ---------------- */
.settings-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.settings-card h2 { font-family: var(--font-serif); font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.settings-desc { font-size: 13.5px; color: var(--ink-soft); line-height: 1.7; }
.stats-grid { display: flex; gap: 10px; }
.stat {
  flex: 1;
  text-align: center;
  background: #faf6ec;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 6px;
}
.stat-num { font-family: var(--font-serif); font-size: 22px; font-weight: 700; color: var(--accent-deep); }
.stat-label { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.ai-setup { margin-top: 12px; }
.ai-setup summary { font-size: 13.5px; color: var(--accent); font-weight: 600; cursor: pointer; }
.setup-steps { font-size: 13px; color: var(--ink-soft); line-height: 1.8; padding-left: 18px; margin-top: 8px; }
.setup-steps code {
  background: var(--paper-deep);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--accent-deep);
}

/* ---------------- 底部导航 ---------------- */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  z-index: 60;
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px;
  color: var(--ink-faint);
  padding: 6px 16px;
  border-radius: 12px;
  min-width: 56px;
  transition: color 0.18s;
}
.tab.active { color: var(--accent-deep); font-weight: 600; }
.tab:active { background: var(--paper-deep); }
.tab-fab { color: var(--ink); }
.tab-fab .fab-ico {
  width: 52px; height: 44px;
  display: grid; place-items: center;
  margin-top: -24px;
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(183, 121, 31, 0.45);
  transition: background 0.2s, transform 0.1s;
}
.tab-fab.active .fab-ico, .tab-fab:active .fab-ico { background: var(--accent-deep); transform: translateY(1px); }

/* ---------------- 弹层 ---------------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(30, 34, 30, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  width: 100%; max-width: 520px;
  max-height: 82vh;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: slideUp 0.26s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-title {
  font-family: var(--font-serif); font-size: 17px; font-weight: 700;
  max-width: 78%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modal-close {
  font-size: 24px; color: var(--ink-faint);
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.modal-close:active { background: var(--paper-deep); }
.modal-body { padding: 16px 18px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; }
.modal-docinfo { font-size: 12.5px; color: var(--ink-faint); line-height: 1.8; margin-bottom: 12px; }
.modal-file-btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--ink);
  color: #f4ecd9;
  border-radius: 11px;
  font-size: 14px; font-weight: 600;
  margin-bottom: 14px;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}
.modal-file-btn:active { background: #2a3d35; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  z-index: 99;
  background: rgba(34, 49, 43, 0.94);
  color: #f4ecd9;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: fadeUp 0.25s ease;
  max-width: 86%;
  text-align: center;
}
.toast.ok { background: rgba(60, 122, 79, 0.95); }
.toast.err { background: rgba(179, 64, 47, 0.95); }

/* ---------------- 骨架屏 ---------------- */
.skeleton { border-radius: 12px; background: linear-gradient(90deg, var(--paper-deep) 25%, #f7f1e4 50%, var(--paper-deep) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-card { height: 78px; border-radius: var(--radius); }

/* 加载动画 */
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 26px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- AI 问答 ---------------- */
.ai-chat { display: flex; flex-direction: column; }
.ai-input {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
  outline: none;
  font-family: inherit;
  box-sizing: border-box;
}
.ai-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(183,121,31,0.12); }
.ai-send { width: 100%; margin-top: 10px; }
.ai-answer { margin-top: 14px; }
.ai-q { font-size: 13px; color: var(--ink-faint); margin-bottom: 6px; }
.ai-a {
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink);
  background: #faf6ec;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-err { border-left-color: var(--danger); color: var(--danger); }
