/* When the drawer is closed, make the entire sidebar non-interactive */
#__drawer:not(:checked) ~ .md-container .md-sidebar--primary {
  display: none !important;
}

/* Hide navigation checkboxes */
.md-nav__toggle {
  display: none !important;
}

/* Hide child nav when parent checkbox is not checked */
.md-nav__item:has(> .md-nav__toggle:not(:checked)) > .md-nav {
  display: none !important;
}

/* When a submenu is open at any level, hide siblings that aren't open */
.md-nav:has(> .md-nav__list > .md-nav__item > .md-nav__toggle:checked) {
  > .md-nav__list > .md-nav__item:not(:has(> .md-nav__toggle:checked)) {
    display: none !important;
  }

  /* Hide the parent link (label or div) when a child submenu is open */
  > .md-nav__list > .md-nav__item:has(> .md-nav__toggle:checked) {
    > .md-nav__container > .md-nav__link:first-child,
    > label.md-nav__link:first-child {
      display: none !important;
    }

    /* Hide back button when a deeper submenu is open */
    &:has(> .md-nav > .md-nav__list > .md-nav__item > .md-nav__toggle:checked) {
      > .md-nav > .md-nav__title {
        display: none !important;
      }
    }
  }
}

/* Ensure keyboard focus is visible */
.md-nav__link:focus-visible {
  outline: 2px solid var(--md-primary-fg-color) !important;
  outline-offset: 2px !important;
}

/* Remove quirky line in front of active link */
.md-nav__link--active::before {
  width: 0 !important;
}

/* Show focus indicator on visible back button when hidden link has focus */
.md-nav__item:has(> .md-nav__container > .md-nav__link[id$="_label"]:focus-visible) > .md-nav > .md-nav__title[for] {
  outline: 2px solid var(--md-primary-fg-color) !important;
  outline-offset: 2px !important;
}

/* Focus indicator for back buttons when they receive direct focus */
.md-nav__title[for]:focus-visible {
  outline: 2px solid var(--md-primary-fg-color) !important;
  outline-offset: 2px !important;
}