/* ============================================================
   LAYOUT — App shell, sidebar, content, TOC
   ============================================================ */

/* ── App Shell ───────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}

.app-shell--home {
  grid-template-columns: 1fr;
  grid-template-areas:
    "header"
    "main";
}

/* ── Header ──────────────────────────────────────────────── */
.site-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-height);
  display: flex;
  align-items: center;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: 0 var(--space-6);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  min-width: calc(var(--sidebar-width) - var(--space-6));
}

.site-logo__icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.site-logo__text span {
  color: var(--brand-primary);
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.site-sidebar {
  grid-area: sidebar;
  width: var(--sidebar-width);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--border-color);
  background: var(--bg-surface);
  padding: var(--space-4) 0;
  scrollbar-width: thin;
}

.sidebar-section {
  margin-bottom: var(--space-2);
}

.sidebar-section__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4) var(--space-1);
}

.sidebar-nav { list-style: none; }

.sidebar-nav__item {}

.sidebar-nav__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-radius: 0;
  transition: all var(--dur-fast) var(--ease-smooth);
  border-left: 3px solid transparent;
  text-decoration: none;
  position: relative;
}

.sidebar-nav__link:hover {
  color: var(--text-primary);
  background: var(--border-subtle);
  text-decoration: none;
}

.sidebar-nav__link.active {
  color: var(--brand-primary);
  background: rgba(99,102,241,.08);
  border-left-color: var(--brand-primary);
  font-weight: var(--weight-medium);
}

.sidebar-nav__icon {
  font-size: 1rem;
  opacity: 0.7;
  flex-shrink: 0;
}

.sidebar-nav__badge {
  margin-left: auto;
  font-size: var(--text-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 1px 6px;
  color: var(--text-muted);
}

/* Sub-nav */
.sidebar-nav__sub {
  list-style: none;
  display: none;
  padding-left: var(--space-4);
}

.sidebar-nav__item--open .sidebar-nav__sub { display: block; }

.sidebar-nav__sub-link {
  display: block;
  padding: var(--space-1) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  border-left: 1px solid var(--border-color);
  transition: all var(--dur-fast);
}

.sidebar-nav__sub-link:hover,
.sidebar-nav__sub-link.active {
  color: var(--brand-primary);
  border-left-color: var(--brand-primary);
  text-decoration: none;
}

/* ── Main Content ─────────────────────────────────────────── */
.site-main {
  grid-area: main;
  display: grid;
  grid-template-columns: 1fr var(--toc-width);
  gap: 0;
  min-width: 0;
}

.site-main--wide {
  grid-template-columns: 1fr;
}

.content-area {
  min-width: 0;
  padding: var(--space-8) var(--space-8);
  max-width: 880px;
}

/* ── TOC Sidebar ─────────────────────────────────────────── */
.toc-sidebar {
  padding: var(--space-8) var(--space-4);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-left: 1px solid var(--border-color);
  font-size: var(--text-sm);
}

.toc-sidebar__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.toc-list { list-style: none; }

.toc-list__item { margin-bottom: var(--space-1); }

.toc-list__link {
  display: block;
  color: var(--text-muted);
  padding: 3px 0 3px var(--space-3);
  border-left: 2px solid transparent;
  transition: all var(--dur-fast);
  text-decoration: none;
  font-size: var(--text-xs);
  line-height: 1.5;
}

.toc-list__link:hover,
.toc-list__link.active {
  color: var(--brand-primary);
  border-left-color: var(--brand-primary);
  text-decoration: none;
}

.toc-list__link--h3 { padding-left: calc(var(--space-3) + var(--space-4)); }

/* ── Markdown Export (AI-friendly download) ──────────────── */
.md-export { margin: var(--space-4) 0; }
.md-export--top    { display: flex; justify-content: flex-end; margin-bottom: var(--space-5); }
.md-export--bottom { margin-top: var(--space-8); padding-top: var(--space-5); border-top: 1px dashed var(--border-color); text-align: center; }

.md-export__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: all var(--dur-fast);
}
.md-export__btn:hover {
  border-color: var(--brand-primary);
  background: rgba(99,102,241,.08);
  color: var(--brand-primary);
  text-decoration: none;
}
.md-export__btn svg { flex-shrink: 0; }

.md-export__hint {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── Page Navigation ─────────────────────────────────────── */
.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-color);
}

.page-nav__btn {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: all var(--dur-fast);
  background: var(--bg-surface);
}

.page-nav__btn:hover {
  border-color: var(--brand-primary);
  background: rgba(99,102,241,.04);
  text-decoration: none;
}

.page-nav__btn--next { text-align: right; }

.page-nav__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.page-nav__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

/* ── Breadcrumbs ─────────────────────────────────────────── */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.breadcrumbs__item { display: flex; align-items: center; gap: var(--space-2); }
.breadcrumbs__link { color: var(--text-muted); text-decoration: none; }
.breadcrumbs__link:hover { color: var(--text-primary); }
.breadcrumbs__sep { opacity: 0.4; }
.breadcrumbs__current { color: var(--text-primary); font-weight: var(--weight-medium); }

/* ── Responsive rules moved to responsive.css ─────────────── */

/* ── Header Nav Links ────────────────────────────────────── */
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: color var(--dur-fast), background var(--dur-fast);
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text-primary);
  background: var(--border-subtle);
  text-decoration: none;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  transition: color var(--dur-fast);
}
.icon-link:hover { color: var(--text-primary); text-decoration: none; }

/* Version selector */
#version-selector {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 5px 8px;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: border-color var(--dur-fast);
  outline: none;
}
#version-selector:hover { border-color: var(--brand-primary); }

/* Sidebar toggle (mobile) */
#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: color var(--dur-fast), background var(--dur-fast);
  flex-shrink: 0;
}
#sidebar-toggle:hover { color: var(--text-primary); background: var(--border-subtle); }

/* Site sidebar open state (used by JS) */
.site-sidebar.site-sidebar--open { left: 0; }

/* Sidebar: hidden on desktop for home page, but always usable on mobile */
.site-sidebar--home-hidden {
  display: none;
}

/* Home layout variant */
.site-main--home {
  grid-template-columns: 1fr;
  grid-column: 1 / -1;
}
.app-shell--home .site-main--home { grid-area: main; }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  grid-column: 1 / -1;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: var(--space-12) 0 var(--space-6);
  margin-top: auto;
}

.site-footer__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-8);
}

.site-footer__grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--space-8);
  margin-bottom: var(--space-10);
}

.footer-logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  text-decoration: none;
  margin-bottom: var(--space-3);
}
.footer-logo span { font-size: 1.4rem; }
.footer-logo:hover { text-decoration: none; color: var(--brand-primary); }

.footer-tagline {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: var(--leading-loose);
  margin-bottom: var(--space-4);
  max-width: 28ch;
}

.footer-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.6;
}

.footer-heading {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.footer-links a {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--dur-fast);
}
.footer-links a:hover { color: var(--brand-primary); text-decoration: none; }

.site-footer__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-color);
}

.site-footer__copy {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.site-footer__dev {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.site-footer__dev a {
  color: var(--brand-primary);
  text-decoration: none;
  font-weight: var(--weight-medium);
}
.site-footer__dev a:hover { text-decoration: underline; }

/* ── Breadcrumbs (updated for ol structure) ─────────────── */
.breadcrumbs__list {
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* ── Responsive footer/sidebar rules moved to responsive.css ── */
