/* ==========================================================================
   Page with TOC  —  auto-generated Table of Contents
   Loaded only on the "Page with TOC" template (pg-toc.php).
   Colours / fonts mirror src/scss/settings/_variables.scss.
   ========================================================================== */

:root {
  --toc-navy:        #243550;
  --toc-teal:        #0A6170;
  --toc-teal-light:  #4D98A5;
  --toc-ice:         #E6EBF4;
  --toc-gray-mid:    #ADC0D7;
  --toc-white:       #fff;

  /* Distance from the top of the viewport to the sticky page header.
     Also used as the scroll offset when jumping to a heading. */
  --toc-offset: 160px;
}

/* Give headings breathing room under the sticky header when linked to. */
.js-toc-content h2 {
  scroll-margin-top: var(--toc-offset);
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.c-toc-page {
  padding-left: 20px;
  padding-right: 20px;
}

.c-toc-page__main {
  min-width: 0; /* let long words / code wrap inside the grid track */
}

/* Two-column layout on tablet-and-up: content + sticky TOC rail. */
@media (min-width: 901px) {
  .c-toc-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 64px;
    align-items: start;
  }
}

/* --------------------------------------------------------------------------
   Shared TOC list styling
   -------------------------------------------------------------------------- */
.c-toc__title {
  margin: 0 0 0.85rem;
  font-family: 'Rubik', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--toc-teal-light);
}

.c-toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.c-toc__item {
  margin: 0;
}

.c-toc__link {
  display: block;
  padding: 8px 0 8px 16px;
  border-left: 2px solid var(--toc-ice);
  color: var(--toc-navy);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.35;
  text-decoration: none;
  transition: color 200ms ease, border-color 200ms ease, font-weight 200ms ease;
}

.c-toc__link:hover,
.c-toc__link:focus-visible {
  color: var(--toc-teal);
  border-color: var(--toc-gray-mid);
}

.c-toc__link.is-active {
  color: var(--toc-teal);
  border-color: var(--toc-teal-light);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Desktop / tablet  —  sticky rail on the right
   -------------------------------------------------------------------------- */
@media (min-width: 901px) {
  .c-toc {
    position: sticky;
    top: var(--toc-offset);
    align-self: start;
    max-height: calc(100vh - var(--toc-offset) - 40px);
    overflow-y: auto;
  }

  /* The pill toggle is a mobile-only affordance. */
  .c-toc__toggle {
    display: none;
  }

  .c-toc__panel {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
  }
}

/* --------------------------------------------------------------------------
   Mobile  —  floating sticky pill with dropdown panel
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .c-toc {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 440px;
    z-index: 9000;
  }

  .c-toc__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 12px 22px;
    border: none;
    border-radius: 999px;
    background: var(--toc-navy);
    color: var(--toc-white);
    box-shadow: 0 8px 26px rgba(36, 53, 80, 0.30);
    font-family: 'DM Sans', sans-serif;
    text-align: left;
    cursor: pointer;
  }

  .c-toc__toggle-label {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .c-toc__toggle-eyebrow {
    font-family: 'Rubik', sans-serif;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--toc-gray-mid);
  }

  .c-toc__toggle-current {
    overflow: hidden;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .c-toc__chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 250ms ease;
  }

  .c-toc.is-open .c-toc__chevron {
    transform: rotate(180deg);
  }

  /* Panel opens upward, above the pill. */
  .c-toc__panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 10px);
    max-height: 55vh;
    padding: 18px 22px;
    overflow-y: auto;
    background: var(--toc-white);
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(36, 53, 80, 0.22);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 200ms ease, transform 200ms ease, visibility 200ms;
  }

  .c-toc.is-open .c-toc__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .c-toc__link {
    padding: 10px 0 10px 16px;
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .c-toc__link,
  .c-toc__chevron,
  .c-toc__panel {
    transition: none;
  }
}
