/* FileBrain 移动 Web — 只读第一期（登录 / 资料工作台 / 笔记阅读） */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1f2328;
  --ink-2: #57606a;
  --ink-3: #8b949e;
  --line: #e4e7eb;
  --brand: #1f6feb;
  --brand-soft: #e8f1fe;
  --danger: #cf222e;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
.app-root { min-height: 100%; padding-bottom: calc(64px + var(--safe-bottom)); }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px calc(32px + var(--safe-bottom));
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 20px;
  max-width: 380px;
  width: 100%;
  margin: 0 auto;
}
.login-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.login-sub { color: var(--ink-3); font-size: 13px; margin: 0 0 22px; }

/* ---------- 通用控件 ---------- */
.field { margin-bottom: 14px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;           /* >=16px 防 iOS 聚焦自动放大 */
  background: var(--card);
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.btn[disabled] { opacity: .55; }
.btn-ghost { background: transparent; color: var(--brand); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

.page-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: calc(12px + var(--safe-top)) 16px 10px;
}
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--ink-3); font-size: 12px; }
.back-row { display: flex; align-items: center; gap: 10px; }
.back-btn {
  border: none; background: none; font-size: 22px; color: var(--brand);
  padding: 0 6px 0 0; cursor: pointer; line-height: 1;
}

.list { padding: 4px 16px 24px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  display: block;
  color: inherit;
  text-decoration: none;
}
.card:active { background: var(--brand-soft); }

