/* ==========================================================================
   ACF + Elementor Post Gallery - Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Universal Gallery Resets & Base
   -------------------------------------------------------------------------- */
.aepg-archive-gallery,
.aepg-single-gallery,
.aepg-main,
.aepg-thumbs {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.aepg-archive-gallery *,
.aepg-single-gallery * {
    box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   2. Archive Post Gallery Container
   -------------------------------------------------------------------------- */
.elementor-post__thumbnail.aepg-has-gallery {
    position: relative;
    overflow: hidden;
}

/* Ensure container adapts when Elementor uses item-ratio */
.elementor-posts-container.elementor-has-item-ratio .elementor-post__thumbnail.aepg-has-gallery,
.elementor-posts-container.elementor-has-item-ratio .aepg-archive-gallery {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.aepg-archive-gallery {
    position: relative;
    width: 100%;
    overflow: hidden;
    background-color: #f7f7f7;
}

.aepg-archive-gallery .aepg-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    margin: 0;
    padding: 0;
}

/* --------------------------------------------------------------------------
   3. Desktop Archive Behavior (>= 768px, Hover-capable)
      Featured image fades down, 1st gallery image fades up on hover
   -------------------------------------------------------------------------- */
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
    .aepg-archive-gallery .swiper-wrapper {
        display: block !important;
        position: relative !important;
        width: 100% !important;
        height: 100% !important;
        transform: none !important;
    }

    .aepg-archive-slide {
        width: 100% !important;
    }

    /* Featured slide: stays in normal flow to give natural height in standard archives */
    .aepg-archive-slide--featured,
    .aepg-archive-gallery .aepg-archive-slide--featured,
    .elementor-post .aepg-archive-slide--featured {
        position: relative !important;
        display: block !important;
        width: 100% !important;
        opacity: 1 !important;
        z-index: 1 !important;
        transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1) !important;
        transition-property: opacity !important;
        transition-duration: 0.4s !important;
        transition-timing-function: cubic-bezier(0.25, 1, 0.5, 1) !important;
        will-change: opacity;
    }

    .aepg-archive-slide--featured .aepg-img--featured {
        height: auto;
    }

    /* In item-ratio mode (e.g. Portfolio widget or item-ratio Archive Posts) */
    .elementor-posts-container.elementor-has-item-ratio .aepg-archive-slide--featured,
    .elementor-posts-container.elementor-has-item-ratio .aepg-archive-slide--featured .aepg-img--featured,
    .elementor-portfolio.elementor-has-item-ratio .aepg-archive-slide--featured,
    .elementor-portfolio.elementor-has-item-ratio .aepg-archive-slide--featured .aepg-img--featured {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    .elementor-posts-container.elementor-has-item-ratio .aepg-archive-gallery .aepg-img,
    .elementor-portfolio.elementor-has-item-ratio .aepg-archive-gallery .aepg-img {
        position: absolute !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        transform: none !important;
    }

    /* Hover slide (1st Gallery Image): absolute overlay */
    .aepg-archive-slide--hover,
    .aepg-archive-gallery .aepg-archive-slide--hover,
    .elementor-post .aepg-archive-slide--hover {
        position: absolute !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        display: block !important;
        opacity: 0 !important;
        z-index: 2 !important;
        pointer-events: none;
        transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1) !important;
        transition-property: opacity !important;
        transition-duration: 0.4s !important;
        transition-timing-function: cubic-bezier(0.25, 1, 0.5, 1) !important;
        will-change: opacity;
        transform: none !important;
    }

    /* Images transition smoothly */
    .aepg-archive-gallery .aepg-img,
    .aepg-archive-slide--featured .aepg-img--featured,
    .aepg-archive-slide--hover .aepg-img--hover {
        transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1) !important;
        transition-property: opacity !important;
        transition-duration: 0.4s !important;
        transition-timing-function: cubic-bezier(0.25, 1, 0.5, 1) !important;
        will-change: opacity;
    }

    /* Hide any additional slides beyond slide 2 on desktop */
    .aepg-archive-slide:not(.aepg-archive-slide--featured):not(.aepg-archive-slide--hover) {
        display: none !important;
    }

    /* Hide pagination on desktop hover */
    .aepg-archive-pagination {
        display: none !important;
    }

    /* Hover triggers: hovering post card, portfolio item, thumbnail link, or gallery */
    .elementor-post:hover .aepg-archive-slide--featured,
    .elementor-portfolio-item:hover .aepg-archive-slide--featured,
    .aepg-archive-gallery:hover .aepg-archive-slide--featured,
    .elementor-post__thumbnail__link:hover .aepg-archive-slide--featured,
    .elementor-portfolio-item__img:hover .aepg-archive-slide--featured,
    .elementor-post__thumbnail__link:focus-visible .aepg-archive-slide--featured,
    .elementor-post:focus-within .aepg-archive-slide--featured {
        opacity: 0 !important;
    }

    .elementor-post:hover .aepg-archive-slide--hover,
    .elementor-portfolio-item:hover .aepg-archive-slide--hover,
    .aepg-archive-gallery:hover .aepg-archive-slide--hover,
    .elementor-post__thumbnail__link:hover .aepg-archive-slide--hover,
    .elementor-portfolio-item__img:hover .aepg-archive-slide--hover,
    .elementor-post__thumbnail__link:focus-visible .aepg-archive-slide--hover,
    .elementor-post:focus-within .aepg-archive-slide--hover {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* --------------------------------------------------------------------------
   4. Mobile Archive Behavior (< 768px, Touch/Swipe)
      Horizontal touch carousel with swipe and modern pagination dots
   -------------------------------------------------------------------------- */
@media (max-width: 767px), (hover: none), (pointer: coarse) {
    .aepg-archive-gallery {
        touch-action: pan-y;
        -webkit-user-select: none;
        user-select: none;
        aspect-ratio: 4 / 3;
    }

    .elementor-posts-container.elementor-has-item-ratio .aepg-archive-gallery {
        aspect-ratio: auto;
        height: 100%;
    }

    .aepg-archive-gallery .swiper-wrapper {
        display: flex !important;
        position: relative !important;
        width: 100% !important;
        height: 100% !important;
    }

    .aepg-archive-slide {
        display: block !important;
        position: relative !important;
        inset: auto !important;
        width: 100% !important;
        height: 100% !important;
        flex-shrink: 0 !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        transform: none !important;
    }

    .aepg-archive-slide .aepg-img {
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* Mobile pagination indicator dots */
    .aepg-archive-pagination {
        position: absolute !important;
        bottom: 8px !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 10 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 5px !important;
        padding: 4px 8px !important;
        pointer-events: none;
    }

    .aepg-archive-pagination .swiper-pagination-bullet {
        width: 6px !important;
        height: 6px !important;
        border-radius: 50% !important;
        background: #ffffff !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45) !important;
        opacity: 0.65 !important;
        margin: 0 !important;
        transition: width 0.25s ease, border-radius 0.25s ease, opacity 0.25s ease !important;
        pointer-events: auto;
    }

    .aepg-archive-pagination .swiper-pagination-bullet-active {
        width: 16px !important;
        border-radius: 4px !important;
        opacity: 1 !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.65) !important;
    }
}

/* --------------------------------------------------------------------------
   5. Single Post Gallery (Combined Featured + ACF Gallery)
   -------------------------------------------------------------------------- */
:root {
    --aepg-primary-default: #7E963A;
}

.aepg-single-gallery {
    --aepg-accent: var(--e-global-color-primary, var(--aepg-primary-default));
    display: block;
    margin-bottom: 24px;
    width: 100%;
    position: relative;
}

/* Main Slider: Clean height limit with object-fit contain */
.aepg-main {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 520px;
    max-height: 75vh;
    background-color: #f8f8f9;
    border-radius: 8px;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}

@media (max-width: 1024px) {
    .aepg-main {
        height: 440px;
        max-height: 65vh;
    }
}

@media (max-width: 767px) {
    .aepg-main {
        height: 340px;
        max-height: 55vh;
    }
}

.aepg-main .swiper-wrapper {
    align-items: center;
    height: 100%;
}

.aepg-main .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background-color: transparent;
}

