/**
 * Marck Engineers — B2B Catalog Mode & Quote Popup
 *
 * This file handles the global inquiry popup and B2B catalog styles.
 */

/* ============================================================
   1. Global Variables & Utility
   ============================================================ */
:root {
    --wpw-accent: #c0151a;
    --wpw-ink: #1a1714;
    --wpw-ink-mid: #444444;
    --wpw-ink-muted: #888888;
    --wpw-border: rgba(0, 0, 0, 0.08);
    --wpw-bg: #f0ede8;
    --wpw-white: #ffffff;
    --wpw-font-serif: 'DM Serif Display', Georgia, serif;
    --wpw-font-sans: 'Inter', system-ui, sans-serif;
    --wpw-radius: 12px;
}

/* ============================================================
   2. Quote Popup Styles (Extracted from Widget)
   ============================================================ */
.wpw-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 23, 20, 0.52);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-family: var(--wpw-font-sans);
}

.wpw-popup-overlay.wpw-popup--open {
    opacity: 1;
    visibility: visible;
}

.wpw-popup {
    background: var(--wpw-white);
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 0;
    position: relative;
    transform: translateY(22px);
    transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.2);
}

.wpw-popup-overlay.wpw-popup--open .wpw-popup {
    transform: translateY(0);
}

.wpw-popup-inner {
    padding: 24px;
}

.wpw-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--wpw-ink-muted);
    width: 32px;
    height: 32px;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.wpw-popup-close:hover {
    background: var(--wpw-bg);
    color: var(--wpw-accent);
}

.wpw-popup-close svg {
    display: block !important;
}

.wpw-popup-product-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--wpw-bg);
    border-radius: 0;
    padding: 10px;
    margin-bottom: 16px;
}

.wpw-popup-product-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    background: var(--wpw-white);
    border-radius: 0;
    padding: 4px;
    border: 1px solid var(--wpw-border);
    flex-shrink: 0;
}

.wpw-popup-product-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--wpw-accent);
    margin-bottom: 2px;
}

.wpw-popup-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--wpw-ink);
    line-height: 1.35;
}

.wpw-popup-heading {
    font-family: var(--wpw-font-serif);
    font-size: 24px;
    font-weight: 400;
    color: var(--wpw-ink);
    margin-bottom: 4px;
    line-height: 1.1;
}

