/* Fibrolux DEV — target ONLY the Konstruktionen submenu (TYPO3 page UID 304). */
/* Preserve the existing dropdown's open/close logic, positions and links. */

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) > ul.dropdown-menu.flx-konstruktionen-grouped {
  column-count: auto !important; /* neutralize temporary column-count experiment */
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  grid-auto-flow: row !important;
  gap: 28px !important;
  align-items: start;
}

@media (min-width: 992px) {
  /* Only show this grid while TYPO3's normal submenu is open. */
  #nav1 li.level2:is(.x304, [data-flx-root-uid="304"]).isopen > ul.dropdown-menu.flx-konstruktionen-grouped {
    display: grid !important;
  }
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) > ul.dropdown-menu.flx-konstruktionen-grouped > li.flx-konstruktionen-group {
  display: block !important;
  position: static !important;
  float: none !important;
  clear: none !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0;
  flex: none !important;
  margin: 0 !important;
  padding: 0 !important;
  list-style: none;
  break-inside: avoid;
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) ul.flx-konstruktionen-group-items {
  display: flex !important;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  background: transparent;
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) ul.flx-konstruktionen-group-items > li.level3 {
  display: block !important;
  position: relative !important;
  float: none !important;
  clear: none !important;
  flex: none !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0;
  margin: 0 !important;
  break-inside: avoid;
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) ul.flx-konstruktionen-group-items > li.level3 > a {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) ul.flx-konstruktionen-group-items > li.flx-menu-group-heading {
  border-top: 1px solid #e1e5e8;
  margin: 0 0 10px !important;
  padding: 14px 0 9px !important;
  color: #0c2d47;
  font-family: Outfit, sans-serif;
  font-weight: 600;
}

#nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) ul.flx-konstruktionen-group-items > li.flx-menu-group-heading::before {
  content: '';
  display: block;
  background: #f07800;
  width: 34px;
  height: 3px;
  margin-bottom: 12px;
}

@media (max-width: 991px) {
  /* The mobile navigation uses another partial. If this menu is shown at a
     narrower width, keep the groups in one column rather than squashing them. */
  #nav1 li.level2:is(.x304, [data-flx-root-uid="304"]) > ul.dropdown-menu.flx-konstruktionen-grouped {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}


/*
 * Fibrolux DEV – Produkte (UID 3), original-size tiles 3 x 2.
 *
 * IMPORTANT: apply ONLY to the top-level card grid while it is CLOSED.
 * When the user opens a category, TYPO3 adds .subopen and all these
 * 3x2 overrides stop applying, restoring the original submenu layout.
 *
 * The Konstruktionen grouping rules (UID 304) above remain unchanged.
 */
@media only screen and (min-width: 1401px) {
  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages.megamenu:not(.subopen) {
    display: grid !important;
    grid-template-columns: repeat(3, 180px) !important;
    grid-auto-flow: row !important;
    grid-auto-rows: 165px !important;
    gap: 0 !important;
    width: 540px !important;
    min-width: 540px !important;
    max-width: 540px !important;
    justify-content: start !important;
    align-content: start !important;
    align-items: stretch !important;
  }

  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages.megamenu:not(.subopen) > li.level2 {
    display: block !important;
    box-sizing: border-box !important;
    flex: none !important;
    float: none !important;
    width: 180px !important;
    min-width: 0 !important;
    max-width: 180px !important;
    height: 165px !important;
    min-height: 165px !important;
    max-height: 165px !important;
    margin: 0 !important;
  }
}

/*
 * Fibrolux DEV – Produkte UID 3: 2 / 2 / 1 VERTICAL columns (v2).
 * First two level2 cards in column 1, next two in column 2, fifth in column 3.
 * No change to third-level groups or to an already opened category (.subopen).
 * :not(.subopen) is essential: when a category is opened, normal submenu rules apply.
 * Do not depend on the .megamenu class (only present when more than five children).
 */
@media only screen and (min-width: 992px) {
  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages:not(.subopen),
  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages.megamenu:not(.subopen) {
    display: grid !important;
    grid-template-columns: repeat(3, 180px) !important;
    grid-template-rows: repeat(2, 165px) !important;
    grid-auto-flow: column !important;
    grid-auto-columns: 180px !important;
    grid-auto-rows: 165px !important;
    gap: 0 !important;
    width: 540px !important;
    min-width: 540px !important;
    max-width: 540px !important;
    height: 330px !important;
    min-height: 330px !important;
    max-height: 330px !important;
    justify-content: start !important;
    align-content: start !important;
    align-items: stretch !important;
  }

  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages:not(.subopen) > li.level2,
  body #nav1 li.level1.x3 > ul.dropdown-menu.hasimages.megamenu:not(.subopen) > li.level2 {
    display: block !important;
    position: relative !important;
    box-sizing: border-box !important;
    float: none !important;
    clear: none !important;
    flex: none !important;
    grid-column: auto !important;
    grid-row: auto !important;
    justify-self: stretch !important;
    width: 180px !important;
    min-width: 0 !important;
    max-width: 180px !important;
    height: 165px !important;
    min-height: 165px !important;
    max-height: 165px !important;
    margin: 0 !important;
  }
}
