/**
 * ========================================================================
 * SYSTEM 1: FLYOUT NAVIGATION MENU
 * ========================================================================
 *
 * Handles the main navigation flyout functionality in the left sidebar.
 * This system manages hover-based dropdown menus for desktop navigation.
 *
 * Usage: Applied to ul.flyout-menu elements
 * Scope: #sidebar navigation area
 * ========================================================================
 */

#sidebar {
  overflow: visible;
  position: relative;
  z-index: 5000;

  /* Enforce left nav min width at all viewports */
  min-width: var(--flyout-item-min-width-left);
}

#aside {
  overflow: visible;
  position: relative;
  z-index: 1500;
}

/* Contrast + animation enhancements (root-controlled) */
:where(#aside) ul.flyout-menu {
  border: 1px solid var(--border-color);
  box-shadow: var(--flyout-shadow-menu);
  line-height: 0;
  list-style: none;
  margin: 0;
  max-width: 100%;
  padding: 0;
  position: relative;
  z-index: 6000; /* above main content */

  /* establishes stacking context for z-index */
}

/* Component's base background */
:where(#aside) ul.flyout-menu,
:where(#aside) ul.flyout-menu ul {
  background-color: var(--surface-color);
}

/* Default flyout widths (legacy-compatible) */
@media screen and (width <= 767px) {
  :where(#aside) ul.flyout-menu .ul-wrapper,
  :where(#aside) ul.flyout-menu ul {
    width: auto;
  }
}

:where(#aside) ul.flyout-menu li {
  border-bottom-color: var(--flyout-divider);
}

:where(#aside) ul.flyout-menu li.open,
:where(#aside) ul.flyout-menu li:hover {
  /* keep base warm surface, add subtle overlay for clearer contrast */
  border: 1px solid var(--primary-color);
  box-shadow: inset 0 0 0 9999px var(--hover-surface-overlay);
}

@media screen and (width >= 768px) {
  :where(#aside) ul.flyout-menu .ul-wrapper,
  :where(#aside) ul.flyout-menu ul {
    background-color: var(--surface-color);
    border-color: var(--flyout-border);
    box-shadow: var(--flyout-shadow-panel);
    width: var(--flyout-width-desktop);
  }

  /* Smooth dropdown reveal */
  :where(#aside) ul.flyout-menu .ul-wrapper {
    background-color: var(--surface-color);
    border-color: var(--flyout-border);
    box-shadow: var(--flyout-shadow-panel);
    display: block;
    opacity: 0;
    transform: translateY(6px);
    visibility: hidden;
    transition:
      opacity var(--flyout-anim-duration) var(--flyout-anim-ease),
      transform var(--flyout-anim-duration) var(--flyout-anim-ease),
      visibility 0s linear var(--flyout-anim-duration);
  }

  :where(#aside) ul.flyout-menu li:hover > .ul-wrapper,
  :where(#aside) ul.flyout-menu li.open > .ul-wrapper,
  :where(#aside) ul.flyout-menu li.opened > .ul-wrapper {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
  }

  /* Elevation for panels */
  /* stylelint-disable-next-line no-duplicate-selectors */
  :where(#aside) ul.flyout-menu ul,
  :where(#aside) ul.flyout-menu .ul-wrapper {
    font-family: inherit;
  }
}

:where(#aside) ul.flyout-menu.text-right {
  text-align: right;
}

:where(#aside) ul.flyout-menu.text-left {
  text-align: left;
}

:where(#aside) ul.flyout-menu.horizontal {
  width: 100%;
  float: left;
}

/* stylelint-disable-next-line no-duplicate-selectors */
:where(#aside) ul.flyout-menu li {
  border-bottom: 1px solid var(--divider-color);
  overflow: visible;
  position: relative;
  vertical-align: middle;

  /* allow submenus to escape li bounds */
}

:where(#aside) ul.flyout-menu li.last,
:where(#aside) ul.flyout-menu li:last-of-type {
  border: inherit;
}

:where(#aside) ul.flyout-menu.horizontal > li.first,
:where(#aside) ul.flyout-menu.horizontal > li:first-child {
  margin-left: 0;
}

:where(#aside) ul.flyout-menu .item-wrapper {
  align-items: center;
  display: flex;
  gap: var(--icon-gap);
  min-height: 32px;
  overflow: visible;
  padding: 4px 6px; /* reduced padding for compact layout */

  /* prevent clipping on hover */
}

:where(#aside) ul.flyout-menu.vertical .item-wrapper {
  width: 100%;
}

:where(#aside) ul.flyout-menu .menu-button {
  align-items: center;
  cursor: pointer;
  display: flex;
  flex: 0 0 var(--icon-slot);
  justify-content: center;
  line-height: 1;
  min-height: 14px;
  padding: 0;
}

:where(#aside) ul.flyout-menu.button-right .menu-button {
  float: right;
}

:where(#aside) ul.flyout-menu.button-left .menu-button {
  float: left;
}

:where(#aside) ul.flyout-menu.button-right .menu-button img,
:where(#aside) ul.flyout-menu.button-left .menu-button img {
  padding: 0; /* compact spacing, icon hugged left of text */
}

:where(#aside) ul.flyout-menu > li > .item-wrapper > .menu-link > a {
  font-weight: normal;
}

/* Compact margins and enforced min-widths per alignment */
:where(#aside) ul.flyout-menu.text-left .menu-link,
:where(#aside) ul.flyout-menu.text-right .menu-link {
  flex: 1 1 auto;
  margin: 0;
}

/* Limit menu min-width rules to sidebar navigation only */
#sidebar ul.flyout-menu.text-left .menu-link,
#aside ul.flyout-menu.text-left .menu-link {
  min-width: var(--flyout-item-min-width-left);
}

#sidebar ul.flyout-menu.text-right .menu-link,
#aside ul.flyout-menu.text-right .menu-link {
  min-width: var(--flyout-item-min-width-right);
}

ul.flyout-menu .menu-link a,
ul.flyout-menu .menu-link p {
  align-items: center;
  box-sizing: border-box;
  display: flex;
  font-family: var(--font-header);
  font-size: 0.85em !important;
  gap: 6px; /* tighten icon-text gap */
  line-height: 1.2;
  min-height: 18px;
  overflow-wrap: anywhere;
  padding: 6px; /* reduce outer padding */
  text-decoration: none;
  white-space: normal;

  /* stylelint-disable-line declaration-no-important */
}

/* Component link colors + states (SSOT) */
ul.flyout-menu a {
  color: var(--menu-text);
  font-weight: 500;
}

ul.flyout-menu .item-wrapper:hover a,
ul.flyout-menu li.current > .item-wrapper a,
ul.flyout-menu li.opened > .item-wrapper a {
  color: var(--primary-color);
  text-decoration: none;
}

/* Hover/open background to guide focus */
/* stylelint-disable-next-line no-duplicate-selectors */
ul.flyout-menu li.open,
ul.flyout-menu li:hover {
  background: var(--surface-warm);
  border: 1px solid var(--primary-color);
}

:where(#aside) ul.flyout-menu .menu-link img {
  aspect-ratio: 1 / 1;
  border: 0 none;
  height: var(--icon-size);
  max-width: 100%;
  object-fit: contain;
  padding-right: 5px;
  vertical-align: -0.125em;
  width: auto;
}

/* Prevent CLS: reserve space for button/link icons */
:where(#aside) ul.flyout-menu .menu-button > img {
  aspect-ratio: 1 / 1;
  height: var(--icon-size);
  object-fit: contain;
  width: auto;
}

:where(#aside) ul.flyout-menu .ul-wrapper {
  display: none;
  position: relative; /* ensure z-index takes effect when shown; fixes validator warning */
  z-index: 2001; /* above dropdowns/modals used elsewhere */
}

:where(#aside) ul.flyout-menu li:hover > .ul-wrapper {
  display: block;
}

@media screen and (width <= 767px) {
  :where(#aside) ul.flyout-menu.vertical li,
  :where(#aside) ul.flyout-menu.horizontal li {
    border-bottom: 1px solid var(--text-color);
    border-right: none;
    display: block;
    margin-left: 0;
  }

  :where(#aside) ul.flyout-menu.vertical li.last,
  :where(#aside) ul.flyout-menu.horizontal li.last,
  :where(#aside) ul.flyout-menu.vertical li:last-of-type,
  :where(#aside) ul.flyout-menu.horizontal li:last-of-type {
    border-bottom: inherit;
    margin-bottom: 1px;
  }

  :where(#aside) ul.flyout-menu.horizontal .item-wrapper {
    width: 100%;
  }

  :where(#aside) ul.flyout-menu .ul-wrapper {
    position: relative;
    top: 0;
  }

  :where(#aside) ul.flyout-menu.horizontal > li > .ul-wrapper {
    left: auto;
  }

  :where(#aside) ul.flyout-menu.vertical ul,
  :where(#aside) ul.flyout-menu.horizontal ul {
    border-bottom: 0;
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--text-color);
  }

  :where(#aside) ul.flyout-menu.flyout-right .ul-wrapper,
  :where(#aside) ul.flyout-menu.flyout-left .ul-wrapper {
    left: auto;
    right: auto;
  }

  :where(#aside) ul.flyout-menu.text-left li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li > .item-wrapper > .menu-link > p {
    padding-left: 20px;
  }

  :where(#aside) ul.flyout-menu.text-left li li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li > .item-wrapper > .menu-link > p {
    padding-left: 30px;
  }

  :where(#aside) ul.flyout-menu.text-left li li li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li li > .item-wrapper > .menu-link > p {
    padding-left: 40px;
  }

  :where(#aside) ul.flyout-menu.text-left li li li li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li li li > .item-wrapper > .menu-link > p {
    padding-left: 50px;
  }
}

@media screen and (width >= 768px) {
  :where(#aside) ul.flyout-menu.horizontal > li {
    border-bottom: none;
    border-right: 1px solid var(--secondary-color);
    display: inline-block;
    float: none;
  }

  :where(#aside) ul.flyout-menu .ul-wrapper {
    position: absolute;
    top: -1px;
  }

  :where(#aside) ul.flyout-menu.horizontal > li > .ul-wrapper {
    left: -1px;
    top: auto;
  }

  :where(#aside) ul.flyout-menu.vertical ul,
  :where(#aside) ul.flyout-menu.horizontal ul {
    border: 1px solid var(--secondary-color);
    margin: 0;
    padding: 0;
  }

  :where(#aside) ul.flyout-menu.flyout-right .ul-wrapper {
    left: 100%;
  }

  :where(#aside) ul.flyout-menu.flyout-left .ul-wrapper {
    right: 100%;
  }

  :where(#aside) ul.flyout-menu.text-left li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li li > .item-wrapper > .menu-link > a,
  :where(#aside) ul.flyout-menu.text-left li li li li li > .item-wrapper > .menu-link > a {
    padding-left: 9px;
  }
}