.wpw-popup-subtext {
    font-size: 12px;
    color: var(--wpw-ink-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* Form Styles */
.wpw-form-row {
    margin-bottom: 12px;
}

.wpw-form-half {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.wpw-field-wrap label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--wpw-ink);
    margin-bottom: 4px;
}

.wpw-field-wrap label span {
    color: var(--wpw-accent);
}

.wpw-field-wrap input,
.wpw-field-wrap textarea {
    width: 100%;
    padding: 8px 12px;
    font-family: var(--wpw-font-sans);
    font-size: 13px;
    color: var(--wpw-ink);
    background: var(--wpw-bg);
    border: 1.5px solid var(--wpw-border);
    border-radius: 0;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.wpw-field-wrap input:focus,
.wpw-field-wrap textarea:focus {
    border-color: var(--wpw-accent);
    background: var(--wpw-white);
}

.wpw-submit-btn {
    background: var(--wpw-accent);
    color: var(--wpw-white);
    border: none;
    padding: 12px 28px;
    border-radius: 40px;
    font-weight: 600;
    cursor: pointer;
}

.wpw-form-success {
    text-align: center;
    padding: 32px 20px;
}

.wpw-success-icon {
    color: #2e7d32;
    font-size: 40px;
    margin-bottom: 10px;
}

/* Body Lock */
body.wpw-locked {
    overflow: hidden;
}

/* ============================================================
   3. Global Button Style
   ============================================================ */
.button.wpw-quote-trigger,
.wpw-quote-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    line-height: 1;
    font-weight: 600;
    color: var(--wpw-accent);
    background: transparent;
    border: 2px solid var(--wpw-accent);
    padding: 12px 24px;
    border-radius: 40px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.25s ease;
    margin-top: 10px;
}

.button.wpw-quote-trigger:hover,
.wpw-quote-btn:hover {
    background: var(--wpw-accent);
    color: var(--wpw-white);
    transform: translateY(-2px);
}

/* Hide Quote Button on Related Products */
.related.products .wpw-quote-btn,
.related.products .button.wpw-quote-trigger {
    display: none !important;
}

/* ============================================================
   4. B2B Overrides
   ============================================================ */
/* Hide standard Cart/Checkout elements just in case */
.woocommerce-Price-amount,
.price,
.add_to_cart_button,
.single_add_to_cart_button,
.woocommerce-cart-form,
.wc-proceed-to-checkout,
.cart-contents,
.elementor-editor-active .add_to_cart_button,
.elementor-editor-active .single_add_to_cart_button,
.elementor-editor-active .woocommerce-loop-product__link + .button,
.elementor-editor-active .product_type_simple,
.elementor-editor-active .product_type_variable {
    display: none !important;
}

@media (max-width: 600px) {
    .wpw-form-half {
        grid-template-columns: 1fr;
    }

    .wpw-popup-inner {
        padding: 24px;
    }
}

/* ============================================================
   5. Archive Grid Alignment Fixes
   ============================================================ */
/* Target almost all possible product image containers in Woo and Elementor */
.woocommerce ul.products li.product a img,
.woocommerce-loop-product__link img,
.dustrium-product-grid .product-image img,
.wpw-product-thumbnail img,
.elementor-widget-woocommerce-products img {
    aspect-ratio: 1 / 1 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 250px !important;
    /* Force a maximum height */
    object-fit: contain !important;
    background: #fff;
    padding: 10px;
    box-sizing: border-box;
}

/* Force the container to be the same height */
.woocommerce ul.products li.product .woocommerce-loop-product__link,
.wpw-product-card {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}

/* Align the product titles and buttons */
.woocommerce ul.products li.product .woocommerce-loop-product__title,
.wpw-product-title,
.woocommerce-loop-product__title {
    min-height: 4em !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 20px !important;
    font-size: 15px !important;
    line-height: 1.4 !important;
}

/* ============================================================
   6. Single Product Image Alignment
   ============================================================ */
/* Target the main product image in Elementor and WooCommerce */
.woocommerce-product-gallery__image img,
.elementor-widget-woocommerce-product-images img {
    aspect-ratio: 1 / 1 !important;
    width: 100% !important;
    height: auto !important;
    max-height: 500px !important;
    /* Limit height on desktop */
    object-fit: contain !important;
    background: transparent;
    padding: 0;
}

/* Ensure the gallery container doesn't collapse */
.woocommerce-product-gallery,
.elementor-widget-woocommerce-product-images .elementor-widget-container {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   7. Hierarchical Sidebar & Grouped Archive
   ============================================================ */
/* Sidebar Nesting */
.wcs-item-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.wcs-item-inner a {
    flex-grow: 1;
}

.wcs-sub-toggle {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--wpw-ink-muted);
    transition: transform 0.3s ease;
}

.wcs-item.has-children.active-parent .wcs-sub-toggle {
    transform: rotate(180deg);
}

.wcs-sub-menu {
    list-style: none;
    margin: 0;
    padding: 0 0 10px 20px;
    display: none;
    /* Controlled by active parent */
    background: rgba(0, 0, 0, 0.02);
}

.wcs-item.has-children.active-parent .wcs-sub-menu {
    display: block;
}

.wcs-sub-item a {
    padding: 8px 20px !important;
    font-size: 0.9em !important;
    opacity: 0.8;
}

.wcs-sub-item:hover a,
.wcs-sub-item.active a {
    opacity: 1;
    color: var(--wpw-accent) !important;
}

/* Grouped Archive Headers */
.marck-category-group {
    margin-bottom: 60px;
}

.marck-category-group-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--wpw-bg);
}

.marck-category-group-header h2 {
    font-family: var(--wpw-font-serif);
    font-size: 28px;
    margin: 0;
    color: var(--wpw-ink);
}

.marck-category-group-header .count {
    background: var(--wpw-bg);
    color: var(--wpw-ink-muted);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.marck-category-group-header .view-all {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--wpw-accent);
    text-decoration: none;
    border-bottom: 1.5px solid transparent;
    transition: all 0.25s ease;
}

/* Grouped Archive Layout */
.marck-archive-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 40px;
    margin: 40px 0;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

.marck-archive-main {
    min-width: 0;
    /* Prevent grid overflow */
}

@media (max-width: 1024px) {
    .marck-archive-layout {
        grid-template-columns: 1fr;
    }

    .marck-archive-sidebar {
        order: 2;
    }
}

/* Force 3 columns in grouped blocks when sidebar is present */
.marck-archive-layout .woocommerce ul.products {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 25px !important;
}

.marck-archive-layout .woocommerce ul.products::before,
.marck-archive-layout .woocommerce ul.products::after {
    display: none !important;
    /* Remove float clearers */
}

.marck-archive-layout .woocommerce ul.products li.product {
    width: 100% !important;
    margin: 0 !important;
    float: none !important;
}

@media (max-width: 768px) {
    .marck-archive-layout .woocommerce ul.products {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .marck-archive-layout .woocommerce ul.products {
        grid-template-columns: 1fr !important;
    }
}

.marck-category-group {
    margin-bottom: 60px;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.03);
}

.marck-category-group-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eee;
}

.marck-category-group-header h2 {
    font-size: 24px !important;
    margin: 0 !important;
    font-weight: 700 !important;
}

/* Ensure the button is always at the bottom */
.woocommerce ul.products li.product .button,
.wpw-quote-btn {
    margin-top: auto !important;
    align-self: center !important;
    width: 100% !important;
    text-align: center !important;
}