:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-bg: #eff6ff;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --sidebar-width: 280px;
  --transition-fast: 0.15s ease;
  --transition: 0.25s ease;
  --transition-slow: 0.35s ease;

  --highlight-bg: #f6f8fa;
  --highlight-color: #24292f;
  --highlight-keyword: #d73a49;
  --highlight-string: #032f62;
  --highlight-comment: #6a737d;
  --highlight-number: #005cc5;
  --highlight-title: #6f42c1;
  --highlight-attr: #005cc5;
  --highlight-builtin: #d73a49;
  --highlight-tag: #22863a;
  --highlight-variable: #e36209;
  --highlight-meta: #005cc5;
  --highlight-regexp: #032f62;
  --highlight-deletion: #b31d28;
  --highlight-addition: #22863a;
  --highlight-literal: #005cc5;
  --highlight-type: #d73a49;
  --highlight-selector-tag: #22863a;
  --highlight-selector-id: #6f42c1;
  --highlight-selector-class: #6f42c1;
  --highlight-template-tag: #22863a;
  --highlight-template-variable: #6f42c1;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

.brand-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 6px;
  display: inline-block;
  flex-shrink: 0;
}

.brand-text {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.navbar-brand:hover .brand-text {
  -webkit-text-fill-color: var(--primary-dark);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.theme-toggle:hover {
  background: var(--primary-bg);
  border-color: var(--primary-light);
}

.sidebar {
  position: fixed;
  top: 56px;
  bottom: 0;
  left: 0;
  z-index: 100;
  padding: 20px 0 60px;
  overflow-y: auto;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  transition: background-color var(--transition), border-color var(--transition);
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.nav-link,
.nav-text {
  display: block;
  padding: 7px 16px;
  color: #64748b;
  text-decoration: none;
  font-size: 0.9em;
  border-radius: 0 6px 6px 0;
  border-left: 3px solid transparent;
  transition: all var(--transition-fast);
  line-height: 1.4;
}

.nav-link:hover {
  color: var(--primary);
  background: var(--primary-bg);
  border-left-color: var(--accent);
}

.nav-link.active {
  background: var(--primary-bg);
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.nav-item.has-children > .nav-text {
  font-weight: 600;
  color: #1e293b;
  margin-top: 18px;
  margin-bottom: 2px;
  font-size: 0.82em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: default;
  padding: 6px 16px;
}

.nav-item.has-children > .nav-text::after {
  content: "";
  display: none;
}

.nav-item.has-children .list-unstyled {
  padding: 0;
}

.nav-item.has-children .nav-link {
  padding-left: 28px;
  font-size: 0.87em;
}

main {
  padding-top: 24px;
  padding-bottom: 60px;
}

.doc {
  line-height: 1.78;
  max-width: 820px;
  font-size: 0.98em;
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.doc > h1 {
  font-size: 2.2em;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.2em;
  background: linear-gradient(135deg, #1e293b, #475569);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.doc h2 {
  font-size: 1.45em;
  font-weight: 700;
  margin-top: 2.5em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid #e2e8f0;
  letter-spacing: -0.01em;
}

.doc h3 { font-size: 1.15em; font-weight: 700; margin-top: 1.8em; }
.doc h4 { font-weight: 600; margin-top: 1.5em; font-size: 1.02em; }

.doc h2[id]:hover .anchor::after,
.doc h3[id]:hover .anchor::after,
.doc h4[id]:hover .anchor::after,
.doc h5[id]:hover .anchor::after {
  content: "#";
  color: var(--primary);
  opacity: 0.5;
  margin-left: 6px;
  font-weight: 400;
}

.doc .anchor {
  position: relative;
  text-decoration: none;
  border-bottom: none;
  color: inherit;
}

.doc .anchor::before {
  content: "";
  display: block;
  height: 70px;
  margin-top: -70px;
  visibility: hidden;
}

.doc a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid var(--primary-light);
  transition: all var(--transition-fast);
}

.doc a:hover {
  color: var(--primary-dark);
  border-bottom-color: var(--primary-dark);
}

.doc code {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, Monaco, monospace;
  font-size: 0.88em;
}

.doc .listingblock,
.doc .literalblock {
  background: var(--highlight-bg);
  border: 1px solid #d0d7de;
  border-radius: 10px;
  overflow: hidden;
  margin: 1.2em 0;
  position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.doc .listingblock::after,
.doc .literalblock::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 14px;
  color: #64748b;
  font-size: 14px;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.doc .listingblock:hover::after,
.doc .literalblock:hover::after {
  opacity: 0.6;
}

.doc .listingblock .content,
.doc .literalblock .content {
  padding: 18px 20px;
  overflow-x: auto;
  background: var(--highlight-bg);
}

.doc .listingblock .content pre,
.doc .literalblock .content pre {
  cursor: pointer;
  margin: 0;
}

.doc .listingblock .title,
.doc .literalblock .title {
  display: block;
  padding: 8px 16px;
  background: #eaeef2;
  color: #57606a;
  font-weight: 500;
  font-size: 0.78em;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  border-bottom: 1px solid #d0d7de;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.doc .listingblock pre,
.doc .literalblock pre,
.doc .listingblock code,
.doc .literalblock code {
  background: none;
  color: #24292f;
  border: none;
  padding: 0;
  font-size: 0.87em;
  line-height: 1.7;
}

.doc table {
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-radius: 8px;
  overflow: hidden;
  margin: 1.2em 0;
}

.doc table th {
  background: #f1f5f9;
  font-weight: 600;
  font-size: 0.88em;
  white-space: nowrap;
}

.doc table td {
  font-size: 0.92em;
}

.doc table tbody tr {
  transition: background var(--transition-fast);
}

.doc table tbody tr:hover {
  background: var(--primary-bg);
}

.doc blockquote {
  border-left: 4px solid var(--primary);
  padding: 14px 20px;
  background: var(--primary-bg);
  border-radius: 0 8px 8px 0;
  color: #64748b;
  font-style: italic;
  margin: 1.5em 0;
}

.doc .note,
.doc .tip,
.doc .important,
.doc .warning,
.doc .caution {
  border-radius: 10px;
  padding: 16px 20px;
  margin: 1.5em 0;
  border: 1px solid;
  position: relative;
  overflow: hidden;
}

.doc .note { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.doc .tip { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.doc .important { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }
.doc .warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.doc .caution { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.doc .note::before { background: #6366f1; }
.doc .tip::before { background: #10b981; }
.doc .important::before { background: #8b5cf6; }
.doc .warning::before { background: #f59e0b; }
.doc .caution::before { background: #ef4444; }

.doc .note::before,
.doc .tip::before,
.doc .important::before,
.doc .warning::before,
.doc .caution::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.doc .admonition-title {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 0.95em;
}

.doc .imageblock { text-align: center; margin: 2em 0; }
.doc .imageblock img { border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); max-width: 100%; }
.doc .imageblock .title { margin-top: 10px; color: #94a3b8; font-size: 0.88em; font-style: italic; }

.doc .ulist ul,
.doc .olist ol { padding-left: 1.5em; }

.doc ul li::marker { color: var(--primary); }
.doc ul li { margin-bottom: 4px; }
.doc ol li::marker { color: var(--primary); font-weight: 600; }

.doc .dlist dt { font-weight: 600; color: #1e293b; margin-top: 0.8em; }
.doc .dlist dd { margin-left: 1em; color: #64748b; }

.doc .sect1,
.doc .sect2,
.doc .sect3 { margin-top: 2em; }

.doc .paragraph {
  margin-bottom: 1em;
}

.page-nav {
  margin-bottom: 20px;
  padding: 14px 18px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.page-nav-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0;
}

.page-nav-list li {
  list-style: none;
}

.page-nav-list a {
  color: #64748b;
  font-size: 0.85em;
  text-decoration: none;
  border-bottom: none;
  transition: color var(--transition-fast);
}

.page-nav-list a:hover { color: var(--primary); }

.to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37,99,235,0.3);
  opacity: 0;
  transform: translateY(20px);
  transition: all var(--transition);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.to-top:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37,99,235,0.4);
}

.to-top.visible { opacity: 1; transform: translateY(0); }

.copy-toast {
  position: fixed;
  top: 80px;
  right: 24px;
  background: #10b981;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85em;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(16,185,129,0.3);
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Dark Mode ===== */
[data-bs-theme="dark"] {
  --primary: #60a5fa;
  --primary-dark: #93bbfd;
  --primary-light: #1e3a5f;
  --primary-bg: #1e293b;
  --accent: #38bdf8;
  --accent-dark: #7dd3fc;

  --highlight-bg: #161b22;
  --highlight-color: #e6edf3;
  --highlight-keyword: #ff7b72;
  --highlight-string: #a5d6ff;
  --highlight-comment: #8b949e;
  --highlight-number: #79c0ff;
  --highlight-title: #d2a8ff;
  --highlight-attr: #79c0ff;
  --highlight-builtin: #ff7b72;
  --highlight-tag: #7ee787;
  --highlight-variable: #ffa657;
  --highlight-meta: #79c0ff;
  --highlight-regexp: #a5d6ff;
  --highlight-deletion: #ff7b72;
  --highlight-addition: #a5d6ff;
  --highlight-literal: #79c0ff;
  --highlight-type: #ff7b72;
  --highlight-selector-tag: #7ee787;
  --highlight-selector-id: #d2a8ff;
  --highlight-selector-class: #d2a8ff;
  --highlight-template-tag: #7ee787;
  --highlight-template-variable: #d2a8ff;
}

[data-bs-theme="dark"] body {
  background: #0f172a;
  color: #e2e8f0;
}

[data-bs-theme="dark"] .navbar {
  background: #0f172a !important;
  border-bottom-color: #1e293b !important;
}

[data-bs-theme="dark"] .sidebar {
  background: #0f172a;
  border-right-color: #1e293b;
}

[data-bs-theme="dark"] .nav-link { color: #94a3b8; }
[data-bs-theme="dark"] .nav-link:hover { color: var(--primary); background: #1e293b; }
[data-bs-theme="dark"] .nav-link.active { background: #1e293b; color: var(--primary); }
[data-bs-theme="dark"] .nav-item.has-children > .nav-text { color: #e2e8f0; }

[data-bs-theme="dark"] .doc > h1 {
  background: linear-gradient(135deg, #e2e8f0, #94a3b8);
  -webkit-background-clip: text;
  background-clip: text;
}

[data-bs-theme="dark"] .doc h2 { border-bottom-color: #1e293b; }
[data-bs-theme="dark"] .doc code { background: #343941; color: #e6edf3; }
[data-bs-theme="dark"] .doc blockquote { background: #1e293b; color: #94a3b8; }

[data-bs-theme="dark"] .doc .listingblock pre,
[data-bs-theme="dark"] .doc .literalblock pre,
[data-bs-theme="dark"] .doc .listingblock code,
[data-bs-theme="dark"] .doc .literalblock code {
  color: var(--highlight-color);
}

.doc .listingblock .hljs-keyword,
.doc .listingblock .hljs-selector-tag,
.doc .listingblock .hljs-type { color: var(--highlight-keyword); }
.doc .listingblock .hljs-string,
.doc .listingblock .hljs-addition { color: var(--highlight-string); }
.doc .listingblock .hljs-comment,
.doc .listingblock .hljs-quote { color: var(--highlight-comment); }
.doc .listingblock .hljs-number,
.doc .listingblock .hljs-literal { color: var(--highlight-number); }
.doc .listingblock .hljs-title,
.doc .listingblock .hljs-name,
.doc .listingblock .hljs-selector-id,
.doc .listingblock .hljs-selector-class,
.doc .listingblock .hljs-template-variable { color: var(--highlight-title); }
.doc .listingblock .hljs-attr,
.doc .listingblock .hljs-attribute { color: var(--highlight-attr); }
.doc .listingblock .hljs-built_in,
.doc .listingblock .hljs-meta { color: var(--highlight-builtin); }
.doc .listingblock .hljs-regexp { color: var(--highlight-regexp); }
.doc .listingblock .hljs-tag,
.doc .listingblock .hljs-template-tag { color: var(--highlight-tag); }
.doc .listingblock .hljs-variable { color: var(--highlight-variable); }
.doc .listingblock .hljs-deletion { color: var(--highlight-deletion); }
.doc .listingblock .hljs-emphasis { font-style: italic; }
.doc .listingblock .hljs-strong { font-weight: bold; }

.doc .hljs {
  background: transparent;
}

[data-bs-theme="dark"] .doc .listingblock,
[data-bs-theme="dark"] .doc .literalblock {
  background: var(--highlight-bg);
  border: none;
  box-shadow: none;
}

[data-bs-theme="dark"] .doc .listingblock .title,
[data-bs-theme="dark"] .doc .literalblock .title {
  background: #0d1117;
  border: none;
}

[data-bs-theme="dark"] .doc table th { background: #1e293b; }
[data-bs-theme="dark"] .doc table tbody tr:hover { background: #1e293b; }

[data-bs-theme="dark"] .doc .note { background: #1e293b; border-color: #1e3a5f; color: #93c5fd; }
[data-bs-theme="dark"] .doc .tip { background: #1e293b; border-color: #064e3b; color: #6ee7b7; }
[data-bs-theme="dark"] .doc .important { background: #1e293b; border-color: #3b0764; color: #c4b5fd; }
[data-bs-theme="dark"] .doc .warning { background: #1e293b; border-color: #78350f; color: #fcd34d; }
[data-bs-theme="dark"] .doc .caution { background: #1e293b; border-color: #7f1d1d; color: #fca5a5; }

[data-bs-theme="dark"] .page-nav {
  background: #1e293b;
  border-color: #334155;
}

[data-bs-theme="dark"] .theme-toggle {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

[data-bs-theme="dark"] .breadcrumb { background: transparent; }
[data-bs-theme="dark"] .breadcrumb-item a { color: var(--primary); }
[data-bs-theme="dark"] .breadcrumb-item.active { color: #94a3b8; }

[data-bs-theme="dark"] footer {
  border-top-color: #1e293b !important;
  color: #64748b !important;
}

[data-bs-theme="dark"] .form-select {
  background-color: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 56px;
    z-index: 1040;
    height: calc(100vh - 56px);
  }

  .sidebar.collapse:not(.show) {
    display: none;
  }

  .sidebar.collapsing {
    height: calc(100vh - 56px);
  }

  main {
    margin-left: 0 !important;
  }
}

@media (max-width: 767.98px) {
  .doc > h1 { font-size: 1.8em; }
  .doc h2 { font-size: 1.35em; }
  .to-top { right: 16px; bottom: 16px; width: 40px; height: 40px; font-size: 18px; }
}

@media print {
  nav.navbar,
  .sidebar,
  footer,
  .to-top,
  .page-nav,
  .theme-toggle { display: none !important; }

  main { margin-left: 0 !important; max-width: 100% !important; padding: 0 !important; }

  .doc .listingblock,
  .doc .literalblock {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #1e293b;
  }

  .doc .listingblock code,
  .doc .literalblock code { color: #1e293b; }

  [data-bs-theme="dark"] body { background: #fff; color: #1e293b; }
}