/* ============================================================================
 * app.css —— 煤矿标准资料系统（纯手写 CSS，无框架依赖）
 * 主题用 CSS 变量；深浅色跟随 prefers-color-scheme；信息密度适合长时间查阅。
 * ==========================================================================*/

/* 馆藏入口与版本导航复用现有主题，不依赖外部字体或动画库。 */
.library-eyebrow { color: rgba(255,255,255,.8); font-size: .82rem; letter-spacing: .12em; }
.library-paths, .library-source-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr)); gap: 12px; margin: 0 0 20px; }
.library-paths a, .library-source { display: flex; flex-direction: column; justify-content: center; gap: 5px; min-height: 88px; padding: 18px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .18s, background-color .18s; }
.library-paths a:hover, .library-source:hover { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.library-paths span { color: var(--ink-2); font-size: .82rem; }
.library-local { border-left: 3px solid var(--accent); }
.library-table-scroll { overflow-x: auto; max-width: 100%; margin-bottom: 16px; }
.library-table-scroll table { min-width: 660px; }
.library-version-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 14px; }
.library-version-tools input { min-height: 44px; max-width: 100%; }
.library-year-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.library-year-nav a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 60px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-subtle); }
.library-timeline .ver-node { scroll-margin-top: var(--sticky-header-offset, 130px); border-radius: var(--radius-sm); transition: background-color .2s; padding-right: 10px; }
.library-timeline .ver-node:target { background: var(--accent-soft); }
.library-timeline .ver-links a, .library-table-scroll .btn-link { display: inline-flex; align-items: center; min-height: 44px; }
#library-categories, #library-topics, #library-sources { scroll-margin-top: var(--sticky-header-offset, 130px); }
@media (max-width: 700px) { .library-paths { grid-template-columns: repeat(2,minmax(0,1fr)); } .library-paths a { padding: 12px; } .library-version-tools input { width: 100%; } }
@media (prefers-reduced-motion: reduce) { .library-paths a, .library-source, .library-timeline .ver-node { transition: none; } .pdf-scroll { scroll-behavior: auto; } .reader-progress span, .thumb-item { transition: none; } }

/* ---------------------------------------------------------------- 主题变量 */
:root {
  color-scheme: light;

  --bg:            #f4f5f7;
  --bg-elev:       #ffffff;
  --bg-subtle:     #f8f9fb;
  --bg-inset:      #eef0f4;
  --bg-hover:      #f0f2f6;

  --ink:           #1c2024;
  --ink-2:         #4a5259;
  --ink-3:         #7b858e;
  --ink-inverse:   #ffffff;

  --line:          #dfe3e8;
  --line-strong:   #c6ccd4;

  --accent:        #1f5f8b;
  --accent-hover:  #174a6d;
  --accent-soft:   #e7f0f7;
  --accent-ink:    #ffffff;

  --ok:            #1c7a4b;
  --ok-soft:       #e4f4ec;
  --warn:          #9a6206;
  --warn-soft:     #fdf3d9;
  --danger:        #a52b21;
  --danger-soft:   #fbeae8;
  --info:          #1f5f8b;
  --info-soft:     #e7f0f7;

  --ann-highlight: #ffd400;
  --ann-note:      #3ddc84;
  --ann-bookmark:  #3b9dff;

  --radius:        8px;
  --radius-sm:     5px;
  --radius-lg:     12px;

  --shadow-1:      0 1px 2px rgba(16, 24, 36, .06), 0 1px 3px rgba(16, 24, 36, .05);
  --shadow-2:      0 4px 14px rgba(16, 24, 36, .10);
  --shadow-3:      0 12px 36px rgba(16, 24, 36, .18);

  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
          "Source Han Sans SC", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;

  --header-h: 56px;
  --side-w: 220px;
  --max-w: 1500px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg:          #14171b;
    --bg-elev:     #1b1f24;
    --bg-subtle:   #1f242a;
    --bg-inset:    #12151a;
    --bg-hover:    #23282f;

    --ink:         #e6e9ed;
    --ink-2:       #b3bac2;
    --ink-3:       #868f99;
    --ink-inverse: #10131a;

    --line:        #2c323a;
    --line-strong: #3d454f;

    --accent:       #6ab0e0;
    --accent-hover: #8cc3ea;
    --accent-soft:  #1c2c3a;
    --accent-ink:   #0f1216;

    --ok:          #57c98d;
    --ok-soft:     #17301f;
    --warn:        #e0b155;
    --warn-soft:   #322717;
    --danger:      #ef7f74;
    --danger-soft: #3a1f1c;
    --info:        #6ab0e0;
    --info-soft:   #1c2c3a;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, .5);
    --shadow-3: 0 12px 36px rgba(0, 0, 0, .6);
  }
}

