/* Keep the article contents and its contact block in one positioning context. */
.cw-article .cw-ed-sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  min-width: 0;
}

.cw-article .cw-ed-sidebar > .cw-ed-contents {
  position: static;
  top: auto;
}

.cw-article .cw-article-toc-scroll {
  max-height: min(48vh, 440px);
  max-height: min(48dvh, 440px);
  margin-top: 14px;
  padding: 4px 12px 4px 4px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--ed-line, #c9cfc3) transparent;
}

/* Only the wrapper scrolls; avoid the previous nested nav scroll container. */
.cw-article .cw-article-toc-scroll > .blog-toc {
  position: static;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: visible;
}

.cw-article .cw-article-toc-scroll .blog-toc__item,
.cw-article .cw-article-toc-scroll .blog-toc__link {
  min-width: 0;
}

.cw-article .cw-article-toc-scroll .blog-toc__link {
  overflow-wrap: anywhere;
}

.cw-article .cw-article-toc-scroll:focus-visible {
  outline: 2px solid var(--ed-accent, #a73328);
  outline-offset: 4px;
}

.cw-article .cw-ed-sidebar > .cw-ed-sidebar-contact {
  position: static;
  display: grid;
  margin-top: 24px;
}

body.admin-bar .cw-article .cw-ed-sidebar {
  top: 56px;
}

/* On a phone or a short window the entire sidebar stays in normal page flow. */
@media (max-width: 760px), (max-height: 680px) {
  .cw-article .cw-ed-sidebar,
  body.admin-bar .cw-article .cw-ed-sidebar {
    position: static;
    top: auto;
  }
}

@media (max-width: 760px) {
  .cw-article .cw-article-toc-scroll {
    max-height: min(50vh, 320px);
    max-height: min(50dvh, 320px);
    padding-right: 10px;
  }

  .cw-article .cw-ed-sidebar > .cw-ed-sidebar-contact {
    margin-top: 20px;
  }
}

@media print {
  .cw-article .cw-ed-sidebar,
  body.admin-bar .cw-article .cw-ed-sidebar {
    position: static;
  }

  .cw-article .cw-article-toc-scroll {
    max-height: none;
    overflow: visible;
  }
}
