/* OPNET 文档站 — 纯静态样式
   布局：header / sidebar(导航树) / content(居中栏) / toc(本页目录)
   无 JS 依赖：折叠靠原生 <details>；搜索为 Pagefind 默认 UI 的下拉面板。 */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-code: #f0f2f4;
  --border: #e2e6ea;
  --border-strong: #d0d7de;
  --text: #1f2328;
  --text-soft: #57606a;
  --accent: #0969da;
  --accent-strong: #0550ae;
  --accent-soft: #ddf4ff;
  --selection: rgba(9, 105, 218, 0.25);
  --row-hover: #eaeef2;
  --mark: #fff8c5;
  --shadow: 0 12px 32px rgba(31, 35, 40, 0.14), 0 2px 8px rgba(31, 35, 40, 0.08);
  --header-h: 56px;
  --sidebar-w: 300px;
  --toc-w: 230px;
  --content-max: 860px;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #161b22;
    --bg-code: #21262d;
    --border: #30363d;
    --border-strong: #3d444d;
    --text: #e6edf3;
    --text-soft: #8b949e;
    --accent: #58a6ff;
    --accent-strong: #79c0ff;
    --accent-soft: #12233a;
    --selection: rgba(88, 166, 255, 0.32);
    --row-hover: #21262d;
    --mark: #4a3d12;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.45);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  font-size: 15.5px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--selection); }

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand {
  flex: none;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand:hover { text-decoration: none; }
.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}
.lang-switch {
  flex: none;
  white-space: nowrap;
  font-size: 0.86rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
}
.lang-switch.muted { color: var(--text-soft); opacity: 0.55; cursor: default; }
a.lang-switch:hover { text-decoration: none; border-color: var(--accent); }

/* ---------- search (Pagefind 默认 UI 的下拉面板化) ---------- */
#search { position: relative; flex: none; width: 240px; max-width: 100%; }
#search .pagefind-ui__form { margin: 0; }
#search .pagefind-ui__form::before {
  top: 9px;
  left: 11px;
  width: 15px;
  height: 15px;
}
#search .pagefind-ui__search-input {
  width: 100%;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 4px 30px 4px 33px;
  font-size: 0.9rem;
}
#search .pagefind-ui__search-input:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--bg);
}
#search .pagefind-ui__search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  font-size: 0.75rem;
  color: var(--text-soft);
  background: transparent;
  border: none;
  cursor: pointer;
}
#search .pagefind-ui__drawer {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: block;
  width: min(520px, 92vw);
  max-height: 72vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  gap: 0;
  padding: 0 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
#search .pagefind-ui__drawer:empty { display: none; }
#search .pagefind-ui__message {
  padding: 0.8rem 0;
  color: var(--text-soft);
  font-size: 0.85rem;
}
#search .pagefind-ui__results { margin: 0; }
#search .pagefind-ui__result { padding: 0.65rem 0 0.75rem; }
#search .pagefind-ui__result-title { font-size: 0.95rem; }
#search .pagefind-ui__result-excerpt {
  font-size: 0.83rem;
  color: var(--text-soft);
  line-height: 1.55;
}
#search .pagefind-ui__result-nested { padding-left: 0.75rem; }
#search mark, article mark {
  background: var(--mark);
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
}
#search .pagefind-ui__button {
  margin: 0.5rem 0 0.9rem;
  padding: 6px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}
#search .pagefind-ui__button:hover { border-color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1520px;
  margin: 0 auto;
}
.layout.no-toc { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

/* 侧栏宽度拖拽手柄（覆盖在侧栏/内容分界线上） */
.sb-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--sidebar-w) - 1px);
  width: 9px;
  cursor: col-resize;
  z-index: 20;
  touch-action: none;
}
.sb-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: transparent;
  transition: background 0.15s ease, width 0.15s ease, left 0.15s ease;
}
.sb-resizer:hover::after, body.sb-resizing .sb-resizer::after {
  left: 3px;
  width: 3px;
  background: var(--accent);
}
body.sb-resizing { user-select: none; cursor: col-resize; }

