/**
 * Responsive Product Grid System CSS
 * Ensures product grids are fully responsive across all devices
 */

/* Loading State */
.product-grid-loading {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3rem;
}

/* Product Grid Container */
.grid-products {
    width: 100%;
    margin: 0 auto;
}

#product-grid {
    display: flex;
    flex-wrap: wrap;
    margin-left: -6px;
    margin-right: -6px;
    gap: 0;
}

#product-grid .item {
    padding: 8px;
    margin-bottom: 20px;
    transition: none; /* Remove transition effect */
    display: flex;
    flex-direction: column;
    background: transparent;
}

#product-grid .item:hover {
    transform: none; /* Remove lift effect */
}

/* Ensure consistent grid item structure - Shein style */
.grid-products .item {
    display: flex;
    flex-direction: column;
    background: transparent;
    border-radius: 16px;
}

/* Product Images - Responsive */
.product-image {
    position: relative;
    overflow: hidden;
    background: #f8f8f8;
    width: 100%;
    padding-bottom: 133.33%; /* 4:3 aspect ratio */
    height: 0;
    border-radius: 24px; /* More rounded corners for aesthetic look */
}

.product-image > a {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.product-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: none;
}

.product-image .hover {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0 !important;
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.product-image:hover .hover,
.product-image:active .hover,
.product-image:focus .hover {
    opacity: 0 !important;
    display: none !important;
    visibility: hidden !important;
}

.product-image:hover .primary,
.product-image:active .primary,
.product-image:focus .primary {
    opacity: 1 !important;
    display: block !important;
}

/* Product Labels - Responsive */
.product-labels {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.product-labels .lbl {
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    display: inline-block;
}

/* Product Buttons - Touch Friendly */
.product-image .variants.add {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

.product-image .btn-addto-cart {
    position: relative;
    width: 100%;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.product-image:hover .btn-addto-cart,
.product-image .btn-addto-cart:focus {
    transform: translateY(0);
}

.button-set {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    gap: 10px;
    z-index: 15;
}

.product-image:hover .button-set {
    opacity: 1;
}

.button-set a {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.button-set a:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Product Details - Enhanced Aesthetic Design */
.product-details {
    padding: 8px 10px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100px;
    text-align: center;
}

.product-name {
    margin-bottom: 8px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-name a {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    text-decoration: none;
    display: block;
    transition: all 0.3s ease;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    letter-spacing: 0.2px;
}

.product-name a:hover {
    color: #667eea;
    transform: translateX(2px);
}

.product-price {
    margin-bottom: 0;
    margin-top: 2px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-price .price {
    font-size: 18px;
    font-weight: 700;
    color: #000;
    letter-spacing: 0.3px;
    display: inline-block;
}

.product-price .old-price {
    font-size: 14px;
    text-decoration: line-through;
    color: #999;
    margin-right: 8px;
    font-weight: 400;
}

/* Product Rating */
.product-review {
    margin-bottom: 10px;
}

.product-review i {
    color: #ffc107;
    margin: 0 1px;
}

/* Product Variants/Swatches */
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    list-style: none;
    padding: 0;
    margin: 0;
}

.swatches .swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #f0f0f0;
    transition: border-color 0.3s ease;
    cursor: pointer;
}

.swatches .swatch:hover {
    border-color: #333;
}

.swatches .swatch img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Pagination - Responsive */
.pagination-container {
	padding: 30px 0;
	display: flex;
	justify-content: center;
}

.pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
	list-style: none;
	padding: 0;
	margin: 0;
	background: transparent;
	border: none;
	box-shadow: none;
}

.pagination .page-item {
	margin: 0;
}

.pagination .page-link {
	position: relative;
	width: 36px;
	height: 36px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	border: 1px solid #dedede;
	background: #ffffff;
	color: #555555;
	text-decoration: none;
	border-radius: 0;
	font-size: 13px;
	font-weight: 500;
	line-height: 1;
	transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.pagination .page-link:hover {
	background: #f5f5f5;
	color: #000000;
	border-color: #c9c9c9;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
	transform: translateY(-1px);
}

.pagination .page-link:focus {
	outline: none;
	box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.pagination .page-item.active .page-link {
	background: #000000;
	color: #ffffff;
	border-color: #000000;
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
	transform: translateY(-1px);
}

.pagination .page-item.disabled .page-link {
	opacity: 0.45;
	cursor: default;
	box-shadow: none;
	transform: none;
}

/* Mobile Optimizations - < 576px - Enhanced Aesthetic */
@media (max-width: 575.98px) {
    #product-grid {
        margin-left: -4px;
        margin-right: -4px;
    }
    
    #product-grid .item {
        padding: 4px;
        margin-bottom: 12px;
    }
    
    .product-image {
        border-radius: 12px;
    }
    
    .product-details {
        padding: 6px 8px 10px !important;
    }
    
    .product-name {
        margin-bottom: 6px;
        min-height: 42px;
    }
    
    .product-name a {
        font-size: 14px;
        line-height: 1.5;
        font-weight: 600;
        letter-spacing: 0.2px;
    }
    
    .product-price {
        margin-top: 2px;
    }
    
    .product-price .price {
        font-size: 15px;
        font-weight: 700;
    }
    
    .product-price .old-price {
        font-size: 12px;
    }
    
    .product-labels .lbl {
        font-size: 9px;
        padding: 3px 6px;
    }
    
    .button-set a {
        width: 35px;
        height: 35px;
    }
    
    .button-set a i {
        font-size: 14px;
    }
    
    /* Always show buttons on mobile */
    .product-image .btn-addto-cart {
        transform: translateY(0);
        position: relative;
        margin-top: 10px;
        padding: 10px;
        font-size: 12px;
    }
    
    .button-set {
        position: relative;
        opacity: 1;
        transform: none;
        top: auto;
        left: auto;
        margin-top: 10px;
        justify-content: center;
    }
    
    .pagination .page-link {
        padding: 6px 10px;
        min-width: 35px;
        font-size: 14px;
    }
}

/* Tablet Optimizations - 576px to 768px - Enhanced Aesthetic */
@media (min-width: 576px) and (max-width: 767.98px) {
    #product-grid {
        margin-left: -5px;
        margin-right: -5px;
    }
    
    #product-grid .item {
        padding: 5px;
        margin-bottom: 15px;
    }
    
    .product-image {
        border-radius: 14px;
    }
    
    .product-details {
        padding: 7px 9px 12px !important;
    }
    
    .product-name {
        margin-bottom: 7px;
        min-height: 44px;
    }
    
    .product-name a {
        font-size: 14.5px;
        font-weight: 600;
    }
    
    .product-price .price {
        font-size: 17px;
        font-weight: 700;
    }
}

/* Desktop Optimizations - 768px to 992px - Shein Style */
@media (min-width: 768px) and (max-width: 991.98px) {
    #product-grid .item {
        padding: 6px;
        margin-bottom: 18px;
    }
    
    .product-image {
        border-radius: 16px;
    }
}

/* Large Desktop - > 1200px - Shein Style */
@media (min-width: 1200px) {
    .grid-products {
        max-width: 100%;
    }
    
    #product-grid .item {
        padding: 8px;
        margin-bottom: 20px;
    }
    
    .product-image {
        border-radius: 16px;
    }
}

