/* ===== Design tokens ===== */
:root {
  --bg: #ffffff;
  --bg-alt: #f6f8fa;
  --bg-elevated: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #59636e;
  --accent: #0969da;
  --accent-bg: #ddf4ff;
  --code-bg: #f6f8fa;
  --shadow: 0 4px 16px rgba(0,0,0,.08);
  --radius: 8px;
  --sidebar-w: 280px;
  --topbar-h: 56px;
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --bg-elevated: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #9198a1;
  --accent: #4493f8;
  --accent-bg: #0c2d6b;
  --code-bg: #161b22;
  --shadow: 0 4px 16px rgba(0,0,0,.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --bg-alt: #161b22; --bg-elevated: #161b22; --border: #30363d;
    --text: #e6edf3; --text-muted: #9198a1; --accent: #4493f8; --accent-bg: #0c2d6b;
    --code-bg: #161b22; --shadow: 0 4px 16px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }

/* ===== Topbar ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar__logo {
  font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap;
}
.topbar__logo span { color: var(--text-muted); font-weight: 400; }
.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  font-size: 18px; padding: 6px 10px; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg-alt); border-color: var(--border); }
#menu-toggle { display: none; }

.search-box { position: relative; flex: 1; max-width: 480px; margin: 0 auto; }
.search-box input {
  width: 100%; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-alt); color: var(--text); font-size: 14px;
}
.search-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-height: 60vh; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 200;
}
.search-result { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg-alt); text-decoration: none; }
.search-result__title { font-weight: 600; font-size: 14px; }
.search-result__snippet { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.search-empty { padding: 14px; color: var(--text-muted); font-size: 14px; }

/* ===== Layout ===== */
.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  overflow-y: auto; border-right: 1px solid var(--border); background: var(--bg-alt);
  padding: 16px 8px;
}
.main-col {
  margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.content { max-width: 900px; padding: 8px 40px 60px; flex: 1; }

.breadcrumb {
  padding: 14px 40px 0; font-size: 13px; color: var(--text-muted); max-width: 900px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb__sep { margin: 0 6px; opacity: .6; }

.site-footer {
  border-top: 1px solid var(--border); padding: 20px 40px 32px; max-width: 900px;
  font-size: 13px; color: var(--text-muted);
}
.site-footer div:first-child { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.site-footer__muted { max-width: 640px; }

.source-bar {
  font-size: 12px; color: var(--text-muted); background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 12px; margin: 10px 0 18px; display: inline-block;
}
.source-bar a { color: var(--text-muted); text-decoration: underline; }
.source-bar a:hover { color: var(--accent); }
.source-bar__date { opacity: .8; }

/* ===== Nav tree ===== */
.nav-group { margin-bottom: 2px; }
.nav-link {
  display: block; padding: 7px 10px; border-radius: 6px; font-size: 14px; color: var(--text);
}
.nav-link:hover { background: var(--bg-elevated); text-decoration: none; }
.nav-link--active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav-link--top { font-weight: 500; }
.nav-group { position: relative; }
.nav-group__toggle {
  position: absolute; left: -2px; top: 6px; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 11px; width: 16px; padding: 4px;
}
.nav-group:has(.nav-group__toggle) .nav-link--top { padding-left: 22px; }
.nav-children { display: none; padding-left: 16px; border-left: 1px solid var(--border); margin-left: 8px; }
.nav-group--expanded .nav-children { display: block; }
.nav-link--child { font-size: 13px; color: var(--text-muted); padding: 5px 10px; }
.nav-link--child.nav-link--active { color: var(--accent); }

/* ===== Content typography ===== */
.content h1 { font-size: 30px; margin: 0 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.content h2 { font-size: 22px; margin: 36px 0 12px; }
.content h3 { font-size: 17px; margin: 24px 0 8px; }
.content h4 { font-size: 15px; margin: 18px 0 6px; color: var(--text-muted); }
.content p { margin: 12px 0; }
.content .lead { font-size: 16px; color: var(--text-muted); }
.content ul, .content ol { padding-left: 24px; }
.content li { margin: 4px 0; }
.content blockquote {
  margin: 12px 0; padding: 8px 16px; border-left: 3px solid var(--accent);
  background: var(--bg-alt); color: var(--text-muted);
}
.content hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.content code { background: var(--code-bg); padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.md-code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.5; margin: 12px 0;
}
.md-code code { background: none; padding: 0; }
.md-table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
th { background: var(--bg-alt); font-weight: 600; }
.note {
  background: var(--accent-bg); border-radius: var(--radius); padding: 10px 14px; font-size: 14px;
}

/* ===== Home / loading / error ===== */
.loading, .empty-state { color: var(--text-muted); padding: 40px 0; text-align: center; }
.error-state h1 { border: none; }

/* ===== Flow diagram ===== */
.flow-diagram { display: flex; flex-direction: column; align-items: center; margin: 24px 0; }
.flow-step {
  display: block; width: 100%; max-width: 480px; background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 18px; color: var(--text);
}
.flow-step:hover { border-color: var(--accent); text-decoration: none; }
.flow-step__label { font-weight: 700; font-size: 15px; }
.flow-step__desc { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.flow-arrow { font-size: 18px; color: var(--text-muted); padding: 2px 0; }

/* ===== Core / file cards ===== */
.core-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-top: 16px; }
.core-cat-card {
  display: block; background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; color: var(--text);
}
.core-cat-card:hover { border-color: var(--accent); text-decoration: none; }
.core-cat-card__title { font-weight: 600; }
.core-cat-card__count { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-card {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-alt);
  padding: 0;
}
.file-card summary {
  display: flex; align-items: baseline; gap: 10px; padding: 10px 14px; cursor: pointer; list-style: none;
}
.file-card summary::-webkit-details-marker { display: none; }
.file-card__name { font-weight: 600; font-family: monospace; }
.file-card__path { font-size: 12px; color: var(--text-muted); }
.file-card__body { padding: 0 14px 14px; }
.file-card__desc { color: var(--text-muted); }
.file-card__exports { margin: 6px 0 10px; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 10px; margin: 2px 3px 2px 0;
  background: var(--accent-bg); color: var(--accent); font-family: monospace;
}
.file-card--error .file-card__err { color: #d1242f; padding: 10px 14px; }

/* ===== Capability grid ===== */
.cap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 16px; }
.cap-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--bg-alt); }
.cap-card h3 { margin: 0 0 6px; font-family: monospace; }
.cap-card__used { font-size: 13px; }

/* ===== ADR list ===== */
.adr-list { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.adr-row {
  display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
  background: var(--bg-alt);
}
.adr-row:hover { border-color: var(--accent); text-decoration: none; }
.adr-row__id { font-family: monospace; font-weight: 700; color: var(--accent); }
.adr-row__status { font-size: 12px; color: var(--text-muted); }

/* ===== API reference table ===== */
.api-filter {
  width: 100%; padding: 8px 12px; margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-alt); color: var(--text); font-size: 14px;
}
.table-wrap { overflow-x: auto; }
.api-table td { vertical-align: top; font-size: 13px; }
.api-row__path { font-size: 11px; color: var(--text-muted); }
.api-row.api-row--hidden { display: none; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  #menu-toggle { display: inline-block; }
  .sidebar {
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
    width: 260px; z-index: 90;
  }
  .sidebar.sidebar--open { transform: translateX(0); }
  .main-col { margin-left: 0; }
  .content { padding: 8px 20px 40px; }
  .breadcrumb, .site-footer { padding-left: 20px; padding-right: 20px; }
  .topbar__logo span { display: none; }
  .search-box { max-width: none; }
}