/* ---------------------------------------------------------------- 基础重置 */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.35; font-weight: 600; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }

p { margin: 0 0 .7em; }

code, kbd, pre {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--bg-inset);
  border-radius: 4px;
  padding: .1em .38em;
}

hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }

.muted  { color: var(--ink-3); }
.small  { font-size: .82rem; }
.num    { text-align: right; font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}

.topbar-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--ink); }

.brand-mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: .92rem;
}

.search-form {
  flex: 1 1 auto;
  display: flex;
  gap: 6px;
  min-width: 0;
}

.search-form input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
}

.search-form select { flex: 0 0 auto; }

.topnav {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  font-size: .9rem;
}

.user-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inline-form { display: inline; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; color: var(--accent-hover); }

/* 分类快捷条 */
.category-bar {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: .88rem;
}
.category-bar a {
  padding: 3px 11px;
  border-radius: 999px;
  color: var(--ink-2);
  border: 1px solid transparent;
}
.category-bar a:hover { background: var(--bg-hover); text-decoration: none; }
.category-bar a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  font-weight: 600;
}

.nav-toggle {
  display: none;
  margin: 0 16px 8px;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--ink-2);
  cursor: pointer;
  font: inherit;
}

/* ---------------------------------------------------------------- 骨架布局 */
.shell {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 18px 16px 40px;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow: auto;
  padding-right: 2px;
}

.side-block h2 {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
  margin: 0 0 7px;
  font-weight: 700;
}

.side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-list a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: .9rem;
  border-left: 3px solid transparent;
}
.side-list a:hover { background: var(--bg-hover); text-decoration: none; color: var(--ink); }
.side-list a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}
.side-list .count {
  font-size: .76rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  background: var(--bg-inset);
  border-radius: 999px;
  padding: 0 7px;
}
.side-list.compact a { padding: 3px 10px; font-size: .85rem; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; }

.main { min-width: 0; }

.foot {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- 首页 */
.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #2a7aa8 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 30px 28px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-2);
}
.hero h1 { font-size: 1.7rem; color: #fff; margin-bottom: .35em; }
.hero-sub { color: rgba(255, 255, 255, .88); max-width: 62ch; margin-bottom: 1.1em; }
.hero-search { display: flex; gap: 8px; max-width: 660px; }
.hero-search input { flex: 1 1 auto; border-color: transparent; }
.hero-search button { background: #0f1216; border-color: transparent; color: #fff; padding: 0 20px; }
.hero-search button:hover { background: #000; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1.2;
}
.stat-label { font-size: .82rem; color: var(--ink-3); margin-top: 2px; }
/* 统计卡下方的补充说明（如「另有 N 条非煤矿内容」） */
.stat-hint { font-size: .74rem; color: var(--ink-3); margin-top: 6px; line-height: 1.45; }
.stat-hint a { color: var(--accent); }

/* 面元面板下方的解释文字（如「收录范围」为什么默认排除无关内容） */
.facet-note {
  font-size: .74rem;
  color: var(--ink-3);
  line-height: 1.5;
  margin: 8px 10px 2px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.cat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.cat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.cat-card:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
  transform: translateY(-1px);
}
/* 专题卡片：与分类卡片同款外观，但用独立类名——`tests/browser_e2e.py`
   以 `.cat-card` 计数断言「分类卡片 = 5 张」，专题卡片不能混进去。 */
.topic-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.topic-card:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
  transform: translateY(-1px);
}
.cat-name { font-weight: 600; }
.cat-count { font-size: 1.25rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.cat-hint { font-size: .78rem; color: var(--ink-3); }

/* ---------------------------------------------------------------- 面板 */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-1);
}
.panel.tight { padding: 12px 14px; }

/* Preserve complete attachment filenames while allowing long hashes to wrap. */
.attachment-filename { min-width: 0; overflow-wrap: anywhere; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; }
.panel-head .more { font-size: .85rem; }

.page-head { margin-bottom: 14px; }
.page-head h1 { margin-bottom: .2em; }

.empty {
  color: var(--ink-3);
  background: var(--bg-subtle);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  margin: 0;
}

/* ---------------------------------------------------------------- 文档列表 */
.doc-list { display: flex; flex-direction: column; }