/* Lightbox Link */
.aepg-main .aepg-lightbox-link {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
    text-decoration: none;
    line-height: 0;
    border-radius: 8px;
    overflow: hidden;
}

/* Main Image: Contained within the limited height, centered with natural proportions */
.aepg-main .aepg-image {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain !important;
    border-radius: 8px;
    transition: transform 0.35s ease;
}

.aepg-main .aepg-lightbox-link:hover .aepg-image {
    transform: scale(1.015);
}

/* Lightbox Zoom Icon Badge */
.aepg-zoom-icon {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(20, 20, 20, 0.65);
    color: #ffffff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.25s ease, transform 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.aepg-lightbox-link:hover .aepg-zoom-icon,
.aepg-main:hover .aepg-zoom-icon {
    opacity: 1;
    transform: scale(1);
}

.aepg-lightbox-link:hover .aepg-zoom-icon {
    background-color: rgba(15, 15, 15, 0.85) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Navigation Buttons (Prev / Next) - Clean White Circle with Black Arrow */
button.aepg-nav-btn,
[type="button"].aepg-nav-btn,
.aepg-single-gallery button.aepg-nav-btn,
.aepg-main button.aepg-nav-btn {
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #111111 !important;
    font-size: 0 !important;
    line-height: 1 !important;
    cursor: pointer !important;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08) !important;
    opacity: 0.96 !important;
    transition: background-color 0.25s ease, color 0.25s ease, transform 0.2s ease, box-shadow 0.25s ease, opacity 0.2s ease !important;
    outline: none !important;
    text-decoration: none !important;
}

button.aepg-nav-btn svg,
.aepg-nav-btn svg {
    display: block !important;
    width: 18px !important;
    height: 18px !important;
    stroke: currentColor !important;
    stroke-width: 3px !important;
    color: #111111 !important;
    pointer-events: none !important;
    transition: stroke 0.2s ease !important;
}

button.aepg-nav-btn:hover,
[type="button"].aepg-nav-btn:hover,
.aepg-single-gallery button.aepg-nav-btn:hover,
.aepg-main button.aepg-nav-btn:hover {
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #000000 !important;
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.1) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22) !important;
}

