/* ====================================
   MODERN PRODUCT CARD STYLE

   ==================================== */

/* Product Grid Container */
/* Mobile-first: 2 cột mặc định */
.product-grid-modern {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 20px;
    padding: 0 8px;
    box-sizing: border-box;
}

/* Mobile: 2 cột (dưới 768px) - Tối ưu */
@media (max-width: 767px) {
    .product-grid-modern {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 0 8px;
        margin-top: 15px;
    }
    
    .product-grid-modern .prod-item,
    .product-grid-modern .product-card-modern {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Tablet (≥768px và <992px): 3 cột */
@media (min-width: 768px) and (max-width: 991px) {
    .product-grid-modern {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        padding: 0 10px;
    }
    
    /* Giữ tỉ lệ 16:9 */
    .product-card-image-wrapper {
        padding-top: 56.25%;
    }
}

/* PC (≥992px): 4 cột */
@media (min-width: 992px) {
    .product-grid-modern {
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
        padding: 0 12px;
    }
    
    /* Giữ tỉ lệ 16:9 */
    .product-card-image-wrapper {
        padding-top: 56.25%;
    }
}

/* Override Bootstrap khi dùng với product-grid-modern */
.product-grid-modern .prod-item {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    margin-bottom: 0 !important;
    /* Đảm bảo không có viền thừa */
    border: none !important;
    box-sizing: border-box !important;
}

/* Đảm bảo product-card-modern trong grid không có margin/padding thừa */
.product-grid-modern .product-card-modern {
    margin: 0;
    padding: 0;
    border: none;
}

/* Product Card Modern */
.product-card-modern {
    position: relative;
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 10px !important;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Đảm bảo không có viền thừa */
    margin: 0;
    padding: 10px !important;
    box-sizing: border-box;
}

.product-card-modern:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    transform: translateY(-2px) !important;
}

.product-card-modern.product-disable {
    opacity: 0.7;
    pointer-events: none;
}

/* Product Image Container */
.product-card-image-wrapper {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* Tỉ lệ 16:9 */
    aspect-ratio: 16 / 9;
    background: #fff; /* Nền trắng để ảnh nhỏ hơn khung vẫn đẹp */
    overflow: hidden;
    border-radius: 8px;
    /* Đảm bảo khung không thay đổi kích thước */
    height: 0;
    /* Loại bỏ mọi viền và khoảng trống */
    margin: 0;
    margin-bottom: 6px;
    padding: 0;
    border: none;
    /* Đảm bảo khung cố định, không giãn */
    box-sizing: border-box;
}

/* Link wrapper bên trong image-wrapper */
.product-card-image-wrapper > a {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    text-decoration: none;
    /* Loại bỏ viền và khoảng trống */
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    /* Đảm bảo link phủ kín wrapper */
    box-sizing: border-box;
}

.product-card-image-wrapper img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Căn giữa hoàn hảo */
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* Ảnh vừa khung, không bị crop - giống logo TikTok */
    object-position: center center; /* Căn giữa ảnh cả ngang và dọc */
    transition: transform 0.3s ease;
    /* Loại bỏ viền trắng và khoảng trống */
    display: block;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent; /* Không có nền */
    /* Đảm bảo ảnh vừa khung dù to hay nhỏ */
    box-sizing: content-box;
}

.product-card-modern:hover .product-card-image-wrapper img {
    transform: translate(-50%, -50%) scale(1.05); /* Giữ căn giữa khi scale */
}

/* Badge Container - Ribbon Shopee style */
.product-card-badges {
    position: absolute;
    top: 8px;
    left: 0;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}

.product-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #fff;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.product-badge.badge-pro {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.product-badge.badge-premium {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.product-badge.badge-hot {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
}

.product-badge.badge-sale {
    background: #ff4757;
}

.product-badge.badge-discount {
    position: relative;
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    height: 32px;
    padding: 0 15px 0 10px;
    border-radius: 0;
    background: linear-gradient(90deg, #ff4d4dad 0%, #ff1a1a 60%, #cc0000 100%);
    -webkit-clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%);
    clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%);
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.5px;
    white-space: nowrap;
    pointer-events: auto;
}

/* Nếp gấp 3D bên trái */
.product-badge.badge-discount::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 10px;
    height: 8px;
    background: #7a0000;
    -webkit-clip-path: polygon(0 0, 100% 0, 100% 100%);
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