.doc-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}
.doc-item:last-child { border-bottom: 0; }
.doc-item:hover { background: var(--bg-subtle); }

.doc-main { min-width: 0; flex: 1 1 auto; }

.doc-line1 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.doc-title { font-weight: 600; color: var(--ink); font-size: .95rem; }
.doc-title:hover { color: var(--accent); }

.stdno {
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}
.stdno.lg { font-size: .95rem; padding: 2px 9px; }

.doc-line2 {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: .8rem;
  color: var(--ink-3);
  align-items: center;
}
.doc-summary {
  margin: 5px 0 0;
  font-size: .85rem;
  color: var(--ink-2);
}

.doc-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  font-size: .74rem;
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--ink-2);
}
.tag-soft { background: transparent; border: 1px solid var(--line-strong); color: var(--ink-3); }
/* 提醒用标签：当前结果集里混入了非煤矿内容 */
.tag-warn { background: var(--warn-soft, var(--bg-inset)); color: var(--warn, var(--ink-2)); }
.tag-warn::before { content: "⚠ "; }

/* 状态徽章 */
.badge {
  display: inline-block;
  font-size: .74rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--ink-2);
  white-space: nowrap;
  border: 1px solid transparent;
}
.status-现行      { background: var(--ok-soft);     color: var(--ok); }
.status-即将实施  { background: var(--info-soft);   color: var(--info); }
.status-废止      { background: var(--danger-soft); color: var(--danger); }
.status-被代替    { background: var(--warn-soft);   color: var(--warn); }
.status-未知      { background: var(--bg-inset);    color: var(--ink-3); }

.badge-pdf      { background: var(--accent-soft); color: var(--accent); }
.badge-ok       { background: var(--ok-soft);     color: var(--ok); }
.badge-off      { background: var(--bg-inset);    color: var(--ink-3); }
.badge-run      { background: var(--info-soft);   color: var(--info); }
.badge-error    { background: var(--danger-soft); color: var(--danger); }
.badge-count    { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- 表单控件 */
input[type="text"], input[type="search"], input[type="password"],
input[type="number"], select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 62px; line-height: 1.55; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

button, .btn-primary, .btn-ghost, .btn-reset {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-subtle);
  color: var(--ink);
  padding: 6px 13px;
  transition: background .15s, border-color .15s, color .15s;
}
button:hover:not(:disabled), .btn-ghost:hover { background: var(--bg-hover); border-color: var(--ink-3); }
button:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary.inline { display: inline-block; padding: 7px 16px; }

.btn-ghost { background: transparent; }
.btn-reset { display: block; text-align: center; margin-top: 4px; }

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  font-size: .85rem;
  color: var(--accent);
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

.stack-form { display: flex; flex-direction: column; gap: 4px; }
.stack-form label { font-size: .82rem; color: var(--ink-2); margin-top: 6px; font-weight: 600; }
.stack-form.compact label:first-child { margin-top: 0; }
.block { width: 100%; margin-top: 12px; }

.alert {
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 12px;
  font-size: .88rem;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* ---------------------------------------------------------------- 表格 */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.data-table thead th {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line-strong);
  background: var(--bg-subtle);
  position: sticky;
  top: 0;
}
.data-table tbody tr:hover { background: var(--bg-subtle); }
.data-table .msg { max-width: 380px; color: var(--ink-2); word-break: break-word; }

.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px 14px; margin: 0 0 16px; }
.kv dt { color: var(--ink-3); font-size: .85rem; }
.kv dd { margin: 0; }

/* ---------------------------------------------------------------- 检索页 */
.search-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236px;
  gap: 20px;
  align-items: start;
}
.results { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.facets { display: flex; flex-direction: column; gap: 12px; position: sticky; top: calc(var(--header-h) + 16px); }

.facet-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.facet-list a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: .87rem;
}
.facet-list a:hover { background: var(--bg-hover); text-decoration: none; }
.facet-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.facet-list .count { color: var(--ink-3); font-size: .78rem; font-variant-numeric: tabular-nums; }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  padding: 10px 0;
}
.pager a, .pager span {
  min-width: 32px;
  text-align: center;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: .87rem;
}
.pager a:hover { background: var(--bg-hover); text-decoration: none; }
.pager .current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pager .disabled { color: var(--ink-3); opacity: .55; }
.pager .gap { border: 0; background: none; min-width: 0; }
.pager-info { border: 0; background: none; color: var(--ink-3); font-size: .82rem; margin-left: 6px; }

