/* ========== 搜索页产品网格优化样式 - 修复版 ========== */

/* ========== PC端网格布局（5列） ========== */
@media (min-width: 1200px) {
    .products-wrapper.grid-view .row {
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 20px !important;
        margin: 0 !important;
    }
    
    .products-wrapper.grid-view .col-6,
    .products-wrapper.grid-view .col-md-4,
    .products-wrapper.grid-view .col-lg-3,
    .products-wrapper.grid-view .col-xl-3 {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        padding: 0 !important;
    }
}

/* ========== 中等屏幕（4列） ========== */
@media (min-width: 992px) and (max-width: 1199px) {
    .products-wrapper.grid-view .row {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 15px !important;
        margin: 0 !important;
    }
    
    .products-wrapper.grid-view .col-6,
    .products-wrapper.grid-view .col-md-4,
    .products-wrapper.grid-view .col-lg-3 {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        padding: 0 !important;
    }
}

/* ========== 平板屏幕（3列） ========== */
@media (min-width: 768px) and (max-width: 991px) {
    .products-wrapper.grid-view .row {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 15px !important;
        margin: 0 !important;
    }
    
    .products-wrapper.grid-view .col-6,
    .products-wrapper.grid-view .col-md-4 {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        padding: 0 !important;
    }
}

