/* ===== Design Tokens ===== */
:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-2: #f3f4f6;
  --text: #171717;
  --text-muted: #6b7280;
  --brand: #2563eb;
  --brand-light: #eff6ff;
  --brand-dark: #1d4ed8;
  --code-bg: #f3f4f6;
  --code-text: #1f2937;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 280px;
  --toc-width: 240px;
  --content-max: 780px;
  --font-sans: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --surface: #121212;
  --surface-2: #1a1a1a;
  --text: #f5f5f5;
  --text-muted: #9ca3af;
  --brand: #3b82f6;
  --brand-light: rgba(59,130,246,0.15);
  --brand-dark: #60a5fa;
  --code-bg: #1f2937;
  --code-text: #e5e7eb;
  --border: #27272a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="system"] {
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0a0a0a;
    --surface: #121212;
    --surface-2: #1a1a1a;
    --text: #f5f5f5;
    --text-muted: #9ca3af;
    --brand: #3b82f6;
    --brand-light: rgba(59,130,246,0.15);
    --brand-dark: #60a5fa;
    --code-bg: #1f2937;
    --code-text: #e5e7eb;
    --border: #27272a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Topbar ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 60px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .topbar,
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .topbar { background: rgba(10,10,10,0.85); }
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap;
}
.logo .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}

.search-wrap {
  flex: 1; max-width: 420px; position: relative;
}
.search-input {
  width: 100%; height: 38px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 14px 0 36px;
  background: var(--bg); color: var(--text); font-size: 14px;
  outline: none;
}
.search-input:focus { border-color: var(--brand); }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
}
.search-dropdown {
  position: absolute; top: 44px; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto;
  display: none; z-index: 200;
}
.search-dropdown.show { display: block; }
.search-dropdown a {
  display: block; padding: 10px 14px; color: var(--text); border-bottom: 1px solid var(--border);
}
.search-dropdown a:hover { background: var(--brand-light); text-decoration: none; }
.search-dropdown small { display: block; color: var(--text-muted); font-size: 12px; }

.topbar-right {
  margin-left: auto; display: flex; align-items: center; gap: 14px;
  font-size: 13px; color: var(--text-muted); white-space: nowrap;
}

.theme-toggle {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 10px; font-size: 13px; color: var(--text); cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ===== Layout ===== */
.layout {
  display: flex;
  padding-top: 60px;
  min-height: 100vh;
}

.sidebar {
  position: fixed; top: 60px; left: 0; bottom: 0;
  width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 20px 0;
}

.sidebar-nav { padding: 0 16px; }
.nav-section { margin-bottom: 24px; }
.nav-section-title {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0 12px 8px;
}
.nav-list { list-style: none; }
.nav-link {
  display: block; padding: 7px 12px; border-radius: var(--radius);
  color: var(--text-muted); font-size: 14px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-light); color: var(--brand); font-weight: 600; }

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 32px 40px;
  min-width: 0;
}

/* ===== Content ===== */
.content {
  width: 100%; max-width: var(--content-max);
  min-width: 0;
}

.doc-page {
  display: grid;
  grid-template-columns: 1fr var(--toc-width);
  gap: 40px;
  align-items: start;
  width: 100%; max-width: calc(var(--content-max) + var(--toc-width) + 40px);
}

.doc-header { margin-bottom: 32px; grid-column: 1; }
.doc-meta { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 100px;
  background: var(--brand-light); color: var(--brand); font-size: 12px; font-weight: 600;
}
.doc-title { font-size: 34px; font-weight: 700; line-height: 1.25; letter-spacing: -0.02em; }
.doc-summary {
  margin-top: 14px; padding: 14px 18px;
  background: var(--brand-light); border-radius: var(--radius-lg);
  color: var(--text-muted); font-size: 14px;
}

