/* Navbar: the Documentation menu opens on hover or keyboard focus; its label is a link. */
@media (min-width: 992px) {
  .navbar .nav-item.dropdown:focus-within > .dropdown-menu {
    display: block;
    margin-top: 0;
  }
}

@media (min-width: 992px) and (hover: hover) {
  .navbar .nav-item.dropdown:hover > .dropdown-menu {
    display: block;
    margin-top: 0;
  }
}

/* Collapsed navbar on small screens: list the Documentation pages under the label. */
@media (max-width: 991.98px) {
  .navbar .nav-item.dropdown > .dropdown-menu {
    display: block;
    padding-top: 0;
    border: 0;
    background: transparent;
  }

  .navbar .nav-item.dropdown > .dropdown-menu .dropdown-item {
    padding-left: 1.5rem;
  }
}

/* Guide layout ============================================================= */

/* Room for the Documentation sidebar while plots keep the width set in the code. */
@media (min-width: 1200px) {
  .container.template-article:has(.guide-nav) {
    max-width: 1380px;
  }
}

.guide-nav h2 {
  margin-top: 1.5rem;
  font-size: 1.25rem;
}

.guide-nav h2 a {
  margin-left: -0.5rem;
  display: inline-block;
}

.guide-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-nav a {
  display: block;
  margin-bottom: 2px;
  padding: 0.25rem 0.5rem;
  border-radius: var(--bs-border-radius);
  color: inherit;
  text-decoration: none;
}

.guide-nav a:hover {
  background-color: var(--bs-tertiary-bg);
}

.guide-nav a[aria-current="page"] {
  background-color: var(--bs-secondary-bg);
  font-weight: 600;
}

@media (min-width: 992px) {
  .guide-nav {
    position: sticky;
    top: 56px;
    align-self: flex-start;
    max-height: calc(100vh - 56px - 1rem);
    overflow-y: auto;
  }
}

/* On small screens the chapter list follows the content. */
@media (max-width: 991.98px) {
  .template-article > .row {
    align-content: flex-start;
  }

  .guide-nav {
    margin-top: 2rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--bs-border-color);
  }
}

/* Previous / next chapter links, added by extra.js ========================= */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--bs-border-color);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  max-width: 48%;
  text-decoration: none;
}

.chapter-nav a:hover,
.chapter-nav a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.chapter-nav-next {
  margin-left: auto;
  text-align: right;
}

.chapter-nav-label {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

/* Plots: shown at the size set in the code, scaled down only when the view is narrower */
main img.r-plt {
  max-width: 100%;
  height: auto;
}

/* Package map on the Documentation page ======================================= */

.pkg-map {
  margin: 1.5rem 0 2rem;
}

.pkg-map-root {
  width: max-content;
  margin: 0 auto;
  padding: 0.375rem 0.875rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
}

.pkg-map-branches {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 1.5rem 0 0;
  list-style: none;
}

/* Connectors: root down to a bar, bar down to each branch. */
.pkg-map-branches::before,
.pkg-map-branches::after,
.pkg-map-branches > li::before {
  content: "";
  position: absolute;
  border-color: var(--bs-border-color);
  border-style: solid;
  border-width: 0;
}

.pkg-map-branches::before {
  top: 0;
  left: 50%;
  height: 0.75rem;
  border-left-width: 1px;
}

.pkg-map-branches::after {
  top: 0.75rem;
  left: calc((100% - 2rem) / 6);
  right: calc((100% - 2rem) / 6);
  border-top-width: 1px;
}

.pkg-map-branches > li {
  position: relative;
}

.pkg-map-branches > li::before {
  top: -0.75rem;
  left: 50%;
  height: 0.75rem;
  border-left-width: 1px;
}

.pkg-map-node {
  display: block;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.pkg-map-node:hover,
.pkg-map-node:focus-visible {
  color: var(--bs-link-hover-color);
  background-color: var(--bs-tertiary-bg);
}

.pkg-map-what {
  margin: 0.5rem 0;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
  text-align: center;
}

.pkg-map-leaves {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}

.pkg-map-leaves li {
  padding: 0.375rem 0;
  border-top: 1px solid var(--bs-border-color-translucent);
}

/* Narrow screens: one branch per row, without connectors. */
@media (max-width: 767.98px) {
  .pkg-map-branches {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding-top: 1rem;
  }

  .pkg-map-branches::before,
  .pkg-map-branches::after,
  .pkg-map-branches > li::before {
    display: none;
  }
}
