:root {
  --bg: #f4f6fa;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-code: #eef1f6;
  --border: #e2e7f0;
  --text: #1f2733;
  --text-dim: #5c6676;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --green: #059669;
  --amber: #b45309;
  --red: #dc2626;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; min-height: 100vh; }

/* ============ 侧边栏 ============ */
#sidebar {
  width: 300px;
  min-width: 300px;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
}
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  color: #fff;
  font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.site-brand h1 { margin: 0; font-size: 16px; line-height: 1.3; color: var(--text); }
.site-brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

.search-box { padding: 0 16px 14px; position: relative; }
.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-results {
  position: absolute; left: 16px; right: 16px; top: 42px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.12); z-index: 30;
  display: none; max-height: 320px; overflow-y: auto;
}
.search-results.show { display: block; }
.sr-item { display: block; padding: 8px 12px; text-decoration: none; border-bottom: 1px solid var(--border); }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg); }
.sr-title { display: block; font-size: 13px; color: var(--text); font-weight: 600; }
.sr-group { display: block; font-size: 11px; color: var(--text-dim); }
.sr-empty { padding: 10px 12px; font-size: 12.5px; color: var(--text-dim); }

#chapter-nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.nav-group {
  padding: 10px 12px 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.nav-page {
  display: block;
  padding: 8px 12px 8px 16px;
  margin: 1px 0;
  border-radius: 7px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 2px solid transparent;
  transition: background .15s, color .15s;
}
.nav-page:hover { background: var(--bg); color: var(--text); }
.nav-page.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* 面包屑 + 上下页 */
.breadcrumb { font-size: 13px; color: var(--text-dim); margin-bottom: 18px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.bc-sep { margin: 0 8px; color: #c3cbd8; }
.bc-group { color: var(--text-dim); }
.bc-current { color: var(--text); font-weight: 600; }

#prevnext { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.pn { display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; color: var(--accent); text-decoration: none; background: #fff; }
.pn:hover { background: var(--accent-soft); }
.pn.disabled { color: var(--text-dim); background: transparent; cursor: default; }

.sidebar-footer { padding: 12px 20px; font-size: 11.5px; color: var(--text-dim); border-top: 1px solid var(--border); }

/* ============ 主内容 ============ */
#content { flex: 1; padding: 40px 48px 60px; max-width: 1080px; }

.page-hero { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.page-hero h1 { font-size: 28px; margin: 0 0 12px; line-height: 1.3; }
.page-hero .lead { color: var(--text-dim); font-size: 15px; margin: 0; }

section[data-sec] { margin-bottom: 44px; scroll-margin-top: 20px; }
section[data-sec] > h1 {
  font-size: 22px;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent-soft);
}
h2 { font-size: 18px; margin: 26px 0 10px; color: #1f2733; }
h2::before { content: "▍"; color: var(--accent); margin-right: 6px; }
h3 { font-size: 15.5px; margin: 20px 0 8px; color: #1f2733; }

.lead { color: var(--text-dim); }
p { margin: 10px 0; }
ul, ol { margin: 10px 0; padding-left: 24px; }
li { margin: 5px 0; }
strong { color: #0f172a; }
a { color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--bg-code);
  padding: 1px 6px;
  border-radius: 5px;
  color: #0b5cad;
  border: 1px solid var(--border);
}

/* 表格 */
.table-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: #f0f4fa; color: #0f172a; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(37, 99, 235, 0.04); }
td:first-child { white-space: nowrap; font-weight: 500; color: #334155; }

/* 提示框 */
.note, .warn, .tip, .danger {
  margin: 18px 0;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: #fff;
  font-size: 14px;
}
.tip { border-left-color: var(--green); }
.warn { border-left-color: var(--amber); }
.danger { border-left-color: var(--red); }

/* 架构图 */
.diagram {
  margin: 22px 0;
  padding: 18px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
}
.diagram svg { width: 100%; height: auto; display: block; }
.diagram figcaption { font-size: 12.5px; color: var(--text-dim); margin-top: 12px; }

/* 参考列表 */
.refs { list-style: none; padding-left: 0; }
.refs li { margin: 8px 0; font-size: 14px; }

.foot-note { font-size: 12.5px; color: var(--text-dim); }

#page-footer {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

/* 搜索高亮隐藏 */
section[data-sec].dimmed { opacity: 0.25; }

/* 响应式 */
@media (max-width: 860px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  #chapter-nav { max-height: 220px; }
  #content { padding: 24px 18px 48px; }
  .page-hero h1 { font-size: 22px; }
}
