/*
 * 商品图片显示优化专用样式 - 最高优先级修复
 * 解决商品图片无法完全填充容器的问题
 * 适用于首页推荐商品、商品列表页面、移动端和桌面端
 * 使用最高优先级选择器确保样式生效
 */

/* ===== 最高优先级商品图片容器优化 ===== */
body .product-card .product-card__image,
body .recommended-products .product-card .product-card__image,
body .woocommerce .product-card .product-card__image,
body .products-grid .product-card .product-card__image,
body .shop-products .product-card .product-card__image,
body .woocommerce ul.products li.product .product-card__image,
body .woocommerce-page .product-card__image {
    position: relative !important;
    aspect-ratio: 4/3 !important;
    overflow: hidden !important;
    background-color: #f8f9fa !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 12px 12px 0 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 200px !important;
}

/* ===== 最高优先级商品图片样式优化 ===== */
body .product-card .product-card__image img,
body .recommended-products .product-card .product-card__image img,
body .woocommerce .product-card .product-card__image img,
body .products-grid .product-card .product-card__image img,
body .shop-products .product-card .product-card__image img,
body .woocommerce ul.products li.product .product-card__image img,
body .woocommerce-page .product-card__image img,
body .woocommerce ul.products li.product img,
body .woocommerce ul.products li.product .attachment-woocommerce_thumbnail {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    transition: transform 0.3s ease !important;
    display: block !important;
    border: none !important;
    outline: none !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    vertical-align: top !important;
}

/* ===== 最高优先级链接包装器优化 ===== */
body .product-card .product-card__image a,
body .recommended-products .product-card .product-card__image a,
body .woocommerce .product-card .product-card__image a,
body .products-grid .product-card .product-card__image a,
body .shop-products .product-card .product-card__image a,
body .woocommerce ul.products li.product a,
body .woocommerce ul.products li.product .woocommerce-loop-product__link {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    line-height: 0 !important;
    text-decoration: none !important;
    border: none !important;
    outline: none !important;
}

body .product-card .product-card__image a img,
body .recommended-products .product-card .product-card__image a img,
body .woocommerce .product-card .product-card__image a img,
body .products-grid .product-card .product-card__image a img,
body .shop-products .product-card .product-card__image a img,
body .woocommerce ul.products li.product a img,
body .woocommerce ul.products li.product .woocommerce-loop-product__link img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ===== 悬停效果 ===== */
.product-card:hover .product-card__image img,
.recommended-products .product-card:hover .product-card__image img,
.woocommerce .product-card:hover .product-card__image img,
.products-grid .product-card:hover .product-card__image img,
.shop-products .product-card:hover .product-card__image img {
    transform: scale(1.05) !important;
}

/* ===== WooCommerce 特定优化 - 最高优先级 ===== */
body.woocommerce ul.products,
body.woocommerce-page ul.products {
    display: block !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.woocommerce ul.products li.product,
body.woocommerce-page ul.products li.product {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    width: auto !important;
}

body.woocommerce ul.products li.product .woocommerce-loop-product__link,
body.woocommerce-page ul.products li.product .woocommerce-loop-product__link {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    text-decoration: none !important;
    border: none !important;
}

body.woocommerce ul.products li.product img,
body.woocommerce-page ul.products li.product img,
body.woocommerce ul.products li.product .attachment-woocommerce_thumbnail,
body.woocommerce-page ul.products li.product .attachment-woocommerce_thumbnail {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
    max-width: none !important;
    max-height: none !important;
}

/* 修复WooCommerce默认图片容器 */
body.woocommerce ul.products li.product .product-card__image,
body.woocommerce-page ul.products li.product .product-card__image {
    position: relative !important;
    aspect-ratio: 4/3 !important;
    overflow: hidden !important;
    background-color: #f8f9fa !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: auto !important;
    min-height: 200px !important;
}

/* ===== 响应式设计 - 桌面端 ===== */
@media (min-width: 1025px) {
    .product-card__image {
        min-height: 240px !important;
    }
}

/* ===== 响应式设计 - 平板端 ===== */
@media (max-width: 1024px) and (min-width: 769px) {
    .product-card__image {
        min-height: 220px !important;
    }
}

/* ===== 响应式设计 - 小平板端 ===== */
@media (max-width: 768px) and (min-width: 481px) {
    .product-card__image {
        min-height: 200px !important;
    }
}

/* ===== 响应式设计 - 移动端 ===== */
@media (max-width: 480px) {
    .product-card__image,
    .recommended-products .product-card__image,
    .woocommerce .product-card__image,
    .products-grid .product-card__image,
    .shop-products .product-card__image {
        aspect-ratio: 4/3 !important;
        min-height: 180px !important;
        height: auto !important;
    }

    .product-card__image img,
    .recommended-products .product-card__image img,
    .woocommerce .product-card__image img,
    .products-grid .product-card__image img,
    .shop-products .product-card__image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        object-position: center !important;
    }
}

