/* ==========================================================================
   Table of contents ("On this page") for Elementor HTML widgets. Paste only
   the HTML - no <style> or <script>; js/oit-toc.js turns the links into
   smooth scrolling and marks the section being read. Loaded on pages whose
   Elementor data mentions oit-toc__list (see oit_register_on_demand_scripts()
   in functions.php).

   Markup:
     nav.oit-toc[aria-labelledby][data-oit-toc]
       p.oit-toc__eyebrow#id
       ol.oit-toc__list
         li > a.oit-toc__link[href="#section-id"][data-match="heading text"]
                span.oit-toc__num + span.oit-toc__text
   A link whose target id isn't on the page is matched to the first heading
   (h1-h4) that starts with its data-match text, and that heading gets the id.
   data-oit-toc-offset="NNN" on the nav sets the space kept above a heading
   after a jump (default 100: the sticky header).

   The list scrolls on its own when it is taller than the screen, so the box
   suits a sticky sidebar. Set --oit-toc-top-offset and --oit-toc-bottom-gap
   on .oit-toc to change the space reserved above and below it.
   ========================================================================== */

.oit-toc {
  --oit-toc-top-offset: 100px;
  --oit-toc-bottom-gap: 96px;
  --oit-toc-max-height: calc(100vh - var(--oit-toc-top-offset) - var(--oit-toc-bottom-gap));

  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-height: var(--oit-toc-max-height);
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family-base);
}

@supports (height: 100dvh) {
  .oit-toc {
    --oit-toc-max-height: calc(100dvh - var(--oit-toc-top-offset) - var(--oit-toc-bottom-gap));
  }
}

.oit-toc *,
.oit-toc *::before,
.oit-toc *::after {
  box-sizing: border-box;
}

.oit-toc p.oit-toc__eyebrow {
  flex: 0 0 auto;
  margin: 0;
  color: var(--text-action);
  font-size: var(--eyebrow-sm-size);
  line-height: var(--eyebrow-sm-line-height);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
}

/* Scrollable list. The 4px padding and matching negative margin keep the
   focus outline from being clipped. Extra bottom padding lets the last item
   scroll clear of the edge instead of sitting against it. */
.oit-toc ol.oit-toc__list {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: 8px;
  margin: -4px -4px 0 -4px;
  padding: 4px 4px 16px 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border-primary) transparent;
}

.oit-toc ol.oit-toc__list::-webkit-scrollbar {
  width: 6px;
}

.oit-toc ol.oit-toc__list::-webkit-scrollbar-track {
  background: transparent;
}

.oit-toc ol.oit-toc__list::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: var(--radius-pill);
}

.oit-toc .oit-toc__list > li {
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
}

.oit-toc .oit-toc__list > li::before,
.oit-toc .oit-toc__list > li::marker {
  content: none;
}

/* Links are set in full (hover, focus and active too) because Elementor and
   Astra restyle every link */
.oit-toc a.oit-toc__link {
  position: relative;
  display: flex;
  align-items: flex-start;
  padding: 6px 12px 6px calc(24px + 1.5em);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 24px;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}

.oit-toc a.oit-toc__link:hover,
.oit-toc a.oit-toc__link:focus,
.oit-toc a.oit-toc__link:active {
  background: transparent;
  color: var(--text-secondary);
  text-decoration: none;
}

.oit-toc a.oit-toc__link:focus-visible {
  outline: var(--border-sm) solid var(--border-action);
  outline-offset: 2px;
}

.oit-toc .oit-toc__num {
  position: absolute;
  top: 6px;
  left: 12px;
  width: 1.5em;
  font-size: inherit;
  line-height: inherit;
  font-weight: var(--font-weight-bold);
  text-decoration: none;
}

.oit-toc .oit-toc__text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
  font-size: inherit;
  line-height: inherit;
  font-weight: var(--font-weight-regular);
}

/* Active section: red text, light background, red bar on the left (the bar
   is drawn over the link, so nothing moves) */
.oit-toc a.oit-toc__link.is-active,
.oit-toc a.oit-toc__link.is-active:hover,
.oit-toc a.oit-toc__link.is-active:focus,
.oit-toc a.oit-toc__link.is-active:active {
  background: var(--surface-secondary);
  color: var(--text-action);
  border-radius: 0;
}

.oit-toc a.oit-toc__link.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--border-md);
  background: var(--border-action);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .oit-toc a.oit-toc__link {
    transition: none;
  }
}
