/*
 * ERG Mega Menu — Hybrid Horizontal + Vertical Layout
 * Best Of Indian Products — Harkanwal Singh
 *
 * DOM produced by ERG_Mega_Menu_Walker_Vertical::walk():
 *
 *  .erg-mm-v-nav-wrapper                        outer flex row
 *    .erg-mm-v-nav                              "Browse Categories" component (only if any top-level item is a WC product category)
 *      .erg-mm-v-trigger                        the button that opens/closes it
 *      .erg-mm-v-menu-wrap                      flex row: sidebar + active panel
 *        .erg-mm-v-menu (ul)                    sidebar — one .erg-mm-v-row per top-level category
 *        .erg-mm-v-panel (div, ×N)               ONE PER CATEGORY, sibling of the ul
 *          .erg-mm-v-columns                    cascading columns wrapper
 *            .erg-mm-v-col (ul, ×N)              one column per depth × branch; only the
 *                                                active chain's columns are visible at once
 *              .erg-mm-v-col-item (li)           each item, chevron if it has children
 *      .erg-mm-v-overlay                        mobile backdrop
 *    .erg-mm-h-menu (ul)                        horizontal bar — top-level items that are
 *                                                NOT WC categories (pages, custom links, …)
 *      .erg-mm-h-item (li)
 *        .erg-mm-h-dropdown (ul)                shown if the item has children
 *          .erg-mm-h-drop-item (li, ×N)         nested items fly out further right, recursively
 *
 * Colours come from the same CSS custom properties as elsewhere in the
 * plugin (ERG_MM_Settings::output_css_vars()) — nothing hardcoded.
 */

.erg-mm-v-nav-wrapper,
.erg-mm-v-nav-wrapper * ,
.erg-mm-v-nav-wrapper *::before,
.erg-mm-v-nav-wrapper *::after {
  box-sizing: border-box;
}

.erg-mm-v-nav-wrapper {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 4px;
}

/* ── THE VERTICAL COMPONENT ITSELF ──────────────────────────── */
.erg-mm-v-nav {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  position: relative;
  z-index: 1000;
}

