/* ---------------------------------------------------------------------
   Site shell: header + sidebar + content + right-hand "on this page"
------------------------------------------------------------------------ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: var(--step-0);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  min-width: 0;
  flex-shrink: 0;
}

.brand:hover {
  color: var(--text);
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.header-search {
  flex: 1;
  max-width: 420px;
  margin-left: 0.5rem;
  min-width: 120px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-raised);
  color: var(--text);
}

.nav-toggle {
  display: none;
}

/* --- Body grid --- */

.site-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  align-items: start;
  min-width: 0;
}

/* --- Sidebar --- */

.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1rem 0.5rem 2rem;
  min-width: 0;
}

.sidebar-tree,
.sidebar-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-tree ul {
  margin-left: 0.9rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border);
}

.tree-node {
  margin: 1px 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.tree-toggle {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: 3px;
}

.tree-toggle:hover {
  background: var(--border);
  color: var(--text);
}

.tree-toggle svg {
  width: 11px;
  height: 11px;
  transition: transform 0.12s ease;
}

.tree-node.expanded > .tree-row .tree-toggle svg {
  transform: rotate(90deg);
}

.tree-toggle-spacer {
  width: 20px;
  flex-shrink: 0;
}

.tree-link {
  flex: 1;
  display: block;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--step--1);
  line-height: 1.35;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-link:hover {
  background: var(--bg-raised);
  color: var(--text);
}

.tree-link.is-active {
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-weight: 600;
}

.tree-label-only {
  flex: 1;
  padding: 0.4rem 0.55rem;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--text-faint);
  text-transform: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  display: none;
}

.tree-node.expanded > .tree-children {
  display: block;
}

/* --- Content column --- */

.content-col {
  min-width: 0;
  padding: 2rem 2.5rem 6rem;
  overflow: hidden;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: var(--step--1);
  color: var(--text-faint);
  margin-bottom: 1.25rem;
  min-width: 0;
}

.breadcrumbs a {
  color: var(--text-faint);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

.breadcrumbs .crumb-sep {
  color: var(--border-strong);
  flex-shrink: 0;
}

.breadcrumbs .crumb-current {
  color: var(--text-muted);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-content {
  max-width: var(--content-max);
  min-width: 0;
}

.doc-content h1,
.doc-content h2,
.doc-content h3,
.doc-content h4 {
  scroll-margin-top: calc(var(--header-h) + 1.25rem);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-content h1 {
  font-size: var(--step-4);
  line-height: 1.2;
  margin: 0 0 1rem;
  letter-spacing: -0.01em;
}

.doc-content h2 {
  font-size: var(--step-2);
  margin: 2.25rem 0 0.75rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.doc-content h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

.doc-content h3 {
  font-size: var(--step-1);
  margin: 1.75rem 0 0.6rem;
}

.doc-content p {
  margin: 0 0 1rem;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  word-break: break-word;
  overflow-wrap: break-word;
}

.doc-content pre {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
}

.doc-content pre code {
  border: none;
  background: none;
  padding: 0;
}

.doc-content ul,
.doc-content ol {
  padding-left: 1.4rem;
  margin: 0 0 1rem;
}

.doc-content li + li {
  margin-top: 0.3rem;
}

.doc-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.25rem;
  font-size: var(--step--1);
  overflow-x: auto;
}

.doc-content th,
.doc-content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-content th {
  background: var(--bg-raised);
}

.doc-content blockquote {
  margin: 0 0 1rem;
  padding: 0.6rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-raised);
  color: var(--text-muted);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Conformance-level pill: reused across the SC pages */
.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  flex-wrap: wrap;
}

.level-pill[data-level="A"] { color: var(--level-a); }
.level-pill[data-level="AA"] { color: var(--level-aa); }
.level-pill[data-level="AAA"] { color: var(--level-aaa); }

/* Success criterion numeric badge */
.sc-id {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-faint);
}

/* Page navigation (prev/next) */
.page-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.page-nav a {
  flex: 1;
  max-width: 48%;
  min-width: 200px;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.page-nav a:hover {
  border-color: var(--accent);
}

.page-nav .dir-label {
  font-size: var(--step--1);
  color: var(--text-faint);
}

.page-nav .next {
  text-align: right;
  margin-left: auto;
}

/* --- Right-hand "On this page" --- */

.toc-col {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem 1.25rem;
  font-size: var(--step--1);
  min-width: 0;
}

.toc-col h2 {
  font-size: var(--step--1);
  color: var(--text-faint);
  margin: 0 0 0.6rem;
  font-weight: 700;
}

.toc-col ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.toc-col li a {
  display: block;
  padding: 0.25rem 0 0.25rem 0.75rem;
  margin-left: -1px;
  border-left: 1px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.toc-col li a:hover {
  color: var(--text);
}

.toc-col li a.is-active {
  border-left-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}

.toc-col li.toc-h3 a {
  padding-left: 1.5rem;
}

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 2rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------------------------------------------------------------------
   Responsive
------------------------------------------------------------------------ */

@media (max-width: 1100px) {
  .site-body {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
  .toc-col {
    display: none;
  }
}

@media (max-width: 820px) {
  .nav-toggle {
    display: inline-flex;
  }

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

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    width: min(85vw, 320px);
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 30;
    box-shadow: var(--shadow-sm);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 20;
  }

  .sidebar-scrim.is-visible {
    display: block;
  }

  .content-col {
    padding: 1.5rem 1.25rem 4rem;
  }

  .header-search {
    max-width: none;
    flex: 1;
    margin-left: 0.25rem;
  }

  .brand {
    font-size: var(--step--1);
  }
}

@media (max-width: 640px) {
  .site-header {
    gap: 0.5rem;
    padding: 0 0.75rem;
  }

  .brand {
    gap: 0.35rem;
  }

  .brand-mark {
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
  }

  .brand span {
    display: none;
  }

  .header-search {
    min-width: 100px;
    max-width: 280px;
  }

  .header-actions {
    gap: 0.25rem;
  }

  .content-col {
    padding: 1rem 0.75rem 3rem;
  }

  .doc-content h1 {
    font-size: var(--step-3);
    margin-bottom: 0.75rem;
  }

  .doc-content h2 {
    font-size: var(--step-1);
    margin: 1.5rem 0 0.5rem;
  }

  .doc-content h3 {
    font-size: var(--step-0);
    margin: 1.25rem 0 0.4rem;
  }

  .page-nav a {
    max-width: 100%;
    min-width: auto;
  }

  .page-nav .next {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .site-header {
    gap: 0.4rem;
    padding: 0 0.5rem;
    height: 50px;
  }

  .icon-btn {
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
  }

  .header-search {
    min-width: 80px;
  }

  .content-col {
    padding: 0.75rem 0.5rem 2.5rem;
  }

  .breadcrumbs {
    font-size: 0.7rem;
    gap: 0.2rem;
    margin-bottom: 0.75rem;
  }

  .doc-content p {
    margin: 0 0 0.75rem;
  }
}
