/* =========================================================================
   ZFA Megamenu — design inspired by the reference board (3-column layout,
   horizontal product carousel in col-3 with chevron navigation, etc.).
   Column 1 lists every top-level parent in the `weighing-products`
   taxonomy and shows the first ~5; the remainder scroll inside the column.
   ========================================================================= */

:root {
  --zfa-menu-border: #ececec;
  --zfa-menu-text: #1f1f1f;
  --zfa-menu-muted: #8a8a8a;
  --zfa-menu-accent: #e58b45;          /* featured / hover orange */
  --zfa-menu-topbar: #1496d4;          /* blue strip on top of panel */
  --zfa-menu-card: #f5f5f5;
  --zfa-menu-card-border: #ededed;
  --zfa-menu-radius: 8px;
  --zfa-menu-radius-sm: 4px;
}

/* ---------- Panel shell ---------- */
.zfa-megamenu {
  position: relative;
  z-index: 100;
  width: 100%;
  background: #fff;
  border-top: 2px solid var(--zfa-menu-topbar);
  border-bottom: 1px solid var(--zfa-menu-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
}

.zfa-megamenu__inner {
  display: grid;
  grid-template-columns: minmax(190px, 0.85fr) minmax(210px, 1fr) minmax(520px, 2.9fr);
  width: min(100%, 1280px);
  min-height: 290px;
  margin: 0 auto;
}

.zfa-megamenu__parents,
.zfa-megamenu__children,
.zfa-megamenu__products {
  min-width: 0;
  padding: 22px 26px;
}

.zfa-megamenu__parents { border-right: 1px solid var(--zfa-menu-border); }
.zfa-megamenu__children { border-right: 1px solid var(--zfa-menu-border); }

/* ---------- Column 1: Parents ----------
   Row height ≈ 32px (min-height) + 6+6 padding ≈ 44px.
   Show ~5 rows by default (~220px) and let the rest scroll inside the
   column. The exact cap is "5 row slots plus the column's own 22px
   padding-top and 22px padding-bottom" = 220 + 44 = 264px. */
.zfa-megamenu__parents {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 264px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--zfa-menu-border) transparent;
}
.zfa-megamenu__parents::-webkit-scrollbar { width: 6px; }
.zfa-megamenu__parents::-webkit-scrollbar-track { background: transparent; }
.zfa-megamenu__parents::-webkit-scrollbar-thumb {
  background: var(--zfa-menu-border);
  border-radius: 3px;
}

/* Parent with no direct products or product-bearing children — still
   listed in the column, but visually de-emphasised so the user can tell
   at a glance which categories currently have inventory. */
.zfa-megamenu__parent--empty {
  color: var(--zfa-menu-muted);
  opacity: 0.85;
}
.zfa-megamenu__parent--empty:hover,
.zfa-megamenu__parent--empty:focus-visible {
  color: var(--zfa-menu-accent);
  opacity: 1;
}

.zfa-megamenu__parent {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  padding: 6px 6px 6px 0;
  color: var(--zfa-menu-text);
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
  white-space: normal;
  transition: color .18s ease, padding-left .18s ease;
}

.zfa-megamenu__parent:hover,
.zfa-megamenu__parent:focus-visible,
.zfa-megamenu__parent.is-active {
  padding-left: 4px;
}

/* Featured parent (orange + arrow, pushed to the bottom) — removed in
   v1.2.0. All parents now share the same styling. The `.is-featured`
   class is applied at runtime by JS to whichever parent/child is
   currently hovered or active. */

/* ---------- Column 2: Children ---------- */
/* Column 2 mirrors column 1's max-height + internal scroll. The cap
   is slightly larger so the "Popular:" sub-label (when present) still
   fits without forcing the user to scroll. */
.zfa-megamenu__children-group {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 324px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--zfa-menu-border) transparent;
}
.zfa-megamenu__children-group::-webkit-scrollbar { width: 6px; }
.zfa-megamenu__children-group::-webkit-scrollbar-track { background: transparent; }
.zfa-megamenu__children-group::-webkit-scrollbar-thumb {
  background: var(--zfa-menu-border);
  border-radius: 3px;
}
.zfa-megamenu__children-group[hidden],
.zfa-megamenu__products-group[hidden] { display: none; }

.zfa-megamenu__children-group a {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 6px 6px 6px 0;
  color: var(--zfa-menu-text);
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
  transition: color .18s ease, padding-left .18s ease;
}
.zfa-megamenu__children-group a:hover,
.zfa-megamenu__children-group a:focus-visible,
.zfa-megamenu__children-group a.is-active {
  padding-left: 4px;
  color: var(--zfa-menu-accent);
}

/* Featured styling — applied to the currently hovered/active row in
   column 1 (parents) and column 2 (children). Both are toggled at runtime
   via JS (see setupMenu / activateParent / activateChild). The :hover and
   :focus-visible selectors keep the visual feedback consistent even
   before JS runs, so the orange+bold "you-are-here" cue is identical
   across the two columns. */
