/**
 * F1GMAT APU Theme · apu-toc.css
 * Auto-generated table-of-contents styling.
 *
 * Renders as a <details open> element. Reader can collapse manually.
 *
 * Mobile design philosophy: smaller typography (12px H2, 11px H3) with
 * full-width block-level tap rows ≥44px tall. Generous vertical padding
 * gives finger-friendly hit areas without bloating the visual footprint.
 * WCAG 2.2 AA target-size minimum is 24×24; we meet 44×44 (Apple HIG).
 *
 * Variables expected from apu-style.css :root —
 *   --fg-ink, --fg-ink-soft, --fg-ink-muted
 *   --fg-paper, --fg-paper-aged
 *   --fg-hairline, --fg-gold-dark, --fg-teal
 */

/* ---------- Container ---------- */

.apu-toc {
  background: var(--fg-paper-aged);
  border-left: 3px solid var(--fg-gold-dark);
  margin: 28px 0 32px;
  padding: 0;
  font-family: Georgia, 'Times New Roman', serif;
}

/* ---------- Summary (clickable header) ---------- */

.apu-toc__summary {
  cursor: pointer;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  list-style: none;
  min-height: 44px;
  box-sizing: border-box;
}

.apu-toc__summary::-webkit-details-marker {
  display: none;
}

.apu-toc__summary::marker {
  content: "";
}

.apu-toc__summary:focus-visible {
  outline: 2px solid var(--fg-teal);
  outline-offset: -2px;
}

.apu-toc__heading {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--fg-ink);
}

.apu-toc__count {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  color: var(--fg-ink-muted);
  letter-spacing: 0.5px;
}

.apu-toc__chevron {
  margin-left: auto;
  font-size: 14px;
  color: var(--fg-ink-muted);
  transition: transform 0.2s ease;
}

.apu-toc[open] .apu-toc__chevron {
  transform: rotate(180deg);
}

/* ---------- Desktop list (default) ---------- */

.apu-toc__list,
.apu-toc__sublist {
  list-style: decimal;
  margin: 0;
  padding: 0 22px 16px 44px;
  color: var(--fg-ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
}

.apu-toc__list > li {
  margin-bottom: 6px;
}

.apu-toc__sublist {
  list-style: lower-alpha;
  margin-top: 4px;
  padding: 0 0 0 1.4em;
  font-size: 0.9rem;
  color: var(--fg-ink-muted);
}

.apu-toc__sublist > li {
  margin-bottom: 3px;
}

.apu-toc__link {
  color: var(--fg-ink);
  text-decoration: none;
  border-bottom: 0.5px solid transparent;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.apu-toc__link:hover {
  color: var(--fg-teal);
  border-bottom-color: var(--fg-gold-dark);
}

.apu-toc__link:focus-visible {
  outline: 2px solid var(--fg-teal);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Heading scroll-offset ---------- */

.apu-toc__target {
  scroll-margin-top: 90px;
}

/* ---------- Sticky variant (desktop only) ---------- */

@media (min-width: 992px) {
  .apu-toc--sticky {
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    z-index: 5;
    box-shadow: 0 1px 0 var(--fg-hairline);
  }

  .apu-toc--sticky::-webkit-scrollbar {
    width: 6px;
  }

  .apu-toc--sticky::-webkit-scrollbar-track {
    background: transparent;
  }

  .apu-toc--sticky::-webkit-scrollbar-thumb {
    background: var(--fg-hairline);
    border-radius: 3px;
  }
}

/* ---------- Mobile: compact type, finger-sized rows ---------- */

@media (max-width: 767px) {
  .apu-toc {
    margin: 18px 0 22px;
    border-left-width: 2px;
  }

  .apu-toc__summary {
    padding: 12px 14px;
    gap: 8px;
  }

  .apu-toc__heading {
    font-size: 11px;
    letter-spacing: 1.2px;
  }

  .apu-toc__count {
    font-size: 10px;
  }

  /* Replace native list markers with CSS counters so the entire row
     becomes a flex tap target with a well-positioned numeric prefix. */
  .apu-toc__list {
    list-style: none;
    counter-reset: apu-toc-h2;
    padding: 0;
    margin: 0;
  }

  .apu-toc__list > li {
    counter-increment: apu-toc-h2;
    margin: 0;
    padding: 0;
    border-top: 0.5px solid var(--fg-hairline);
  }

  .apu-toc__list > li:first-child {
    border-top: 0.5px solid var(--fg-hairline);
  }

  .apu-toc__list > li > .apu-toc__link {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 14px;
    min-height: 44px;
    line-height: 1.4;
    font-size: 12px;
    color: var(--fg-ink);
    text-decoration: none;
    border-bottom: 0;
    box-sizing: border-box;
  }

  .apu-toc__list > li > .apu-toc__link::before {
    content: counter(apu-toc-h2) ".";
    flex: 0 0 auto;
    min-width: 20px;
    color: var(--fg-ink-muted);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: 500;
    padding-top: 1px;
  }

  /* H3 sublist — slight tint, alpha numbering, deeper indent */
  .apu-toc__sublist {
    list-style: none;
    counter-reset: apu-toc-h3;
    padding: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.35);
  }

  .apu-toc__sublist > li {
    counter-increment: apu-toc-h3;
    margin: 0;
    padding: 0;
    border-top: 0.5px solid var(--fg-hairline);
  }

  .apu-toc__sublist > li > .apu-toc__link {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px 12px 38px;
    min-height: 44px;
    line-height: 1.4;
    font-size: 11px;
    color: var(--fg-ink-soft);
    text-decoration: none;
    border-bottom: 0;
    box-sizing: border-box;
  }

  .apu-toc__sublist > li > .apu-toc__link::before {
    content: counter(apu-toc-h3, lower-alpha) ".";
    flex: 0 0 auto;
    min-width: 18px;
    color: var(--fg-ink-muted);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    padding-top: 1px;
  }

  /* Tap feedback */
  .apu-toc__link:active {
    background: var(--fg-paper-aged);
  }

  .apu-toc__link:focus-visible {
    outline: 2px solid var(--fg-teal);
    outline-offset: -2px;
    border-radius: 0;
  }

  .apu-toc__target {
    scroll-margin-top: 60px;
  }

  /* Sticky has no effect on mobile */
  .apu-toc--sticky {
    position: static;
    max-height: none;
    overflow-y: visible;
    box-shadow: none;
  }
}

/* ---------- Print: always expanded, no chevron ---------- */

@media print {
  .apu-toc {
    background: transparent;
    border-left-width: 1px;
  }

  .apu-toc__chevron {
    display: none;
  }

  .apu-toc[open] .apu-toc__list,
  .apu-toc:not([open]) .apu-toc__list {
    display: block !important;
  }
}
