/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/

/* Force consistent product image height in grid (4:5 ratio) — scoped to grid only */
.products .wd-product .product-element-top .wd-product-img-link,
.products .wd-product .product-element-top .product-image-link {
  aspect-ratio: 4/5;
  overflow: hidden;
  display: block;
}
.products .wd-product .product-element-top .wd-product-img-link img,
.products .wd-product .product-element-top .product-image-link img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* === PRODUCT GRID ALIGNMENT === */

/* Equal height product cards in grid rows */
.products .wd-product {
  display: flex;
  flex-direction: column;
}
.wd-product .wd-product-wrapper,
.wd-product .product-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Product info section fills remaining space */
.wd-product .product-element-bottom.product-information {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

/* Title: fixed 2-line height with ellipsis overflow */
.wd-product .product-element-bottom .wd-entities-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
  line-height: 1.4;
}

/* Category: single line */
.wd-product .product-element-bottom .wd-product-cats {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 1.6em;
}

/* Price pushed to bottom of info section */
.wd-product .product-element-bottom .product-rating-price {
  margin-top: auto;
  padding-top: 4px;
}

/* Hide the description text inside hover card (clutters the grid) but keep action buttons */
.wd-product .wd-product-card-hover .hover-content.wd-more-desc {
  display: none !important;
}

/* === PREVENT HOVER FOUC (flash of unstyled content) ===
 * WoodMart's base hover requires JS to add .hover-ready class before CSS hover effects work.
 * Without this fix, hovering during page load shows wrong/no effects, then "flashes" to correct.
 * Solution: hide the hover card content until JS initializes, matching final resting state. */
.wd-hover-with-fade:not(.hover-ready) .wd-product-card-hover {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

/* Keep bottom actions (wishlist, cart, quickview) at very bottom */
.wd-product .product-element-bottom .wd-bottom-actions {
  margin-top: 0;
}

/* === SIDE CART IMAGE FIX ===
 * WoodMart's native cart uses .cart-item-image which has flex: 0 0 auto.
 * When thumbnails aren't generated (51GB library), full-size images need constraining. */
.woocommerce-mini-cart .cart-item-image {
  width: 80px;
  min-width: 80px;
  max-width: 80px;
}
.woocommerce-mini-cart .cart-item-image img {
  width: 100%;
  height: auto;
}

/* === FARMILOOMAD MEGA MENU — remove wrapper padding so background image fills flyout === */
#menu-item-216472 > .wd-dropdown-menu.wd-design-sized {
  padding: 0 !important;
}

/* === DYNAMIC SUBCATEGORY FILTER — Native WoodMart look + collapsible level-5 children ===
 * Inherits WoodMart's native layered-nav styling (green active count, bold active link).
 * We only override the minimum needed so nested children stack vertically instead of
 * getting squashed into WoodMart's flex row, and style the chevron + nested list. */

/* Make our parent <li> a block so the row and the nested <ul> stack vertically */
.r24-subcat-filter .r24-subcat-filter__list > .r24-subcat-filter__item {
  display: block;
  margin-bottom: 5px;
}