/* ========== 移动端布局（2列优化） ========== */
@media (max-width: 767px) {
    /* 网格容器 - 更紧凑的间距 */
    .products-wrapper.grid-view .row {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        margin: 0 !important;
        padding: 10px !important;
        background: #f8f9fa !important;
    }
    
    /* 重置Bootstrap列类 */
    .products-wrapper.grid-view .col-6,
    .products-wrapper.grid-view .col-md-4,
    .products-wrapper.grid-view .col-lg-3,
    .products-wrapper.grid-view .col-xl-3 {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* 产品卡片容器 - 美化设计 */
    .products-wrapper.grid-view .product-card {
        display: flex !important;
        flex-direction: column !important;
        background: #fff !important;
        border: none !important;
        border-radius: 16px !important;
        padding: 0 !important;
        height: 100% !important;
        overflow: hidden !important;
        position: relative !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    
    .products-wrapper.grid-view .product-card:active {
        transform: scale(0.97) !important;
        box-shadow: 0 4px 16px rgba(0,0,0,0.1) !important;
    }
    
    /* 图片容器 - 优化比例和显示 */
    .products-wrapper.grid-view .product-image-wrapper {
        position: relative !important;
        width: 100% !important;
        padding-bottom: 100% !important; /* 1:1宽高比 */
        overflow: hidden !important;
        background: linear-gradient(145deg, #f8f9fa, #fff) !important;
        margin-bottom: 0 !important;
    }
    
    /* 产品图片 - 智能适配 */
    .products-wrapper.grid-view .product-image-wrapper img,
    .products-wrapper.grid-view .product-image-wrapper .product-image {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 85% !important; /* 缩小到85%避免太满 */
        height: 85% !important;
        object-fit: contain !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        transition: transform 0.3s ease !important;
    }
    
    .products-wrapper.grid-view .product-card:hover img {
        transform: translate(-50%, -50%) scale(1.05) !important;
    }
    
    /* 快速查看按钮 */
    .products-wrapper.grid-view .grid-quick-view {
        position: absolute !important;
        top: 8px !important;
        right: 8px !important;
        width: 32px !important;
        height: 32px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        opacity: 0 !important;
        transition: opacity 0.3s !important;
        z-index: 2 !important;
    }
    
    .products-wrapper.grid-view .product-card:hover .grid-quick-view {
        opacity: 1 !important;
    }
    
    /* 折扣标签 */
    .products-wrapper.grid-view .grid-discount-badge {
        position: absolute !important;
        top: 8px !important;
        left: 8px !important;
        background: #ef4444 !important;
        color: white !important;
        padding: 2px 6px !important;
        border-radius: 4px !important;
        font-size: 10px !important;
        font-weight: 600 !important;
        z-index: 2 !important;
    }
    
    /* 产品标签 */
    .products-wrapper.grid-view .grid-product-badges {
        position: absolute !important;
        top: 8px !important;
        right: 8px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
        z-index: 2 !important;
    }
    
    .products-wrapper.grid-view .grid-badge {
        padding: 2px 6px !important;
        border-radius: 3px !important;
        font-size: 9px !important;
        font-weight: 600 !important;
        text-transform: uppercase !important;
    }
    
    .products-wrapper.grid-view .grid-badge.new {
        background: #10b981 !important;
        color: white !important;
    }
    
    .products-wrapper.grid-view .grid-badge.hot {
        background: #f59e0b !important;
        color: white !important;
    }
    
    .products-wrapper.grid-view .grid-badge.sale {
        background: #ef4444 !important;
        color: white !important;
    }
    
    /* 产品信息区域 - 美化布局 */
    .products-wrapper.grid-view .product-info {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        padding: 10px !important;
        background: #fff !important;
    }
    
    /* 产品名称 - 美化样式 */
    .products-wrapper.grid-view .product-name {
        margin-bottom: 6px !important;
        height: 30px !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        line-height: 1.25 !important;
    }
    
    .products-wrapper.grid-view .product-name a {
        color: #2c3e50 !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        text-decoration: none !important;
        letter-spacing: -0.3px !important;
    }
    
    /* 移动端隐藏评分 */
    .products-wrapper.grid-view .grid-product-rating {
        display: none !important;
    }
    
    /* 价格区域 - 美化设计 */
    .products-wrapper.grid-view .product-price {
        margin-top: auto !important;
        padding-top: 6px !important;
        border-top: none !important;
        margin-bottom: 8px !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }
    
    .products-wrapper.grid-view .price-new {
        color: #e74c3c !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        display: inline-block !important;
        line-height: 1 !important;
    }
    
    .products-wrapper.grid-view .price-old {
        color: #95a5a6 !important;
        font-size: 11px !important;
        text-decoration: line-through !important;
        margin-left: 0 !important;
        display: inline-block !important;
        line-height: 1.2 !important;
    }
    
    /* 操作按钮 - 美化设计 */
    .products-wrapper.grid-view .grid-product-actions {
        margin-top: auto !important;
        position: relative !important;
        display: flex !important;
        gap: 4px !important;
        align-items: center !important;
    }
    
    .products-wrapper.grid-view .add-to-cart,
    .products-wrapper.grid-view .grid-btn-view {
        flex: 1 !important;
        padding: 8px 4px !important;
        background: linear-gradient(135deg, #e74c3c, #c0392b) !important;
        color: #fff !important;
        border: none !important;
        border-radius: 10px !important;
        font-size: 18px !important;
        font-weight: 500 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-decoration: none !important;
        cursor: pointer !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        min-height: 36px !important;
        box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3) !important;
    }
    
    .products-wrapper.grid-view .add-to-cart:active,
    .products-wrapper.grid-view .grid-btn-view:active {
        transform: scale(0.95) !important;
        background: #b71c1c !important;
    }
    
    .products-wrapper.grid-view .add-to-cart i,
    .products-wrapper.grid-view .grid-btn-view i {
        font-size: 14px !important;
    }
    
    /* 移动端隐藏按钮文字，只显示图标 */
    .products-wrapper.grid-view .add-to-cart span,
    .products-wrapper.grid-view .grid-btn-view span {
        display: none !important;
    }
    
    /* 移动端隐藏收藏按钮 */
    .products-wrapper.grid-view .grid-secondary-actions {
        display: none !important;
    }
    
    /* 购物车按钮占满宽度 */
    .products-wrapper.grid-view .add-to-cart,
    .products-wrapper.grid-view .grid-btn-view {
        width: 100% !important; /* 占满宽度 */
    }
}

/* ========== 超小屏幕优化 ========== */
@media (max-width: 375px) {
    .products-wrapper.grid-view .row {
        gap: 8px !important;
        padding: 8px !important;
    }
    
    .products-wrapper.grid-view .product-info {
        padding: 0 2px !important;
    }
    
    .products-wrapper.grid-view .product-name {
        font-size: 11px !important;
    }
    
    .products-wrapper.grid-view .price-new {
        font-size: 14px !important;
    }
}

/* ========== 通用样式 ========== */

/* 产品卡片基础样式 */
.products-wrapper.grid-view .product-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.products-wrapper.grid-view .product-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

/* 图片容器基础样式 */
.products-wrapper.grid-view .product-image-wrapper {
    background: linear-gradient(135deg, #f5f5f5 0%, #fafafa 100%);
    position: relative;
    overflow: hidden;
}

/* 确保所有图片正确加载 */
.products-wrapper.grid-view img {
    max-width: none;
    min-height: auto;
}

/* 防止内容溢出 */
.products-wrapper.grid-view .product-card * {
    max-width: 100%;
    word-break: break-word;
}

/* 确保网格容器全宽 */
.products-wrapper.grid-view {
    width: 100%;
}

/* 加载状态样式 */
.products-wrapper.grid-view .product-card.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.products-wrapper.grid-view .product-card {
    animation: fadeIn 0.3s ease;
}
