/* collapsible-toctree.js adds this class before the toctrees are parsed and
   removes it once it has given their rows toggles, which move the titles.
   Only a toctree with a code or example entry gets a toggle (isMagmaAnchor);
   hiding one of prose entries would only make it pop in.
   CSS cannot see that the entry is the anchor's whole text, so a prose
   heading with inline code, like "The Support Function", still hides the
   toctree until the script finds nothing to toggle. */
html.toc-pending .bd-article .toctree-wrapper:has(
  a > code.literal:only-child, a > .magma-example-entry:only-child
) {
  display: none;
}

.toc-page-controls {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 0.75rem;
}

.toc-page-toggle-all {
  background: var(--pst-color-on-background);
  border: 1px solid var(--pst-color-border);
  border-radius: 8px;
  color: var(--pst-color-text-base);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.65rem;
}

.toc-page-toggle-all:hover {
  background: var(--pst-color-surface);
  border-color: var(--pst-color-primary);
  color: var(--pst-color-primary);
}

/* 1.5rem (24px) is the WCAG 2.5.8 minimum target size, for the toggles
   and for the rows they sit in. */
.toc-page-row,
.toc-section-row {
  align-items: center;
  display: flex;
  gap: 0.45rem;
  min-height: 1.5rem;
}

.toc-page-toggle,
.toc-section-toggle {
  flex: 0 0 1.5rem;
  height: 1.5rem;
  width: 1.5rem;
}

.toc-page-toggle,
.toc-section-toggle {
  align-items: center;
  background: transparent;
  border: 1px solid var(--pst-color-border);
  border-radius: 3px;
  color: var(--pst-color-text-muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.9rem;
  justify-content: center;
  line-height: 1;
  margin: 0;
  padding: 0;
}

/* A childless page/section (e.g. a plain "Introduction" entry), or a
   sectioned page's own row (which gets no functional toggle -- see
   collapsible-toctree.js), has nothing of its own to collapse here. This
   still reserves the exact same width as a real toggle, deliberately: a
   narrower spacer was tried and made the title text start at a different
   column than sibling rows with a real toggle instead of lining up with
   them -- the whole point of the spacer is that every title at a given
   level (all pages under the root, or all sections under one page)
   starts in the same text column regardless of which rows have a real,
   clickable toggle. */
.toc-page-toggle-spacer,
.toc-section-toggle-spacer {
  display: inline-block;
  flex: 0 0 1.5rem;
  height: 1.5rem;
  width: 1.5rem;
}

.toc-page-toggle::before,
.toc-section-toggle::before {
  content: "+";
}

.toc-page-toggle[aria-expanded="true"]::before,
.toc-section-toggle[aria-expanded="true"]::before {
  content: "−";
}

.toc-page-toggle:hover,
.toc-section-toggle:hover {
  border-color: var(--pst-color-primary);
  color: var(--pst-color-primary);
}

/* Indent a revealed child list by exactly one toggle-button-width to the
   right of its parent row's own title text -- not its parent's toggle --
   so opening a page's toggle and opening a section's toggle reveal their
   contents at a visually consistent depth, whatever level the toggle is
   at. A parent row's title starts one toggle-width (1.5rem) plus the
   row's own gap (0.45rem) from the row's left edge; children start a
   further toggle-width past that, i.e. 2 * 1.5rem + 0.45rem. This
   replaces (not adds to) the theme's own li[class^=toctree-l]>ul
   indent, which is a single fixed 1.5em applied uniformly regardless of
   a row's own toggle/gap width, and so drifted out of step with it. */
.toctree-wrapper li[class^="toctree-l"] > ul {
  padding-inline-start: 3.45rem;
}

/* The theme sizes toctree links by a direct li>a match (li[class^=toctree-l]>a
   at 1.1em, .toctree-l1>a bigger still at 1.3em) -- wrapping the link in
   our own toggle/spacer row (toc-page-row/toc-section-row) breaks that
   direct-child match, so a page/section with a toggle or spacer silently
   lost the theme's sizing and read smaller than a page with neither
   (e.g. a sectioned page's own row, which we deliberately leave
   unwrapped -- see collapsible-toctree.js). Restore both rules for the
   wrapped case explicitly. */
.toctree-wrapper li[class^="toctree-l"] > .toc-page-row > a,
.toctree-wrapper li[class^="toctree-l"] > .toc-section-row > a {
  font-size: 1.1em;
}

.toctree-wrapper .toctree-l1 > .toc-page-row > a {
  font-size: 1.3em;
}

@media (prefers-reduced-motion: reduce) {
  .toc-page-toggle,
  .toc-section-toggle,
  .toc-page-toggle-all {
    transition: none;
  }
}

/* The primary sidebar's expand chevron. The theme puts the 30px chevron
   box absolutely inside a zero-height <summary>, so link hinting (Vimium)
   finds no box for a closed branch and stacks hints on open ones (#2546).
   Make the summary itself the 30px box, with the chevron filling it. */
nav.bd-docs-nav li.has-children > details > summary {
  height: 30px;
  position: absolute;
  right: 0;
  top: 0;
  width: 30px;
}

nav.bd-docs-nav li.has-children > details > summary > .toctree-toggle {
  height: 100%;
  position: static;
  width: 100%;
}

/* Vimium hints a <details> at its first box, which for an open branch
   started at its first child, so the two hints sat together (#2719). Inline,
   that box is empty and the hint falls to the positioned summary, as a
   closed branch's already did. Nothing renders differently. */
nav.bd-docs-nav li.has-children > details {
  display: inline;
}
