/* Page layout: top nav, sidebar, content, table of contents */

.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topnav-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  z-index: 100;
}

.topnav__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  font-weight: 700;
  font-size: var(--fs-lg);
  white-space: nowrap;
}
.topnav__brand .dot { color: var(--accent-400); }

.topnav__hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.4rem;
}

.topnav__search {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.topnav__search input {
  width: 100%;
  background: var(--bg-sidebar-hover);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.8rem 0.5rem 2.2rem;
  font-size: var(--fs-sm);
  font-family: var(--font-sans);
}
.topnav__search input::placeholder { color: #94a3b8; }
.topnav__search svg.search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: #94a3b8;
  pointer-events: none;
}
.topnav__search kbd {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-xs);
  color: #94a3b8;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  font-family: var(--font-mono);
}

.topnav__spacer { flex: 1; }

.topnav__links {
  display: flex;
  gap: 1.2rem;
  align-items: center;
}
.topnav__links a {
  color: #cbd5e1;
  font-size: var(--fs-sm);
  font-weight: 500;
}
.topnav__links a:hover { color: #fff; text-decoration: none; }

.theme-toggle {
  background: var(--bg-sidebar-hover);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: var(--radius-md);
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.theme-toggle svg { width: 18px; height: 18px; }

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  min-width: 420px;
  background: var(--bg-content);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 200;
  display: none;
}
.search-results.open { display: block; }
.search-result-item {
  display: block;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-card); text-decoration: none; }
.search-result-item .srt-title { font-weight: 600; font-size: var(--fs-sm); }
.search-result-item .srt-breadcrumb { font-size: var(--fs-xs); color: var(--accent-600); margin: 0.15rem 0; }
.search-result-item .srt-excerpt { font-size: var(--fs-xs); color: var(--text-muted); }
.search-empty { padding: 1rem; color: var(--text-muted); font-size: var(--fs-sm); }

/* Body shell */
.app-shell {
  display: flex;
  padding-top: var(--topnav-height);
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  position: fixed;
  top: var(--topnav-height);
  bottom: 0;
  left: 0;
  overflow-y: auto;
  padding: 1.2rem 0.8rem 3rem;
  z-index: 50;
}

.sidebar__section { margin-bottom: 0.3rem; }

.sidebar__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 0.6rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.sidebar__heading:hover { background: var(--bg-sidebar-hover); }
.sidebar__heading .chev { transition: transform 0.15s ease; width: 14px; height: 14px; }
.sidebar__heading[aria-expanded="false"] .chev { transform: rotate(-90deg); }

.sidebar__list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 0.4rem;
}
.sidebar__list.collapsed { display: none; }

.sidebar__list a {
  display: block;
  color: var(--text-sidebar);
  font-size: var(--fs-sm);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
}
.sidebar__list a:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar__list a.active {
  color: var(--text-sidebar-active);
  background: var(--bg-sidebar-hover);
  border-left-color: var(--accent-400);
  font-weight: 600;
}

.sidebar__top-link {
  display: block;
  color: var(--text-sidebar);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
}
.sidebar__top-link:hover { background: var(--bg-sidebar-hover); color: #fff; text-decoration: none; }
.sidebar__top-link.active { color: var(--text-sidebar-active); background: var(--bg-sidebar-hover); }

/* Main content area */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  min-width: 0;
}

.content {
  flex: 1;
  min-width: 0;
  max-width: 860px;
  padding: 2.4rem 3rem 5rem;
}

.toc {
  width: var(--toc-width);
  flex-shrink: 0;
  padding: 2.4rem 1.5rem 2rem 0;
}
.toc__inner {
  position: sticky;
  top: calc(var(--topnav-height) + 24px);
}
.toc__title {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.toc ul { list-style: none; padding-left: 0; margin: 0; }
.toc ul ul { padding-left: 0.9rem; }
.toc a {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  padding: 0.25rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.6rem;
}
.toc a:hover { color: var(--accent-600); text-decoration: none; }
.toc a.active { color: var(--accent-600); border-left-color: var(--accent-600); font-weight: 600; }

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}
.sidebar-overlay.open { display: block; }

footer.page-footer {
  border-top: 1px solid var(--border-color);
  margin-top: 3rem;
  padding-top: 1.5rem;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Mobile breakpoint */
@media (max-width: 1100px) {
  .toc { display: none; }
}

@media (max-width: 768px) {
  .topnav__hamburger { display: flex; align-items: center; }
  .topnav__links { display: none; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 85%;
    max-width: 320px;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .content { padding: 1.5rem 1.2rem 3rem; }
  .topnav__search { max-width: none; }
}

@media (max-width: 480px) {
  .topnav__search { display: none; }
}
