/* Define CSS Variables for common values */
:root {
    --product-width: 250px;  /* Fixed item width */
    --gap: 1rem;
    --spinner-size: 50px;
    --spinner-border: 5px;
    --primary-color: #3498db;
    --rv-columns-desktop: 6;
    --rv-columns-tablet: 4;
    --rv-columns-mobile: 2;
}

/* Overall container settings */
.wc-recently-viewed-products {
    margin: 2em auto;
    width: 95%;
    max-width: 100%;
    padding: 1px;
}

/* --- Grid Layout using CSS Grid --- */
.products-grid {
    display: grid;
    gap: var(--gap);
    justify-content: center;  /* Center the grid in the container */
}

/* Responsive grid:
   Desktop (min-width: 992px): 6 columns,
   Tablet (576px - 991px): 4 columns,
   Mobile (max-width: 575px): 2 columns */
@media (min-width: 992px) {
    .products-grid {
        grid-template-columns: repeat(var(--rv-columns-desktop), minmax(0, 1fr));
    }
}
@media (max-width: 991px) and (min-width: 576px) {
    .products-grid {
        grid-template-columns: repeat(var(--rv-columns-tablet), minmax(0, 1fr));
    }
}
@media (max-width: 575px) {
    .products-grid {
        grid-template-columns: repeat(var(--rv-columns-mobile), minmax(0, 1fr));
    }
}

/* --- Product Item Styling (common to grid and slider) --- */
.product-item {
    position: relative;
    box-sizing: border-box;
    background: #fff;
    text-align: center;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: box-shadow 0.3s ease;
}
.product-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.product-item img {
    max-width: 100%;
    height: auto;
    margin-bottom: 10px;
}
.product-main-link {
    color: inherit;
    text-decoration: none;
}
.product-sale-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
}
.product-sale-badge .onsale {
    min-height: auto;
    min-width: auto;
    margin: 0;
    padding: 0.35rem 0.75rem;
    line-height: 1.2;
    border-radius: 999px;
}

/* Truncate product name to 3 lines with ellipsis while inheriting theme styles */
.product-item h3 {
    font: inherit;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Price styling */
.product-item .price {
    color: #77a464;
    font-weight: 700;
}
.product-rating {
    margin: 0.5rem 0;
}
.product-rating .star-rating {
    margin: 0 auto;
}
.product-actions {
    margin-top: 0.9rem;
}
.product-actions .button {
    width: 100%;
}

/* --- Spinner Styles --- */
.spinner {
    display: block;
    width: var(--spinner-size);
    height: var(--spinner-size);
    border: var(--spinner-border) solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Slider Layout --- */
.products-slider-shell {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
}
.products-slider {
    --rv-slider-columns: var(--rv-columns-desktop);
    display: grid;
    flex: 1 1 auto;
    grid-auto-columns: calc((100% - (var(--gap) * (var(--rv-slider-columns) - 1))) / var(--rv-slider-columns));
    grid-auto-flow: column;
    gap: var(--gap);
    min-width: 0;
    overflow-x: auto;
    padding: 0.25rem 0.1rem 0.85rem;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    text-align: left;
}
.products-slider .product-item {
    min-width: 0;
    scroll-snap-align: start;
}
.products-slider-arrow {
    align-self: center;
    appearance: none;
    background-color: rgba(0, 0, 0, 0.68);
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    flex: 0 0 2.25rem;
    font-size: 1rem;
    font-weight: 700;
    height: 2.25rem;
    line-height: 1;
    text-align: center;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    width: 2.25rem;
}
.products-slider-arrow:hover,
.products-slider-arrow:focus {
    background-color: rgba(0, 0, 0, 0.85);
}
.products-slider-arrow:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}
.products-slider-dots {
    display: flex;
    justify-content: center;
    gap: 0.45rem;
    margin-top: 0.75rem;
}
.products-slider-dot {
    appearance: none;
    background: #cfd7df;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    height: 0.55rem;
    padding: 0;
    transition: background-color 0.2s ease, transform 0.2s ease;
    width: 0.55rem;
}
.products-slider-dot.is-active {
    background: var(--primary-color);
    transform: scale(1.25);
}
@media (max-width: 575px) {
    .products-slider-shell {
        gap: 0.35rem;
    }
    .products-slider-arrow {
        flex-basis: 1.9rem;
        height: 1.9rem;
        width: 1.9rem;
    }
}

.wc-recently-viewed-empty {
    padding: 2rem 1.5rem;
    border: 1px dashed #cfd7df;
    border-radius: 12px;
    background: linear-gradient(180deg, #f7fafc 0%, #eef3f7 100%);
    text-align: center;
}
.wc-recently-viewed-empty__eyebrow {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #5f6b76;
}
.wc-recently-viewed-empty__message {
    margin: 0;
    font-size: 1rem;
    color: #2f3b45;
}
