:root {
  --bg: #eef2f6;
  --paper: #fff;
  --ink: #1d2129;
  --muted: #86909c;
  --line: #e5e6eb;
  --brand: #165dff;
  --top: #0e1b2a;
  --tip: #e8f3ff;
  --ok: #f3faf4;
  --warn: #fff7e8;
  /* 阅读栏：约 65–75 汉字舒适宽；大屏侧栏+正文+目录占比约 18% / 64% / 18% */
  --side-w: clamp(200px, 18vw, 240px);
  --toc-w: clamp(160px, 16vw, 200px);
  --read-max: 44rem; /* ~704px @16px：正文为主 */
  --fig-max: 40rem;
  --fig-pair-h: 240px;
  --fig-real-h: 360px;
  --fig-flow-h: 320px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 28px;
  --space-6: 40px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.7 "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* —— 顶栏 —— */
.top { position: sticky; top: 0; z-index: 5; background: var(--top); color: #fff; }
.top-inner { display: flex; align-items: center; gap: 18px; height: 52px; padding: 0 20px; }
.brand { color: #fff; font-weight: 650; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: #9fb0c3; font-weight: 400; margin-left: 8px; font-size: 13px; }
.top-nav { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.top-nav a { color: #d5dde6; font-size: 13px; text-decoration: none; }
.top-nav a:hover { color: #fff; }

/* —— 三栏壳：侧栏 | 正文 | 目录 —— */
.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--toc-w);
  min-height: calc(100vh - 52px);
  gap: 0;
}
.side, .toc { background: var(--paper); padding: 12px 10px 32px; }
.side {
  border-right: 1px solid var(--line);
  position: sticky; top: 52px; align-self: start;
  max-height: calc(100vh - 52px); overflow: auto;
}
.toc {
  border-left: 1px solid var(--line);
  position: sticky; top: 52px; align-self: start;
  max-height: calc(100vh - 52px); overflow: auto;
}
.nav-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; border: 0; background: transparent; color: var(--muted);
  font-size: 12px; letter-spacing: .04em; padding: 12px 8px 4px; cursor: pointer;
}
.nav-title:hover { color: var(--brand); }
.nav-caret {
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid currentColor; transition: transform .15s ease; flex: none;
}
.nav-group.is-collapsed .nav-caret { transform: rotate(-90deg); }
.nav-group.is-collapsed .nav-items { display: none; }
.nav-link {
  display: block; padding: 6px 10px; border-radius: 6px; color: var(--ink);
  font-size: 13.5px; line-height: 1.35; text-decoration: none;
}
.nav-link.active, .nav-link:hover { background: #e8f3ff; color: var(--brand); text-decoration: none; }

/* —— 正文栏：居中阅读宽 —— */
.main {
  padding: var(--space-4) clamp(16px, 3vw, 40px) 72px;
  max-width: calc(var(--read-max) + 48px);
  width: 100%;
  margin: 0 auto;
  justify-self: center;
}
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: var(--space-1); }
.article h1 {
  font-size: clamp(1.45rem, 2.2vw, 1.75rem);
  margin: 0 0 var(--space-2); letter-spacing: -.02em; line-height: 1.25;
  font-weight: 700;
}
.article h2 {
  font-size: 1.15rem; margin: var(--space-6) 0 var(--space-2); padding-bottom: 6px;
  border-bottom: 1px solid var(--line); scroll-margin-top: 68px; font-weight: 650;
}
.article h2:first-of-type { margin-top: var(--space-5); }
.article h3 {
  font-size: 0.95rem; margin: var(--space-4) 0 var(--space-1); color: #4e5969; font-weight: 650;
  scroll-margin-top: 68px;
}
.article p { margin: 0 0 var(--space-3); color: #2b3038; max-width: 42rem; }
.article li { color: #2b3038; }
.article ul, .article ol { margin: 0 0 var(--space-3); padding-left: 1.25rem; max-width: 42rem; }
.article code { background: #eef1f4; padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.article table {
  width: 100%; max-width: 100%; border-collapse: collapse; background: #fff;
  margin: var(--space-2) 0 var(--space-4); font-size: 13.5px;
}
.article th, .article td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.article th { background: #f7f8fa; font-weight: 650; white-space: nowrap; }
.lead {
  color: var(--muted); margin: 0 0 var(--space-3); font-size: 15px;
  line-height: 1.65; max-width: 40rem;
}

/* —— 图：限制视口占比，避免连屏压正文 —— */
.figure {
  position: relative;
  margin: var(--space-3) 0 var(--space-4);
  max-width: var(--fig-max);
}
.figure img {
  width: 100%; max-width: 100%; max-height: var(--fig-flow-h);
  height: auto; object-fit: contain; object-position: top center;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; display: block;
  margin: 0 auto;
}
.figure-wide { max-width: 100%; }
.figure-wide img { max-height: min(var(--fig-flow-h), 42vh); }
.figure-real img {
  max-height: min(var(--fig-real-h), 46vh);
  border-style: solid;
}
.figure-schematic img {
  max-height: min(280px, 36vh);
  background: repeating-linear-gradient(-45deg, #fafbfc, #fafbfc 8px, #f3f5f8 8px, #f3f5f8 16px);
  border-style: dashed;
}
.figure-compact { margin: 0; max-width: none; }
.figure-compact img { max-height: var(--fig-pair-h); }
/* 图文阅读：流程大图后紧跟短步骤，降低「字墙」感 */
.article > .figure-wide + .steps,
.article > .figure-pair + .steps,
.article > .figure-wide + .callout,
.article > .figure-pair + .callout {
  margin-top: 10px;
}
.article h2 + .figure,
.article h2 + .figure-pair,
.article h2 + .figure-wide {
  margin-top: 8px;
}
.figure-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: var(--space-3) 0 var(--space-4);
  align-items: start;
}
.figure-pair .figure { margin: 0; }
.cap {
  color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.45;
  max-width: 36rem;
}
.fig-badge {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  background: rgba(14, 27, 42, .72); color: #fff;
  font-size: 11px; letter-spacing: .06em; padding: 2px 8px; border-radius: 4px;
}
.fig-badge-real { background: rgba(0, 160, 48, .88); }

/* 连续图/提示块：收紧节奏，避免「提示墙」 */
.article > .callout + .callout { margin-top: 8px; }
.article > .figure-pair + .figure,
.article > .figure + .figure { margin-top: 10px; }
.article > .page-outline + .callout { margin-top: 10px; }

.callout {
  background: var(--tip); border-left: 3px solid var(--brand);
  padding: 10px 12px; margin: var(--space-2) 0 var(--space-3);
  border-radius: 0 8px 8px 0; max-width: 42rem; font-size: 14px; line-height: 1.55;
}
.callout.ok { background: var(--ok); border-left-color: #00b42a; }
.callout.warn { background: var(--warn); border-left-color: #ff7d00; }
.callout.tip { background: #f3f8fd; border-left-color: #165dff; }
.callout ul { margin: 0; padding-left: 18px; max-width: none; }
.steps { margin: 8px 0 0; padding-left: 20px; max-width: 42rem; }
.steps li { margin: 6px 0; }
.doc-boundary {
  margin: 0 0 var(--space-3); padding: 10px 12px; background: #f7f8fa;
  border: 1px dashed var(--line); border-radius: 8px; color: #4e5969; font-size: 14px;
  max-width: 42rem;
}
.page-outline {
  display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center;
  margin: 0 0 var(--space-3); padding: 8px 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
  /* uc_docs_outline_sticky_v1：长章阅读时本章目录贴在顶栏下 */
  position: sticky; top: 52px; z-index: 2;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}
.page-outline-lab {
  font-size: 12px; color: var(--muted); font-weight: 650; margin-right: 2px;
}
.page-outline a {
  font-size: 12.5px; color: var(--ink); background: #f7f8fa;
  padding: 3px 8px; border-radius: 6px; text-decoration: none;
}
.page-outline a:hover { background: #e8f3ff; color: var(--brand); }
.toc a {
  display: block; font-size: 12.5px; color: var(--muted); padding: 3px 0;
  line-height: 1.35; text-decoration: none;
}
.toc a:hover, .toc a:focus { color: var(--brand); }
.toc a.toc-h3 { padding-left: 10px; font-size: 12px; }
.pager { display: flex; justify-content: space-between; margin-top: var(--space-6); gap: 12px; }
.pager a {
  flex: 1; max-width: 48%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink); font-size: 14px; line-height: 1.4;
  text-decoration: none;
}
.pager a:hover { border-color: var(--brand); color: var(--brand); background: #f7fbff; }
.pager span { flex: 1; max-width: 48%; }
.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 12px 20px; background: #fff; }
.foot-legal { margin-top: 6px; max-width: 920px; line-height: 1.5; color: #86909c; }
.nav-toggle { display: none; border: 0; background: transparent; color: #fff; font-size: 14px; cursor: pointer; }
.doc-search-wrap { position: relative; margin-left: 12px; }
.doc-search { width: 168px; height: 30px; border: 0; border-radius: 6px; padding: 0 10px; font: inherit; }
.doc-hits {
  position: absolute; top: 36px; left: 0; z-index: 6; width: 280px; background: #fff;
  color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px;
}
.doc-hits a, .doc-hit-empty { display: block; padding: 6px 8px; border-radius: 6px; color: var(--ink); font-size: 13px; text-decoration: none; }
.doc-hits a strong { display: block; font-weight: 600; }
.doc-hit-snip { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.doc-hits a:hover { background: #e8f3ff; }
.doc-hits mark { background: #ffe58f; color: inherit; padding: 0 2px; border-radius: 2px; }
.doc-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, #165dff, #00b42a); z-index: 20; pointer-events: none;
}
.doc-top {
  position: fixed; right: 18px; bottom: 24px; z-index: 15;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font: inherit; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
}
.doc-top:hover { border-color: var(--brand); color: var(--brand); }
.doc-help {
  position: fixed; right: 18px; bottom: 72px; z-index: 16;
  width: 260px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 28px rgba(0,0,0,.12);
  color: var(--ink); font-size: 13px;
}
.doc-help strong { display: block; margin-bottom: 8px; }
.doc-help ul { margin: 0; padding-left: 18px; }
.doc-help li { margin: 4px 0; }
.doc-help kbd {
  display: inline-block; min-width: 1.2em; padding: 1px 5px;
  border: 1px solid var(--line); border-radius: 4px; background: #f7f8fa;
  font: 12px/1.4 Consolas, monospace;
}
.doc-help-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.doc-resume {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  margin: 0 0 var(--space-3); padding: 10px 12px; background: #f3faf4;
  border: 1px solid #b7eb8f; border-radius: 10px; font-size: 14px;
}
.doc-resume a { font-weight: 650; }
.doc-resume-dismiss {
  margin-left: auto; border: 0; background: transparent; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.doc-resume-dismiss:hover { color: var(--ink); }
.doc-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 var(--space-3); }
.doc-toolbar button {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 6px 12px; font: inherit; cursor: pointer;
}
.doc-toolbar button:hover { border-color: var(--brand); color: var(--brand); }
.doc-sister {
  display: inline-block; margin-left: 4px; padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--line); color: var(--brand); font-size: 13px; background: #fff;
  text-decoration: none;
}
.doc-sister:hover { background: #e8f3ff; text-decoration: none; }
pre.doc-code {
  margin: var(--space-2) 0 var(--space-4);
  padding: 12px 14px; border-radius: 8px;
  background: #0e1b2a; color: #e8eef5;
  font-size: 12px; line-height: 1.45;
  overflow-x: auto; border: 1px solid #243447;
  max-height: min(360px, 48vh);
}
pre.doc-code code {
  font-family: Consolas, "Courier New", monospace;
  white-space: pre;
}
.checklist { list-style: none; margin: 8px 0 0; padding: 0; max-width: 42rem; }
.checklist li { margin: 8px 0; padding: 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; color: #2b3038; }
.checklist input { margin-top: 4px; flex: none; }
.article h2 + ul { margin-top: 4px; }
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 0;
  font-size: 14px; font-weight: 600;
}
.skip-link:focus { left: 0; outline: 2px solid #fff; outline-offset: 2px; }

@media print {
  .doc-progress, .doc-top, .doc-help, .doc-resume { display: none !important; }
  .top, .side, .toc, .pager, .foot, .doc-search-wrap, .doc-toolbar, .page-outline,
  .doc-sister, .nav-toggle, .skip-link { display: none !important; }
  .shell { display: block; }
  .main { max-width: none; padding: 0; }
  .article a[href]::after { content: none; }
  .figure, .figure-pair, .callout, .tip, .warn, .ok, table, .checklist { break-inside: avoid; page-break-inside: avoid; }
  .figure img { max-width: 100%; max-height: none; height: auto; }
  .checklist input { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  h2, h3 { break-after: avoid; page-break-after: avoid; }
}

@media (max-width: 1100px) {
  .shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .toc { display: none; }
  .main { max-width: calc(var(--read-max) + 32px); }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    display: none; border-right: 0; border-bottom: 1px solid var(--line);
    position: static; max-height: none;
  }
  /* R-087：窄屏侧栏抽屉。marker: r087_docs_mobile_nav_v1 */
  body.nav-open .side { display: block; }
  .main { padding: 16px 16px 64px; max-width: none; }
  .nav-toggle { display: inline-block; }
  .doc-search { width: 112px; }
  .portal-grid { grid-template-columns: 1fr; }
  .chap-list { grid-template-columns: 1fr 1fr; }
  .figure-pair { grid-template-columns: 1fr; }
  .figure-pair .figure-compact img { max-height: 280px; }
  .page-outline { display: flex; }
}
@media (max-width: 560px) {
  .chap-list { grid-template-columns: 1fr; }
  .doc-search { width: 96px; }
  .article h1 { font-size: 1.35rem; }
  .figure-real img, .figure-wide img { max-height: 52vh; }
}

/* portal */
body.portal .main.portal-main {
  max-width: 1080px; margin: 0 auto; padding: 28px 24px 48px; justify-self: stretch;
}
.portal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 20px 0; }
.portal-card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px 14px; }
.portal-card h2 { margin: 0 0 8px; font-size: 22px; border: 0; padding: 0; }
.portal-card h3 { margin: 14px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.portal-card > p { margin: 0 0 10px; color: #2b3038; max-width: none; }
.portal-entry { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 12px 0 !important; }
.portal-btn {
  display: inline-block; background: var(--brand); color: #fff !important;
  padding: 6px 14px; border-radius: 8px; font-weight: 600; text-decoration: none;
}
.portal-btn:hover { filter: brightness(1.05); text-decoration: none; }
.chap-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.chap-list a {
  display: block; padding: 6px 8px; border-radius: 6px; color: var(--ink);
  background: #f7f8fa; text-decoration: none; font-size: 13px;
}
.chap-list a:hover { background: #e8f3ff; color: var(--brand); }
.portal-meta { margin-top: 14px !important; color: var(--muted); font-size: 13px; }
.portal-note { margin-top: 8px; }
.portal-readpath {
  margin: 0 0 4px; padding: 12px 14px; background: #f3f8fd;
  border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0;
  color: #2b3038; font-size: 14px; line-height: 1.55;
}
.portal-diff {
  margin: 12px 0 0; padding: 10px 12px; background: #fff; border: 1px dashed var(--line);
  border-radius: 8px; font-size: 13px; color: #4e5969;
}
.portal-roles {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin: 18px 0 8px;
}
.portal-role {
  display: block; background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 14px 12px; color: var(--ink); text-decoration: none;
}
.portal-role:hover { border-color: var(--brand); background: #f7fbff; text-decoration: none; }
.portal-role strong { display: block; font-size: 15px; margin-bottom: 4px; }
.portal-role span { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; }
@media (max-width: 960px) {
  .portal-roles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .portal-roles { grid-template-columns: 1fr; }
}
