/* Shared responsive "On this page" navigation.
 * Mobile/tablet: accessible bottom-sheet dialog.
 * Wide desktop: compact dot rail whose labels expand into the side gutter.
 */

.section-nav {
  --section-nav-button: #0f172a;
  --section-nav-active-text: #0f172a;
  --section-nav-dot-active: #0369a1;
  --section-nav-muted: #64748b;
  --section-nav-border: #e2e8f0;
  --section-nav-content-width: 1200px;
}

.section-nav--rain {
  --section-nav-button: var(--rain-primary, #0c4a6e);
  --section-nav-active-text: var(--rain-primary, #0c4a6e);
  --section-nav-dot-active: var(--rain-accent, #0ea5e9);
  --section-nav-content-width: 1180px;
}

.section-nav--crime {
  --section-nav-button: var(--cr-primary, #1a1a2e);
  --section-nav-active-text: #9f1239;
  --section-nav-dot-active: var(--cr-accent, #e94560);
  --section-nav-content-width: 1200px;
}

body.section-nav-open { overflow: hidden; }

.section-nav-target {
  scroll-margin-top: calc(var(--ecpt-content-offset, 64px) + 16px);
}

.section-nav__trigger {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 1080;
  display: inline-flex;
  max-width: min(80vw, 20rem);
  min-height: 44px;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--section-nav-button);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.35);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.section-nav__icon,
.section-nav__caret,
.section-nav__close svg {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.section-nav__trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-nav__caret {
  width: 0.8rem;
  height: 0.8rem;
  transition: transform 0.2s ease;
}

.section-nav.is-open .section-nav__caret { transform: rotate(180deg); }

.section-nav__backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  visibility: hidden;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.section-nav.is-open .section-nav__backdrop {
  visibility: visible;
  opacity: 1;
}

.section-nav__sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1100;
  visibility: hidden;
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateY(100%);
  border-radius: 1rem 1rem 0 0;
  background: #fff;
  box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.2);
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}

.section-nav.is-open .section-nav__sheet {
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
}

.section-nav__sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0.15rem 0;
}

.section-nav__sheet-title {
  color: var(--section-nav-muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-nav__close {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--section-nav-muted);
  cursor: pointer;
}

.section-nav__links {
  display: flex;
  flex-direction: column;
}

.section-nav__item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.25rem;
  border-bottom: 1px solid var(--section-nav-border);
  color: var(--section-nav-button);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
}

.section-nav__item:last-child { border-bottom: 0; }

.section-nav__dot {
  width: 0.6rem;
  height: 0.6rem;
  flex: 0 0 auto;
  border: 2px solid rgba(15, 23, 42, 0.3);
  border-radius: 50%;
  background: transparent;
}

.section-nav__item.is-active { color: var(--section-nav-active-text); }
.section-nav__item.is-active .section-nav__dot {
  border-color: var(--section-nav-dot-active);
  background: var(--section-nav-dot-active);
}

.section-nav__trigger:focus-visible,
.section-nav__close:focus-visible,
.section-nav__item:focus-visible {
  outline: 3px solid var(--section-nav-dot-active);
  outline-offset: 3px;
}

/* Phones: a compact icon-only button that stays out of the way until the
 * reader is actually into the article (see .is-scrolled in section_nav.js). */
@media (max-width: 575.98px) {
  .section-nav__trigger {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    height: 44px;
    justify-content: center;
    padding: 0;
    gap: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .section-nav__trigger-label,
  .section-nav__trigger .section-nav__caret { display: none; }

  .section-nav.is-scrolled .section-nav__trigger {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .section-nav__caret { transition: none; }
  .section-nav__sheet { transition: none; }
  .section-nav__trigger { transition: none; }
}

/* Only expose the rail when the viewport has enough gutter for its labels. */
@media (min-width: 1640px) {
  body.section-nav-open { overflow: auto; }

  .section-nav__trigger,
  .section-nav__backdrop,
  .section-nav__sheet-head { display: none; }

  .section-nav__sheet {
    position: fixed;
    top: 50%;
    right: auto;
    bottom: auto;
    left: calc((100vw - var(--section-nav-content-width)) / 2 - 2rem);
    z-index: 40;
    visibility: visible;
    max-height: none;
    overflow: visible;
    padding: 0;
    transform: translateY(-50%);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .section-nav__links { gap: 0.35rem; }

  .section-nav__item {
    position: relative;
    min-height: 0;
    padding: 0.3rem 0.4rem;
    border: 0;
    border-radius: 0.5rem;
    color: var(--section-nav-muted);
    font-size: 0.78rem;
  }

  .section-nav__dot { width: 0.55rem; height: 0.55rem; }

  .section-nav__label {
    position: absolute;
    right: calc(100% + 0.35rem);
    max-width: 11rem;
    overflow: hidden;
    opacity: 0;
    text-align: right;
    text-overflow: ellipsis;
    transition: opacity 0.15s ease;
    white-space: nowrap;
  }

  .section-nav__links:hover .section-nav__label,
  .section-nav__item:focus-visible .section-nav__label,
  .section-nav__item.is-active .section-nav__label { opacity: 1; }

  .section-nav__item:hover,
  .section-nav__item.is-active { color: var(--section-nav-active-text); }
}
