/* ============================================
   Image Gallery Widget
   - Square (min of cell width/height)
   - Top-aligned in cell
   - 2/3 main image, 1/3 thumbnail strip
   - Carousel-like draggable thumbnail strip
   - Fullscreen popup with zoom + pan + thumb strip
   ============================================ */

/* Gallery container - square, top-aligned, no background by default */
.widget-image-gallery {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    height: auto !important;
    max-height: none !important;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 6px;
    user-select: none;
}

/* Main image area - 2/3 of column width as height */
.ig-main-container {
    position: relative;
    flex: 2 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

.ig-main-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s ease;
}

.ig-placeholder {
    color: #888;
    font-size: 1.2em;
    text-align: center;
    padding: 2em;
}

/* Main image arrows */
.ig-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    font-size: 1.6em;
    padding: 12px 14px;
    cursor: pointer;
    z-index: 5;
    border-radius: 4px;
    transition: background 0.15s;
    line-height: 1;
}
.ig-arrow:hover {
    background: rgba(0,0,0,0.8);
}
.ig-arrow-left {
    left: 0;
}
.ig-arrow-right {
    right: 0;
}

/* Thumbnail strip area - 1/3 of column width as height */
.ig-thumbnails {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    position: relative;
    overflow: visible;
    padding: 0 28px;
}

/* Thumbnail strip scroll container */
.ig-thumb-strip {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

/* Inner wrapper that slides via transform */
.ig-thumb-strip-inner {
    display: flex;
    align-items: stretch;
    gap: 4px;
    padding: 4px 2px;
    transition: transform 0.3s ease;
    height: 100%;
}
.ig-thumb-strip::-webkit-scrollbar {
    display: none;
}

/* Individual thumbnail */
.ig-thumb {
    flex: 0 0 auto;
    height: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, opacity 0.15s;
    opacity: 0.6;
    box-sizing: border-box;
}
.ig-thumb:hover {
    opacity: 0.85;
    border-color: rgba(255,255,255,0.4);
}
.ig-thumb-active {
    opacity: 1;
    border-color: #fff;
}
.ig-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* Thumbnail strip arrows - overlaid on left/right */
.ig-thumb-arrow {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 28px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: auto;
    transition: background 0.15s;
}
.ig-thumb-arrow:hover {
    background: rgba(0,0,0,0.85);
}
.ig-thumb-arrow-left {
    left: 0;
}
.ig-thumb-arrow-right {
    right: 0;
}

/* ============================================
   Fullscreen Popup / Lightbox
   ============================================ */
.ig-popup-overlay {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.88);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: igFadeIn 0.15s ease;
}

.ig-popup-container {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 95vw;
    overflow: visible;
}

.ig-popup-image {
    max-width: 90vw;
    max-height: calc(100vh - 120px);
    cursor: grab;
    user-select: none;
    transform-origin: center center;
    will-change: transform;
}

/* Popup navigation arrows */
.ig-popup-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    font-size: 2em;
    padding: 16px 18px;
    cursor: pointer;
    z-index: 5;
    border-radius: 4px;
    transition: background 0.15s;
    line-height: 1;
}
.ig-popup-nav:hover {
    background: rgba(0,0,0,0.8);
}
.ig-popup-nav-left {
    left: 16px;
}
.ig-popup-nav-right {
    right: 16px;
}

/* Popup thumbnail strip at bottom */
.ig-popup-thumbs {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    background: rgba(0,0,0,0.6);
}

.ig-popup-thumb-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 90vw;
    cursor: grab;
    padding: 4px 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.ig-popup-thumb-strip::-webkit-scrollbar {
    display: none;
}

.ig-popup-thumb {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    opacity: 0.5;
    transition: border-color 0.15s, opacity 0.15s;
    box-sizing: border-box;
}
.ig-popup-thumb:hover {
    opacity: 0.8;
    border-color: rgba(255,255,255,0.4);
}
.ig-popup-thumb-active {
    opacity: 1;
    border-color: #fff;
}
.ig-popup-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.ig-popup-close {
    position: fixed;
    top: 16px;
    right: 24px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 2.2em;
    cursor: pointer;
    z-index: 100000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s;
}
.ig-popup-close:hover {
    background: rgba(255,255,255,0.2);
}

@keyframes igFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================
   Responsive adjustments
   ============================================ */
@media (max-width: 768px) {
    /* Override page-sizing.css .widget img { max-height: 200px } */
    .widget-image-gallery .ig-main-img {
        max-height: none !important;
        max-width: 100%;
        height: 100%;
        width: 100%;
    }
    .widget-image-gallery {
        aspect-ratio: auto;
        width: 100%;
    }
    .ig-main-container {
        min-height: 250px;
    }
    .ig-thumbnails {
        min-height: 60px;
    }
    .ig-thumb img {
        max-height: none !important;
    }
}
@media (max-width: 600px) {
    .ig-arrow {
        font-size: 1.2em;
        padding: 8px 10px;
    }
    .ig-thumb-arrow {
        padding: 0 6px;
        font-size: 0.9em;
    }
    .ig-popup-nav {
        font-size: 1.5em;
        padding: 12px 14px;
    }
    .ig-popup-nav-left {
        left: 8px;
    }
    .ig-popup-nav-right {
        right: 8px;
    }
    .ig-popup-close {
        font-size: 1.65em;
        width: 36px;
        height: 36px;
        top: 10px;
        right: 14px;
    }
}
