/* ===========================
   TABLE OF CONTENTS — SHARED
   =========================== */

.toc {
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 20px 24px;
  box-sizing: border-box;
}

.toc-title {
  font-weight: bold;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  color: #333;
}

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

.toc-item {
  margin: 0;
  padding: 0;
  min-width: 0;
}

.toc-item.toc-level-2 {
  padding-left: 0;
  font-size: 14px;
}

.toc-item.toc-level-3 {
  padding-left: 12px;
  font-size: 13px;
}

.toc-link {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 4px 0;
  color: #555;
  text-decoration: none !important;
  border-left: 3px solid transparent;
  padding-left: 12px;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.toc-link:hover {
  color: #111;
  border-left-color: black;
}

.toc-link:focus-visible,
.toc-toggle:focus-visible,
.article-mobile-dock__toc-toggle:focus-visible {
  outline: 2px solid #0067f0;
  outline-offset: 2px;
}

.toc-link--active {
  color: #111;
  font-weight: 600;
  border-left-color: #ffdc52;
}

/* The in-article slot is unused: mobile ToC lives in the bottom dock. */
.article-toc-slot {
  display: none;
}

/* ===========================
   MOBILE  (≤ 992px)
   =========================== */

@media (max-width: 992px) {
  .toc-link {
    min-height: 44px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .toc-sidebar {
    display: none;
  }
}

.article-mobile-dock {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 98;
  box-sizing: border-box;
  padding:
    0
    max(12px, env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.article-mobile-dock__panel {
  box-sizing: border-box;
  pointer-events: auto;
  width: 100%;
  max-width: 720px;
  min-width: 0;
  margin: 0 auto;
}

.article-mobile-dock__sheet {
  max-height: 0;
  margin: 0 0 8px;
  overflow: hidden;
  visibility: hidden;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, visibility 0s linear 0.25s;
}

.article-mobile-dock.is-expanded .article-mobile-dock__sheet {
  max-height: min(50vh, 24rem);
  overflow-y: auto;
  visibility: visible;
  opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease, visibility 0s;
}

.article-mobile-dock .toc--mobile {
  margin: 0;
  padding: 12px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.article-mobile-dock__bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 56px;
  padding: 8px 12px;
  box-sizing: border-box;
  background: #f0f0f0;
  border: 1px solid #d8d8d8;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.article-mobile-dock__vote {
  flex: 0 0 auto;
}

.article-mobile-dock__vote:empty {
  display: none;
}

.article-mobile-dock__bar:has([data-toc-toggle][hidden]) {
  justify-content: center;
}

.article-mobile-dock .article-vote-layout {
  display: flex;
  flex-direction: row;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0;
  background: transparent;
  border-radius: 0;
}

.article-mobile-dock .article-vote-layout h4 {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.article-mobile-dock .article-vote-layout .button-group {
  align-self: auto;
}

.article-mobile-dock .article-vote-layout .button {
  min-width: 44px !important;
  min-height: 44px !important;
}

.article-mobile-dock__toc-toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.article-mobile-dock__toc-label {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.article-mobile-dock__toc-action {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  color: #333;
  font-size: 13px;
  font-weight: 600;
}

.article-mobile-dock__toc-title {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .article-mobile-dock__toc-action [data-toc-action-text] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

.article-mobile-dock__toc-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: #111;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  background: #ffdc52;
  border-radius: 50%;
}

.article-mobile-dock__toc-menu {
  flex-shrink: 0;
}

html.has-article-mobile-dock #page-container,
html.has-article-mobile-dock .footer {
  padding-bottom: calc(var(--article-mobile-dock-height, 84px) + 16px);
}

html.has-article-mobile-dock [data-element="back-to-top"].fixed {
  bottom: var(--article-mobile-dock-height, 84px);
  z-index: 94;
}

html.has-article-mobile-dock:has(.article-mobile-dock.is-expanded) [data-element="back-to-top"].fixed {
  visibility: hidden;
  pointer-events: none;
}

html.mobile-menu-open .article-mobile-dock {
  display: none;
}

@media (min-width: 993px) {
  .article-mobile-dock {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .article-mobile-dock__sheet,
  .article-mobile-dock.is-expanded .article-mobile-dock__sheet {
    transition: none;
  }
}

/* ===========================
   DESKTOP  (> 992px)
   =========================== */

@media (min-width: 993px) {
  #page-container > .row {
    flex-wrap: nowrap;
  }

  .toc-sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 16px;
    align-self: flex-start;
    width: clamp(240px, 24vw, 320px);
    padding-left: 1rem;
    max-height: calc(100vh - var(--toc-sticky-top, 88px) - 24px);
    min-height: 0;
    position: sticky;
    top: var(--toc-sticky-top, 88px);
  }

  .toc--desktop {
    position: relative;
    top: auto;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }

  .toc-sidebar .article-vote-layout {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    align-items: stretch;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    margin: 0;
    text-align: center;
  }

  .toc-sidebar .article-vote-layout .button-group {
    align-self: center;
  }
}

.toc--desktop::-webkit-scrollbar {
  width: 4px;
}

.toc--desktop::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

/* Expandable TOC */
.toc-item--hidden {
  display: none;
}

.toc-item--hidden.toc-item--visible {
  display: list-item;
}

.toc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 12px;
  min-height: 44px;
  padding: 8px;
  background: none;
  border: none;
  /* WCAG 1.4.3: grey (#808080) is 3.94:1 on white — #6d6d6d gives 5.3:1 */
  color: #6d6d6d;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}

.toc-toggle:hover {
  color: black;
}

.toc-toggle-arrow {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
  transition: transform 0.25s ease;
}

.toc-toggle.is-expanded .toc-toggle-arrow {
  transform: rotate(180deg);
}

.article-content h2,
.article-content h3,
.article-content img {
  scroll-margin-top: 88px;
}
