/* ============================================================
   Multimedia Gallery – Frontend Styles
   ============================================================ */

/* ── CSS variables & base ─────────────────────────────────── */
.mg-gallery {
    --mg-columns: 3;
    --mg-gap: 16px;
    --mg-radius: 6px;
    --mg-transition: 0.3s ease;
    box-sizing: border-box;
    width: 100%;
}

.mg-gallery *,
.mg-gallery *::before,
.mg-gallery *::after {
    box-sizing: inherit;
}

/* ── Grid layout ──────────────────────────────────────────── */
.mg-layout-grid {
    display: grid;
    grid-template-columns: repeat(var(--mg-columns), 1fr);
    gap: var(--mg-gap);
}

/* ── Masonry layout ───────────────────────────────────────── */
.mg-layout-masonry {
    columns: var(--mg-columns);
    column-gap: var(--mg-gap);
}

.mg-layout-masonry .mg-item {
    break-inside: avoid;
    margin-bottom: var(--mg-gap);
    display: block;
}

/* ── Item base ────────────────────────────────────────────── */
.mg-item {
    position: relative;
}

.mg-item-inner {
    position: relative;
    border-radius: var(--mg-radius);
    background: #111;
    transition: transform var(--mg-transition), box-shadow var(--mg-transition);
    /* NO overflow:hidden here — it breaks iframe compositing in Chrome/Safari */
}

/* Hover lift — images only */
.mg-item-image .mg-item-inner:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

/* ── Images ───────────────────────────────────────────────── */
.mg-image {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: var(--mg-radius);
    transition: transform var(--mg-transition);
    overflow: hidden;
}

.mg-item-image a {
    display: block;
    overflow: hidden;
    border-radius: var(--mg-radius);
}

.mg-item-image:hover .mg-image {
    transform: scale(1.04);
}

/* Hover overlay on images only */
.mg-item-image .mg-item-inner::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background var(--mg-transition);
    pointer-events: none;
    z-index: 2;
    border-radius: var(--mg-radius);
}

.mg-item-image .mg-item-inner:hover::after {
    background: rgba(0, 0, 0, 0.25);
}

/* ── Skeleton shimmer — images only ──────────────────────── */
.mg-item-image .mg-item-inner::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
    background-size: 200% 100%;
    animation: mgShimmer 1.4s infinite;
    z-index: 0;
    border-radius: var(--mg-radius);
}

.mg-item-image .mg-item-inner img {
    position: relative;
    z-index: 1;
}

@keyframes mgShimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

/* ── Video wrapper (aspect-ratio box) ─────────────────────── */
.mg-video-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* default 16:9 — overridden inline per item */
    height: 0;
    overflow: hidden;
    background: #000;
    border-radius: var(--mg-radius);
    /* Force GPU compositing so iframe renders correctly */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Direct <video> and iframes inside the aspect-ratio wrapper */
.mg-video-wrapper video,
.mg-video-wrapper iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0;
    /* Ensure iframe is above any background */
    z-index: 1;
}

/* ── Inline embed: thumbnail background so no black flash ─── */
.mg-embed-wrapper {
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

/* ── Lightbox thumbnail trigger ───────────────────────────── */
.mg-video-thumb-wrap {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* default — overridden inline per item */
    background: #111 center / cover no-repeat;
    cursor: pointer;
    overflow: hidden;
    border-radius: var(--mg-radius);
}

.mg-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 68px;
    height: 48px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    z-index: 5;
    transition: opacity var(--mg-transition), transform var(--mg-transition);
}

.mg-play-btn:hover {
    opacity: 0.85;
    transform: translate(-50%, -50%) scale(1.1);
}

.mg-play-btn svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

.mg-video-placeholder-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    color: rgba(255, 255, 255, 0.6);
}

/* ── Caption ──────────────────────────────────────────────── */
.mg-caption {
    padding: 8px 12px;
    font-size: 0.85em;
    color: #555;
    background: rgba(255, 255, 255, 0.92);
    text-align: center;
    line-height: 1.4;
    border-radius: 0 0 var(--mg-radius) var(--mg-radius);
}

/* ── Lightbox overlay ─────────────────────────────────────── */
.mg-lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.92);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.mg-lightbox-overlay.mg-is-open {
    display: flex;
    animation: mgFadeIn 0.25s ease;
}

@keyframes mgFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.mg-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mg-lightbox-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.8);
    animation: mgZoomIn 0.25s ease;
}

@keyframes mgZoomIn {
    from { transform: scale(0.93); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.mg-lightbox-iframe-wrap {
    position: relative;
    width: min(1000px, 90vw);
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.8);
}

.mg-lightbox-iframe-wrap iframe,
.mg-lightbox-iframe-wrap video {
    width: 100%;
    height: 100%;
    border: 0;
}

.mg-lightbox-caption {
    margin-top: 12px;
    color: #ddd;
    font-size: 0.95em;
    text-align: center;
    max-width: 700px;
}

/* Lightbox controls */
.mg-lightbox-close,
.mg-lightbox-prev,
.mg-lightbox-next {
    position: fixed;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 1000001;
    backdrop-filter: blur(4px);
}

.mg-lightbox-close:hover,
.mg-lightbox-prev:hover,
.mg-lightbox-next:hover {
    background: rgba(255, 255, 255, 0.25);
}

.mg-lightbox-close {
    top: 16px;
    right: 16px;
    font-size: 20px;
}

.mg-lightbox-prev {
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.mg-lightbox-next {
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
}

/* ── Lightbox cursor hints ────────────────────────────────── */
.mg-has-lightbox .mg-item-image .mg-item-inner {
    cursor: zoom-in;
}

.mg-has-lightbox .mg-lightbox-video .mg-item-inner {
    cursor: pointer;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .mg-layout-grid {
        grid-template-columns: repeat(min(var(--mg-columns), 2), 1fr);
    }
    .mg-layout-masonry {
        columns: min(var(--mg-columns), 2);
    }
    .mg-lightbox-prev { left: 6px; }
    .mg-lightbox-next { right: 6px; }
}

@media (max-width: 480px) {
    .mg-layout-grid    { grid-template-columns: 1fr; }
    .mg-layout-masonry { columns: 1; }
}
