/* ══════════════════════════════════════════════════════════════
 *  CW GALLERY - BENTO GRID & LIGHTBOX
 * ══════════════════════════════════════════════════════════════ */

/* ─── Grid Justificado (Sin Espacios Vacíos) ─── */
.cw-gallery-wrapper {
    width: 100%;
    margin: 0 auto;
}

.cw-gallery-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--cw-gallery-gap, 15px);
    width: 100%;
}

.cw-gallery-item {
    flex: 1 1 280px; /* Ancho base */
    height: 300px; /* Altura fija para alineación */
}

/* Alterar la proporción de flex-grow para darle asimetría creativa */
@media (min-width: 768px) {
    .cw-gallery-item:nth-child(odd) {
        flex-grow: 1.5; /* Elementos impares son ligeramente más anchos */
    }
    .cw-gallery-item:nth-child(4n) {
        flex-grow: 2.5; /* Cada cuarto elemento es muy ancho */
    }
}

@media (max-width: 767px) {
    .cw-gallery-item {
        height: 220px;
        flex: 1 1 150px;
    }
}

/* ─── Gallery Items ─── */
.cw-gallery-item {
    position: relative;
    border-radius: var(--cw-gallery-radius, 12px);
    overflow: hidden;
    cursor: zoom-in;
    transform: translateZ(0); /* Force hardware acceleration */
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.4s ease;
}

.cw-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.15);
    z-index: 2;
}

.cw-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: block;
}

.cw-gallery-item:hover img {
    transform: scale(1.05);
}

/* Hover Overlay */
.cw-gallery-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.3) 100%);
    opacity: 0;
    transition: opacity 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.cw-gallery-item:hover .cw-gallery-overlay {
    opacity: 1;
}

.cw-gallery-icon {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transform: scale(0.8) translateY(20px);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.cw-gallery-icon svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cw-gallery-item:hover .cw-gallery-icon {
    transform: scale(1) translateY(0);
}

/* ══════════════════════════════════════════════════════════════
 *  LIGHTBOX / SLIDER MODAL
 * ══════════════════════════════════════════════════════════════ */
.cw-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    display: flex;
    flex-direction: column;
}

.cw-lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

/* Toolbar */
.cw-lightbox-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    z-index: 10;
}

.cw-lightbox-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

.cw-lightbox-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
}

.cw-lightbox-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Slider Track */
.cw-lightbox-slider {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.cw-lightbox-track {
    display: flex;
    align-items: center;
    height: 100%;
    width: 100%;
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform;
}

.cw-lightbox-slide {
    flex: 0 0 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    box-sizing: border-box;
}

.cw-lightbox-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    user-select: none;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

.cw-lightbox-slide.is-active img {
    opacity: 1;
    transform: scale(1);
}

/* Navigation Arrows */
.cw-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    border: none;
    z-index: 10;
    transition: background 0.3s ease, transform 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.cw-lightbox-nav:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-50%) scale(1.1);
}

.cw-lightbox-nav.prev {
    left: 20px;
}

.cw-lightbox-nav.next {
    right: 20px;
}

.cw-lightbox-nav svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Loading Spinner */
.cw-lightbox-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cw-spin 1s linear infinite;
    z-index: 5;
    display: none;
}

.cw-lightbox.is-loading .cw-lightbox-loader {
    display: block;
}

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

/* Light Theme Support */
.cw-lightbox[data-theme="light"] {
    background: rgba(255, 255, 255, 0.95);
}
.cw-lightbox[data-theme="light"] .cw-lightbox-btn,
.cw-lightbox[data-theme="light"] .cw-lightbox-nav {
    background: rgba(0,0,0,0.05);
    color: #111;
}
.cw-lightbox[data-theme="light"] .cw-lightbox-btn:hover,
.cw-lightbox[data-theme="light"] .cw-lightbox-nav:hover {
    background: rgba(0,0,0,0.15);
}
.cw-lightbox[data-theme="light"] .cw-lightbox-loader {
    border: 3px solid rgba(0,0,0,0.1);
    border-top-color: #111;
}
.cw-lightbox[data-theme="light"] .cw-lightbox-slide img {
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
}
