/* ============================================================
   Lucas Gallery Pro — Frontend Styles
   v1.0.0
============================================================ */

/* ===== BASE ===== */
.lg-gallery {
    width: 100%;
    box-sizing: border-box;
}
.lg-gallery *,
.lg-gallery *::before,
.lg-gallery *::after {
    box-sizing: border-box;
}
.lg-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--lg-radius, 4px);
}
/* Trigger del lightbox — ahora es <button> para no interferir con Blocksy */
.lg-link {
    display: block;
    overflow: hidden;
    position: relative;
    border-radius: var(--lg-radius, 4px);
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    /* Reset estilos de <button> */
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    width: 100%;
    text-align: left;
    font: inherit;
    -webkit-appearance: none;
    appearance: none;
}
.lg-item img {
    display: block;
    width: 100%;
}

/* ============================================================
   LAYOUTS
============================================================ */

/* ===== GRID ===== */
.lg-layout-grid {
    display: grid;
    grid-template-columns: repeat(var(--lg-cols, 3), 1fr);
    gap: var(--lg-gap, 8px);
}
.lg-layout-grid .lg-item img {
    height: 220px;
    object-fit: cover;
}

/* ===== MASONRY ===== */
.lg-layout-masonry {
    column-count: var(--lg-cols, 3);
    column-gap: var(--lg-gap, 8px);
}
.lg-layout-masonry .lg-item {
    break-inside: avoid;
    margin-bottom: var(--lg-gap, 8px);
    display: block;
}
.lg-layout-masonry .lg-item img {
    height: auto;
}

/* ===== JUSTIFIED (controlled by JS) ===== */
.lg-layout-justified {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
}
.lg-layout-justified .lg-item {
    overflow: hidden;
    flex-shrink: 0;
}
.lg-layout-justified .lg-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== MOSAIC ===== */
.lg-layout-mosaic {
    display: grid;
    grid-template-columns: repeat(var(--lg-cols, 3), 1fr);
    gap: var(--lg-gap, 8px);
    grid-auto-rows: 200px;
}
.lg-layout-mosaic .lg-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.lg-layout-mosaic .lg-item:nth-child(1) {
    grid-column: span 2;
    grid-row: span 2;
}
/* Pattern: after featured, every 6th item gets featured treatment */
.lg-layout-mosaic .lg-item:nth-child(7n+1):not(:first-child) {
    grid-column: span 2;
    grid-row: span 2;
}

/* ============================================================
   HOVER EFFECTS
============================================================ */
.lg-hover-zoom .lg-item img {
    transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}
.lg-hover-zoom .lg-item:hover img {
    transform: scale(1.08);
}

/* ===== OVERLAY ===== */
.lg-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.38);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    gap: 8px;
}
.lg-hover-overlay .lg-item:hover .lg-overlay,
.lg-hover-overlay .lg-link:hover .lg-overlay {
    opacity: 1;
}
.lg-overlay-icon {
    width: 36px;
    height: 36px;
    color: #fff;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}
.lg-overlay-caption {
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
    padding: 0 12px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    line-height: 1.3;
}

/* ===== CAPTION BELOW ===== */
.lg-caption {
    padding: 6px 8px 8px;
    font-size: 0.82rem;
    color: #555;
    text-align: center;
    line-height: 1.4;
}

/* ============================================================
   RESPONSIVE
   Las columnas y gaps responsive se manejan con <style> inline
   generado por PHP por cada galería (usando las vars CSS).
   Solo se mantienen ajustes de altura/imagen que no dependen de columnas.
============================================================ */
@media (max-width: 680px) {
    .lg-layout-grid .lg-item img {
        height: 160px;
    }
    .lg-layout-mosaic {
        grid-auto-rows: 150px;
    }
}
@media (max-width: 420px) {
    .lg-layout-mosaic .lg-item:nth-child(1) {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* ============================================================
   LIGHTBOX
============================================================ */
.lg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999990;
    display: none;
    align-items: center;
    justify-content: center;
}
.lg-lightbox.lg-active {
    display: flex;
}

/* Overlay */
.lg-lb-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    cursor: pointer;
}

/* Close */
.lg-lb-close {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 10;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    padding: 0;
    line-height: 1;
}
.lg-lb-close:hover {
    background: rgba(255,255,255,0.25);
    transform: rotate(90deg);
}

/* Nav buttons */
.lg-lb-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
    line-height: 1;
    font-size: 1.5rem;
}
.lg-lb-nav:hover { background: rgba(255,255,255,0.28); }
.lg-lb-nav:disabled { opacity: 0.18; cursor: default; pointer-events: none; }
.lg-lb-prev { left: 10px; }
.lg-lb-next { right: 10px; }

/* Main container */
.lg-lb-container {
    position: relative;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 95vw;
    max-height: 95vh;
}

