:root {
  color-scheme: light dark;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2333;
  --text: #e6edf3;
  --muted: #8b949e;
  --link: #58a6ff;
  --border: #30363d;
  --accent: #238636;
  --danger: #f85149;
  --code-bg: rgba(110, 118, 129, 0.15);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --panel: #ffffff;
    --panel-2: #f6f8fa;
    --text: #1f2328;
    --muted: #656d76;
    --link: #0969da;
    --border: #d0d7de;
    --accent: #1a7f37;
    --danger: #cf222e;
    --code-bg: rgba(175, 184, 193, 0.2);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.app {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

.brand {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: .75rem;
  color: var(--text);
}

.search input {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

.tree-nav {
  padding: .75rem 0 2rem;
  overflow: auto;
  flex: 1;
}

.tree {
  list-style: none;
  margin: 0;
  padding: 0 .5rem 0 1rem;
}

.tree li {
  margin: .1rem 0;
  font-size: .92rem;
}

.tree details > summary {
  cursor: pointer;
  list-style: none;
  padding: .2rem .35rem;
  border-radius: 6px;
}

.tree details > summary::-webkit-details-marker { display: none; }

.tree details > summary:hover,
.tree li.file a:hover {
  background: var(--panel-2);
}

.tree li.active > a,
.tree li.active > details > summary {
  background: var(--panel-2);
  font-weight: 600;
}

.tree .icon {
  display: inline-block;
  width: 1.6rem;
  opacity: .75;
  font-size: .75rem;
}

.content-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 1;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  color: var(--muted);
  font-size: .9rem;
}

.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--link); }

.actions .btn,
.btn {
  display: inline-flex;
  align-items: center;
  padding: .45rem .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: .9rem;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn:hover { text-decoration: none; filter: brightness(1.05); }

.main {
  padding: 1.25rem 1.5rem 2.5rem;
  overflow: auto;
}

.doc, .welcome, .search-results {
  max-width: 900px;
}

.doc h1, .welcome h1, .search-results h1 {
  margin-top: 0;
  line-height: 1.25;
}

.meta, .muted, .lead {
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.stats dt {
  color: var(--muted);
  font-size: .85rem;
}

.stats dd {
  margin: .15rem 0 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.alert.error {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.markdown-body pre,
.markdown-body code {
  background: var(--code-bg);
  border-radius: 6px;
}

.markdown-body pre {
  padding: .85rem 1rem;
  overflow: auto;
}

.markdown-body code {
  padding: .12rem .35rem;
  font-size: .92em;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  display: block;
  overflow: auto;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: .45rem .65rem;
}

.result-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}

.result-list li {
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}

.result-meta {
  color: var(--muted);
  font-size: .85rem;
  margin-top: .15rem;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}
