/* 循造插件开发文档中心 — 独立样式，可直接部署 */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --sidebar-bg: #0f1b2d;
  --sidebar-text: #c5d0e0;
  --sidebar-muted: #7a8ba3;
  --sidebar-active: #1a9fff;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --topbar-h: 56px;
  --sidebar-w: 260px;
  --toc-w: 200px;
  --text: #1a2332;
  --text-secondary: #5a6a7e;
  --border: #e4e9f0;
  --link: #0b6bcb;
  --link-hover: #0854a0;
  --accent: #0b6bcb;
  --code-bg: #f0f3f7;
  --quote-border: #0b6bcb;
  --table-stripe: #f8fafc;
  --shadow-drawer: 0 0 0 9999px rgba(15, 27, 45, 0.45);
  --font-sans: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "Consolas", "Source Code Pro", monospace;
  --radius: 6px;
  --content-max: 780px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ========== 顶栏 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius);
}

.menu-btn:hover {
  background: var(--bg);
}

.menu-btn__bar {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text);
  border-radius: 1px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: inherit;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
  color: inherit;
}

.brand__logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: block;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand__name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand__sub {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.topbar__search {
  flex: 1;
  max-width: 360px;
  margin-left: 8px;
}

.topbar__search input {
  width: 100%;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg);
  font: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.topbar__search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 203, 0.12);
  background: var(--surface);
}

.topbar__links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.topbar__links a {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius);
  text-decoration: none;
}

.topbar__links a:hover {
  color: var(--accent);
  background: rgba(11, 107, 203, 0.06);
  text-decoration: none;
}

/* ========== 布局壳 ========== */
.shell {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

/* ========== 侧栏 ========== */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: flex-start;
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  flex-shrink: 0;
  background: var(--sidebar-bg);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__inner {
  padding: 20px 0 40px;
}

.sidebar__label {
  margin: 0 20px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.nav-group {
  margin-bottom: 20px;
}

.nav-group__title {
  margin: 0 20px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-muted);
}

.nav-group__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-group__list a {
  display: block;
  padding: 8px 20px 8px 24px;
  font-size: 13.5px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
}

.nav-group__list a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.nav-group__list a.is-active {
  background: rgba(26, 159, 255, 0.12);
  color: #fff;
  border-left-color: var(--sidebar-active);
  font-weight: 600;
}

.nav-group__list a.is-dim {
  opacity: 0.35;
  pointer-events: none;
}

.sidebar-backdrop {
  display: none;
}

/* ========== 主内容 ========== */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 28px 32px 64px;
}

.main__inner {
  flex: 1;
  max-width: var(--content-max);
  min-width: 0;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.breadcrumb a {
  color: var(--text-secondary);
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb__sep {
  opacity: 0.45;
  user-select: none;
}

.breadcrumb__current {
  color: var(--text);
  font-weight: 500;
}

.doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px 40px 48px;
  min-height: 280px;
}

.doc-loading,
.doc-error {
  color: var(--text-secondary);
  padding: 24px 0;
}

.doc-error {
  color: #b42318;
}

/* Markdown 渲染 */
.doc h1 {
  margin: 0 0 20px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.doc h2 {
  margin: 36px 0 14px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.doc h2:first-of-type {
  margin-top: 24px;
}

.doc h3 {
  margin: 28px 0 10px;
  font-size: 16px;
  font-weight: 650;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.doc h4 {
  margin: 20px 0 8px;
  font-size: 14.5px;
  font-weight: 650;
}

.doc p {
  margin: 0 0 14px;
}

.doc ul,
.doc ol {
  margin: 0 0 16px;
  padding-left: 1.4em;
}

.doc li {
  margin-bottom: 6px;
}

.doc li > ul,
.doc li > ol {
  margin-top: 6px;
  margin-bottom: 0;
}

.doc hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.doc strong {
  font-weight: 650;
}

.doc blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--quote-border);
  background: rgba(11, 107, 203, 0.05);
  color: var(--text-secondary);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.doc blockquote p:last-child {
  margin-bottom: 0;
}

.doc code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 0.12em 0.4em;
  background: var(--code-bg);
  border-radius: 4px;
  color: #c7254e;
}

.doc pre {
  margin: 0 0 18px;
  padding: 14px 16px;
  background: #0f1b2d;
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.55;
}

.doc pre code {
  padding: 0;
  background: transparent;
  color: #e8eef6;
  font-size: 13px;
  border-radius: 0;
}

.doc pre code.hljs {
  background: transparent;
  padding: 0;
}

.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 20px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}

.doc thead,
.doc tbody,
.doc tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.doc th,
.doc td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.doc th {
  background: var(--bg);
  font-weight: 650;
  color: var(--text);
}

.doc tbody tr:nth-child(even) {
  background: var(--table-stripe);
}

.doc img {
  max-width: 100%;
  height: auto;
}

/* 上下篇 */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pager a:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(11, 107, 203, 0.08);
  text-decoration: none;
  color: inherit;
}

.pager a.is-empty {
  visibility: hidden;
  pointer-events: none;
}

.pager__dir {
  font-size: 12px;
  color: var(--text-secondary);
}

.pager__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.pager__next {
  text-align: right;
}

/* ========== 本页 TOC ========== */
.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 28px);
  align-self: flex-start;
  width: var(--toc-w);
  flex-shrink: 0;
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
  padding-left: 4px;
}

.toc__label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-secondary);
}

.toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--border);
}

.toc__list a {
  display: block;
  padding: 4px 0 4px 12px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
}

.toc__list a:hover {
  color: var(--accent);
}

.toc__list a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc__list .toc-h3 {
  padding-left: 22px;
  font-size: 12px;
}

.toc.is-empty {
  display: none;
}

/* ========== 搜索无结果提示 ========== */
.search-hint {
  margin: 8px 20px 0;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--sidebar-muted);
}

/* ========== 响应式：平板 / 手机 ========== */
@media (max-width: 1100px) {
  .toc {
    display: none;
  }
}

@media (max-width: 860px) {
  .menu-btn {
    display: flex;
  }

  .topbar__links {
    display: none;
  }

  .topbar__search {
    max-width: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-drawer);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 80;
    background: transparent;
  }

  .sidebar-backdrop[hidden] {
    display: none !important;
  }

  .main {
    padding: 16px 14px 48px;
  }

  .doc {
    padding: 24px 18px 36px;
    border-radius: 6px;
  }

  .doc h1 {
    font-size: 22px;
  }

  .doc h2 {
    font-size: 18px;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager__next {
    text-align: left;
  }

  .brand__sub {
    display: none;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .topbar__search input {
    font-size: 14px;
  }
}

/* 打印 */
@media print {
  .topbar,
  .sidebar,
  .toc,
  .pager,
  .menu-btn {
    display: none !important;
  }

  .main {
    padding: 0;
  }

  .doc {
    border: none;
    padding: 0;
  }
}
