.tp-mega-gallery,
.tp-mega-gallery * {
    box-sizing: border-box;
}

.tp-mega-gallery {
    width: 100%;
    clear: both;
    margin: 34px auto;
    font-family: Arial, Helvetica, sans-serif;
}

.tp-mega-gallery__header {
    text-align: center;
    margin: 0 0 22px;
}

.tp-mega-gallery__title {
    margin: 0 0 8px !important;
    padding: 0 !important;
    font-size: clamp(24px, 3vw, 34px) !important;
    font-weight: 800 !important;
    line-height: 1.15 !important;
    color: #1f1f1f !important;
}

.tp-mega-gallery__subtitle {
    margin: 0 !important;
    padding: 0 !important;
    color: #666 !important;
    font-size: 15px !important;
    line-height: 1.5 !important;
}

.tp-mega-gallery__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--tp-mg-min, 180px), 1fr));
    gap: var(--tp-mg-gap, 14px);
    width: 100%;
}

.tp-mega-gallery__button {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: var(--tp-mg-radius, 14px) !important;
    overflow: hidden;
    background: #111 !important;
    box-shadow: 0 8px 22px rgba(0,0,0,.16);
    cursor: zoom-in;
    transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}

.tp-mega-gallery__button:hover,
.tp-mega-gallery__button:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(0,0,0,.22);
    outline: 3px solid rgba(34,113,177,.35);
    outline-offset: 2px;
}

.tp-mega-gallery__thumb {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    object-fit: cover !important;
    border: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.tp-mega-gallery-empty {
    padding: 14px 16px;
    background: #fff8e5;
    border: 1px solid #dba617;
    border-radius: 8px;
}

body.tp-mg-lock {
    overflow: hidden !important;
}

.tp-mg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.94);
    padding: 72px 86px 74px;
    font-family: Arial, Helvetica, sans-serif;
}

.tp-mg-lightbox.is-open {
    display: flex;
}

/* [U-02] Wrapper da imagem permite spinner por pseudo-elemento ::before. */
.tp-mg-lightbox__image {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: calc(100vw - 190px);
    max-height: calc(100vh - 165px);
    min-width: 76px;
    min-height: 76px;
}

/* [U-02] Spinner de carregamento. */
.tp-mg-lightbox__image::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    display: none;
    border: 4px solid rgba(255,255,255,.24);
    border-top-color: rgba(255,255,255,.95);
    border-radius: 50%;
    animation: tp-mg-spin .75s linear infinite;
    z-index: 2;
}

.tp-mg-lightbox.is-loading .tp-mg-lightbox__image::before {
    display: block;
}

.tp-mg-lightbox__img {
    display: block;
    width: auto;
    max-width: calc(100vw - 190px);
    max-height: calc(100vh - 165px);
    height: auto;
    object-fit: contain;
    border: 0;
    border-radius: 14px;
    box-shadow: 0 0 45px rgba(0,0,0,.85);
    background: transparent;
    opacity: 1;
    transition: opacity .15s ease;
}

.tp-mg-lightbox.is-loading .tp-mg-lightbox__img {
    opacity: 0;
}

@keyframes tp-mg-spin {
    to {
        transform: rotate(360deg);
    }
}

.tp-mg-lightbox__button {
    position: fixed;
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255,255,255,.35) !important;
    background: rgba(255,255,255,.18) !important;
    color: #fff !important;
    border-radius: 999px !important;
    cursor: pointer;
    text-decoration: none !important;
    transition: background .18s ease, transform .18s ease;
}

.tp-mg-lightbox__button:hover,
.tp-mg-lightbox__button:focus-visible {
    background: rgba(255,255,255,.28) !important;
    outline: 2px solid rgba(255,255,255,.45);
}

.tp-mg-lightbox__close {
    top: 22px;
    right: 28px;
    width: 52px;
    height: 52px;
    font-size: 38px;
    line-height: 1;
}

.tp-mg-lightbox__prev,
.tp-mg-lightbox__next {
    top: 50%;
    width: 58px;
    height: 58px;
    transform: translateY(-50%);
    font-size: 48px;
    line-height: 1;
}

.tp-mg-lightbox__prev {
    left: 28px;
}

.tp-mg-lightbox__next {
    right: 28px;
}

.tp-mg-lightbox__counter,
.tp-mg-lightbox__caption,
.tp-mg-lightbox__open-original {
    position: fixed;
    z-index: 2147483647;
    color: #fff !important;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 999px;
    font-size: 14px;
    line-height: 1.2;
    text-decoration: none !important;
}

.tp-mg-lightbox__counter {
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    padding: 8px 15px;
}

.tp-mg-lightbox__caption {
    left: 50%;
    bottom: 64px;
    max-width: min(760px, calc(100vw - 44px));
    transform: translateX(-50%);
    padding: 9px 16px;
    text-align: center;
    border-radius: 12px;
}

.tp-mg-lightbox__caption:empty {
    display: none;
}

.tp-mg-lightbox__open-original {
    left: 28px;
    bottom: 24px;
    padding: 9px 14px;
}

@media (max-width: 768px) {
    .tp-mega-gallery {
        margin: 24px auto;
    }

    .tp-mega-gallery__grid {
        grid-template-columns: repeat(auto-fill, minmax(min(145px, 48%), 1fr));
        gap: 10px;
    }

    .tp-mg-lightbox {
        padding: 66px 14px 80px;
    }

    .tp-mg-lightbox__image,
    .tp-mg-lightbox__img {
        max-width: calc(100vw - 28px);
        max-height: calc(100vh - 170px);
        border-radius: 10px;
    }

    .tp-mg-lightbox__close {
        top: 14px;
        right: 14px;
        width: 46px;
        height: 46px;
        font-size: 34px;
    }

    .tp-mg-lightbox__prev,
    .tp-mg-lightbox__next {
        width: 46px;
        height: 46px;
        font-size: 39px;
        top: auto;
        bottom: 20px;
        transform: none;
    }

    .tp-mg-lightbox__prev {
        left: 14px;
    }

    .tp-mg-lightbox__next {
        right: 14px;
    }

    .tp-mg-lightbox__open-original {
        display: none;
    }

    .tp-mg-lightbox__counter {
        bottom: 24px;
    }

    .tp-mg-lightbox__caption {
        bottom: 72px;
        font-size: 13px;
    }
}