/* ---- 卡片统一高度：标题单行 / 摘要固定两行 / 元信息单行，内容长度不影响几何 ---- */
.card .title {
  font-weight: 600; font-size: 15px;
  height: 23px; line-height: 23px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .title .t-inner { display: inline-block; white-space: nowrap; }
.card .meta {
  color: var(--ink-3); font-size: 12px; margin-top: 6px;
  display: flex; gap: 10px; flex-wrap: nowrap; align-items: center;
  white-space: nowrap; overflow: hidden;
  height: 18px; line-height: 18px;
}
.card .preview {
  color: var(--ink-2); font-size: 13px; margin-top: 5px;
  height: 38px; line-height: 19px;                 /* 固定两行高度，空内容同样占位 */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- 标题溢出：单行缓慢水平滚动（transform 合成器动画），末尾停顿后循环 ---- */
.card .title.marquee { text-overflow: clip; }
.card .title.marquee .t-inner {
  will-change: transform;
  animation: fb-title-scroll var(--marquee-duration, 12s) linear infinite;
}
@keyframes fb-title-scroll {
  0%, 14%   { transform: translateX(0); }                              /* 起点停顿 */
  76%, 90%  { transform: translateX(var(--scroll-distance, -120px)); } /* 末尾停顿 */
  100%      { transform: translateX(0); }                              /* 回卷再循环 */
}
@media (prefers-reduced-motion: reduce) {
  .card .title.marquee .t-inner { animation: none; will-change: auto; }
  .card .title.marquee { text-overflow: ellipsis; }                   /* 退化为静态省略号 */
}
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-size: 11px;
}
.group-head {
  color: var(--ink-3); font-size: 12px; font-weight: 600;
  margin: 18px 2px 8px; letter-spacing: .5px;
}

.empty { text-align: center; color: var(--ink-3); padding: 48px 24px; font-size: 14px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}
.tabbar a {
  flex: 1; text-align: center; padding: 9px 0 7px;
  color: var(--ink-3); text-decoration: none; font-size: 11px;
}
.tabbar a .ico { display: block; font-size: 20px; line-height: 1.15; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

/* ---------- 分段控件 ---------- */
.segment {
  display: flex; background: #e9ecef; border-radius: 10px; padding: 3px; margin: 8px 0 4px;
}
.segment button {
  flex: 1; border: none; background: transparent; padding: 7px 0;
  border-radius: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.segment button.active { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.search-box { display: flex; gap: 8px; margin: 6px 0 4px; }
.search-box input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: var(--card);
}
.search-box button {
  border: none; background: var(--brand); color: #fff; border-radius: 10px;
  padding: 0 18px; font-size: 14px; cursor: pointer;
}

/* ---------- 阅读器 ---------- */
.reader-head {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(10px + var(--safe-top)) 16px 8px;
}
.reader-head h1 { font-size: 19px; margin: 0; word-break: break-all; }
.reader-meta { color: var(--ink-3); font-size: 12px; margin-top: 4px; }
.reader-body {
  /* 桌面纸面 CSS 变量的 Web 对应物（图表底座色取色通道，editor.py 同源语义） */
  --fb-paper-bg: #ffffff;
  --fb-paper-text: #1f2328;
  --fb-paper-text-secondary: #57606a;
  --fb-paper-muted: #8b949e;
  --fb-paper-grid: #e4e7eb;
  --fb-paper-link: #1f6feb;
  --fb-diagram-bg: #f6f8fa;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 6px 16px 24px; padding: 18px 16px;
  overflow-wrap: break-word;
}
.reader-body img { max-width: 100%; border-radius: 8px; }
.reader-body pre {
  background: #f6f8fa; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-size: 13px;
}
.reader-body code { font-size: 13px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.reader-body th, .reader-body td { border: 1px solid var(--line); padding: 6px 10px; font-size: 13px; }
.reader-body blockquote { margin: 10px 0; padding: 2px 12px; border-left: 3px solid var(--brand); color: var(--ink-2); }
.reader-body a { color: var(--brand); }

/* ---- 表格：桌面 .table-wrap 契约（layoutTables 按源文本测宽分配列宽） ---- */
.reader-body .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.reader-body table { border-collapse: collapse; }

/* ---- 全能力对齐：图表/乐谱/分子/思维导图/流程图容器（窄屏适配） ---- */
.reader-body .diagram-error {
  background: #fff1f0; border: 1px solid #ffa39e; color: #cf222e;
  border-radius: 8px; padding: 10px 12px; font-size: 13px; overflow-x: auto;
}
.reader-body .mermaid-block {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 12px 0; text-align: center;
}
.reader-body .mermaid-block svg { max-width: 100%; height: auto; }
.reader-body .markmap {
  position: relative; height: 340px; margin: 12px 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--fb-diagram-bg);
}
.reader-body .markmap svg { width: 100%; height: 100%; touch-action: none; }  /* 触屏缩放/拖动 */
.reader-body .flowchart-diagram {
  overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0; text-align: center;
}
.reader-body .flowchart-diagram svg { max-width: 100%; }
.reader-body .abcjs-score { margin: 12px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.reader-body .abcjs-score svg { max-width: 100%; height: auto; }
.reader-body .plotly-chart, .reader-body .echarts-chart { margin: 12px 0; }
.reader-body .plotly-target, .reader-body .echarts-target { width: 100%; }
.reader-body .smiles-structure { margin: 12px 0; text-align: center; }
.reader-body .smiles-target canvas, .reader-body .smiles-target svg { max-width: 100%; height: auto; }
.reader-body .smiles-caption {
  color: var(--ink-3); font-size: 12px; margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.reader-body .mermaid-source-title {
  color: var(--ink-3); font-size: 12px; margin: 8px 0 4px;
}

/* ---- 桌面同源杂项：空行占位 / 引用 chip / 任务列表 ---- */
.reader-body .blank-line { height: 1.5em; }
.reader-body .mention-file, .reader-body .mention-image {
  display: inline-block; background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 1px 10px; font-size: 13px; margin: 0 2px;
}
.reader-body ul.task-list-item, .reader-body li.task-list-item { list-style: none; margin-left: -1.2em; }
.reader-body .task-checkbox { color: var(--brand); font-size: 15px; }
.reader-body li.task-list-item.checked { color: var(--ink-3); }
.reader-body li.task-list-item.checked > :not(.task-checkbox) { color: inherit; }

/* ---- 数学公式（KaTeX）宽度治理：公式不得撑宽页面，超长仅在公式区横向滚动 ----
 * 链路（桌面镜像）：服务端输出 <div class="math-display">$$…$$</div>（独立块）
 * 与行内 $…$ 原文（escape 保护穿越 markdown），客户端 auto-render 生成
 * .katex-display / .katex。独立公式滚动容器给 .katex-display；行内公式
 * 仅对实际超宽者加 .katex-long（overflow≠visible 改基线，不能无差别施加）。 */
.reader-body .math-display:has(.katex-display) { display: block; }
.reader-body .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.reader-body .katex.katex-long {
  display: inline-block;   /* 此版 KaTeX 的 .katex 是 inline，行内盒不受 overflow/max-width 约束 */
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: bottom;  /* overflow≠visible 会丢 inline-block 基线，bottom 对齐补偿 */
  -webkit-overflow-scrolling: touch;
}

/* ---------- 媒体查看 ---------- */
.media-view { padding: 0 16px 24px; }
.media-view img { width: 100%; border-radius: var(--radius); background: #000; }
.media-view audio, .media-view video { width: 100%; border-radius: var(--radius); }
.open-ext {
  display: block; text-align: center; margin-top: 12px; padding: 12px;
  background: var(--brand); color: #fff; border-radius: 10px; text-decoration: none; font-weight: 600;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-bottom));
  background: rgba(31,35,40,.92); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 13px;
  z-index: 99; max-width: 80vw;
}
.spinner {
  text-align: center; color: var(--ink-3); padding: 32px 0; font-size: 13px;
}