.zfa-megamenu__parent.is-featured,
.zfa-megamenu__parent:hover,
.zfa-megamenu__parent:focus-visible,
.zfa-megamenu__parent.is-active,
.zfa-megamenu__children-group a.is-featured,
.zfa-megamenu__children-group a:hover,
.zfa-megamenu__children-group a:focus-visible,
.zfa-megamenu__children-group a.is-active {
  color: var(--zfa-menu-accent);
  font-weight: 600;
}

.zfa-megamenu__empty {
  display: inline-block;
  padding: 6px 0;
  color: var(--zfa-menu-muted);
  font-size: 12px;
  font-style: italic;
}

/* ---------- Arrow glyph ---------- */
.zfa-megamenu__arrow {
  display: inline-block;
  flex-shrink: 0;
  margin-left: 8px;
  color: var(--zfa-menu-accent);
  font-size: 16px;
  line-height: 1;
  font-weight: 400;
  transition: transform .2s ease, opacity .2s ease;
  opacity: .85;
}
a:hover .zfa-megamenu__arrow,
a:focus-visible .zfa-megamenu__arrow { transform: translateX(3px); opacity: 1; }

/* =========================================================================
   Column 3: Product grid.

   A static grid of product cards (no carousel, no slider library, no
   horizontal scroll). Each panel (.zfa-megamenu__products-group) is a
   CSS-grid container that auto-fits 2, 3, or 4 cards per row depending
   on the panel's width. With per_tab=4 (default) and ~520px of column
   width, you get a 4-up grid. Drop per_tab to 2 or 3 for fewer cards
   per row.
   ========================================================================= */

.zfa-megamenu__products {
  position: relative;
  padding-right: 12px;
}

.zfa-megamenu__products-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  align-content: start;
  /* Cap so a tall grid stays inside the auto-injected drop-down.
     Vertical overflow scrolls inside the panel. */
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--zfa-menu-border) transparent;
  padding-right: 4px;
}
.zfa-megamenu__products-group::-webkit-scrollbar { width: 6px; }
.zfa-megamenu__products-group::-webkit-scrollbar-track { background: transparent; }
.zfa-megamenu__products-group::-webkit-scrollbar-thumb {
  background: var(--zfa-menu-border);
  border-radius: 3px;
}

/* The "see more" pill is its own row beneath the grid. */
.zfa-megamenu__see-more {
  grid-column: 1 / -1;
  justify-self: start;
  margin-top: 4px;
}

.zfa-megamenu__product {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.zfa-megamenu__product-image {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100px;
  overflow: hidden;
  background: var(--zfa-menu-card);
  border: 1px solid var(--zfa-menu-card-border);
  border-radius: var(--zfa-menu-radius);
  text-decoration: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.zfa-megamenu__product:hover .zfa-megamenu__product-image {
  border-color: var(--zfa-menu-accent);
  box-shadow: 0 4px 14px rgba(229, 139, 69, 0.18);
}
.zfa-megamenu__product-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
  padding: 8px;
  transition: transform .28s ease;
}
.zfa-megamenu__product:hover .zfa-megamenu__product-image img { transform: scale(1.06); }
.zfa-megamenu__no-image {
  display: block;
  width: 60%;
  height: 60%;
  background: #e9e9e9;
  border-radius: var(--zfa-menu-radius-sm);
}

.zfa-megamenu__product-title {
  display: block;
  margin-top: 6px;
  color: var(--zfa-menu-text);
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  transition: color .18s ease;
}
.zfa-megamenu__product-title:hover,
.zfa-megamenu__product-title:focus-visible { color: var(--zfa-menu-accent); }
.zfa-megamenu__product--empty .zfa-megamenu__product-title { color: var(--zfa-menu-muted); }

/* "See more" pill button beneath the grid. */
.zfa-megamenu__see-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 16px 8px 14px;
  border: 1px solid var(--zfa-menu-accent);
  border-radius: 999px;
  color: var(--zfa-menu-accent);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: .01em;
  transition: background .18s ease, color .18s ease, transform .15s ease;
}
.zfa-megamenu__see-more::after {
  content: "→";
  display: inline-block;
  font-size: 14px;
  line-height: 1;
  transition: transform .2s ease;
}
.zfa-megamenu__see-more:hover,
.zfa-megamenu__see-more:focus-visible {
  background: var(--zfa-menu-accent);
  color: #fff;
  outline: none;
}
.zfa-megamenu__see-more:hover::after,
.zfa-megamenu__see-more:focus-visible::after { transform: translateX(3px); }

/* =========================================================================
   Tier 1.3 — Column header labels (small uppercase eyebrows that anchor
   the eye to each column). Renders as <h3 class="zfa-megamenu__col-label">.
   ========================================================================= */

.zfa-megamenu__col-label {
  margin: 0 0 12px 0;
  padding: 0 6px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--zfa-menu-muted);
  border-bottom: 1px solid var(--zfa-menu-border);
}

