/**
 * Gallery Slider Image Magnifier Styles
 */

/* Magnifier glass styles */
.image-magnifier-glass {
    position: absolute;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    cursor: none;
    z-index: 9999;
    pointer-events: none;
    background-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Preview area styles */
.image-magnifier-preview {
    position: absolute;
    border: 3px solid #ffffff;
    background-repeat: no-repeat;
    background-color: #ffffff;
    z-index: 9998;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15),
                0 4px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

/* Ensure slider container supports magnifier */
.wpkj-gallery-slider {
    position: relative;
}

.wpkj-gallery-slider .flexy-items {
    position: relative;
}

.wpkj-gallery-slider .flexy-items a {
    display: block;
    cursor: zoom-in;
}

.wpkj-gallery-slider .flexy-items a:hover {
    cursor: zoom-in;
}

/* Hide magnifier on mobile */
@media (max-width: 768px) {
    .image-magnifier-glass,
    .image-magnifier-preview {
        display: none !important;
    }
    
    .wpkj-gallery-slider .flexy-items a {
        cursor: pointer;
    }
}

/* Hide magnifier on touch devices */
@media (hover: none) and (pointer: coarse) {
    .image-magnifier-glass,
    .image-magnifier-preview {
        display: none !important;
    }
    
    .wpkj-gallery-slider .flexy-items a {
        cursor: pointer;
    }
}

/* When zoom is disabled */
.wpkj-gallery-slider[data-enable-zoom="false"] .flexy-items a {
    cursor: pointer;
}

/* Optimize image loading experience */
.wpkj-gallery-slider .flexy-items img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Responsive adjustment - Medium screens */
@media (min-width: 769px) and (max-width: 1024px) {
    .image-magnifier-preview {
        width: 300px !important;
        height: 300px !important;
    }
}

/* Responsive adjustment - Small laptops */
@media (min-width: 769px) and (max-width: 1366px) {
    .image-magnifier-preview {
        width: 350px !important;
        height: 350px !important;
    }
}

/* Hide when printing */
@media print {
    .image-magnifier-glass,
    .image-magnifier-preview {
        display: none !important;
    }
}

/* Accessibility - Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .image-magnifier-glass,
    .image-magnifier-preview {
        transition: none;
    }
}

/* High contrast mode optimization */
@media (prefers-contrast: high) {
    .image-magnifier-glass {
        border: 3px solid #000000;
        background-color: rgba(255, 255, 255, 0.4);
    }
    
    .image-magnifier-preview {
        border: 4px solid #000000;
    }
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    .image-magnifier-preview {
        border-color: #2d2d2d;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4),
                    0 4px 8px rgba(0, 0, 0, 0.3);
    }
}

/* Loading state */
.wpkj-gallery-slider .flexy-items a.loading {
    cursor: wait;
}

/* Ensure compatibility with Blocksy Flexy styles */
.flexy-container .image-magnifier-glass,
.flexy-container .image-magnifier-preview {
    font-family: inherit;
}

/* Performance optimization - GPU acceleration */
.image-magnifier-glass,
.image-magnifier-preview {
    will-change: transform, opacity;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* ============================================================
 * Thumbnail Strip: Vertical Layout (left / right position)
 * ============================================================ */

/* Flex row layout for left/right thumbnail strip */
.flexy-container[data-pills-position="left"],
.flexy-container[data-pills-position="right"] {
    display: flex;
    flex-direction: row;
    align-items: flex-start; /* Pills height is synced to .flexy via JS */
    gap: 8px;
}

/* Main slider fills remaining space */
.flexy-container[data-pills-position="left"] .flexy,
.flexy-container[data-pills-position="right"] .flexy {
    flex: 1;
    min-width: 0;
}

/* Vertical pills container */
.flexy-pills--vertical {
    --thumbs-width: 80px; /* fallback; overridden by inline style */
    display: flex;
    flex-direction: column;
    width: var(--thumbs-width);
    flex-shrink: 0;
    overflow: hidden; /* Clip excess content; height is set by JS */
}

/* Up arrow at top, thumbnail list in middle, down arrow at bottom */
.flexy-pills--vertical .flexy-arrow-prev { order: 1; }
.flexy-pills--vertical ol               { order: 2; flex: 1; }
.flexy-pills--vertical .flexy-arrow-next { order: 3; }

/* Vertical scrollable thumbnail list */
.flexy-pills--vertical ol {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 4px;
    padding: 0;
    margin: 0;
    list-style: none;
    /* CRITICAL: allows this flex child to shrink below content size,
     * enabling overflow-y scrolling to actually work */
    min-height: 0;
    /* Items stack from the top — no stretching or distributing */
    justify-content: flex-start;
    /* Hide scrollbar visually; still scrollable via JS */
    scrollbar-width: none;      /* Firefox */
    -ms-overflow-style: none;   /* IE / Edge */
}

.flexy-pills--vertical ol::-webkit-scrollbar {
    display: none;
}

/* Square thumbnail items */
.flexy-pills--vertical li {
    width: var(--thumbs-width);
    height: var(--thumbs-width);
    flex-shrink: 0;
    flex-grow: 0;   /* Explicitly prevent items from growing to fill space */
    overflow: hidden;
}

.flexy-pills--vertical li > span {
    display: block;
    width: 100%;
    height: 100%;
}

.flexy-pills--vertical li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Rotate prev/next arrows to become up/down arrows.
 * SVG viewBox 0 0 16 10 — prev points LEFT (←), next points RIGHT (→).
 * rotate(-90deg) CCW:  ← → ↑,  → → ↓  */
.flexy-pills--vertical .flexy-arrow-prev svg,
.flexy-pills--vertical .flexy-arrow-next svg {
    transform: rotate(-90deg);
}

/* Hide up/down scroll arrows in vertical mode; users scroll via touch or
 * the JS MutationObserver auto-scrolls the active thumb into view. */
.wpkj-gallery-slider .flexy-pills--vertical .flexy-arrow-prev,
.wpkj-gallery-slider .flexy-pills--vertical .flexy-arrow-next {
    display: none;
}

/* ============================================================
 * Gallery Slider Pills — general styles
 * Moved from wpkj-wblock-addon-public.css and scoped to this block
 * to avoid affecting other flexy-pills instances (e.g. WooCommerce).
 * ============================================================ */

.wpkj-gallery-slider .flexy-pills ol {
    margin: 0 -5px;
    padding-left: 0;
}

.wpkj-gallery-slider .flexy-pills ol:not([data-flexy]) ~ [class*=arrow],
.wpkj-gallery-slider .flexy-pills ol[data-flexy*=no] ~ [class*=arrow] {
    display: flex;
}

/* Horizontal thumbs: 5px padding creates visual spacing;
 * the -5px ol negative-margin compensates at the strip edges */
.wpkj-gallery-slider .flexy-pills ol li {
    padding: 5px;
}

/* Horizontal strip arrows: size and vertically center alongside the strip */
.wpkj-gallery-slider .flexy-pills [class*=flexy-arrow] {
    top: calc(var(--thumbs-spacing, 15px) / 2 + 50% - 25px);
    width: 30px;
    height: 30px;
}

/* Inactive thumbnail border ring */
.wpkj-gallery-slider .flexy-pills .ct-media-container::after {
    position: absolute;
    content: "";
    z-index: 2;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border: 2px solid var(--theme-palette-color-5);
    transition: border-color .25s cubic-bezier(0.215, 0.61, 0.355, 1);
    opacity: .8;
}

.wpkj-gallery-slider .flexy-pills li.active .ct-media-container::after {
    border-color: var(--theme-palette-color-1);
    opacity: 1;
}

/* Horizontal strip arrows: float just outside the strip on each side */
.wpkj-gallery-slider .flexy-pills .flexy-arrow-prev {
    left: -15px;
}

.wpkj-gallery-slider .flexy-pills .flexy-arrow-next {
    right: -15px;
}

/* ============================================================
 * Vertical pills: reset / override horizontal-mode defaults above
 * ============================================================ */

/* Cancel the negative ol-margin used for edge-alignment in horizontal mode */
.wpkj-gallery-slider .flexy-pills--vertical ol {
    margin: 0;
}

/* Remove item padding: vertical gap is handled by the ol gap property.
 * Padding-free li also ensures the first thumbnail aligns flush with
 * the top edge of the main image. */
.wpkj-gallery-slider .flexy-pills--vertical ol li {
    padding: 0;
}

/* ============================================================
 * Mobile: revert to bottom layout (≤ 768px)
 * ============================================================ */
@media (max-width: 768px) {
    .flexy-container[data-pills-position="left"],
    .flexy-container[data-pills-position="right"] {
        flex-direction: column;
    }

    /* Force main image on top, thumbnail strip on bottom — regardless of
     * DOM order (left position puts pills before .flexy in HTML). */
    .flexy-container[data-pills-position="left"] .flexy,
    .flexy-container[data-pills-position="right"] .flexy {
        order: 1;
        width: 100%;
    }

    .flexy-container[data-pills-position="left"] .flexy-pills--vertical,
    .flexy-container[data-pills-position="right"] .flexy-pills--vertical {
        order: 2;
    }

    .flexy-pills--vertical {
        width: 100%;
        flex-direction: row;
        /* Remove the vertical-mode clip so the ol scroll container is unobstructed */
        overflow: visible;
    }

    /* Force a single-row horizontal scroll strip.
     * Use !important + scoped selector to override any Blocksy defaults. */
    .wpkj-gallery-slider .flexy-pills--vertical ol {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;   /* Single row only */
        overflow-x: auto !important;
        overflow-y: hidden;
        max-height: none;
        /* Smooth touch scroll on iOS */
        -webkit-overflow-scrolling: touch;
    }

    /* Thumbnails must not shrink or wrap */
    .wpkj-gallery-slider .flexy-pills--vertical li {
        flex-shrink: 0 !important;
        width: var(--thumbs-width);
        height: var(--thumbs-width);
    }

    /* Restore horizontal arrow orientation */
    .flexy-pills--vertical .flexy-arrow-prev { order: 1; }
    .flexy-pills--vertical .flexy-arrow-next { order: 3; }

    .flexy-pills--vertical .flexy-arrow-prev svg,
    .flexy-pills--vertical .flexy-arrow-next svg {
        transform: none;
    }

    /* On mobile, hide strip arrows — user can touch-scroll */
    .flexy-pills--vertical .flexy-arrow-prev,
    .flexy-pills--vertical .flexy-arrow-next {
        display: none;
    }
}

/* ============================================================
 * RTL support
 * ============================================================ */

/* Flip main-slider prev/next arrows for RTL reading direction */
[dir="rtl"] .wpkj-gallery-slider .flexy > .flexy-arrow-prev svg,
[dir="rtl"] .wpkj-gallery-slider .flexy > .flexy-arrow-next svg {
    transform: scaleX(-1);
}

/* Vertical pill arrows are up/down — no horizontal flip needed in RTL.
 * The DOM order already handles logical start/end via flex-direction: row. */