.erg-mm-v-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--erg-mm-nav-text, #FFFFFF);
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  padding: 0 14px;
  height: 48px;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s;
}
.erg-mm-v-trigger:hover,
.erg-mm-v-trigger[aria-expanded="true"] {
  color: var(--erg-mm-accent, #D4500A);
}

.erg-mm-v-trigger-chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.erg-mm-v-trigger[aria-expanded="true"] .erg-mm-v-trigger-chevron {
  transform: rotate(180deg);
}

/* ── DROPDOWN SHELL ──────────────────────────────────────────── */
.erg-mm-v-menu-wrap {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: flex;
  align-items: stretch;
  background: var(--erg-mm-drop-bg, #fff);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  z-index: 1001;
  min-width: 620px;
  max-width: min(1100px, calc(100vw - 32px));

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
}

.erg-mm-v-nav.erg-mm-v-nav--open .erg-mm-v-menu-wrap {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* ── SIDEBAR (top-level categories) ─────────────────────────── */
.erg-mm-v-menu {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  width: 240px;
  flex-shrink: 0;
  background: var(--erg-mm-v-sidebar-bg, #fff);
  border-right: 1px solid var(--erg-mm-v-border, #ececec);
  overflow-y: auto;
}

.erg-mm-v-row {
  border-bottom: 1px solid var(--erg-mm-v-border, #f2f2f2);
}
.erg-mm-v-row:last-child {
  border-bottom: none;
}

.erg-mm-v-row-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  color: var(--erg-mm-drop-text, #1E1E1E);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.erg-mm-v-row:not(.erg-mm-v-row--leaf):hover .erg-mm-v-row-link,
.erg-mm-v-row--active .erg-mm-v-row-link {
  background: var(--erg-mm-drop-hover, #F9F5EE);
  color: var(--erg-mm-accent, #D4500A);
}
.erg-mm-v-row--leaf:hover .erg-mm-v-row-link {
  background: var(--erg-mm-drop-hover, #F9F5EE);
}

.erg-mm-v-row-icon--emoji {
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}
.erg-mm-v-row-icon--img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}

.erg-mm-v-row-label {
  flex: 1;
  min-width: 0;
  white-space: normal;
}

.erg-mm-v-row-badge {
  font-size: 9px;
  flex-shrink: 0;
}

.erg-mm-v-row-chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.12s, transform 0.12s;
}
.erg-mm-v-row:hover .erg-mm-v-row-chevron,
.erg-mm-v-row--active .erg-mm-v-row-chevron {
  opacity: 1;
  transform: translateX(2px);
}

/* ── RIGHT PANEL ─────────────────────────────────────────────── */
/* .erg-mm-v-panel is a direct sibling of .erg-mm-v-menu inside
   .erg-mm-v-menu-wrap (a flex row) — sits next to the sidebar
   instead of underneath a single row. Only one panel has --active
   at a time; the rest are display:none. */
.erg-mm-v-panel {
  display: none;
  flex: 1;
  min-width: 0;
  max-height: min(560px, calc(100vh - 160px));
  overflow: hidden;
}
.erg-mm-v-panel--active {
  display: block;
}

/* ── CASCADING COLUMNS ──────────────────────────────────────── */
.erg-mm-v-columns {
  display: flex;
  align-items: stretch;
  height: 100%;
  max-height: min(560px, calc(100vh - 160px));
  overflow-x: auto;
  overflow-y: hidden;
}

.erg-mm-v-col {
  display: none;
  flex-direction: column;
  list-style: none;
  margin: 0;
  padding: 20px 12px;
  width: 250px;
  flex-shrink: 0;
  max-height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--erg-mm-v-border, #f0f0f0);
}
.erg-mm-v-col:last-child {
  border-right: none;
}
.erg-mm-v-col--active {
  display: flex;
}

.erg-mm-v-col-item {
  border-radius: 6px;
}
.erg-mm-v-col-item--active > .erg-mm-v-col-link,
.erg-mm-v-col-item:hover > .erg-mm-v-col-link {
  background: var(--erg-mm-drop-hover, #F9F5EE);
  color: var(--erg-mm-accent, #D4500A);
}

.erg-mm-v-col-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--erg-mm-drop-text, #4B4B4B);
  font-size: 13px;
  text-decoration: none;
  line-height: 1.4;
  transition: background 0.12s, color 0.12s;
}

.erg-mm-v-col-link .erg-mm-child-img-wrap {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #f4f4f4;
}
.erg-mm-v-col-link .erg-mm-child-img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  display: block;
}

.erg-mm-v-col-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.erg-mm-v-col-text .erg-mm-child-count {
  font-size: 11px;
  color: #999;
}

.erg-mm-v-col-badge {
  font-size: 9px;
  flex-shrink: 0;
}

.erg-mm-v-col-chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.45;
  transition: opacity 0.12s, transform 0.12s;
}
.erg-mm-v-col-item--active > .erg-mm-v-col-link .erg-mm-v-col-chevron,
.erg-mm-v-col-item:hover > .erg-mm-v-col-link .erg-mm-v-col-chevron {
  opacity: 1;
  transform: translateX(2px);
}

/* "Back" row — only meaningful in the mobile drill-down accordion */
.erg-mm-v-col-back {
  display: none;
}
.erg-mm-v-col-back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--erg-mm-accent, #D4500A);
  border-bottom: 1px solid var(--erg-mm-v-border, #f0f0f0);
}

/* ── HORIZONTAL ITEMS (top-level items that aren't WC categories) ─ */
.erg-mm-h-menu {
  display: flex;
  align-items: stretch;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.erg-mm-h-item {
  position: relative;
  display: flex;
  align-items: stretch;
}

.erg-mm-h-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 48px;
  color: var(--erg-mm-nav-text, #FFFFFF);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.erg-mm-h-link:hover,
.erg-mm-h-link[aria-current="page"] {
  color: var(--erg-mm-accent, #D4500A);
  border-bottom-color: var(--erg-mm-accent, #D4500A);
}

.erg-mm-h-icon--emoji {
  font-size: 14px;
  line-height: 1;
}
.erg-mm-h-icon--img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}
.erg-mm-h-badge {
  font-size: 9px;
}
.erg-mm-h-chevron {
  display: flex;
  align-items: center;
  transition: transform 0.15s;
}

/* ── HORIZONTAL DROPDOWN (non-category items with children) ──── */
.erg-mm-h-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  list-style: none;
  margin: 0;
  padding: 8px;
  background: var(--erg-mm-drop-bg, #fff);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  z-index: 1002;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s;
}

.erg-mm-h-item--has-drop:hover > .erg-mm-h-dropdown,
.erg-mm-h-item--has-drop:focus-within > .erg-mm-h-dropdown,
.erg-mm-h-item--open > .erg-mm-h-dropdown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.erg-mm-h-item--has-drop:hover > .erg-mm-h-link .erg-mm-h-chevron,
.erg-mm-h-item--open > .erg-mm-h-link .erg-mm-h-chevron {
  transform: rotate(180deg);
}

.erg-mm-h-drop-item {
  position: relative;
}

.erg-mm-h-drop-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--erg-mm-drop-text, #1E1E1E);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.erg-mm-h-drop-item:hover > .erg-mm-h-drop-link,
.erg-mm-h-drop-item--open > .erg-mm-h-drop-link {
  background: var(--erg-mm-drop-hover, #F9F5EE);
  color: var(--erg-mm-accent, #D4500A);
}

.erg-mm-h-drop-chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.5;
}

/* Nested dropdown levels fly out to the right of their parent item */
.erg-mm-h-drop-item .erg-mm-h-dropdown {
  top: -8px;
  left: 100%;
  margin-left: 6px;
}
.erg-mm-h-drop-item:hover > .erg-mm-h-dropdown,
.erg-mm-h-drop-item:focus-within > .erg-mm-h-dropdown,
.erg-mm-h-drop-item--open > .erg-mm-h-dropdown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* ── MOBILE OVERLAY (backdrop behind the open drawer) ─────────── */
.erg-mm-v-overlay {
  display: none;
}

/* ── TABLET: narrower columns ───────────────────────────────── */
@media (min-width: 768px) and (max-width: 1100px) {
  .erg-mm-v-col {
    width: 210px;
  }
}

/* ── MOBILE: stacked, full-width drawer + drill-down accordion ─── */
@media (max-width: 767px) {
  .erg-mm-v-nav-wrapper {
    flex-direction: column;
    width: 100%;
    gap: 0;
  }

  .erg-mm-v-nav {
    width: 100%;
  }
  .erg-mm-v-trigger {
    width: 100%;
    justify-content: flex-start;
    border-radius: 4px;
    background: var(--erg-mm-nav-bg, #1B3F6B);
    color: var(--erg-mm-nav-text, #fff);
    padding: 0 18px;
  }
  .erg-mm-v-trigger:hover,
  .erg-mm-v-trigger[aria-expanded="true"] {
    background: var(--erg-mm-nav-bg-hover, #16335A);
    color: var(--erg-mm-nav-text, #fff);
  }

  .erg-mm-v-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
  }
  .erg-mm-v-nav--open .erg-mm-v-overlay {
    display: block;
  }

  .erg-mm-v-menu-wrap {
    position: fixed;
    top: 0;
    left: -100%;
    right: auto;
    width: min(340px, 88vw);
    height: 100vh;
    max-width: none;
    min-width: 0;
    border-radius: 0;
    flex-direction: column;
    overflow-y: auto;
    z-index: 999;
    transform: none;
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .erg-mm-v-nav--open .erg-mm-v-menu-wrap {
    left: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .erg-mm-v-menu {
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--erg-mm-v-border, #ececec);
    flex-shrink: 0;
  }

  /* Drill-down: the active category's panel becomes a single
     full-width column stack directly below the sidebar. Each
     .erg-mm-v-col takes the FULL panel — only the currently
     active depth is shown, "Back" steps up one level. */
  .erg-mm-v-panel {
    width: 100%;
    max-height: none;
    overflow: visible;
    background: var(--erg-mm-drop-hover, #F9F5EE);
  }
  .erg-mm-v-columns {
    max-height: none;
    overflow: visible;
  }
  .erg-mm-v-col {
    width: 100%;
    max-height: none;
    padding: 12px 20px;
    border-right: none;
  }
  .erg-mm-v-col-back {
    display: block;
  }

  .erg-mm-h-menu {
    flex-direction: column;
    width: 100%;
  }
  .erg-mm-h-item {
    flex-direction: column;
  }
  .erg-mm-h-link {
    height: auto;
    padding: 12px 18px;
    border-bottom: 1px solid var(--erg-mm-v-border, #f2f2f2);
  }

  /* Horizontal dropdowns become tap-to-expand accordions, stacked
     in place instead of flying out over the page. */
  .erg-mm-h-dropdown,
  .erg-mm-h-drop-item .erg-mm-h-dropdown {
    position: static;
    display: none;
    min-width: 0;
    margin: 0;
    padding: 0 0 0 16px;
    box-shadow: none;
    border-radius: 0;
    background: var(--erg-mm-drop-hover, #F9F5EE);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }
  .erg-mm-h-item--open > .erg-mm-h-dropdown,
  .erg-mm-h-drop-item--open > .erg-mm-h-dropdown {
    display: block;
  }
  .erg-mm-h-drop-link {
    padding: 10px 12px;
  }
}

/* ── FOCUS STYLES ────────────────────────────────────────────── */
.erg-mm-v-trigger:focus-visible,
.erg-mm-v-row-link:focus-visible,
.erg-mm-v-col-link:focus-visible,
.erg-mm-h-link:focus-visible,
.erg-mm-h-drop-link:focus-visible,
.erg-mm-v-col-back-btn:focus-visible {
  outline: 2px solid var(--erg-mm-accent, #D4500A);
  outline-offset: -2px;
}
