/* --- Variables & Layout --- */
.lpg-widget-wrapper {
    display: flex;
    gap: 20px; 
    height: var(--gallery-height, 600px);
    position: relative;
    user-select: none;
    --primary-color: #000;
    touch-action: pan-y;
    box-sizing: border-box;
    
    /* Defaults */
    --thumbs-per-view: 4;
    --thumb-gap: 10px;
    --thumbs-width: 80px; 
}

.lpg-widget-wrapper * {
    box-sizing: border-box;
}

/* --- Mobile Styling (< 768px) --- */
@media (max-width: 768px) {
    .lpg-widget-wrapper {
        flex-direction: column;
        height: auto !important;
    }
    .lpg-main-stage {
        width: 100%;
        aspect-ratio: 1/1;
        height: auto;
    }
    .lpg-thumbs-stage {
        display: none;
    }
    .lpg-nav-btn {
        display: none !important;
    }
    .lpg-pagination {
        display: flex !important;
    }
    /* Show mobile trigger */
    .lpg-mobile-trigger {
        display: flex !important;
    }
}

/* --- Desktop Styling (>= 769px) --- */
@media (min-width: 769px) {
    .lpg-pagination {
        display: none !important;
    }
    /* Hide mobile trigger on desktop */
    .lpg-mobile-trigger {
        display: none !important;
    }
    
    /* --- Layout: Left Thumbs (Vertical) --- */
    .lpg-widget-wrapper.pos-left {
        flex-direction: row-reverse;
    }

    .lpg-widget-wrapper.pos-left .lpg-main-stage {
        flex: 1;
        width: 0;
        height: 100%;
    }

    .lpg-widget-wrapper.pos-left .lpg-thumbs-stage {
        width: var(--thumbs-width);
        height: 100%;
        flex-shrink: 0;
        overflow: hidden;
        padding: 1px; 
    }

    .lpg-widget-wrapper.pos-left .lpg-thumbs-track {
        display: flex;
        flex-direction: column;
        gap: var(--thumb-gap);
        height: 100%;
        transition: transform 0.4s ease-out;
        padding-top: 1px;
    }

    /* FIX: Restore height calculation based on Thumbs Per View */
    .lpg-widget-wrapper.pos-left .lpg-thumb {
        width: 100%;
        /* Calculate height to fit exactly N items in the container height */
        height: calc((100% - (var(--thumb-gap) * (var(--thumbs-per-view) - 1))) / var(--thumbs-per-view));
        flex-shrink: 0;
        position: relative;
    }

    /* Disable aspect-ratio hack for vertical so height is controlled by calculation */
    .lpg-widget-wrapper.pos-left .lpg-thumb::after {
        display: none;
    }

    /* --- Layout: Bottom Thumbs (Horizontal) --- */
    .lpg-widget-wrapper.pos-bottom {
        flex-direction: column;
    }

    .lpg-widget-wrapper.pos-bottom .lpg-main-stage {
        width: 100%;
        height: calc(100% - 130px);
        flex-grow: 1;
    }

    .lpg-widget-wrapper.pos-bottom .lpg-thumbs-stage {
        height: auto;
        width: 100%;
        overflow: hidden;
        padding: 1px 1px 5px 1px; 
    }

    .lpg-widget-wrapper.pos-bottom .lpg-thumbs-track {
        display: flex;
        flex-direction: row;
        gap: var(--thumb-gap);
        width: 100%;
        transition: transform 0.4s ease-out;
    }

    /* Horizontal: Width is calculated, Height is auto (Square via padding hack) */
    .lpg-widget-wrapper.pos-bottom .lpg-thumb {
        width: calc((100% - (var(--thumb-gap) * (var(--thumbs-per-view) - 1))) / var(--thumbs-per-view));
        height: auto;
        flex-shrink: 0;
    }
}

/* --- Main Slider --- */
.lpg-main-stage {
    position: relative;
    overflow: hidden;
    background: #fff;
}

.lpg-track {
    display: flex;
    height: 100%;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    width: 100%;
    will-change: transform;
}

.lpg-slide {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.lpg-zoom-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    cursor: zoom-in;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-drag: none;
}

.lpg-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.1s linear;
    pointer-events: none;
}

/* --- Mobile Lightbox Trigger Icon --- */
.lpg-mobile-trigger {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    width: 35px;
    height: 35px;
    background: transparent;
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: none;
}

/* --- Nav & Pagination --- */
.lpg-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(255, 255, 255, 0.9);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: all 0.3s;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 0;
}
.lpg-main-stage:hover .lpg-nav-btn { opacity: 1; }
.lpg-nav-btn svg { width: 20px; height: 20px; stroke: currentColor; }
.lpg-prev { left: 15px; }
.lpg-next { right: 15px; }

.lpg-pagination {
    display: none;
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    gap: 8px;
    z-index: 10;
}
.lpg-dot {
    width: 8px;
    height: 8px;
    background-color: #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s;
}
.lpg-dot.active { background-color: #000; }

/* --- Thumbs --- */
.lpg-thumb {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s, border-color 0.3s;
    border: 1px solid transparent;
    position: relative;
    box-sizing: border-box;
}
/* This pseudo-element maintains square aspect ratio by default (used in horizontal) */
.lpg-thumb::after {
    content: '';
    display: block;
    padding-bottom: 100%; 
}
.lpg-thumb img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.lpg-thumb.active {
    opacity: 1;
    border-color: #000;
}

/* --- Lightbox --- */
.lpg-lightbox-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #fff;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: lpgFadeIn 0.2s ease-out;
}
@keyframes lpgFadeIn { from {opacity: 0;} to {opacity: 1;} }
.lpg-lb-content {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
}
.lpg-lb-close {
    position: absolute;
    top: 20px;
    right: 25px;
    color: #000;
    font-size: 35px;
    cursor: pointer;
    z-index: 10001;
    line-height: 1;
}
.lpg-lb-nav-container {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    pointer-events: none;
}
.lpg-lb-nav {
    background: rgba(255,255,255,0.8);
    border: none;
    cursor: pointer;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: transform 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.lpg-lb-nav:active { transform: scale(0.9); }
.lpg-lb-nav svg { width: 24px; height: 24px; stroke: #000; }

@media (max-width: 768px) {
    .lpg-lb-content { max-height: 75vh; margin-top: -50px; }
    .lpg-lb-nav-container {
        top: auto; bottom: 30px; left: 50%; transform: translateX(-50%);
        width: auto; gap: 20px; padding: 0;
    }
}