/* ==========================================================================
   Premium Gallery – Styles
   ========================================================================== */

/* ----- Gallery Grid ----- */
.dmg-gallery-wrapper {
    position: relative;
    width: 100%;
}

.dmg-gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
}

/* Masonry variant */
.dmg-gallery-grid.dmg-masonry {
    display: block;
    column-count: 3;
    column-gap: 15px;
}

.dmg-gallery-grid.dmg-masonry .dmg-gallery-item {
    break-inside: avoid;
    margin-bottom: 15px;
    aspect-ratio: auto !important;
}

/* ----- Load More / Hidden Items ----- */
.dmg-gallery-item.dmg-hidden {
    display: none !important;
}

.dmg-gallery-item.dmg-reveal {
    animation: dmgRevealItem 0.4s ease forwards;
}

@keyframes dmgRevealItem {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dmg-load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 24px auto 0;
    padding: 12px 32px;
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.25s ease;
    -webkit-appearance: none;
    appearance: none;
}

.dmg-load-more-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.dmg-load-more-btn svg {
    transition: transform 0.25s ease;
    stroke: currentColor;
}

.dmg-load-more-btn:hover svg {
    transform: translateY(2px);
}

.dmg-load-more-btn.dmg-btn-hidden {
    display: none;
}

/* ----- Gallery Item ----- */
.dmg-gallery-item {
    position: relative;
    overflow: hidden;
    margin: 0;
    padding: 0;
    cursor: pointer;
    border-radius: 0;
    transition: box-shadow 0.3s ease;
    will-change: transform;
    contain: layout style;
}

.dmg-gallery-item[data-lightbox="true"] {
    cursor: zoom-in;
}

.dmg-gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        opacity 0.3s ease,
        filter 0.3s ease;
    will-change: transform;
}

/* ----- Overlay ----- */
.dmg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.35s ease;
    pointer-events: none;
    z-index: 2;
}

.dmg-gallery-item:hover .dmg-overlay {
    background-color: rgba(0, 0, 0, 0.15);
}

.dmg-zoom-icon {
    color: #ffffff;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.dmg-gallery-item:hover .dmg-zoom-icon {
    opacity: 1;
    transform: scale(1);
}

/* ----- Media File Link ----- */
.dmg-media-link {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */
.dmg-lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 999999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    will-change: opacity;
    -webkit-overflow-scrolling: touch;
}

.dmg-lightbox-overlay.active {
    display: flex;
    opacity: 1;
}

.dmg-lightbox-overlay.dmg-fade-in {
    animation: dmgFadeIn 0.3s ease forwards;
}

.dmg-lightbox-overlay.dmg-fade-out {
    animation: dmgFadeOut 0.25s ease forwards;
}

/* ----- Toolbar ----- */
.dmg-lightbox-toolbar {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0;
    z-index: 20;
    background: rgba(40, 40, 40, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-bottom-left-radius: 8px;
    padding: 0;
}

.dmg-toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.65) !important;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
    padding: 0;
    line-height: 0;
    position: relative;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
}

.dmg-toolbar-btn svg {
    stroke: currentColor !important;
    fill: none !important;
}

.dmg-toolbar-btn:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}

.dmg-toolbar-btn.active {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.15);
}

.dmg-toolbar-btn:last-child {
    border-bottom-left-radius: 0;
}

/* ----- Navigation Arrows ----- */
.dmg-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #ffffff !important;
    cursor: pointer;
    z-index: 10;
    padding: 12px 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    line-height: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
}

.dmg-lightbox-nav svg {
    stroke: currentColor !important;
    fill: none !important;
}

.dmg-lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.dmg-lightbox-prev {
    left: 20px;
}

.dmg-lightbox-next {
    right: 20px;
}

/* ----- Main Image ----- */
.dmg-lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: calc(100% - 140px);
    max-height: calc(100vh - 160px);
    position: relative;
    z-index: 5;
}

.dmg-lightbox-image-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: calc(100vh - 180px);
}

.dmg-lightbox-image {
    max-width: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease, transform 0.4s ease;
    will-change: transform, opacity;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

/* Zoom states */
.dmg-lightbox-image.dmg-zoomed {
    cursor: grab;
    max-width: none;
    max-height: none;
}

.dmg-lightbox-image.dmg-zoomed:active {
    cursor: grabbing;
}

.dmg-lightbox-image.dmg-img-loading {
    opacity: 0.3;
}

.dmg-lightbox-image.dmg-img-zoom-in {
    animation: dmgZoomIn 0.35s ease forwards;
}

.dmg-lightbox-image.dmg-img-slide-left {
    animation: dmgSlideLeft 0.3s ease forwards;
}

.dmg-lightbox-image.dmg-img-slide-right {
    animation: dmgSlideRight 0.3s ease forwards;
}

/* ----- Caption ----- */
.dmg-lightbox-caption {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    text-align: center;
    margin-top: 12px;
    max-width: 600px;
    line-height: 1.5;
    font-weight: 300;
}

.dmg-lightbox-caption:empty {
    display: none;
}

/* ----- Counter ----- */
.dmg-lightbox-counter {
    position: absolute;
    top: 14px;
    left: 20px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 500;
    z-index: 10;
    letter-spacing: 1px;
}

/* ----- Thumbnail Strip ----- */
.dmg-lightbox-thumbs-wrapper {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 1280px;
    padding: 10px 24px 14px 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 100%);
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
}

