/* Docs layout styles */

/* Docs sidebar chrome (#main-nav.docs-nav) lives in navigation.css. */

.docs-nav-list {
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

/* Collapsible chapter sections, mirroring the notch docs sidebar:
   a header row (uppercase label + fold chevron) over each section's own
   list. Labels sit at the base 0.75rem inset; chapter links indent
   slightly past them (1rem + 3px marker border) so titles read as
   children of their section. */
#main-nav .docs-nav-section {
  margin: 0;
}

#main-nav .docs-nav-section + .docs-nav-section {
  margin-top: 0.75rem;
}

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  padding-right: 0.5rem;
  /* The whole row toggles the fold (see docs-sidebar.js), not just the
     chevron. */
  cursor: pointer;
  user-select: none;
}

#main-nav .docs-nav-section-label {
  flex: 1;
  min-width: 0;
  padding-left: 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);

  &:hover {
    color: var(--text);
    background: var(--primary-hover);
  }

  .nav-chevron {
    transition: transform 0.2s ease;
  }
}

#main-nav .docs-nav-section.collapsed {
  .nav-section-toggle .nav-chevron {
    transform: rotate(-90deg);
  }

  .docs-nav-list {
    display: none;
  }
}

#main-nav .docs-nav-chapter {
  padding: 0;
  /* Cancel the global prose li margin — it opened the row pitch 4px
     wider than pika's sidebar. */
  margin: 0;

  & > a {
    display: block;
    padding: 0.3rem 0.75rem 0.3rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-left: 3px solid transparent;
    /* One line per title; the ellipsis tracks the sidebar as it resizes. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;

    &:hover {
      background: var(--primary);
      color: var(--text);
    }
  }

  &.active > a {
    border-left-color: var(--text);
    background: var(--primary);
    color: var(--text);
    font-weight: 500;
  }
}

/* ===== CONTENT ===== */

@media (min-width: 769px) {
  body.docs-page {
    padding: 0;
  }
}

.docs-content {
  max-width: 100%;
  padding: 2rem clamp(1rem, 3vw, 2rem);
  transition: max-width 0.3s ease;
}

.docs-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-muted);

  h1 {
    margin-bottom: 0.5rem;
  }

  .docs-subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 0;
  }
}

.docs-body {
  line-height: 1.8;

  h2 {
    margin-top: 2rem;
  }

  pre {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
  }

  table {
    margin: 1rem 0;
  }
}

/* ===== INDEX PAGE ===== */

.docs-intro p {
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.docs-chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: chapter-list;
}

.docs-chapter-list li {
  counter-increment: chapter-list;
  margin-bottom: 0.75rem;

  a {
    display: block;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: transform 0.15s ease, box-shadow 0.15s ease;

    &::before {
      content: counter(chapter-list) ". ";
      color: var(--text-muted);
    }

    &:hover {
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
  }

  .docs-chapter-subtitle {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.25rem;
    padding-left: 1.25rem;
  }
}

/* ===== RIGHT TOC ===== */

.docs-layout {
  display: flex;
  gap: 0;
}

.docs-toc {
  display: none;
  flex: 0 0 220px;
  /* Collapses by animating flex-basis (see navigation.css) instead of
     display:none, which would pop. min-width lets the basis shrink.
     overflow: clip (NOT hidden) — hidden would make this a scroll
     container and silently break the inner position: sticky. */
  min-width: 0;
  overflow: clip;
  transition: flex-basis 0.3s ease, opacity 0.3s ease;
}

.docs-toc-inner {
  /* Fixed width so the TOC clips during collapse instead of re-wrapping. */
  width: 220px;
  position: sticky;
  top: var(--toolbar-height);
  max-height: calc(100vh - var(--toolbar-height));
  overflow-y: auto;
  padding: 1.5rem 1rem 2rem;
  border-left: 1px solid var(--border-muted);
}

.docs-toc-heading {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.docs-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;

  li {
    margin-bottom: 0;
  }

  li a {
    display: block;
    padding: 0.2rem 0 0.2rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;

    &:hover { color: var(--text); }
    &.active {
      color: var(--primary-inverse);
      border-left-color: var(--primary-inverse);
      font-weight: 500;
    }
  }
}

/* ===== RESPONSIVE TOC ===== */

@media (min-width: 1200px) {
  .docs-toc {
    display: block;
  }
}

/* ===== MOBILE (<768px) ===== */

@media (max-width: 768px) {
  .docs-content {
    max-width: 100%;
  }
}

/* ===== START READING CTA ===== */

.start-reading-btn {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 0.6rem 1.25rem;
  background: var(--primary);
  color: var(--text);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s ease;

  &:hover {
    background: var(--primary-hover);
  }
}

/* ===== PREV / NEXT PAGINATION ===== */

.docs-pagination {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-muted);
}

.docs-prev,
.docs-next {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: var(--font-size-sm);
  transition: background 0.15s ease;

  &:hover {
    background: var(--primary-hover);
  }
}

.docs-next {
  margin-left: auto;
}
