/* Merch.v3 Product Card - Base Layout */

.merch-v3-product-card {
    display: flex;
    flex-direction: column;
    width: 100% !important;
    height: 100%;
    max-width: none !important;
    min-width: 0 !important;
    border-radius: 8px;
    overflow: hidden;
    background: var(--wp--preset--color--neutral-050, #161616);
    box-sizing: border-box;
    position: relative;
    /* Support aspect-ratio from parent container */
    aspect-ratio: inherit;
    border: 1px solid var(--wp--preset--color--border-product-card, var(--merch-v3-border-product-card, rgb(53, 53, 53)));
}

.merch-v3-product-card__link {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.merch-v3-product-card__link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.merch-v3-product-card__image {
    flex: 1;
    background: var(--wp--preset--color--neutral-200, #2A2A2A);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    border-radius: 8px 8px 0 0;
}

.merch-v3-product-card__image-element {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    display: block !important;
    max-width: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    transition: transform 0.3s ease;
}

.merch-v3-product-card__link:hover .merch-v3-product-card__image-element {
    transform: scale(1.05);
}

/* Section 2: INFO - 30% */
.merch-v3-product-card__info {
    background: var(--wp--preset--color--neutral-100, #212121);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
    box-sizing: border-box;
    position: relative;
    min-height: 148px;
}

/* Product Name - максимум 2 рядки */
.merch-v3-product-card__name {
    margin: 0;
    font-size: 0.95rem; /* 1rem * 0.95 */
    line-height: 1.1875rem; /* 1.25rem * 0.95 */
    font-weight: 600;
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    transition: color 0.2s ease;
    /* Обмеження до 2 рядків */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.merch-v3-product-card__link:hover .merch-v3-product-card__name {
    color: var(--wp--preset--color--primary-light, #6BA0FF);
}

/* Product Region */
.merch-v3-product-card__region {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.831rem; /* 0.875rem * 0.95 */
    line-height: 1.1875rem; /* 1.25rem * 0.95 */
    color: var(--wp--preset--color--gray-medium, #8F8F8F);
}

.merch-v3-product-card__region-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.merch-v3-product-card__region-icon img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    display: block !important;
    max-width: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    filter: brightness(0) saturate(100%) invert(62%) sepia(0%) saturate(0%) hue-rotate(180deg) brightness(93%) contrast(89%);
}

.merch-v3-product-card__region-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* Price Label */
.merch-v3-product-card__price-label {
    font-size: 0.712rem; /* 0.75rem * 0.95 */
    line-height: 0.712rem;
    color: var(--wp--preset--color--gray-medium, #8F8F8F);
    margin-bottom: 2px;
}

/* Price Section */
.merch-v3-product-card__price-section {
    /* Removed position: relative - not needed without absolute positioning */
}

/* Price Wrapper */
.merch-v3-product-card__price-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: space-between;
    width: 100%;
}

/* Price - збільшено в 1.5 рази, потім -5% */
.merch-v3-product-card__price {
    font-size: 1.425rem; /* 1.5rem * 0.95 */
    line-height: 1.781rem; /* 1.875rem * 0.95 */
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    font-weight: 600;
    flex: 1;
}

.merch-v3-product-card__price .woocommerce-Price-amount {
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
}

/* Cart Button */
.merch-v3-product-card__cart-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--wp--preset--color--primary-500, #2437A4);
    border: none;
    border-radius: 8px;
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    text-decoration: none;
    /* Removed absolute positioning - button is now in flex container */
}

.merch-v3-product-card__cart-button:hover {
    background: var(--wp--preset--color--primary-600, #1B2E8C);
    transform: scale(1.05);
}

.merch-v3-product-card__cart-button:active {
    transform: scale(0.95);
}

.merch-v3-product-card__cart-button:disabled {
    background: var(--wp--preset--color--gray-600, #4B5563);
    cursor: not-allowed;
    opacity: 0.6;
    position: relative;
}

.merch-v3-product-card__cart-button svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

/* Out of stock icon with crossed line */
.merch-v3-product-card__cart-icon-out-of-stock {
    position: relative;
}

/* Tooltip for out of stock */
.merch-v3-product-card__cart-button:disabled::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--merch-v3-nav-bg, var(--wp--preset--color--dark, #212121));
    color: var(--merch-v3-footer-text, var(--wp--preset--color--white, #FFFFFF));
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateX(-50%) translateY(5px);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.merch-v3-product-card__cart-button:disabled::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--merch-v3-nav-bg, var(--wp--preset--color--dark, #212121));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1001;
}

.merch-v3-product-card__cart-button:disabled:hover::after,
.merch-v3-product-card__cart-button:disabled:hover::before {
    opacity: 1;
    visibility: visible;
}

.merch-v3-product-card__cart-button:disabled:hover::after {
    transform: translateX(-50%) translateY(0);
}

/* User Currency Price - бейдж з іконкою */
.merch-v3-product-card__user-price {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border: 1px solid var(--wp--preset--color--primary-500, #7B68EE);
    border-radius: 8px;
    font-size: 0.95rem; /* 1rem * 0.95 */
    line-height: 1.1875rem; /* 1.25rem * 0.95 */
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    font-weight: 500;
}

.merch-v3-product-card__user-price-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background: var(--wp--preset--color--primary-500, #7B68EE);
    border-radius: 50%;
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    font-weight: 700;
    font-size: 0.831rem; /* 0.875rem * 0.95 */
}

.merch-v3-product-card__user-price-text {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex: 1;
}

.merch-v3-product-card__user-price-label {
    font-size: 0.75rem; /* 1rem * 0.95 */
    line-height: 1.1875rem; /* 1.25rem * 0.95 */
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    font-weight: 500;
}

.merch-v3-product-card__user-price-value {
    font-size: 0.75rem; /* 1rem * 0.95 */
    line-height: 1.1875rem; /* 1.25rem * 0.95 */
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
    font-weight: 600;
}

.merch-v3-product-card__user-price-value .woocommerce-Price-amount {
    color: var(--wp--preset--color--neutral-000, #FFFFFF);
}

/* Integration with product-short-list block */
.product-short-list-block__card {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}

.product-short-list-block__card .merch-v3-product-card {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    /* Remove aspect-ratio inheritance when inside product-short-list (parent already has it) */
    aspect-ratio: unset;
    box-sizing: border-box !important;
}

/* FORCE: Override inline styles from parent JS - let CSS Grid handle sizing */
.product-short-list-block__grid .product-short-list-block__item[style] {
    /* More specific selector to override inline styles */
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-sizing: border-box !important;
}

/* Fallback for items without inline styles */
.product-short-list-block__grid .product-short-list-block__item {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-sizing: border-box !important;
}

/* Ensure grid container takes full width and grid works properly */
.product-short-list-block__grid {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    display: grid !important;
}

/* STRONGEST: Remove any width constraints on grid items when using merch-v3 cards */
.product-short-list-block__grid:has(.merch-v3-product-card) .product-short-list-block__item,
.product-short-list-block__grid:has(.merch-v3-product-card) .product-short-list-block__item[style*="max-width"],
.product-short-list-block__grid:has(.merch-v3-product-card) .product-short-list-block__item[style*="min-width"] {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
}

/* For inline mode */
.product-short-list-block__inline-grid .product-short-list-block__card .merch-v3-product-card {
    width: 100% !important;
    height: 100% !important;
}

/* Remove padding from parent card when using our shortcode */
.product-short-list-block__card:has(.merch-v3-product-card) {
    padding: 0 !important;
    box-sizing: border-box !important;
}

/* Fallback if :has() not supported - target card directly */
.product-short-list-block__item:has(.merch-v3-product-card) .product-short-list-block__card {
    padding: 0 !important;
}

/* Fix: Override parent theme JavaScript that limits columns */
/* This ensures all items are visible and grid respects the columns setting */
.product-short-list-block__grid .product-short-list-block__item {
    display: block !important;
}

/* Desktop grid columns - JavaScript will apply these dynamically */
/* Keeping CSS as fallback if JS fails */
@media (min-width: 1025px) {
    .product-short-list-block__grid[data-columns="5"] {
        grid-template-columns: repeat(5, 1fr) !important;
    }
    .product-short-list-block__grid[data-columns="6"] {
        grid-template-columns: repeat(6, 1fr) !important;
    }
    .product-short-list-block__grid[data-columns="7"] {
        grid-template-columns: repeat(7, 1fr) !important;
    }
    .product-short-list-block__grid[data-columns="8"] {
        grid-template-columns: repeat(8, 1fr) !important;
    }
}

/* ============================================
   PRODUCT TABLE BLOCK INTEGRATION
   ============================================
   
   Usage in Product Table block settings:
   [merch_v3_product_card product_id="[product_id]" aspect_ratio="0.43" aspect_ratio_mobile="0.55"]
   
   This integration ensures the Merch.v3 product card
   works seamlessly within the Product Table grid layout:
   
   - Removes padding from parent containers
   - Overrides width constraints for proper grid sizing
   - Inherits aspect ratio from block settings
   - Ensures all items are visible in grid
   
   ============================================ */

/* Integration with product-table block */
.product-table-block-product__card {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    aspect-ratio: var(--aspect-ratio, 0.42);
}

.product-table-block-product__card .merch-v3-product-card {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    /* Remove aspect-ratio inheritance when inside product-table (parent already has it) */
    aspect-ratio: unset;
    box-sizing: border-box !important;
}

/* FORCE: Override inline styles from parent - let CSS Grid handle sizing */
.product-table-block-product__grid .product-table-block-product__item[style] {
    /* More specific selector to override inline styles */
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-sizing: border-box !important;
}

/* Fallback for items without inline styles */
.product-table-block-product__grid .product-table-block-product__item {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-sizing: border-box !important;
}

/* Ensure grid container takes full width and grid works properly */
.product-table-block-product__grid {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    display: grid !important;
}

/* STRONGEST: Remove any width constraints on grid items when using merch-v3 cards */
.product-table-block-product__grid:has(.merch-v3-product-card) .product-table-block-product__item,
.product-table-block-product__grid:has(.merch-v3-product-card) .product-table-block-product__item[style*="max-width"],
.product-table-block-product__grid:has(.merch-v3-product-card) .product-table-block-product__item[style*="min-width"] {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
}

/* Remove padding from parent card when using our shortcode */
.product-table-block-product__card:has(.merch-v3-product-card) {
    padding: 0 !important;
    box-sizing: border-box !important;
    background: transparent !important;
    border-radius: 0 !important;
}

/* Fallback if :has() not supported - target card directly */
.product-table-block-product__item:has(.merch-v3-product-card) .product-table-block-product__card {
    padding: 0 !important;
    background: transparent !important;
    border-radius: 0 !important;
}

/* Fix: Override parent theme that might limit visibility */
.product-table-block-product__grid .product-table-block-product__item {
    display: block !important;
}

/* Responsive grid columns support for product-table */
/* Grid columns are defined via inline styles from PHP */

/* Mobile aspect ratio (≤768px); card shortcode vars drive height (not block --aspect-ratio) */
@media (max-width: 768px) {
    /* Parent wrappers: release block-level aspect-ratio so the child can size itself */
    .product-short-list-block__inline-grid .product-short-list-block__card:has(.merch-v3-product-card),
    .product-short-list-block__card:has(.merch-v3-product-card),
    .product-table-block-product__card:has(.merch-v3-product-card) {
        aspect-ratio: auto !important;
        height: auto !important;
        min-height: 0;
        display: block;
    }

    /* Child card: use shortcode --aspect-ratio-mobile (falls back to --aspect-ratio) */
    .product-short-list-block__inline-grid .product-short-list-block__card .merch-v3-product-card,
    .product-short-list-block__card .merch-v3-product-card,
    .product-table-block-product__card .merch-v3-product-card,
    .merch-v3-product-card {
        aspect-ratio: var(--aspect-ratio-mobile, var(--aspect-ratio, 0.46)) !important;
        height: auto !important;
        min-height: 0;
        width: 100% !important;
    }

    .product-short-list-block__inline-grid .product-short-list-block__item:has(.merch-v3-product-card) {
        align-self: start;
    }
}