.dmg-lightbox-thumbs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    max-width: 90%;
    padding: 0;
    scrollbar-width: none;
    scroll-behavior: smooth;
    justify-content: flex-end;
    align-items: flex-end;
}

.dmg-lightbox-thumbs::-webkit-scrollbar {
    display: none;
}

.dmg-lightbox-thumb {
    flex-shrink: 0;
    width: 45px;
    height: 65px;
    border: 2px solid transparent;
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.25s ease, border-color 0.25s ease, width 0.3s ease, height 0.3s ease;
    padding: 0;
    background: none;
    line-height: 0;
}

.dmg-lightbox-thumb:hover {
    opacity: 0.9;
}

.dmg-lightbox-thumb.active {
    opacity: 1;
    width: 70px;
    height: 70px;
    border-color: rgba(255, 255, 255, 0.9);
}

.dmg-lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ----- Slideshow indicator ----- */
.dmg-lightbox-overlay.dmg-slideshow-active .dmg-btn-slideshow {
    color: #4fc3f7;
    background-color: rgba(79, 195, 247, 0.15);
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes dmgFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes dmgFadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes dmgZoomIn {
    from {
        opacity: 0;
        transform: scale(0.85);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes dmgSlideLeft {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes dmgSlideRight {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==========================================================================
   Loading Spinner
   ========================================================================== */
.dmg-lightbox-overlay .dmg-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: dmgSpin 0.8s linear infinite;
    z-index: 4;
    display: none;
}

.dmg-lightbox-overlay .dmg-spinner.active {
    display: block;
}

@keyframes dmgSpin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ==========================================================================
   Responsive – Tablet
   ========================================================================== */
@media (max-width: 1024px) {
    .dmg-lightbox-content {
        max-width: calc(100% - 100px);
    }

    .dmg-lightbox-prev {
        left: 10px;
    }

    .dmg-lightbox-next {
        right: 10px;
    }
}

/* ==========================================================================
   Responsive – Mobile
   ========================================================================== */
@media (max-width: 767px) {

    /* Overlay becomes flex-column — everything stacks naturally */
    .dmg-lightbox-overlay {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        touch-action: manipulation;
        padding: 0;
    }

    .dmg-lightbox-overlay * {
        touch-action: manipulation;
    }

    /* Toolbar – sits at top, full width, NOT absolute */
    .dmg-lightbox-toolbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 0;
        justify-content: flex-end;
        background: rgba(0, 0, 0, 0.6);
        z-index: 30;
        padding-top: env(safe-area-inset-top, 0px);
    }

    /* iOS aggressive button color fix */
    .dmg-toolbar-btn,
    .dmg-lightbox-nav {
        color: rgba(255, 255, 255, 0.75) !important;
        -webkit-text-fill-color: rgba(255, 255, 255, 0.75) !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }

    .dmg-toolbar-btn svg,
    .dmg-lightbox-nav svg {
        stroke: rgba(255, 255, 255, 0.75) !important;
        fill: none !important;
        color: rgba(255, 255, 255, 0.75) !important;
    }

    .dmg-toolbar-btn {
        width: 44px;
        height: 44px;
    }

    .dmg-toolbar-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Image content – takes available space */
    .dmg-lightbox-content {
        max-width: 100%;
        max-height: none;
        padding: 0;
        margin: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .dmg-lightbox-image-wrapper {
        max-height: calc(100vh - 200px);
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dmg-lightbox-image {
        max-height: calc(100vh - 200px);
        max-width: 100%;
        width: auto;
        border-radius: 0;
        box-shadow: none;
        object-fit: contain;
    }

    /* Nav arrows – inside image area */
    .dmg-lightbox-nav {
        padding: 20px 6px;
        border-radius: 0;
        background: rgba(0, 0, 0, 0.2);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .dmg-lightbox-nav svg {
        width: 22px;
        height: 22px;
    }

    .dmg-lightbox-prev {
        left: 0;
        border-radius: 0 4px 4px 0;
    }

    .dmg-lightbox-next {
        right: 0;
        border-radius: 4px 0 0 4px;
    }

    /* Thumbnails – fixed bottom, centered */
    .dmg-lightbox-thumbs-wrapper {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        max-width: 100%;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
        justify-content: center;
        background: rgba(0, 0, 0, 0.6);
        z-index: 30;
    }

    .dmg-lightbox-thumbs {
        justify-content: center;
        max-width: 100%;
        gap: 3px;
    }

    .dmg-lightbox-thumb {
        width: 40px;
        height: 56px;
    }

    .dmg-lightbox-thumb.active {
        width: 60px;
        height: 60px;
    }

    /* Counter – top left, fixed */
    .dmg-lightbox-counter {
        position: fixed;
        top: 14px;
        left: 14px;
        transform: none;
        font-size: 13px;
        opacity: 0.7;
        z-index: 31;
        padding-top: env(safe-area-inset-top, 0px);
    }

    /* Caption */
    .dmg-lightbox-caption {
        font-size: 12px;
        margin-top: 6px;
        padding: 0 16px;
    }
}

/* ----- Body Lock (no scroll when lightbox open) ----- */
body.dmg-lightbox-active {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}