/* ============================================================
   TARTAK MEGA MENU
   ============================================================ */

/* ---- Integrate with theme .main-menu .container (flex) ---- */
.tartak-megamenu {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.mm-nav {
  flex: 1;
  display: flex;
  align-items: stretch;
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

/* Top-level items */
.mm-nav > .mm-item {
  position: relative;
}

/* Top-level links: inherit .main-menu a (white, uppercase, font).
   flex-direction:column + justify-content:center allows multi-line labels via .mm-p. */
.main-menu .mm-nav > .mm-item > a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  white-space: nowrap;
}

/* Multi-line label spans (generated from "LINE1||LINE2" in menu config).
   Desktop: block → stacks vertically inside column-flex <a>.
   Sub-levels and mobile: inline with space separator (see below). */
.mm-nav > .mm-item > a .mm-p {
  display: block;
  line-height: 1.15;
  text-align: center;
}

.mm-dropdown .mm-p,
.mm-flyout .mm-p {
  display: inline;
}

.main-menu .mm-nav > .mm-item > a:hover,
.main-menu .mm-nav > .mm-item.mm-open > a {
  color: #fff;
}

.main-menu .mm-nav > .mm-item.mm-current > a::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* Mobile toggle button — hidden on desktop */
.mm-mobile-toggle { display: none; }

/* ---- Level-1 dropdown ------------------------------------- */
.mm-dropdown {
  display: none;
  position: absolute;
  /* Serves as positioned ancestor for child flyouts */
  top: 100%;
  left: 0;
  z-index: 1050;
  min-width: 230px;
  background: var(--wood-dark, #3e2723);
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
}

.mm-nav > .mm-item.mm-open > .mm-dropdown,
.mm-nav > .mm-item:hover > .mm-dropdown {
  display: block;
}

/* Override theme's .main-menu ul { display:flex } — must be column */
.main-menu .mm-dropdown > .mm-list {
  list-style: none;
  margin: 0;
  padding: 0.3rem 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  overflow: visible;
}

/* ---- Level 1+ items --------------------------------------- */
/* NO position:relative here — flyout must position relative to the
   parent container (.mm-dropdown or .mm-flyout), not the <li>.
   This makes all flyout panels align to the top of the dropdown column. */
.mm-dropdown .mm-item,
.mm-flyout .mm-item {
  position: static;
}

/* Sub-level links: inherit .main-menu a (white, uppercase, font-weight).
   Only adjust layout, padding, hover bg. Remove gold underline. */
.main-menu .mm-dropdown .mm-item > a,
.main-menu .mm-flyout .mm-item > a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  white-space: nowrap;
  height: auto;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  transition: background 0.15s;
}

.main-menu .mm-dropdown .mm-item > a::after,
.main-menu .mm-flyout .mm-item > a::after {
  display: none;
}

.main-menu .mm-dropdown .mm-item > a:hover,
.main-menu .mm-flyout .mm-item > a:hover,
.main-menu .mm-dropdown .mm-item.mm-open > a,
.main-menu .mm-flyout .mm-item.mm-open > a {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.main-menu .mm-dropdown .mm-item.mm-current > a,
.main-menu .mm-flyout .mm-item.mm-current > a {
  color: var(--gold, #c9a227);
}

/* Feature-value items — slightly smaller text */
.main-menu .mm-dropdown .mm-feature-value > a,
.main-menu .mm-flyout .mm-feature-value > a {
  font-size: 0.7rem;
  padding-left: 1.5rem;
  text-transform: none;
}

/* Arrow indicator for has-submenu */
.mm-arrow {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  margin-left: 0.8rem;
  flex-shrink: 0;
  opacity: 0.65;
}

/* ---- Feature group header --------------------------------- */
.mm-feature-header {
  padding: 0.5rem 1.2rem 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
  display: block;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 0.2rem;
}

.mm-list > .mm-feature-header:first-child,
.mm-flyout > .mm-feature-header:first-child {
  border-top: none;
  margin-top: 0;
}

/* ---- Level 2+ flyout (right-expand) -----------------------
   CRITICAL: use .main-menu prefix so our display:none beats
   the theme's .main-menu ul { display:flex } rule (specificity
   0,2,0 > 0,1,1).
   ---------------------------------------------------------- */
.main-menu .mm-flyout {
  display: none;
  position: absolute;
  top: 0;
  left: 100%;
  z-index: 1060;
  min-width: 210px;
  min-height: 100%;   /* stretch to full height of parent container */
  background: var(--wood-medium, #5d4037);
  border-left: 3px solid var(--gold, #c9a227);
  box-shadow: 6px 4px 20px rgba(0,0,0,0.35);
  list-style: none;
  margin: 0;
  padding: 0.3rem 0;
  flex-direction: column;
  flex-wrap: nowrap;
  overflow: visible;
}

/* Notch — filled with flyout background color */
.mm-flyout::before {
  content: '';
  position: absolute;
  left: 0;
  top: var(--mm-notch-top, 1.2rem);
  transform: translateY(-50%) translateX(-100%);
  border: 7px solid transparent;
  border-right-color: var(--wood-medium, #5d4037);
  pointer-events: none;
  z-index: 1;
}

/* Notch border — orange to match border-left */
.mm-flyout::after {
  content: '';
  position: absolute;
  left: -3px;
  top: var(--mm-notch-top, 1.2rem);
  transform: translateY(-50%) translateX(-100%);
  border: 8px solid transparent;
  border-right-color: var(--gold, #c9a227);
  pointer-events: none;
}

/* Show flyout — .main-menu prefix keeps specificity above theme's ul rules */
.main-menu .mm-has-sub:hover > .mm-flyout,
.main-menu .mm-has-sub.mm-open > .mm-flyout {
  display: flex;
}

/* ---- Mobile -----------------------------------------------
   Theme's initMobileMenu() finds .mm-nav (first <ul> in
   .main-menu) and toggles .active. We use that same mechanism.
   .main-menu .mm-nav overrides .main-menu ul (higher specificity).
   ---------------------------------------------------------- */
@media (max-width: 991px) {

  .main-menu .mm-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 2000;
    background: var(--wood-dark, #3e2723);
    flex-direction: column;
    align-items: stretch;
    max-height: 75vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    padding: 0;
  }

  .main-menu .mm-nav.active {
    display: flex;
  }

  .main-menu .mm-nav > .mm-item > a {
    display: block;
    height: auto;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 13px 18px;
  }

  /* Multi-line label spans: inline on mobile (no line breaks) */
  .mm-nav > .mm-item > a .mm-p { display: inline; }
  .mm-p + .mm-p::before { content: ' '; }

  .mm-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: rgba(255,255,255,0.8);
    transition: transform 0.25s;
  }

  .mm-mobile-toggle[aria-expanded="true"] {
    transform: translateY(-50%) rotate(180deg);
  }

  /* Sub-levels: collapse vertically on mobile */
  .main-menu .mm-dropdown,
  .main-menu .mm-flyout {
    display: none;
    position: static;
    box-shadow: none;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.07);
    border-radius: 0;
    border-left: none;
    background: rgba(0,0,0,0.15);
    padding: 0;
    margin: 0;
    min-width: 0;
    flex-direction: column;
  }

  /* Kill desktop :hover/:open rules — on touch devices :hover sticks after tap,
     causing dropdown to remain visible even after JS removes mm-mobile-open.
     These selectors match the desktop rules exactly (spec 0,4,0) but appear later. */
  .mm-nav > .mm-item:hover > .mm-dropdown,
  .mm-nav > .mm-item.mm-open > .mm-dropdown,
  .main-menu .mm-has-sub:hover > .mm-flyout,
  .main-menu .mm-has-sub.mm-open > .mm-flyout {
    display: none;
  }

  /* Show only when JS explicitly opens via class */
  .mm-nav > .mm-item > .mm-dropdown.mm-mobile-open,
  .main-menu .mm-has-sub > .mm-flyout.mm-mobile-open {
    display: flex;
  }

  .main-menu .mm-dropdown .mm-item > a,
  .main-menu .mm-flyout .mm-item > a {
    padding-left: 2rem;
    height: auto;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }

  .mm-flyout::before,
  .mm-flyout::after { display: none; }

  .mm-feature-header { padding-left: 2rem; }
}