button.aepg-nav-btn:hover svg,
.aepg-main button.aepg-nav-btn:hover svg {
    color: #000000 !important;
}

button.aepg-nav-btn:active,
.aepg-main button.aepg-nav-btn:active {
    transform: translateY(-50%) scale(0.95) !important;
}

.aepg-prev {
    left: 14px !important;
    right: auto !important;
}

.aepg-next {
    right: 14px !important;
    left: auto !important;
}

button.aepg-nav-btn.swiper-button-disabled,
.aepg-main button.aepg-nav-btn.swiper-button-disabled,
.aepg-single-gallery .swiper-button-disabled {
    opacity: 0.3 !important;
    cursor: not-allowed !important;
    pointer-events: auto !important;
    transform: translateY(-50%) scale(0.95) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
}

button.aepg-nav-btn.swiper-button-disabled:hover,
.aepg-main button.aepg-nav-btn.swiper-button-disabled:hover,
.aepg-single-gallery .swiper-button-disabled:hover {
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #111111 !important;
    opacity: 0.3 !important;
    cursor: not-allowed !important;
    pointer-events: auto !important;
    transform: translateY(-50%) scale(0.95) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
}

/* Main Slider Pagination Dots */
.aepg-main-pagination {
    bottom: 14px !important;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    z-index: 10;
}

.aepg-main-pagination .swiper-pagination-bullet {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.75);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    opacity: 0.75;
    margin: 0 !important;
    transition: width 0.25s ease, border-radius 0.25s ease, background-color 0.25s ease, opacity 0.25s ease, box-shadow 0.25s ease;
    cursor: pointer;
}

.aepg-main-pagination .swiper-pagination-bullet:hover {
    opacity: 1;
    background: #ffffff;
}

.aepg-main-pagination .swiper-pagination-bullet-active {
    width: 22px;
    border-radius: 4px;
    opacity: 1 !important;
    background-color: var(--e-global-color-primary, #7E963A) !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35) !important;
}

/* Thumbnail Slider Strip - Full width row, larger size & object-fit top */
.aepg-thumbs {
    margin-top: 14px;
    overflow: hidden;
    padding: 4px 0;
    width: 100%;
}

.aepg-thumbs .swiper-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
}

.aepg-thumb {
    height: 105px !important;
    width: auto !important;
    flex-shrink: 0;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    background-color: #f0f0f2;
    cursor: pointer;
    opacity: 0.65;
    transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

@media (max-width: 767px) {
    .aepg-thumb {
        height: 85px !important;
    }
}

.aepg-thumb:hover {
    opacity: 0.95;
    transform: translateY(-2px);
    border-color: rgba(126, 150, 58, 0.4);
}

.aepg-thumb.swiper-slide-thumb-active {
    opacity: 1 !important;
    border-color: var(--e-global-color-primary, #7E963A) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
    transform: translateY(-2px);
}

.aepg-thumb img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: top !important; /* Focus on top of image */
}

/* Fix Elementor DialogsManager lightbox content offset (prevents bottom-right displacement) */
.dialog-widget-content.dialog-lightbox-widget-content,
.elementor-lightbox .dialog-widget-content {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    transform: none !important;
}

/* Support PowerPack Image Slider arrows & dots with Elementor Primary Color */
.elementor-widget-pp-image-slider .swiper-button-prev:hover,
.elementor-widget-pp-image-slider .swiper-button-next:hover,
.elementor-widget-pp-image-slider .pp-arrow:hover {
    color: var(--e-global-color-primary, #7E963A) !important;
    background-color: rgba(255, 255, 255, 0.9) !important;
}

.elementor-widget-pp-image-slider .swiper-pagination-bullet-active {
    background: var(--e-global-color-primary, #7E963A) !important;
}

/* --------------------------------------------------------------------------
   6. Accessibility & Motion Preferences
   -------------------------------------------------------------------------- */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

.aepg-nav-btn:focus-visible,
.aepg-thumb:focus-visible {
    outline: 2px solid var(--e-global-color-primary, #7E963A);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .aepg-archive-gallery *,
    .aepg-nav-btn,
    .aepg-thumb,
    .aepg-archive-slide--hover {
        transition-duration: 0.001ms !important;
        animation-duration: 0.001ms !important;
    }
}
