.pjtl-gallery,
.pjtl-gallery *,
.pjtl-gallery *::before,
.pjtl-gallery *::after {
    box-sizing: border-box;
}

.pjtl-gallery {
    --pjtl-gallery-green: #2c541d;
    --pjtl-gallery-thumb-size: 76px;
    --pjtl-gallery-thumb-gap: 8px;

    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0;
    overflow: visible;
    font-family: inherit;
}

.pjtl-gallery [hidden] {
    display: none !important;
}


/* Main desktop layout */

.pjtl-gallery__layout {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 16px;

    width: 100%;
    min-width: 0;

    align-items: stretch;
    overflow: visible;
}


/* Thumbnail rail */

.pjtl-gallery__rail {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;

    width: 92px;
    min-width: 92px;
    height: 100%;
    min-height: 0;

    gap: 8px;
    overflow: hidden;
}

.pjtl-gallery__thumb-viewport {
    width: 100%;
    min-height: 0;

    max-height: calc(
        var(--pjtl-gallery-thumb-size) * 5 +
        var(--pjtl-gallery-thumb-gap) * 4
    );

    display: block;

    overflow-x: hidden;
    overflow-y: auto;

    scrollbar-width: none;
    overscroll-behavior: contain;
}

.pjtl-gallery__thumb-viewport::-webkit-scrollbar {
    display: none;
}

/*
 * Keep the desktop thumbnail window inside the main-image height.
 * The track remains taller than the viewport, allowing images after
 * the fifth thumbnail to remain accessible through the arrows.
 */
.pjtl-gallery__rail.has-overflow
.pjtl-gallery__thumb-viewport {
    flex: 1 1 0;
}

/*
 * Center the thumbnails when all of them fit.
 */
.pjtl-gallery__rail:not(.has-overflow)
.pjtl-gallery__thumb-viewport {
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;
}

.pjtl-gallery__thumb-track {
    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    height: auto;
    min-height: max-content;

    flex: 0 0 auto;

    gap: var(--pjtl-gallery-thumb-gap);
}

.pjtl-gallery__thumb {
    width: var(--pjtl-gallery-thumb-size);
    min-width: var(--pjtl-gallery-thumb-size);

    height: var(--pjtl-gallery-thumb-size);
    min-height: var(--pjtl-gallery-thumb-size);

    flex: 0 0 var(--pjtl-gallery-thumb-size);

    display: block;

    margin: 0;
    padding: 0 !important;

    overflow: hidden;

    border: 1px solid #d7d7d7 !important;
    border-radius: 0;
    outline: none !important;

    background: #ffffff !important;
    box-shadow: none !important;

    cursor: pointer;
    touch-action: manipulation;
}

.pjtl-gallery__thumb:hover,
.pjtl-gallery__thumb:focus,
.pjtl-gallery__thumb.is-active {
    border-color: var(--pjtl-gallery-green) !important;

    box-shadow:
        inset 0 0 0 1px
        var(--pjtl-gallery-green) !important;
}