/* ---------- sidebar（导航树，原生 details 折叠） ---------- */
.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.75rem 3rem 1.25rem;
  border-right: 1px solid var(--border);
  font-size: 0.9rem;
  scrollbar-gutter: stable;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar .doc-home {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.7rem;
  padding: 4px 10px;
}
.sidebar .doc-home:hover { text-decoration: none; color: var(--accent); }
.sidebar a {
  display: block;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-soft);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.sidebar a:hover { text-decoration: none; background: var(--bg-soft); color: var(--text); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.sidebar details { margin: 0; }
.sidebar summary {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  cursor: pointer;
  border-radius: 6px;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::before {
  content: "";
  flex: none;
  width: 0;
  height: 0;
  margin: 0 2px 0 4px;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--text-soft);
  transition: transform 0.15s ease;
}
.sidebar details[open] > summary::before { transform: rotate(90deg); }
.sidebar summary > a { flex: 1; min-width: 0; }
.sidebar .sec { margin: 1px 0; }
.sidebar .sec > .sec-link,
.sidebar .sec summary > .sec-link { font-weight: 600; color: var(--text); font-size: 0.92rem; }
.sidebar .sec.current > .sec-link,
.sidebar .sec.current > details > summary > .sec-link { color: var(--accent-strong); }
.sidebar .chapters {
  margin: 2px 6px 8px 14px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.sidebar .chapter-link { font-size: 0.88rem; }
.sidebar .chapter.current > .chapter-link,
.sidebar .chapter.current > details > summary > .chapter-link { color: var(--accent-strong); font-weight: 600; }
.sidebar .pages {
  margin: 2px 6px 6px 14px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.sidebar .pages a { font-size: 0.84rem; padding-top: 2px; padding-bottom: 2px; }
.sidebar .module > details > summary > .module-link { font-weight: 600; color: var(--text); font-size: 0.89rem; }
.sidebar .module.current > details > summary > .module-link { color: var(--accent-strong); }

/* ---------- content ---------- */
.content {
  min-width: 0;
  padding: 1.6rem 2.5rem 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.content > * { width: 100%; max-width: var(--content-max); }
.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: 1.1rem;
  overflow-wrap: anywhere;
}
.breadcrumbs .sep { margin: 0 6px; color: var(--border-strong); }
.breadcrumbs .current { color: var(--text-soft); }

/* ---------- typography ---------- */
article h1, article h2, article h3, article h4, article h5, article h6 {
  line-height: 1.35;
  overflow-wrap: anywhere;
  scroll-margin-top: calc(var(--header-h) + 16px);
}
article h1 { font-size: 1.6rem; margin: 0.3rem 0 1.2rem; }
article h2 { font-size: 1.28rem; margin: 2rem 0 0.8rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); }
article h3 { font-size: 1.12rem; margin: 1.6rem 0 0.6rem; }
article h4 { font-size: 1rem; margin: 1.4rem 0 0.5rem; }
article h5, article h6 { font-size: 0.95rem; margin: 1.2rem 0 0.5rem; color: var(--text-soft); }
article p, article li { overflow-wrap: break-word; }
article a { overflow-wrap: anywhere; }
article img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; }
article p:has(> img:only-child) { text-align: center; }
article blockquote {
  margin: 1rem 0;
  padding: 0.1rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  color: var(--text-soft);
}
article code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  overflow-wrap: anywhere;
}
article pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  line-height: 1.55;
}
article pre code { background: none; padding: 0; font-size: 0.85rem; overflow-wrap: normal; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal { color: #cf222e; }
.hljs-string, .hljs-attr { color: #0a3069; }
.hljs-comment { color: #6e7781; font-style: italic; }
.hljs-number, .hljs-built_in { color: #0550ae; }
.hljs-title, .hljs-function, .hljs-name { color: #8250df; }
@media (prefers-color-scheme: dark) {
  .hljs-keyword, .hljs-selector-tag, .hljs-literal { color: #ff7b72; }
  .hljs-string, .hljs-attr { color: #a5d6ff; }
  .hljs-comment { color: #8b949e; }
  .hljs-number, .hljs-built_in { color: #79c0ff; }
  .hljs-title, .hljs-function, .hljs-name { color: #d2a8ff; }
}
article table {
  border-collapse: collapse;
  margin: 1.2rem 0;
  width: 100%;
  max-width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 0.92rem;
}
article th, article td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
  vertical-align: top;
}
article th { background: var(--bg-soft); font-weight: 600; }
article tbody tr:nth-child(even) { background: var(--bg-soft); }
article tbody tr:hover { background: var(--row-hover); }
article hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ---------- toc（本页目录） ---------- */
.toc {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.6rem 1rem 3rem 0.25rem;
  font-size: 0.84rem;
}
.toc-title { font-weight: 600; color: var(--text-soft); margin-bottom: 0.5rem; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc li.h3 { padding-left: 1rem; }
.toc a {
  display: block;
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--border);
  color: var(--text-soft);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.toc a:hover { color: var(--accent); text-decoration: none; border-left-color: var(--accent); }

/* ---------- pager & footer ---------- */
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.8rem; }
.pager a {
  flex: 1 1 0;
  max-width: 49%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  color: var(--text);
  overflow-wrap: anywhere;
}
.pager a:hover { text-decoration: none; border-color: var(--accent); box-shadow: 0 2px 8px rgba(31, 35, 40, 0.08); }
.pager a span { display: block; font-size: 0.76rem; color: var(--text-soft); }
.pager .next { margin-left: auto; text-align: right; }
.pager span.empty { flex: 1 1 0; max-width: 49%; }
.site-footer {
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 0.8rem;
}

/* ---------- landing ---------- */
.landing { max-width: 880px; margin: 0 auto; padding: 3rem 1.5rem 4rem; }
.landing h1 { font-size: 2rem; margin-bottom: 0.4rem; }
.landing .tagline { color: var(--text-soft); margin-bottom: 2.2rem; }
.lang-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.lang-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem 1.5rem;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lang-card:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow); }
.lang-card .big { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.lang-card span:last-child { font-size: 0.85rem; color: var(--text-soft); }
.landing-notes { margin-top: 2.5rem; color: var(--text-soft); font-size: 0.86rem; }
.landing-notes p { margin: 0.4rem 0; }
.landing .site-footer { max-width: none; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout, .layout.no-toc { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .site-header { padding: 0 0.75rem; gap: 0.5rem; }
  .brand { font-size: 0.95rem; max-width: 32vw; }
  #search { width: auto; flex: 1 1 auto; min-width: 0; }
  .lang-switch { padding: 3px 8px; font-size: 0.8rem; }
  .layout, .layout.no-toc { display: block; }
  .sb-resizer { display: none; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0.75rem 0.7rem;
  }
  .sidebar .doc-home { margin-bottom: 0.4rem; padding: 2px 6px; }
  .sidebar .secs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 4px; }
  .sidebar .sec { flex: none; margin: 0; }
  .sidebar .sec > .sec-link,
  .sidebar .sec details > summary > .sec-link {
    white-space: nowrap;
    background: var(--bg-soft);
    border-radius: 999px;
    padding: 4px 12px;
    font-weight: 500;
  }
  .sidebar .sec.current > .sec-link,
  .sidebar .sec.current > details > summary > .sec-link {
    background: var(--accent-soft);
    color: var(--accent-strong);
  }
  .sidebar summary::before { display: none; }
  .sidebar .chapters, .sidebar .pages { display: none; }
  .content { padding: 1.25rem 1.1rem 3rem; }
  .content > * { max-width: none; }
  .lang-cards { grid-template-columns: 1fr; }
  #search .pagefind-ui__drawer { width: min(520px, calc(100vw - 24px)); }
  .pager { flex-direction: column; }
  .pager a, .pager span.empty { max-width: none; }
  .pager .next { text-align: left; }
}

/* ---------- print ---------- */
@media print {
  .site-header, .sidebar, .toc, .pager, .sb-resizer { display: none; }
  .layout, .layout.no-toc { display: block; }
  .content { padding: 0; }
  .content > * { max-width: none; }
}
