/**
 * Independent Product Core CSS
 */

/* --- Gallery Styles --- */
.unf-custom-product-gallery {
    margin-bottom: 30px;
}

.unf-product-gallery__wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.unf-product-gallery__main-image-container {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #fdfdfd;
    border: 1px solid #efefef;
    position: relative;
}

.unf-product-gallery__main-image {
    margin: 0;
    position: relative;
    height: 480px; /* Compact fixed height */
    cursor: zoom-in;
}

@media (min-width: 992px) {
    .unf-product-gallery__main-image {
        height: 550px; /* Slightly taller on desktop context */
    }
}

.unf-product-gallery__main-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s;
}

.unf-product-gallery__thumbnails {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.unf-product-gallery__thumbnails::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}
.unf-product-gallery__thumbnails::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

.unf-product-thumb {
    flex: 0 0 80px;
    height: 106px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.7;
    transition: all 0.2s;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.unf-product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.unf-product-thumb:hover,
.unf-product-thumb.unf-thumb-active {
    opacity: 1;
    border-color: #28462F;
}

/* Desktop Side-by-Side Gallery */
@media (min-width: 992px) {
    .unf-product-gallery__wrapper {
        flex-direction: row-reverse; /* Main on right, thumbs on left */
        align-items: flex-start;
        gap: 15px;
    }

    .unf-product-gallery__main-image-container {
        flex: 1;
        min-width: 0;
    }

    .unf-product-gallery__thumbnails {
        flex: 0 0 75px;
        flex-direction: column;
        max-height: 550px; /* Match main image height */
        overflow-y: auto;
        overflow-x: hidden;
        padding-right: 5px;
        padding-bottom: 0;
    }

    .unf-product-thumb {
        width: 100%;
        height: 100px;
        flex: 0 0 auto;
    }
}

/* --- Variation Swatch Styles --- */
.unf-custom-variations-form .variations {
    width: 100%;
    margin-bottom: 25px;
}

.unf-custom-variations-form .variations th {
    text-align: left;
    padding: 10px 15px 10px 0;
    font-weight: 600;
    color: #333;
    width: 60px;
}

/* Hide Woodmart's own swatch system inside our custom form to prevent conflicts */
.unf-custom-variations-form .wd-swatches-product,
.unf-custom-variations-form .wd-swatches-wrap {
    display: none !important;
}

.unf-swatch-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 10;
}

.unf-swatch {
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    position: relative;
    z-index: 11;
    pointer-events: auto !important;
}

/* Text Swatches (Size) */
.unf-swatch-text {
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: #fff;
    color: #333;
    font-size: 14px;
    font-weight: 600;
}

.unf-swatch-text:hover {
    border-color: #888;
}

.unf-swatch-text.unf-active {
    background: #222;
    color: #fff;
    border-color: #222;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* Color Swatches (Now Image Thumbnails) */
.unf-swatch-color {
    width: 44px;
    height: 55px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #f7f7f7;
}

.unf-swatch-color:hover {
    border-color: #888;
}

.unf-swatch-color.unf-active {
    border-color: #222 !important;
    border-width: 2px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
}

.unf-reset-link {
    display: inline-block;
    margin-top: 10px;
    font-size: 13px;
    color: #666;
    text-decoration: underline;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .unf-product-thumb {
        flex: 0 0 70px;
        height: 93px;
    }
    .unf-swatch-text {
        min-width: 50px;
        height: 50px;
        font-size: 15px; /* Minimum 16px usually better for touch, but 15 is ok */
    }
    .unf-swatch-color {
        width: 48px;
        height: 60px;
    }
    .unf-product-gallery__main-image {
        max-height: 450px;
    }
}

/* --- Arrows & Lightbox --- */
.unf-gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #efefef;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 10;
    transition: all 0.2s;
    color: #444;
}
.unf-gallery-arrow:hover {
    background: #fff;
    color: #000;
    transform: translateY(-50%) scale(1.05);
}
.unf-gallery-prev { left: 10px; }
.unf-gallery-next { right: 10px; }

/* Lightbox Overlay */
.unf-lightbox-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}
.unf-lightbox-overlay.unf-lightbox-open {
    opacity: 1;
    visibility: visible;
}
.unf-lightbox-content {
    position: relative;
    max-width: 90vw;
    width: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.unf-lightbox-img-wrap {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    max-width: 100vw;
}
.unf-lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
    display: block;
}
.unf-lightbox-close {
    position: fixed;
    top: 25px;
    right: 30px;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    color: #fff;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 100;
}
.unf-lightbox-close:hover { 
    background: #B30A08; 
    border-color: #B30A08;
    transform: scale(1.05);
}
.unf-lightbox-counter {
    color: rgba(255,255,255,0.9);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 2px;
    margin-top: 20px;
}
.unf-lightbox-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.95);
    color: #222;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.2s;
    z-index: 100;
}
.unf-lightbox-arrow svg {
    width: 26px;
    height: 26px;
}
.unf-lightbox-arrow:hover { 
    background: #fff; 
    color: #B30A08;
    transform: translateY(-50%) scale(1.08);
}
.unf-lightbox-prev { left: 40px; }
.unf-lightbox-next { right: 40px; }
@media (max-width: 900px) {
    .unf-lightbox-img-wrap {
        padding: 5px;
        border-radius: 8px;
    }
    .unf-lightbox-close { right: 15px; top: 15px; width: 38px; height: 38px; }
    .unf-lightbox-prev { left: 10px; width: 44px; height: 44px; }
    .unf-lightbox-next { right: 10px; width: 44px; height: 44px; }
}

/* --- Color Code Tooltip on Hover --- */
.unf-swatch-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 100;
    letter-spacing: 0.5px;
}

/* Arrow pointing down from tooltip */
.unf-swatch-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #222;
}

/* Show on hover */
.unf-swatch-color:hover .unf-swatch-tooltip {
    opacity: 1;
    visibility: visible;
}

/* --- Variation Gallery Filtering --- */
/* When a color swatch is selected, thumbnails not matching the color get this class */
.unf-product-thumb.unf-thumb-hidden {
    display: none !important;
}