/* Product Content */
.product-card-content {
    padding: 0;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: transparent !important;
}

/* Product Name */
.product-card-name {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937 !important;
    margin-bottom: 4px;
    line-height: 1.4;
    min-height: auto;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.product-card-name a {
    color: #1f2937 !important;
    text-decoration: none;
    transition: color 0.2s;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-card-name a:hover {
    color: var(--primary) !important;
}

/* Tooltip cho tên dài - chỉ hiển thị khi text bị cắt */
.product-card-name a[title] {
    cursor: help;
}

/* Product Duration/Type */
.product-card-duration {
    font-size: 12px;
    color: #6b7280 !important;
    margin-bottom: 2px;
    font-weight: 500;
}

/* Price Container */
.product-card-price-wrapper {
    margin-top: auto;
    padding-top: 0;
    border-top: none !important;
    margin-top: 6px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.product-card-price-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 0;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.product-card-price-row > div {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.product-card-price-current {
    font-size: 16px;
    font-weight: 700;
    color: #ef4444 !important;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
}

.product-card-price-original {
    font-size: 12px;
    color: #7a8a99;
    text-decoration: line-through;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.product-card-discount-badge {
    background: #ff4757;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

/* Buy Button */
.product-card-buy-btn {
    width: 100%;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary1) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.product-card-buy-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.product-card-buy-btn:active:not(:disabled) {
    transform: translateY(0);
}

.product-card-buy-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    opacity: 0.7;
}

.product-card-buy-btn i {
    font-size: 12px;
}

/* Buy Button with Image (Mua Ngay style) */
.product-card-buy-btn.btn-muangay img,
.btn-buy.btn-muangay img {
    max-width: 100px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Stock Info */
.product-card-stock-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 12px;
    margin-top: 0;
    margin-bottom: 6px;
    padding: 0;
    border: none !important;
}

.product-card-stock-info .product-card-stock,
.product-card-stock-info .product-card-sold {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #ff0000;
    font-weight: 600;
}

.product-card-stock-info .product-card-sold {
    justify-content: flex-end;
    color: #ff0000;
}

.product-card-stock-info .label-text {
    font-size: 13px;
    padding: 4px 2px;
    border-radius: 4px;
    margin: 0;
    white-space: nowrap;
    color: #000 !important;
    font-weight: 600;
}

/* Action Buttons Container */
.product-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 0;
    margin-bottom: 0;
    justify-content: flex-start;
    align-items: flex-start;
}

/* Detail Button */
.product-card-detail-btn {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--primary);
    border-radius: 6px;
    background: transparent;
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.product-card-detail-btn:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.product-card-detail-btn i {
    font-size: 12px;
}

/* Buy Button - Adjust width when with detail button */
.product-card-actions .product-card-buy-btn {
    flex: 1;
}

/* Stock Info (Optional - có thể ẩn) */
.product-card-stock {
    font-size: 11px;
    color: #636e72;
    margin-top: 8px;
    text-align: center;
}

.product-card-stock .stock-label {
    font-weight: 600;
}

.product-card-stock .stock-value {
    color: #00b894;
    font-weight: 700;
}

/* Sold Info (Optional) */
.product-card-sold {
    font-size: 11px;
    color: #636e72;
    margin-top: 4px;
    text-align: center;
}

/* Responsive Adjustments - Mobile (<768px) */
@media (max-width: 767px) {
    .product-card-modern {
        border-radius: 10px;
        padding: 8px !important;
    }
    
    .product-card-image-wrapper {
        padding-top: 56.25%; /* Giữ 16:9 trên mobile */
        border-radius: 8px;
        margin-bottom: 6px;
    }
    
    /* Ảnh tự động vừa khung, không bị crop */
    .product-card-image-wrapper img {
        /* Ảnh vừa khung dù to hay nhỏ - giống logo TikTok */
        object-fit: contain;
        object-position: center center;
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    
    .product-card-content {
        padding: 0;
        display: flex;
        flex-direction: column;
    }
    
    .product-card-name {
        font-size: 13px;
        line-height: 1.35;
        min-height: auto;      /* bỏ ép chiều cao */
        margin-bottom: 4px;
        order: 1;
    }
    
    .product-card-duration {
        font-size: 11px;
        margin-bottom: 0;
        order: 2;
    }
    
    /* Giá nằm 1 dòng riêng */
    .product-card-price-wrapper {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 6px;
        margin-top: auto;
        padding-top: 0;
        border-top: none !important;
        margin-bottom: 8px;
        order: 4;
    }
    
    .product-card-price-row {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 6px;
        width: 100%;
        flex-wrap: nowrap;
        min-width: 0;
    }
    
    .product-card-price-row > div {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: nowrap;
        min-width: 0;
    }
    
    .product-card-price-current {
        font-size: 13px;
        font-weight: 700;
        color: #ef4444 !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .product-card-price-original {
        font-size: 10px;
        color: #7a8a99;
        text-decoration: line-through;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .product-card-discount-badge {
        background: #ff4757;
        color: #fff;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 11px;
        font-weight: 700;
        white-space: nowrap;
    }
    
    /* Nút "Mua Ngay" xuống dòng dưới cùng */
    .product-card-actions {
        display: flex;
        flex-direction: column;
        gap: 6px;
        margin-top: 0;
        margin-bottom: 0;
        width: 100%;
        order: 5;
    }
    
    .product-card-detail-btn {
        padding: 6px 8px;
        font-size: 10px;
        min-height: 30px;
        width: 100%;
    }
    
    .product-card-buy-btn {
        padding: 6px 8px;
        font-size: 10px;
        min-height: 30px;
        width: 100%;
        order: 2;
    }
    
    .product-card-stock-info {
        flex-direction: row;
        gap: 6px;
        margin-top: 0px;
        margin-bottom: 3px;
        padding: 0;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        border-bottom: none;
        order: 3;
    }
    
    .product-card-stock-info .product-card-stock,
    .product-card-stock-info .product-card-sold {
        flex: 1;
        min-width: 0;
        font-size: 11px;
        gap: 3px;
    }
    
    .product-card-stock-info .product-card-stock {
        justify-content: flex-start;
    }
    
     .product-card-sold {
        justify-content: flex-end;
    }
}

/* Responsive Adjustments - Extra Small Mobile (≤575px) */
@media (max-width: 575px) {
    .product-card-modern {
        border-radius: 10px;
        padding: 8px !important;
    }
    
    .product-card-image-wrapper {
        padding-top: 56.25%; /* Giữ 16:9 trên mobile */
        border-radius: 8px;
        margin-bottom: 6px;
    }
    
    /* Ảnh tự động vừa khung, không bị crop */
    .product-card-image-wrapper img {
        /* Ảnh vừa khung dù to hay nhỏ - giống logo TikTok */
        object-fit: contain;
        object-position: center center;
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

/* Override Bootstrap grid khi dùng với product-grid-modern */
.product-grid-modern .prod-item {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    /* Đảm bảo không có viền thừa */
    border: none !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
}

/* Đảm bảo product-card-modern trong grid không có margin/padding thừa */
.product-grid-modern .product-card-modern {
    margin: 0;
    padding: 0;
    border: none;
    /* Đảm bảo kích thước đồng nhất */
    width: 100%;
    box-sizing: border-box;
}

/* Đảm bảo image-wrapper có kích thước đồng nhất trên mọi thiết bị */
.product-grid-modern .product-card-image-wrapper {
    /* Luôn giữ tỉ lệ 16:9 trên mọi thiết bị */
    aspect-ratio: 16 / 9;
    padding-top: 56.25%;
}

/* Đảm bảo ảnh vừa khung - áp dụng cho tất cả breakpoint */
.product-grid-modern .product-card-image-wrapper img {
    /* Ảnh vừa khung, không bị crop - giống logo TikTok */
    object-fit: contain !important;
    object-position: center center !important;
    /* Căn giữa hoàn hảo */
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
}

/* Đảm bảo container không overflow trên mobile */
@media (max-width: 767px) {
    .product-grid-modern {
        width: 100%;
        overflow: hidden;
    }
    
    .product-grid-modern .prod-item,
    .product-grid-modern .product-card-modern {
        overflow: hidden;
    }
}

@media (max-width: 576px) {
    .product-badge.badge-discount {
        height: 24px;
        font-size: 12px;
        padding: 0 10px 0 5px;
    }

    .product-badge.badge-discount::before {
        width: 8px;
        height: 7px;
        bottom: -7px;
    }
}