/* ---------------------------------------------------------------- 登录/注册 */
.auth-wrap { display: flex; justify-content: center; padding: 26px 0; }
.auth-card { width: 100%; max-width: 400px; padding: 26px 28px; }
.auth-card h1 { margin-bottom: .3em; }
.auth-foot { margin: 16px 0 0; font-size: .88rem; text-align: center; }

/* ---------------------------------------------------------------- 详情页头部 */
.crumbs {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--ink-3);
  margin-bottom: 10px;
}
.crumb-current { color: var(--ink-2); }

.doc-header {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.doc-header-main { min-width: 0; flex: 1 1 480px; }
.doc-header-main h1 {
  font-size: 1.28rem;
  margin-bottom: .4em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}
.doc-meta-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; font-size: .82rem; }
.doc-header-actions { flex: 0 0 auto; }

.collect-box {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  box-shadow: var(--shadow-1);
}
.collect-box.guest { font-size: .85rem; }
.hint-inline { color: var(--warn); font-size: .8rem; }

/* ---------------------------------------------------------------- 阅读器 */
.reader-shell {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}

.reader-toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  padding: 7px 12px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--line);
  font-size: .85rem;
}

.tb-group { display: flex; align-items: center; gap: 5px; }
.tb-group button {
  min-width: 30px;
  padding: 3px 9px;
  line-height: 1.5;
}
.tb-group input[type="number"] { width: 58px; padding: 3px 6px; text-align: center; }
.tb-total { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tb-zoom { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.tb-check { display: flex; align-items: center; gap: 4px; color: var(--ink-2); cursor: pointer; }
.tb-check input { margin: 0; }
.tb-right { margin-left: auto; }
.tb-status { color: var(--ink-3); font-size: .8rem; }
.tb-status.warn { color: var(--warn); }

.reader-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  min-height: 70vh;
}

.pdf-stage { position: relative; min-width: 0; background: var(--bg-inset); }

.pdf-scroll {
  height: 76vh;
  min-height: 460px;
  overflow: auto;
  position: relative;
  scroll-behavior: smooth;
}

.pdf-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px;
  min-height: 100%;
}

.reader-loading, .pdf-load-error {
  color: var(--ink-3);
  padding: 40px 20px;
  text-align: center;
}
.pdf-load-error { color: var(--danger); }
.pdf-page-error { color: var(--danger); padding: 30px; text-align: center; }

/* 单个 PDF 页：canvas / textLayer / anno-layer 三层重叠 */
.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.pdf-page[data-rendered] { border-color: var(--line-strong); }

.pdf-canvas { display: block; background: #fff; }

.pdf-page-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 6;
  font-size: .72rem;
  color: var(--ink-3);
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 6px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* 文本层：必须可选中，否则无法选词标注 */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
  z-index: 4;
  text-align: initial;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: transparent;
  user-select: text;
  -webkit-user-select: text;
}
.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
}
.textLayer ::selection { background: rgba(31, 95, 139, .32); }
.textLayer ::-moz-selection { background: rgba(31, 95, 139, .32); }
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: -1;
  cursor: default;
  user-select: none;
}
.textLayer.selecting .endOfContent { top: 0; }

/* 标注层 */
.anno-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
.anno-box {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 2px;
  transition: box-shadow .15s, filter .15s;
}
.anno-highlight { opacity: var(--ann-alpha, .32); }
.anno-note {
  opacity: calc(var(--ann-alpha, .36) * .85);
  color: var(--ann-color, #3ddc84);
  border-bottom: 2px solid var(--ann-color, #3ddc84);
  background: none !important;
  box-shadow: inset 0 -2px 0 0 currentColor;
}
.anno-bookmark { opacity: var(--ann-alpha, .2); }
.anno-box:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 70%, transparent); filter: brightness(1.03); }
.anno-box.flash { animation: ann-flash 1.4s ease-out 1; }

@keyframes ann-flash {
  0%   { box-shadow: 0 0 0 0 rgba(31, 95, 139, .85); }
  60%  { box-shadow: 0 0 0 6px rgba(31, 95, 139, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 95, 139, 0); }
}

.anno-note-dot {
  position: absolute;
  left: -9px;
  bottom: -9px;
  font-size: 12px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3));
}

.anno-flag {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 3px 3px 3px 0;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

/* ---------------------------------------------------------------- 标注右栏 */
.ann-panel {
  border-left: 1px solid var(--line);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: 76vh;
}

.ann-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
}
.ann-head h2 { margin: 0; font-size: .95rem; }