.pjtl-gallery__thumb img {
    width: 100% !important;
    min-width: 100% !important;
    max-width: none !important;

    height: 100% !important;
    min-height: 100% !important;

    display: block;

    object-fit: cover;
    object-position: center;

    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.pjtl-gallery__thumb-arrow {
    width: 100%;
    height: 32px;
    flex: 0 0 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0;
    padding: 0 !important;

    border: none !important;
    outline: none !important;

    background: transparent !important;
    box-shadow: none !important;

    color: #111111 !important;

    cursor: pointer;

    font-family: inherit;
    font-size: 18px;
    line-height: 1;

    touch-action: manipulation;
}

.pjtl-gallery__thumb-arrow:hover,
.pjtl-gallery__thumb-arrow:focus,
.pjtl-gallery__thumb-arrow:active {
    border: none !important;
    outline: none !important;

    background: transparent !important;
    box-shadow: none !important;

    color: #666666 !important;
}

.pjtl-gallery__thumb-arrow:disabled {
    opacity: 0.22;
    cursor: default;
    pointer-events: none;
}

.pjtl-gallery__mobile-symbol {
    display: none;
}


/* Main image */

.pjtl-gallery__main {
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: visible;
}

.pjtl-gallery__stage {
    position: relative;

    width: 100%;
    aspect-ratio: 1 / 1;

    overflow-x: hidden;
    overflow-y: hidden;

    border: 1px solid #cfdde8;
    background: #ffffff;

    scroll-behavior: smooth;
    scrollbar-width: none;

    cursor: zoom-in;

    user-select: none;
    -webkit-user-select: none;
}

.pjtl-gallery__stage::-webkit-scrollbar {
    display: none;
}

.pjtl-gallery__stage:focus-visible {
    outline: 2px solid var(--pjtl-gallery-green);
    outline-offset: 3px;
}

.pjtl-gallery__track {
    display: flex;
    width: 100%;
    height: 100%;
}

.pjtl-gallery__slide {
    width: 100%;
    min-width: 100%;
    height: 100%;

    flex: 0 0 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0;

    overflow: hidden;
    background: #ffffff;

    scroll-snap-align: start;
    scroll-snap-stop: always;
}

.pjtl-gallery__image {
    width: 100% !important;
    min-width: 100% !important;
    max-width: none !important;

    height: 100% !important;
    min-height: 100% !important;

    display: block;

    object-fit: contain;
    object-position: center;

    background: #ffffff;

    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}


/* Desktop zoom lens */

.pjtl-gallery__zoom-lens {
    position: absolute;
    top: 0;
    left: 0;

    border:
        1px solid
        rgba(45, 95, 36, 0.72);

    background:
        rgba(255, 255, 255, 0.28);

    pointer-events: none;
    z-index: 20;
}


/* Desktop zoom preview */

.pjtl-gallery__zoom-preview {
    position: absolute;
    top: 0;
    left: calc(100% + 16px);

    width: 100%;
    aspect-ratio: 1 / 1;

    overflow: hidden;

    border: 1px solid #cfdde8;

    background-color: #ffffff;
    background-repeat: no-repeat;

    box-shadow:
        0 8px 30px
        rgba(0, 0, 0, 0.18);

    pointer-events: none;
    z-index: 99999;
}


/* Lightbox */

.pjtl-gallery__lightbox:not([hidden]) {
    position: fixed;
    inset: 0;

    width: 100%;
    height: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 72px 90px;

    background:
        rgba(0, 0, 0, 0.84);

    z-index: 999999;
}

.pjtl-gallery__lightbox-image {
    width: auto !important;
    max-width: min(1200px, 86vw) !important;

    height: auto !important;
    max-height: 84vh !important;

    display: block;

    object-fit: contain;
    background: #ffffff;

    border-radius: 3px;

    box-shadow:
        0 8px 40px
        rgba(0, 0, 0, 0.35);

    user-select: none;
    -webkit-user-drag: none;
}

.pjtl-gallery__lightbox-close {
    position: absolute;
    top: 18px;
    right: 24px;

    width: 48px;
    height: 48px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0;
    padding: 0 !important;

    border: none !important;
    outline: none !important;

    background: transparent !important;
    box-shadow: none !important;

    color: #ffffff !important;

    cursor: pointer;

    font-family: Arial, sans-serif;
    font-size: 40px;
    font-weight: 300;
    line-height: 1;

    z-index: 1000002;
}

.pjtl-gallery__lightbox-arrow {
    position: absolute;
    top: 50%;

    width: 56px;
    height: 64px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0;
    padding: 0 !important;

    border:
        1px solid
        rgba(255, 255, 255, 0.25) !important;

    outline: none !important;

    background:
        rgba(255, 255, 255, 0.12) !important;

    box-shadow: none !important;

    color: #ffffff !important;

    transform: translateY(-50%);

    cursor: pointer;

    font-family: inherit;
    font-size: 24px;
    line-height: 1;

    z-index: 1000001;
}

.pjtl-gallery__lightbox-arrow:hover,
.pjtl-gallery__lightbox-arrow:focus {
    background:
        rgba(255, 255, 255, 0.24) !important;
}

.pjtl-gallery__lightbox-prev {
    left: 4%;
}

.pjtl-gallery__lightbox-next {
    right: 4%;
}


/* Empty state */

.pjtl-gallery__empty {
    width: 100%;
    aspect-ratio: 1 / 1;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid #e2e2e2;

    background: #f4f4f4;
    color: #999999;

    font-size: 14px;
}


/* Gutenberg static preview */

.editor-styles-wrapper
.pjtl-gallery__zoom-lens,
.editor-styles-wrapper
.pjtl-gallery__zoom-preview,
.block-editor-iframe__body
.pjtl-gallery__zoom-lens,
.block-editor-iframe__body
.pjtl-gallery__zoom-preview {
    display: none !important;
}


/* Tablet and mobile */

@media (max-width: 1024px) {
    .pjtl-gallery {
        --pjtl-gallery-thumb-size: 64px;
    }

    .pjtl-gallery__layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .pjtl-gallery__main {
        order: 1;
    }

    .pjtl-gallery__rail {
        order: 2;

        width: 100%;
        min-width: 0;
        height: var(--pjtl-gallery-thumb-size);

        display: flex;
        flex-direction: row;
        align-items: center;

        gap: 6px;
    }

    .pjtl-gallery__thumb-viewport {
        width: 100%;
        height: var(--pjtl-gallery-thumb-size);
        min-height: var(--pjtl-gallery-thumb-size);
        max-height: none;

        flex: 1 1 auto;

        display: block;

        overflow-x: auto;
        overflow-y: hidden;

        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;

        touch-action: pan-x;
    }

    .pjtl-gallery__rail.has-overflow
    .pjtl-gallery__thumb-viewport,
    .pjtl-gallery__rail:not(.has-overflow)
    .pjtl-gallery__thumb-viewport {
        flex: 1 1 auto;

        display: block;

        align-items: initial;
        justify-content: initial;

        overflow-x: auto;
        overflow-y: hidden;
    }

    .pjtl-gallery__thumb-track {
        width: max-content;
        height: 100%;
        min-height: 0;

        flex: 0 0 auto;
        flex-direction: row;

        margin: 0;

        gap: var(--pjtl-gallery-thumb-gap);
    }

    .pjtl-gallery__thumb-arrow {
        width: 34px;
        min-width: 34px;
        height: var(--pjtl-gallery-thumb-size);

        flex: 0 0 34px;
    }

    .pjtl-gallery__desktop-symbol {
        display: none;
    }

    .pjtl-gallery__mobile-symbol {
        display: inline;
    }

    /*
     * Native image swiping is enabled only
     * on tablet and mobile.
     */
    .pjtl-gallery__stage {
        overflow-x: auto;
        overflow-y: hidden;

        scroll-snap-type: x mandatory;

        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;

        touch-action:
            pan-x
            pan-y
            pinch-zoom;

        cursor: default;
    }

    .pjtl-gallery__zoom-lens,
    .pjtl-gallery__zoom-preview {
        display: none !important;
    }

    .pjtl-gallery__lightbox:not([hidden]) {
        padding: 60px 14px;
    }

    .pjtl-gallery__lightbox-image {
        max-width: 94vw !important;
        max-height: 80vh !important;
    }

    .pjtl-gallery__lightbox-arrow {
        width: 42px;
        height: 54px;
        font-size: 19px;
    }

    .pjtl-gallery__lightbox-prev {
        left: 6px;
    }

    .pjtl-gallery__lightbox-next {
        right: 6px;
    }

    .pjtl-gallery__lightbox-close {
        top: 10px;
        right: 12px;
    }
}


/* Reduced motion */

@media (prefers-reduced-motion: reduce) {
    .pjtl-gallery__stage,
    .pjtl-gallery__thumb-viewport {
        scroll-behavior: auto;
    }
}