/* The row div takes over the flex layout that WoodMart normally puts on <li> */
.r24-subcat-filter .r24-subcat-filter__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.r24-subcat-filter .r24-subcat-filter__row > .layered-nav-link {
  flex: 1 1 auto;
  min-width: 0;
}
.r24-subcat-filter .r24-subcat-filter__row > .layered-nav-link .layer-term-lable {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Chevron toggle button — clearly visible square with bordered background so users notice it */
.r24-subcat-filter .r24-subcat-filter__toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0 0 0 2px;
  border: 1px solid var(--brdcolor-gray-300, rgba(0, 0, 0, 0.12));
  border-radius: 4px;
  background: #fff;
  color: var(--color-gray-700, #334155);
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.r24-subcat-filter .r24-subcat-filter__toggle:hover {
  background: var(--bgcolor-gray-100, #f1f5f9);
  border-color: var(--brdcolor-gray-500, rgba(0, 0, 0, 0.25));
  color: var(--color-gray-900, #0f172a);
}
.r24-subcat-filter .r24-subcat-filter__toggle:focus-visible {
  outline: 2px solid var(--wd-primary-color, #0a8a56);
  outline-offset: 2px;
}
/* Active parent: keep the button visible on the green row */
.r24-subcat-filter .r24-subcat-filter__item.wd-active > .r24-subcat-filter__row > .r24-subcat-filter__toggle {
  background: #fff;
  border-color: var(--wd-primary-color, #0a8a56);
  color: var(--wd-primary-color, #0a8a56);
}
.r24-subcat-filter .r24-subcat-filter__chevron {
  width: 14px;
  height: 14px;
  transition: transform 0.22s ease;
  pointer-events: none; /* clicks always land on the button, not the SVG */
}
.r24-subcat-filter .r24-subcat-filter__item.is-open > .r24-subcat-filter__row > .r24-subcat-filter__toggle .r24-subcat-filter__chevron {
  transform: rotate(180deg);
}

/* Nested level-5 list — indented with a subtle guide line, lets WoodMart's native
 * layered-nav styles handle the rows (green count pill on hover/active, bold active) */
.r24-subcat-filter .r24-subcat-filter__children {
  display: block;
  list-style: none;
  margin: 4px 0 2px 14px;
  padding: 2px 0 2px 10px;
  border-left: 1px solid var(--brdcolor-gray-300, rgba(0, 0, 0, 0.1));
  overflow: hidden;
}
.r24-subcat-filter .r24-subcat-filter__children[hidden] {
  display: none;
}
.r24-subcat-filter .r24-subcat-filter__children > .r24-subcat-filter__child {
  font-size: 0.95em;
}

/* Smooth expand/collapse animation (driven by JS toggling is-animating) */
.r24-subcat-filter .r24-subcat-filter__children.is-animating {
  transition: height 0.24s ease;
}

/* ============================================================
   Force consistent SINGLE PRODUCT PAGE main image dimensions
   Added 2026-04-18 for visual consistency across all products.

   Problem: WooCommerce's single-product main image has a fixed
   width but natural height (follows source aspect ratio). Tall
   products (e.g. spray bottles) render much taller than square
   products — different page heights per product, inconsistent UX.

   Fix: force every gallery image slot to a 1:1 square aspect
   ratio with object-fit:contain so the WHOLE product is visible
   (no crop) with small white bars above/below for tall sources.

   To tweak later: adjust the aspect-ratio value below.
     1 / 1  = square (current — matches most e-com sites)
     4 / 5  = slight portrait (matches grid cards on this site)
     3 / 4  = more portrait (better for tall fashion items)
   ============================================================ */
.woocommerce-product-gallery__image {
  aspect-ratio: 1 / 1 !important;
  overflow: hidden !important;
  background: #fff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.woocommerce-product-gallery__image > a,
.woocommerce-product-gallery__image img {
  width: 100% !important;
  height: 100% !important;
}

.woocommerce-product-gallery__image img {
  object-fit: contain !important;
  object-position: center !important;
  max-height: none !important;
}

/* ============================================================
   Force consistent thumbnails in Woodmart AJAX search dropdown
   Added 2026-04-18 — same rationale as single-product fix above.

   Problem: The instant-search dropdown (Woodmart's built-in,
   triggered by typing in the header search box) uses the
   WooCommerce_thumbnail size. If thumbnail_cropping is set to
   "uncropped" (Woodmart's install default), source-aspect-ratio
   is preserved → tall products show tall thumbnails, square
   products show square thumbnails → inconsistent dropdown rows.

   Fix: force every .wd-suggestion-thumb to 60×60 square with
   object-fit:contain. Full product visible, uniform row height.

   To tweak size: change the three `60px` values below together.
   ============================================================ */
.wd-search-results .wd-suggestion-thumb,
.wd-search-results-wrapper .wd-suggestion-thumb {
  width: 60px !important;
  min-width: 60px !important;
  max-width: 60px !important;
  height: 60px !important;
  aspect-ratio: 1 / 1 !important;
  overflow: hidden !important;
  background: #fff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
}

.wd-search-results .wd-suggestion-thumb img,
.wd-search-results-wrapper .wd-suggestion-thumb img {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  object-position: center !important;
}
