:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-elev: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #59636e;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --code-bg: #f6f8fa;
  --code-border: #d8dee4;
  --topbar-h: 60px;
  --sidebar-w: 290px;
  --toc-w: 240px;
}

html.dark {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-elev: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(56, 139, 253, 0.15);
  --code-bg: #161b22;
  --code-border: #30363d;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  line-height: 1.65;
  font-size: 15px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-wrap { display: flex; align-items: center; gap: 10px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.topnav { display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.nav-link {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--bg-soft); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.search-trigger, .theme-toggle, .menu-toggle {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.search-trigger kbd {
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  background: var(--bg);
}
.menu-toggle { display: none; }

.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  background: var(--bg-soft);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.sidebar-group { margin-bottom: 20px; }
.sidebar-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text); }
.sidebar-badge { margin: 4px 0 8px; }
.sidebar-badge code { font-size: 11px; color: var(--text-muted); }
.sidebar-group ul { list-style: none; margin: 0; padding: 0; }
.sidebar-link {
  display: block;
  padding: 5px 10px;
  margin: 2px 0;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13.5px;
}
.sidebar-link:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.sidebar-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.content-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 32px;
  padding: 28px 36px 64px;
}

.doc-article { max-width: 860px; min-width: 0; }
.breadcrumbs { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.doc-article h1 { font-size: 30px; line-height: 1.25; margin: 0 0 18px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.doc-article h2 { font-size: 22px; margin: 32px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.doc-article h3 { font-size: 17px; margin: 22px 0 8px; }
.doc-article h4 { font-size: 15px; margin: 16px 0 6px; }
.header-anchor { opacity: 0; margin-left: 6px; font-weight: 400; font-size: 0.85em; }
h1:hover .header-anchor, h2:hover .header-anchor, h3:hover .header-anchor { opacity: 0.7; }

.code-block {
  margin: 16px 0;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--code-border);
  font-size: 12px;
  color: var(--text-muted);
}
.copy-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.code-block pre code { border: none; background: transparent; padding: 0; }

.table-wrap { overflow-x: auto; margin: 16px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); font-weight: 600; }

.callout {
  margin: 16px 0;
  padding: 12px 16px;
  border-radius: 6px;
  border-left: 4px solid var(--accent);
  background: var(--bg-soft);
}
.callout-title { font-weight: 700; font-size: 12px; margin-bottom: 4px; letter-spacing: 0.04em; }
.callout p { margin: 0; }
.callout-warning, .callout-caution { border-left-color: #d29922; }
.callout-important { border-left-color: #8250df; }
.callout-tip { border-left-color: #1a7f37; }

blockquote {
  margin: 16px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding-left: 14px;
  font-size: 13px;
}
.toc-title { font-weight: 700; margin-bottom: 8px; font-size: 12px; text-transform: uppercase; color: var(--text-muted); }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 4px 0; }
.toc li.toc-l3 { padding-left: 12px; font-size: 12.5px; }
.toc a { color: var(--text-muted); }
.toc a:hover { color: var(--accent); }

.pager {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.pager-link {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.pager-link.next { text-align: right; }
.pager-link:hover { border-color: var(--accent); text-decoration: none; }
.pager-dir { font-size: 12px; color: var(--text-muted); }
.pager-title { font-weight: 600; font-size: 14px; }

.search-modal[hidden] { display: none; }
.search-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding-top: 10vh; }
.search-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); }
.search-dialog {
  position: relative;
  z-index: 61;
  width: min(640px, 92vw);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}
.search-input-row { display: flex; padding: 10px 12px; border-bottom: 1px solid var(--border); gap: 8px; }
.search-input-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}
.search-input-row button {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
}
.search-results { list-style: none; margin: 0; padding: 8px; max-height: 55vh; overflow-y: auto; }
.search-results li a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
}
.search-results li a:hover, .search-results li a.selected { background: var(--accent-soft); text-decoration: none; }
.search-res-title { font-weight: 600; font-size: 14px; }
.search-res-role { font-size: 11.5px; color: var(--accent); margin-left: 6px; }
.search-res-snippet { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 1120px) {
  .content-wrap { grid-template-columns: 1fr; padding: 24px; }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; }
  .topnav { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    display: none;
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    width: 290px;
    z-index: 40;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
  }
  .sidebar.open { display: block; }
}