.endpoint-summary {
  margin-bottom: 32px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  grid-column: 1;
}
.endpoint-summary summary {
  font-weight: 600; cursor: pointer; color: var(--text);
}
.endpoint-list { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.endpoint-chip {
  display: inline-block; padding: 4px 10px; border-radius: 6px;
  background: var(--code-bg); color: var(--code-text); font-size: 13px; font-family: var(--font-mono);
}

.doc-body { grid-column: 1; }

/* ===== TOC ===== */
.toc {
  position: sticky; top: 90px;
  width: var(--toc-width);
  font-size: 13px; color: var(--text-muted);
  align-self: start;
}
.toc-title {
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 12px; color: var(--text-muted);
}
.toc ul { list-style: none; }
.toc li { margin: 6px 0; }
.toc a {
  display: block; color: var(--text-muted); padding: 3px 0;
  border-left: 2px solid transparent; padding-left: 10px;
}
.toc a:hover { color: var(--brand); text-decoration: none; }
.toc a.active { color: var(--brand); border-left-color: var(--brand); font-weight: 600; }
.toc-empty { color: var(--text-muted); font-style: italic; }

/* ===== Markdown Body ===== */
.md-body h1 { font-size: 30px; margin: 40px 0 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.md-body h2 { font-size: 24px; margin: 32px 0 14px; font-weight: 700; }
.md-body h3 { font-size: 19px; margin: 24px 0 10px; font-weight: 600; }
.md-body p { margin: 14px 0; }
.md-body ul, .md-body ol { margin: 14px 0; padding-left: 24px; }
.md-body li { margin: 6px 0; }
.md-body code {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--code-bg); color: var(--code-text);
  padding: 2px 6px; border-radius: 5px;
}
.md-body pre {
  position: relative;
  background: var(--code-bg); color: var(--code-text);
  padding: 16px; border-radius: var(--radius-lg); overflow-x: auto;
  margin: 16px 0; font-size: 13px; line-height: 1.6;
}
.md-body pre code { background: transparent; padding: 0; }
.md-body table {
  width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px;
}
.md-body th, .md-body td {
  padding: 10px 12px; border: 1px solid var(--border); text-align: left; vertical-align: top;
}
.md-body th { background: var(--surface-2); font-weight: 600; }
.md-body blockquote {
  border-left: 3px solid var(--brand); background: var(--brand-light);
  padding: 12px 16px; margin: 16px 0; border-radius: 0 var(--radius) var(--radius) 0;
}
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.md-body details { margin: 16px 0; }
.md-body summary { cursor: pointer; font-weight: 600; }

/* Copy button */
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 10px; font-size: 12px; color: var(--text-muted); cursor: pointer;
}
.copy-btn:hover { background: var(--border); color: var(--text); }
.copy-btn.copied { color: var(--brand); }

/* ===== Home Page ===== */
.home-page { max-width: 1000px; }
.hero { text-align: center; padding: 60px 0 50px; }
.hero h1 { font-size: 42px; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 14px; }
.hero p { font-size: 18px; color: var(--text-muted); max-width: 560px; margin: 0 auto 24px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 22px; border-radius: var(--radius); font-size: 15px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.section-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px;
  margin-bottom: 60px;
}
.section-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px;
}
.section-card h2 { font-size: 16px; font-weight: 700; margin-bottom: 14px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; }
.section-card ul { list-style: none; }
.section-card li { margin: 8px 0; }
.section-card a { font-size: 14px; color: var(--text); }
.section-card a:hover { color: var(--brand); }

.home-features { margin-bottom: 60px; }
.home-features h2 { font-size: 22px; margin-bottom: 20px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.feature-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.feature-card h3 { font-size: 16px; margin-bottom: 8px; }
.feature-card p { font-size: 14px; color: var(--text-muted); }

.doc-footer-nav { margin-top: 60px; padding-top: 24px; border-top: 1px solid var(--border); }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .doc-page { grid-template-columns: 1fr; }
  .toc { display: none; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 24px 20px; }
  .topbar { padding: 0 16px; }
  .topbar-right { display: none; }
  .search-wrap { max-width: none; }
  .hero h1 { font-size: 30px; }
}