/* ===== 超小屏幕优化 ===== */
@media (max-width: 360px) {
    .product-card__image {
        min-height: 160px !important;
    }
}

/* ===== 占位图片优化 ===== */
.product-card__image img[src*="placeholder"],
.product-card__image img[src*="via.placeholder"] {
    background-color: #f8f9fa !important;
    color: #6c757d !important;
}

/* ===== 图片加载状态优化 ===== */
.product-card__image img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.product-card__image img[loading="lazy"].loaded,
.product-card__image img:not([loading="lazy"]) {
    opacity: 1;
}

/* ===== 确保图片不会被其他样式覆盖 ===== */
.product-card__image {
    z-index: 1 !important;
}

.product-card__image img {
    z-index: 2 !important;
}

/* ===== 商品标签位置调整 ===== */
.product-card__badge {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    z-index: 10 !important;
}

/* ===== 修复可能的布局问题 ===== */
.product-card {
    overflow: hidden !important;
}

.product-card__content {
    position: relative !important;
    z-index: 3 !important;
}

/* ===== 浏览器兼容性修复 - 针对不支持aspect-ratio的浏览器 ===== */

/* 为不支持aspect-ratio的浏览器提供fallback */
body .product-card .product-card__image,
body .recommended-products .product-card .product-card__image,
body .woocommerce .product-card .product-card__image,
body .products-grid .product-card .product-card__image,
body .shop-products .product-card .product-card__image {
    /* 使用padding-bottom技术创建4:3比例 */
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 75% !important; /* 4:3 = 75% */
    overflow: hidden !important;
    background-color: #f8f9fa !important;
}

/* 支持aspect-ratio的现代浏览器 */
@supports (aspect-ratio: 4/3) {
    body .product-card .product-card__image,
    body .recommended-products .product-card .product-card__image,
    body .woocommerce .product-card .product-card__image,
    body .products-grid .product-card .product-card__image,
    body .shop-products .product-card .product-card__image {
        height: auto !important;
        padding-bottom: 0 !important;
        aspect-ratio: 4/3 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* 图片在padding-bottom容器中的绝对定位 */
body .product-card .product-card__image img,
body .recommended-products .product-card .product-card__image img,
body .woocommerce .product-card .product-card__image img,
body .products-grid .product-card .product-card__image img,
body .shop-products .product-card .product-card__image img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
}

/* 支持aspect-ratio的现代浏览器中的图片 */
@supports (aspect-ratio: 4/3) {
    body .product-card .product-card__image img,
    body .recommended-products .product-card .product-card__image img,
    body .woocommerce .product-card .product-card__image img,
    body .products-grid .product-card .product-card__image img,
    body .shop-products .product-card .product-card__image img {
        position: static !important;
        top: auto !important;
        left: auto !important;
    }
}

/* 链接在padding-bottom容器中的绝对定位 */
body .product-card .product-card__image a,
body .recommended-products .product-card .product-card__image a,
body .woocommerce .product-card .product-card__image a,
body .products-grid .product-card .product-card__image a,
body .shop-products .product-card .product-card__image a {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    line-height: 0 !important;
}

/* 支持aspect-ratio的现代浏览器中的链接 */
@supports (aspect-ratio: 4/3) {
    body .product-card .product-card__image a,
    body .recommended-products .product-card .product-card__image a,
    body .woocommerce .product-card .product-card__image a,
    body .products-grid .product-card .product-card__image a,
    body .shop-products .product-card .product-card__image a {
        position: static !important;
        top: auto !important;
        left: auto !important;
    }
}