.ann-hint {
  margin: 0;
  padding: 9px 13px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: .82rem;
  border-bottom: 1px solid var(--line);
}

.ann-filter { display: flex; gap: 5px; padding: 8px 13px; border-bottom: 1px solid var(--line); }
.chip {
  padding: 2px 10px;
  font-size: .78rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink-2);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.ann-list {
  flex: 1 1 auto;
  overflow: auto;
  padding: 8px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ann-empty { color: var(--ink-3); font-size: .84rem; text-align: center; padding: 22px 10px; margin: 0; }

.ann-item {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: .84rem;
  transition: border-color .15s, box-shadow .15s;
}
.ann-item.kind-highlight { border-left-color: var(--ann-highlight); }
.ann-item.kind-note      { border-left-color: var(--ann-note); }
.ann-item.kind-bookmark  { border-left-color: var(--ann-bookmark); }
.ann-item:hover { box-shadow: var(--shadow-1); }
.ann-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
.ann-item.current-page { background: color-mix(in srgb, var(--accent-soft) 55%, var(--bg-elev)); }

.ann-item-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ann-kind { font-weight: 600; font-size: .8rem; }
.ann-page { color: var(--ink-3); font-size: .78rem; }

.kind-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, .15);
}
.kind-dot.kind-highlight { background: var(--ann-highlight); }
.kind-dot.kind-note      { background: var(--ann-note); }
.kind-dot.kind-bookmark  { background: var(--ann-bookmark); }

.ann-quote {
  margin: 4px 0 5px;
  padding: 4px 8px;
  border-left: 2px solid var(--line-strong);
  background: var(--bg-inset);
  color: var(--ink-2);
  font-size: .79rem;
  border-radius: 0 4px 4px 0;
  max-height: 82px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.ann-comment { margin: 3px 0 0; color: var(--ink); white-space: pre-wrap; word-break: break-word; }

.ann-actions { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 7px; }
.btn-mini {
  padding: 1px 8px;
  font-size: .76rem;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background: var(--bg-subtle);
  color: var(--ink-2);
}
.btn-mini.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-mini.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }

.ann-edit { margin-top: 7px; display: flex; flex-direction: column; gap: 6px; }
.ann-edit textarea { font-size: .84rem; }
.ann-edit-actions { display: flex; gap: 6px; }

/* ---------------------------------------------------------------- 选区工具条 */
.sel-toolbar {
  position: absolute;
  z-index: 40;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  animation: sel-pop .12s ease-out;
}
.sel-toolbar[hidden] { display: none; }
.sel-toolbar button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  font-size: .82rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  color: var(--ink);
}
.sel-toolbar button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.sel-toolbar button.needs-login { opacity: .55; }

@keyframes sel-pop {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- 弹层 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 14, 20, .48);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 460px;
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  padding: 20px 22px;
}
.modal h3 { margin-bottom: .6em; }
.modal textarea { width: 100%; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------- 无 PDF 占位 */
.no-pdf h2 { margin-bottom: .5em; }
.no-pdf .kv { margin-top: 14px; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 1180px) {
  .reader-body { grid-template-columns: minmax(0, 1fr) 250px; }
  .ann-panel { max-height: 68vh; }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    max-height: none;
    display: none;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
  }
  .sidebar.open { display: flex; }
  .nav-toggle { display: inline-block; }
  .search-layout { grid-template-columns: minmax(0, 1fr); }
  .facets { position: static; }
  .reader-body { grid-template-columns: minmax(0, 1fr); }
  .ann-panel { border-left: 0; border-top: 1px solid var(--line); max-height: 52vh; }
  .pdf-scroll { height: 62vh; }
}