/* Image wrap — position:relative + overflow:hidden contiene el slide */
.lg-lb-img-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;          /* recorta imagen saliente/entrante */
    max-width: 90vw;
    max-height: 82vh;
    cursor: zoom-in;
    border-radius: 3px;
}
.lg-lb-img-wrap.lg-zoomed {
    cursor: grab;
    overflow: visible;
}
.lg-lb-img-wrap.lg-zoomed:active {
    cursor: grabbing;
}

/* Image */
.lg-lb-img {
    max-width: 90vw;
    max-height: 82vh;
    object-fit: contain;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    transform-origin: center center;
    /* Sin transition por defecto — la maneja JS para el slide */
}

/* Loading spinner */
.lg-lb-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    min-height: 80px;
}
.lg-lb-spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: rgba(255,255,255,0.8);
    border-radius: 50%;
    animation: lg-spin 0.75s linear infinite;
}
@keyframes lg-spin { to { transform: rotate(360deg); } }

/* Toolbar */
.lg-lb-toolbar {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 90vw;
    padding: 10px 0 0;
    gap: 10px;
    flex-wrap: wrap;
}
.lg-lb-counter {
    color: rgba(255,255,255,0.55);
    font-size: 0.82rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 44px;
}
.lg-lb-caption {
    color: rgba(255,255,255,0.85);
    font-size: 0.88rem;
    flex: 1;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.lg-lb-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.lg-lb-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.22);
    color: #fff;
    padding: 6px 13px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
    line-height: 1.2;
}
.lg-lb-btn:hover {
    background: rgba(255,255,255,0.24);
    transform: translateY(-1px);
}
.lg-lb-btn:active {
    transform: translateY(0);
}
.lg-lb-btn svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}
.lg-lb-btn.lg-zoomed-active {
    background: rgba(255,220,100,0.2);
    border-color: rgba(255,220,100,0.5);
    color: #ffd860;
}

/* ===== Mobile lightbox ===== */
@media (max-width: 600px) {
    /* El lightbox ocupa toda la pantalla incluyendo safe areas (notch, barra inferior) */
    .lg-lightbox {
        /* Usar las safe areas de iOS/Android */
        padding: env(safe-area-inset-top) env(safe-area-inset-right)
                 env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    .lg-lb-nav { width: 38px; height: 38px; font-size: 1.2rem; }
    .lg-lb-prev { left: 4px; }
    .lg-lb-next { right: 4px; }
    .lg-lb-close { top: 10px; right: 10px; width: 36px; height: 36px; }
    /* La imagen ocupa todo el ancho disponible en móvil */
    .lg-lb-img {
        max-width: 100vw !important;
        max-height: 70vh !important;
    }
    .lg-lb-img-wrap {
        max-width: 100vw !important;
        max-height: 70vh !important;
    }
    .lg-lb-toolbar { padding: 8px 6px 0; gap: 5px; flex-wrap: wrap; }
    .lg-lb-btn { padding: 5px 10px; font-size: 0.72rem; }
    .lg-lb-caption { font-size: 0.78rem; max-width: 60vw; }
    .lg-lb-counter { min-width: 36px; }
}
/* iOS: prevenir que el body haga scroll detrás del lightbox */
html[style*="overflow: hidden"] body {
    position: fixed;
    width: 100%;
}

/* ============================================================
   GALERÍA ANCHO COMPLETO EN MÓVIL
   Blocksy tiene contenedores con max-width y padding propios.
   Usamos position:relative + márgenes negativos basados en
   el padding real del viewport para salir del contenedor.
============================================================ */
@media (max-width: 480px) {
    .lg-gallery {
        width:        100vw !important;
        max-width:    100vw !important;
        position:     relative !important;
        left:         50% !important;
        right:        50% !important;
        margin-left:  -50vw !important;
        margin-right: -50vw !important;
        box-sizing:   border-box !important;
    }
}

/* ============================================================
   TOAST — mensaje de confirmación
============================================================ */
#lg-toast {
    position:        fixed;
    bottom:          28px;
    left:            50%;
    transform:       translateX(-50%) translateY(16px);
    z-index:         9999999;
    background:      #1a1a2e;
    color:           #fff;
    padding:         12px 24px;
    border-radius:   40px;
    font-size:       14px;
    font-weight:     500;
    letter-spacing:  0.01em;
    white-space:     nowrap;
    box-shadow:      0 4px 20px rgba(0,0,0,0.35);
    pointer-events:  none;
    opacity:         0;
    transition:      opacity 0.28s ease, transform 0.28s ease;
}
#lg-toast.lg-toast--show {
    opacity:   1;
    transform: translateX(-50%) translateY(0);
}
#lg-toast.lg-toast--success {
    border-left: 4px solid #4caf50;
}
#lg-toast.lg-toast--error {
    border-left: 4px solid #f44336;
}
@media (max-width: 480px) {
    #lg-toast {
        bottom:    20px;
        font-size: 13px;
        padding:   10px 18px;
        max-width: 88vw;
        white-space: normal;
        text-align: center;
    }
}