/* No Products State */
.no-products-message {
    text-align: center;
    padding: 60px 20px;
}

.no-products-message h3 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #333;
}

.no-products-message p {
    font-size: 16px;
    color: #666;
}

/* Error State */
.alert {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.alert-danger {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert i {
    margin-right: 8px;
}

/* Loading Animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-border {
    animation: spin 0.75s linear infinite;
    border: 0.3rem solid #f3f3f3;
    border-top: 0.3rem solid #333;
    border-radius: 50%;
}

/* Touch Device Optimizations */
@media (hover: none) {
    .product-image .btn-addto-cart {
        transform: translateY(0);
        position: relative;
        margin-top: 10px;
    }
    
    .button-set {
        position: relative;
        opacity: 1;
        transform: none;
        top: auto;
        left: auto;
        margin-top: 10px;
        justify-content: center;
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus Styles for Accessibility */
a:focus,
button:focus {
    outline: 2px solid #4A90E2;
    outline-offset: 2px;
}

/* Prevent layout shift when modal opens */
body.modal-open {
    overflow: hidden;
    padding-right: 0 !important;
}

body.modal-open .pageWrapper {
    padding-right: 0 !important;
}

/* Ensure grid maintains position when modal is open */
.modal-open #product-grid,
.modal-open .grid-products {
    position: static !important;
}

/* Force images to maintain their dimensions */
.product-image img.primary,
.product-image img.hover {
    min-width: 100%;
    min-height: 100%;
    max-width: 100%;
    max-height: 100%;
}

/* Prevent any layout recalculation */
.grid-products .item .product-image,
#product-grid .item .product-image {
    contain: layout size style;
    will-change: auto;
}