/* Tier 1.5 — Trailing chevron on parent rows that have at least one child.
   Single `›` glyph at the row's right edge, only visible when the parent
   is not the active one (the active state uses orange+bold instead). */
.zfa-megamenu__parent--has-children .zfa-megamenu__parent-chevron {
  margin-left: 8px;
  color: var(--zfa-menu-muted);
  font-size: 18px;
  line-height: 1;
  font-weight: 400;
  transition: transform .18s ease, color .18s ease;
}
.zfa-megamenu__parent--has-children:hover .zfa-megamenu__parent-chevron,
.zfa-megamenu__parent--has-children:focus-visible .zfa-megamenu__parent-chevron {
  color: var(--zfa-menu-accent);
  transform: translateX(3px);
}

/* Stack the label and chevron correctly (parent row uses space-between). */
.zfa-megamenu__parent {
  gap: 8px;
}
.zfa-megamenu__parent-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tier 2.2 — "Popular:" sub-label under each parent's children list.
   Lives below the regular children list as a quieter, secondary path
   that lets users skip exploration overhead. */
.zfa-megamenu__popular {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--zfa-menu-border);
}
.zfa-megamenu__popular-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--zfa-menu-accent);
  background: rgba(229, 139, 69, .08);
  padding: 2px 6px;
  border-radius: 3px;
}
.zfa-megamenu__popular-link {
  font-size: 12px;
  color: var(--zfa-menu-text);
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color .18s ease, background .18s ease;
}
.zfa-megamenu__popular-link:hover,
.zfa-megamenu__popular-link:focus-visible {
  color: var(--zfa-menu-accent);
  background: rgba(229, 139, 69, .08);
  outline: none;
}

/* Tier 1.1 — Friendly empty state when a parent has no products. */
.zfa-megamenu__empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 16px;
  background: var(--zfa-menu-card);
  border-radius: var(--zfa-menu-radius);
}
.zfa-megamenu__empty-state-icon {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 8px;
  opacity: .65;
}
.zfa-megamenu__empty-state-title {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--zfa-menu-text);
}
.zfa-megamenu__empty-state-body {
  margin: 0;
  font-size: 12px;
  color: var(--zfa-menu-muted);
  max-width: 280px;
}

/* ---------- Focus state ---------- */
.zfa-megamenu a:focus-visible {
  outline: 2px solid var(--zfa-menu-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* =========================================================================
   Auto-mode (drop-down from header).

   When the shortcode is auto-injected via wp_footer we wrap it in a slot
   <div data-zfa-megamenu-auto="1">. This class repositions the panel as a
   fixed drop-down under the header and hides it until the user hovers the
   matching header link. The toggle behaviour lives in megamenu.js.
   ========================================================================= */
.zfa-megamenu-slot {
  /* Empty placeholder; the actual .zfa-megamenu element handles styling. */
}
.zfa-megamenu-slot .zfa-megamenu {
  position: fixed;
  top: 88px;                                  /* adjust to header height */
  left: 0;
  right: 0;
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  display: none;
  z-index: 99;
}
.zfa-megamenu-slot.is-open .zfa-megamenu { display: block; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1100px) {
  .zfa-megamenu__inner {
    grid-template-columns: minmax(170px, 0.8fr) minmax(195px, 1fr) minmax(440px, 2.2fr);
  }
  .zfa-megamenu__parents,
  .zfa-megamenu__children,
  .zfa-megamenu__products {
    padding-left: 18px;
    padding-right: 18px;
  }
}

@media (max-width: 860px) {
  .zfa-megamenu__inner {
    grid-template-columns: minmax(150px, 0.7fr) minmax(170px, 1fr) minmax(360px, 1.8fr);
    min-height: 260px;
  }
  .zfa-megamenu__product-image { height: 108px; }
}

@media (max-width: 640px) {
  .zfa-megamenu { border-top-width: 1px; }
  .zfa-megamenu__inner {
    display: block;
    min-height: 0;
  }
  .zfa-megamenu__parents,
  .zfa-megamenu__children,
  .zfa-megamenu__products {
    border-right: 0;
    border-bottom: 1px solid var(--zfa-menu-border);
    padding-top: 14px;
    padding-bottom: 14px;
  }
  .zfa-megamenu__parents {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
  }
  .zfa-megamenu__product-image { height: 102px; }
  .zfa-megamenu__product-title { font-size: 11px; }
  .zfa-megamenu__products-track.is-splide .splide__arrow { display: none; }   /* on mobile, native scroll */
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .zfa-megamenu *,
  .zfa-megamenu *::before,
  .zfa-megamenu *::after { transition: none !important; animation: none !important; }
}

/* =========================================================================
   Debug panel (shown only to logged-in editors when the menu has no data)
   ========================================================================= */
.zfa-megamenu--debug {
  display: block !important;
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  max-height: none !important;
}
