/**
 * Media Lightbox Plugin - Styles
 * Glassmorphic, theme-aware lightbox overlay using Core CMS CSS variables.
 *
 * Theme Override Guide:
 * Use high-specificity `body` prefix on all selectors to override these defaults.
 * e.g. body #ml-overlay { ... }  /  body #ml-modal { ... }
 */

/* ── Overlay ──────────────────────────────────────────────────────────────── */
#ml-overlay {
    position: fixed;
    inset: 0;
    z-index: 99990;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, var(--ml-overlay-opacity, 0.92));
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--ml-speed, 300ms) ease, visibility var(--ml-speed, 300ms) ease;
    padding: 20px;
    box-sizing: border-box;
}

#ml-overlay.ml-open {
    opacity: 1;
    visibility: visible;
}

/* ── Modal Container (Glassmorphic) ──────────────────────────────────────── */
#ml-modal {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 92vw;
    max-height: 92vh;
    background: var(--card-bg, rgba(30, 41, 59, 0.85));
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 16px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(99, 102, 241, 0.08);
    padding: 16px;
    gap: 12px;
    transform: translateY(20px) scale(0.97);
    transition: transform var(--ml-speed, 300ms) cubic-bezier(0.34, 1.56, 0.64, 1);
}

#ml-overlay.ml-open #ml-modal {
    transform: translateY(0) scale(1);
}

/* ── Image ────────────────────────────────────────────────────────────────── */
#ml-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    width: 100%;
}

#ml-image {
    display: block;
    max-width: min(80vw, 1200px);
    max-height: 75vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    opacity: 0;
    transition: opacity var(--ml-speed, 300ms) ease;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

#ml-image.ml-loaded {
    opacity: 1;
}

/* ── Caption ──────────────────────────────────────────────────────────────── */
#ml-caption {
    color: var(--text-muted, #94a3b8);
    font-size: 0.875rem;
    font-style: italic;
    text-align: center;
    max-width: 640px;
    line-height: 1.5;
    padding: 0 8px;
    min-height: 1.2em; /* Reserve space to prevent layout shift */
}

/* ── Counter Badge ────────────────────────────────────────────────────────── */
#ml-counter {
    position: absolute;
    top: -14px;
    right: 14px;
    background: var(--card-bg, rgba(30, 41, 59, 0.9));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 20px;
    color: var(--text-muted, #94a3b8);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 3px 12px;
    white-space: nowrap;
}

/* ── Close Button ─────────────────────────────────────────────────────────── */
#ml-close {
    position: absolute;
    top: -18px;
    left: -18px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    background: var(--card-bg, rgba(30, 41, 59, 0.9));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-color, #f8fafc);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    z-index: 10;
}

#ml-close:hover {
    background: rgba(239, 68, 68, 0.8);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
    transform: scale(1.1) rotate(90deg);
}

/* ── Navigation Arrows ────────────────────────────────────────────────────── */
#ml-prev,
#ml-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    background: var(--card-bg, rgba(30, 41, 59, 0.75));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-color, #f8fafc);
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    z-index: 10;
}

#ml-prev {
    left: -64px;
}

#ml-next {
    right: -64px;
}

#ml-prev:hover,
#ml-next:hover {
    background: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
    transform: translateY(-50%) scale(1.08);
}

#ml-prev:disabled,
#ml-next:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* Hide arrows when only one image */
#ml-overlay[data-count="1"] #ml-prev,
#ml-overlay[data-count="1"] #ml-next {
    display: none;
}

/* ── Loading Spinner ──────────────────────────────────────────────────────── */
#ml-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-top-color: var(--accent-color, #6366f1);
    border-radius: 50%;
    animation: ml-spin 0.75s linear infinite;
    position: absolute;
}

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

/* ── Body Lock (prevents scroll while open) ───────────────────────────────── */
body.ml-active {
    overflow: hidden;
}

/* ── Clickable image cursor ───────────────────────────────────────────────── */
.entry-content img.ml-trigger,
.product-image img.ml-trigger,
.product-detail-wrapper .description img.ml-trigger {
    cursor: zoom-in;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.entry-content img.ml-trigger:hover,
.product-image img.ml-trigger:hover,
.product-detail-wrapper .description img.ml-trigger:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #ml-prev {
        left: -4px;
        top: auto;
        bottom: -60px;
        transform: none;
    }

    #ml-next {
        right: -4px;
        top: auto;
        bottom: -60px;
        transform: none;
    }

    #ml-prev:hover,
    #ml-next:hover {
        transform: scale(1.08);
    }

    #ml-modal {
        max-width: 96vw;
        padding: 12px;
        margin-bottom: 70px;
    }

    #ml-image {
        max-width: 90vw;
        max-height: 60vh;
    }

    #ml-close {
        top: -16px;
        left: -12px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
}
