/* 知识库手机入口 - 手机优先，深色跟随系统 */
:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --text2: #6b7280;
  --primary: #1a56db;
  --primary-press: #1543ad;
  --border: #e5e7eb;
  --ok: #15803d;
  --err: #dc2626;
  --hm0: #ebedf0;
  --hm1: #9be9a8;
  --hm2: #40c463;
  --hm3: #30a14e;
  --hm4: #216e39;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --card: #1a1f2b;
    --text: #e8eaf0;
    --text2: #9aa3b2;
    --primary: #3b6fe0;
    --primary-press: #2f5cc0;
    --border: #2a3140;
    --ok: #4ade80;
    --err: #f87171;
    --hm0: #242b38;
    --hm1: #0e4429;
    --hm2: #006d32;
    --hm3: #26a641;
    --hm4: #39d353;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
#login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 28px;
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  background: var(--primary); color: #fff;
  border-radius: 16px; font-size: 32px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 13px 14px; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.error-text { color: var(--err); font-size: 13px; margin-top: 12px; }

/* ---------- 通用按钮 ---------- */
.btn-primary {
  width: 100%; padding: 13px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-primary:active { background: var(--primary-press); }
.btn-primary:disabled { opacity: .55; }
.btn-inline { width: auto; padding: 0 18px; flex-shrink: 0; height: 46px; }
.btn-ghost {
  width: 100%; margin-top: 24px; padding: 12px;
  background: transparent; color: var(--text2);
  border: 1px solid var(--border); border-radius: 10px; font-size: 14px;
}

/* ---------- 主布局 ---------- */
#main {
  max-width: 640px; margin: 0 auto;
  padding: 20px 16px calc(76px + env(safe-area-inset-bottom));
}
.page-title { font-size: 20px; margin-bottom: 4px; }
.page-hint { color: var(--text2); font-size: 13px; margin-bottom: 14px; }
.section-title { font-size: 16px; margin: 22px 0 10px; }
.status-text { font-size: 13px; margin-top: 12px; color: var(--text2); }
.status-text.ok { color: var(--ok); }
.status-text.err { color: var(--err); }

/* ---------- 收藏 ---------- */
#save-input {
  width: 100%; padding: 14px; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text);
  font-size: 16px; font-family: inherit; line-height: 1.6;
  resize: vertical;
}
#save-input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- 兴趣百科入口 ---------- */
.moc-entry {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 18px; padding: 13px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-size: 15px; font-weight: 600; text-decoration: none;
}
.moc-entry:active { opacity: .8; }
.moc-entry .moc-icon { font-size: 18px; }

/* ---------- 搜索 ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 4px; }
.search-bar input {
  flex: 1; padding: 0 14px; height: 46px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 16px;
  -webkit-appearance: none;
}
.search-bar input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- 卡片列表 ---------- */
.card-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.bm-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
  display: block; text-decoration: none; color: inherit;
}
.bm-card:active { opacity: .8; }
.bm-title { font-size: 15px; font-weight: 600; line-height: 1.4; margin-bottom: 6px; }
.bm-summary {
  font-size: 13px; color: var(--text2); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; margin-bottom: 8px;
}
.bm-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--text2); }
.bm-tag {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 9px; font-size: 11px;
}
.bm-url { word-break: break-all; }

/* ---------- AI 问答 ---------- */
.chat-box {
  min-height: 280px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-empty { color: var(--text2); font-size: 13px; text-align: center; padding: 40px 20px; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.ai.thinking { color: var(--text2); }
.msg .sources { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 12px; color: var(--text2); }
.msg .sources div { margin-top: 4px; }
.msg .sources a { color: var(--primary); text-decoration: none; word-break: break-all; }
.chat-input-bar { display: flex; gap: 8px; position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); }
.chat-input-bar input {
  flex: 1; padding: 0 14px; height: 46px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 16px;
}
.chat-input-bar input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- 热力图 ---------- */
.heatmap-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
}
.heatmap-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.heatmap-title { font-size: 14px; font-weight: 600; }
.heatmap-total { font-size: 12px; color: var(--text2); }
.heatmap { overflow-x: auto; }
.heatmap svg { display: block; }
.heatmap-legend {
  display: flex; align-items: center; gap: 4px;
  justify-content: flex-end; margin-top: 8px;
  font-size: 11px; color: var(--text2);
}
.heatmap-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.heatmap-legend .lv0 { background: var(--hm0); }
.heatmap-legend .lv1 { background: var(--hm1); }
.heatmap-legend .lv2 { background: var(--hm2); }
.heatmap-legend .lv3 { background: var(--hm3); }
.heatmap-legend .lv4 { background: var(--hm4); }
.hmc.lv0 { fill: var(--hm0); }
.hmc.lv1 { fill: var(--hm1); }
.hmc.lv2 { fill: var(--hm2); }
.hmc.lv3 { fill: var(--hm3); }
.hmc.lv4 { fill: var(--hm4); }
.heatmap svg { color: var(--text2); }

/* ---------- 详情层 ---------- */
.detail-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.detail-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.detail-title { font-size: 17px; font-weight: 700; line-height: 1.5; }
.detail-meta { font-size: 12px; color: var(--text2); margin-top: 6px; }
.detail-body {
  flex: 1; overflow-y: auto;
  padding: 18px;
  font-size: 16px; line-height: 1.9;
  white-space: pre-wrap; word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.detail-bar {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
}
.detail-bar .detail-link { height: 44px; display: flex; align-items: center; text-decoration: none; }
.detail-bar .detail-close { flex: 1; margin-top: 0; height: 44px; }
.bm-hasn {
  background: var(--primary); color: #fff;
  border-radius: 4px; padding: 1px 6px; font-size: 10px;
}

/* ---------- 底部导航 ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab-item {
  flex: 1; padding: 8px 0 6px;
  background: none; border: none;
  color: var(--text2); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
}
.tab-item .tab-icon { font-size: 20px; line-height: 1.2; }
.tab-item.active { color: var(--primary); font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px;
  transform: translateX(-50%);
  background: rgba(20, 24, 34, .92); color: #fff;
  padding: 11px 20px; border-radius: 24px;
  font-size: 14px; z-index: 100;
  max-width: 84vw; text-align: center;
}
