/* ===========================
   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 {
  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: the mobile ToC opens from the header. */
.article-toc-slot {
  display: none;
}

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

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

  .toc-sidebar,
  .toc-sidebar-col,
  .sidebar-qr {
    display: none !important;
  }
}

.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__bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 6px 8px;
  box-sizing: border-box;
  overflow: hidden;
  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 .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;
  padding-right: 8px;
  padding-left: 8px;
}

.article-mobile-dock .contact-icons {
  display: flex;
  flex: 1 1 auto;
  gap: 6px;
  min-width: 0;
  margin-left: auto;
}

.article-mobile-dock .contact-icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
}

.article-mobile-dock .contact-icon-btn--label {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding: 0 10px;
  font-size: 14px;
}

.article-mobile-dock .contact-icon-btn--label span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.article-mobile-dock .js-email-us.contact-icon-btn {
  color: #333333;
  background: #fff;
  border: 1px solid #d8d8d8;
}

.article-mobile-dock .js-email-us.contact-icon-btn:hover {
  background: #f6f7fa;
}

/* Header table of contents toggle (mobile) */
.header-toc-toggle {
  display: none;
  align-items: center;
  justify-content: flex-start;
  flex: 0 1 auto;
  gap: 8px;
  min-width: 0;
  height: auto;
  min-height: 44px;
  margin-left: 0.75rem;
  padding: 0 4px;
  color: #111;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.header-toc-toggle svg {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
}

.header-toc-toggle__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-toc-toggle:not([hidden]) {
  display: inline-flex;
}

.header-toc-toggle.is-active .header-toc-toggle__label {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.header-toc-toggle:focus-visible {
  outline: 2px solid #0067f0;
  outline-offset: 2px;
}

.header-toc-panel {
  position: fixed;
  top: var(--toc-panel-top, 64px);
  right: max(8px, env(safe-area-inset-right));
  left: max(8px, env(safe-area-inset-left));
  z-index: 99;
  box-sizing: border-box;
  max-width: 720px;
  max-height: calc(100vh - var(--toc-panel-top, 64px) - var(--article-mobile-dock-height, 84px) - 16px);
  max-height: calc(100dvh - var(--toc-panel-top, 64px) - var(--article-mobile-dock-height, 84px) - 16px);
  margin: 8px auto 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.header-toc-panel[hidden] {
  display: none;
}

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

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.mobile-menu-open .article-mobile-dock,
html.mobile-menu-open .header-toc-panel {
  display: none;
}

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

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

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

  .toc-sidebar-col {
    display: block;
    flex-shrink: 0;
    align-self: flex-start;
    position: relative;
    box-sizing: border-box;
    width: clamp(240px, 24vw, 320px);
    padding-left: 1rem;
  }

  .article-chat-disclaimer {
    display: none;
  }

  .toc-sidebar-col > .sidebar-qr {
    position: absolute;
    left: 1rem;
    right: 0;
    z-index: 1;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin: 0;
    padding: 0;
    text-align: center;
    background: transparent;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__heading {
    margin: 0;
    color: var(--saily-text, #333333);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 16px;
    overflow: hidden;
    background: #94D1F0;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__waves {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__waves svg {
    display: block;
    width: 100%;
    height: 100%;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__title,
  .toc-sidebar-col > .sidebar-qr .sidebar-qr__frame,
  .toc-sidebar-col > .sidebar-qr .sidebar-qr__text,
  .toc-sidebar-col > .sidebar-qr .sidebar-qr__link {
    position: relative;
    z-index: 1;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__title {
    margin: 0;
    color: #333333;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
    background: transparent;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__frame {
    padding: 8px;
    background: #fff;
    border-radius: 12px;
    line-height: 0;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__img {
    display: block;
    width: 132px;
    max-width: 100%;
    height: auto;
    background: #fff;
    border-radius: 0;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__text {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
    color: #333333;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__link {
    color: #333333;
    font-size: 12px;
    font-weight: 700;
    text-decoration: underline;
  }

  .toc-sidebar-col > .sidebar-qr .contact-btn {
    width: 100%;
    color: var(--saily-text, #333333);
    white-space: normal;
    background-color: #fff;
    border: 2px solid #d8d8d8;
  }

  .toc-sidebar-col > .sidebar-qr .contact-btn:hover {
    background-color: #f6f7fa;
  }

  .toc-sidebar-col > .sidebar-qr .sidebar-qr__disclaimer {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
  }

  .toc-sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 16px;
    margin-bottom: 24px;
    align-self: flex-start;
    width: 100%;
    padding-left: 0;
    min-height: 0;
    overflow: visible;
    position: sticky;
    top: var(--toc-sticky-top, 88px);
  }

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

  .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;
  }
}

@media (max-width: 1199.98px) {
  /* The burger's auto margin was taking the free space, so the label
     shrank to nothing. Let the toggle fill the gap between logo and menu. */
  .navbar:has(#header-toc-toggle:not([hidden])) .navbar-toggle {
    margin-left: 0.5rem !important;
  }

  #header-toc-toggle.header-toc-toggle:not([hidden]) {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }
}

/* 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;
}