@media (max-width: 700px) {
  .topbar { position: static; }
  .topbar-inner { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 10px; }
  .search-form { order: 3; flex-basis: 100%; }
  .search-form button { flex-shrink: 0; white-space: nowrap; min-height: 44px; }
  .hero { padding: 22px 18px; }
  .hero h1 { font-size: 1.35rem; }
  .doc-item { flex-direction: column; }
  .doc-actions { align-self: flex-start; }
  .category-bar { flex-wrap: wrap; padding-bottom: 6px; gap: 8px; }
  .category-bar a { flex: 0 0 auto; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; }
  .doc-header-actions, .doc-tools { min-width: 0; max-width: 100%; width: 100%; }
  .doc-header-actions { flex: 1 1 auto; }
  .doc-tools { gap: 8px; }
  .doc-tools .btn-link { display: inline-flex; align-items: center; min-height: 44px; }
  .doc-tools .export-form { flex-wrap: wrap; min-width: 0; max-width: 100%; gap: 8px; }
  .doc-tools .export-form select { min-width: 0; max-width: 100%; min-height: 44px; }
  .doc-tools .export-form button { min-height: 44px; }
  .doc-header-actions .collect-box { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  .doc-header-actions a:focus-visible, .category-bar a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .tb-right { margin-left: 0; }
}

/* 打印：只保留内容 */
@media print {
  .topbar, .sidebar, .foot, .reader-toolbar, .ann-panel, .sel-toolbar { display: none !important; }
  .shell { display: block; padding: 0; }
  body { background: #fff; }
}

/* ============================================================================
 * v1.7 新增：下载 / 导出 / 版本沿革
 * ==========================================================================*/

/* 「N 个版本」徽标：可点进族页，用独立类名，避免影响既有 .badge 计数断言 */
.badge-ver {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
  text-decoration: none;
}
a.badge-ver:hover { background: var(--accent); color: var(--accent-ink); }

/* 下载 / 导出工具条 */
.doc-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.export-bar { margin: 2px 0 14px; }
.export-form { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.export-label { color: var(--ink-2); font-size: .88rem; }
.export-form select {
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
}
.export-form button { padding: 6px 12px; font-size: .88rem; }
.btn-link.disabled { opacity: .48; cursor: not-allowed; text-decoration: none; }
.hero-export { margin: 10px 0 0; }

/* 版本沿革：时间线 */
.ver-timeline {
  list-style: none;
  margin: 0;
  padding: 4px 0 0 14px;
  border-left: 2px solid var(--line);
}
.ver-node { position: relative; padding: 10px 0 16px 18px; }
.ver-node::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 16px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg-elev);
}
.ver-year { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.ver-body { display: flex; flex-direction: column; gap: 6px; }
.ver-links, .ver-rel { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: .86rem; }

/* 详情页「版本沿革」面板 */
.ver-mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ver-mini li {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}
.ver-mini li.current { border-color: var(--accent); background: var(--accent-soft); }

/* ---------------------------------------------- 「整本」与重复行（v2.0 展示层） */
/* 「整本」徽标：没有标准号的完整文件（如《煤矿安全规程》整本），与单条标准区分 */
.badge-fullbook {
  background: var(--ok-soft);
  color: var(--ok);
  white-space: nowrap;
}
/* 详情页重复行提示：被折叠的直链仍可达，这里说明它与主条目是同一份文件 */
.dup-notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--ink-2);
  font-size: .88rem;
  line-height: 1.65;
}
.dup-notice-tag {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
}
.dup-notice a { color: var(--accent); font-weight: 600; }
/* 详情页版本沿革小卡里的年份（族键无标准号的行也要有年份） */
.ver-year-mini {
  font-weight: 700;
  color: var(--accent);
  min-width: 3.2em;
}

/* 族总览表 */
.ver-table th, .ver-table td { vertical-align: middle; }
.ver-table td:nth-child(2) { min-width: 260px; }

/* ---------------------------------------------- 公告展开（第四阶段） */
/* 独立命名空间 .annc-*：不复用 .cat-card（首页「分类卡片 == 5 张」是被测断言），
   也不复用 .ann-item（那是阅读器标注）。 */
.panel.annc-children .panel-head { align-items: baseline; }
.annc-note {
  margin: 0 0 10px;
  color: var(--ink-2);
  font-size: .86rem;
  line-height: 1.6;
}
.annc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.annc-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}
.annc-item .annc-title { font-size: .92rem; text-decoration: none; }
.annc-item .annc-title:hover { text-decoration: underline; }
.annc-item .meta { font-size: .78rem; color: var(--ink-3); margin-left: auto; }
.annc-origin p { margin: 0; color: var(--ink-2); }
.badge-annc {
  background: var(--info-soft);
  color: var(--info);
  font-weight: 600;
}
@media (max-width: 700px) {
  .annc-item .meta { margin-left: 0; }
}

/* 版本字段差异保留可读列宽，在容器内横滚。 */
.ver-field-diff-table { width: auto; }
.ver-field-diff-table th:first-child { white-space: nowrap; min-width: 96px; }
.ver-field-diff-table th:not(:first-child), .ver-field-diff-table td { min-width: 220px; width: 220px; max-width: 320px; white-space: normal; overflow-wrap: anywhere; }
.library-table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
