/**
 * Hagstone Project Gallery
 * Clean layout + modern interactions + accessible lightbox
 *
 * @package Hagstone
 * @since 1.0
 */

/* ============================================
   Layout: Two-Column Single Post
   ============================================ */

.single-post-main.has-gallery {
    display: flex;
    min-height: calc(100vh - var(--header-height, 80px));
}

.single-post-main.has-gallery .single-container {
    flex: 0 0 45%;
    max-width: 45%;
    padding-right: 2rem;
}

/* ============================================
   Gallery Section
   ============================================ */

.project-gallery-sidebar {
    flex: 1;
    position: relative;
    display: flex;
}

.project-gallery {
    flex: 1;
    padding: 2rem 2rem 2rem 0;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height, 80px));
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.project-gallery::-webkit-scrollbar {
    width: 4px;
}

.project-gallery::-webkit-scrollbar-track {
    background: transparent;
}

.project-gallery::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================
   Gallery Grid (JS handles layout)
   ============================================ */

.gallery-grid {
    position: relative;
}

.gallery-item {
    display: block;
    overflow: hidden;
}

.gallery-item img,
.gallery-item video {
    display: block;
    width: 100%;
    height: auto;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover: subtle zoom */
.gallery-item:hover img,
.gallery-item:hover video {
    transform: scale(1.03);
}

/* Linked items */
.gallery-item a {
    display: block;
    position: relative;
}

/* External link indicator */
.gallery-item a[target="_blank"]::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    opacity: 0;
    transition: opacity 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3'/%3E%3C/svg%3E");
    background-size: contain;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6));
}

.gallery-item a[target="_blank"]:hover::after {
    opacity: 1;
}

/* Screen reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   Lightbox
   ============================================ */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    overflow: hidden;
}

.gallery-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.95);
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 80px;
    box-sizing: border-box;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    animation: lightboxZoomIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: zoom-in;
    transition: transform 0.2s ease;
    user-select: none;
    -webkit-user-drag: none;
}

@media (prefers-reduced-motion: reduce) {
    .lightbox-image {
        animation: none;
        transition: none;
    }
}

@keyframes lightboxZoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.gallery-lightbox .lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1) !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s ease;
}

.gallery-lightbox .lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2) !important;
}

.gallery-lightbox .lightbox-close svg {
    width: 24px;
    height: 24px;
    stroke: #fff;
}

.gallery-lightbox .lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    cursor: pointer;
}

.gallery-lightbox .lightbox-prev {
    left: 20px;
}

.gallery-lightbox .lightbox-next {
    right: 20px;
}

.gallery-lightbox .lightbox-nav svg {
    width: 28px;
    height: 28px;
    stroke: rgba(255, 255, 255, 0.6);
    transition: stroke 0.2s ease;
}

.gallery-lightbox .lightbox-nav:hover svg {
    stroke: #fff;
}

/* Lightbox CTA - thicc obvious bar */
.gallery-lightbox .lightbox-cta {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px 40px;
    background: #fff !important;
    color: #111 !important;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease;
    z-index: 10;
}

.gallery-lightbox .lightbox-cta:hover {
    background: #f0f0f0 !important;
}

.gallery-lightbox .lightbox-cta svg {
    width: 20px;
    height: 20px;
    stroke: #111;
    transition: transform 0.2s ease;
}

.gallery-lightbox .lightbox-cta:hover svg {
    transform: translateX(4px);
}

/* ============================================
   Entrance Animation
   ============================================ */

@keyframes gallerySlideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.project-gallery-sidebar {
    animation: gallerySlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.05s;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .project-gallery-sidebar {
        animation: none;
        opacity: 1;
    }

    .gallery-item img,
    .gallery-item video {
        transition: none;
    }

    .lightbox-image {
        animation: none;
    }
}

/* ============================================
   Mobile: Stacked Layout
   ============================================ */

@media (max-width: 1024px) {
    .single-post-main.has-gallery {
        flex-direction: column;
    }

    .single-post-main.has-gallery .single-container {
        flex: none;
        max-width: 100%;
        padding-right: 0;
    }

    .project-gallery-sidebar {
        flex: none;
        max-width: 100%;
        animation: none;
        opacity: 1;
    }

    .project-gallery {
        max-height: none;
        overflow: visible;
        padding: 1.5rem;
    }

    /* Lightbox adjustments */
    .lightbox-content {
        padding: 60px 20px;
    }

    .lightbox-nav {
        display: none;
    }
}

/* Small mobile */
@media (max-width: 600px) {
    .project-gallery {
        padding: 1rem;
    }
}
