/* ===========================================
   pagePartials/galleryModal.css - Gallery Modal
   =========================================== */

/* Width caps start at 768px — below that (phones, iPad mini portrait at 744px)
   the modal shell's full-width sheet must not be narrowed by a desktop cap. */
@media screen and (min-width: 768px) {
    .page-modal-gallery {
        max-width: 720px;
    }

    .page-modal-gallery[data-item-count="1"] {
        max-width: 400px;
    }

    .page-modal-gallery[data-item-count="2"] {
        max-width: 560px;
    }
}

@media screen and (min-width: 900px) {
    .page-modal-gallery {
        max-width: 860px;
    }

    .page-modal-gallery[data-item-count="3"],
    .page-modal-gallery[data-item-count="4"] {
        max-width: 720px;
    }
}

@media screen and (min-width: 1100px) {
    .page-modal-gallery {
        max-width: 960px;
    }
}


/* Album Filter Tabs */
.page-gallery-album-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 17px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 3px 0;
}

.page-gallery-album-tabs::-webkit-scrollbar {
    display: none;
}

/* 3px top/bottom keeps the ring inside the overflow clip; 3 + 17 keeps the
   20px gap below the pills. Same arithmetic as the portfolio strip. */
.page-gallery-album-tab:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

.page-gallery-album-tab {
    padding: 7px 18px; /* Parity with the services / FAQ / portfolio tab strips */
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
    background: #f3f4f6;
    border: 1px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.page-gallery-album-tab:hover {
    color: #374151;
    background: #e5e7eb;
}

.page-gallery-album-tab.active {
    /* Same clamp as the services / FAQ / portfolio strips. The raw accent was
       1.00:1 against its own 8% tint for a white accent. */
    color: #1f2937;
    color: color-mix(in srgb, var(--section-tag-color, var(--page-accent, #2563eb)) 35%, #1f2937);
    /* Resolved tint, not accent + white veil: a background-image is not animatable and
       flashes the raw accent on the way out. Full note in faqsModal.css. */
    background-color: #eef2fd;
    background-color: color-mix(in srgb, var(--section-tag-color, var(--page-accent, #2563eb)) 8%, #fff);
    border-color: rgba(37, 99, 235, 0.25);
    border-color: color-mix(in srgb, var(--section-tag-color, var(--page-accent, #2563eb)) 25%, transparent);
}

/* Gallery Grid */
.page-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

/* Media Item */
.page-gallery-item {
    border-radius: 12px;
    background: transparent;
    transition: all 0.2s ease;
}

/* Image Wrapper */
.page-gallery-img-wrapper {
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: #f9fafb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.page-gallery-img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}

/* Video Wrapper */
.page-gallery-video-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #f9fafb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* Link-out card (non-embeddable platforms) */
.page-gallery-link-card {
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a2e;
    background-size: cover;
    background-position: center;
}

.page-gallery-link-card.has-thumbnail .page-gallery-external-link {
    background: rgba(0, 0, 0, 0.4);
}

.page-gallery-external-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
    transition: opacity 0.2s ease;
}

/* Pointer devices only: on touch this state sticks after the tap. */
@media (hover: hover) {
    .page-gallery-external-link:hover {
        opacity: 0.85;
    }
}

.page-gallery-platform-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
}

.page-gallery-platform-badge.platform-tiktok {
    background: rgba(255, 255, 255, 0.12);
}

.page-gallery-platform-badge.platform-other {
    background: rgba(255, 255, 255, 0.1);
}

/* Caption */
.page-gallery-caption {
    padding: 8px 4px 0 4px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--page-text-secondary, #6b7280);
    text-align: center;
    margin: 0;
}

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

.page-gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10002;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.page-gallery-lightbox.open {
    display: flex;
}

.lightbox-close {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top));
    right: calc(16px + env(safe-area-inset-right));
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 10;
}

.lightbox-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.lightbox-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-top: 24px;
    margin-bottom: 8px;
    z-index: 2;
}

.lightbox-control-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Pointer devices only: on touch this state sticks after the tap. */
@media (hover: hover) {
    .lightbox-control-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        border-color: rgba(255, 255, 255, 0.25);
        color: #fff;
        transform: scale(1.05);
    }
}

.lightbox-control-btn:active {
    transform: scale(0.95);
}

.lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* The height budget drives the WIDTH here. `width` on the image is a definite
       length, so CSS Sizing 4 does not transfer a max-height back through the
       aspect ratio: the box stayed 80vw, lost its height and object-fit: cover
       cropped a landscape-phone photo to a strip. 190px is the caption, the
       prev/next row and the close button. */
    width: min(80vw, 860px, 133.33vh);
    width: min(80vw, 860px, calc(min(75vh, 100dvh - 190px) * 16 / 9));
}

.lightbox-img,
.lightbox-video-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    background: #000;
    overflow: hidden;
}

.lightbox-video-container iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

/* TikTok is portrait — reached via prev/next it must not sit in the 16:9 box */
.lightbox-video-container.platform-tiktok {
    width: auto;
    height: 75vh;
    height: min(75vh, calc(100dvh - 190px)); /* Its own clamp, now that the shared max-height is gone */
    aspect-ratio: 9 / 16;
}

.lightbox-caption {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    min-height: 21px; /* One line (14px × 1.5) reserved so prev/next don't jump between captioned and uncaptioned items */
    margin-top: 16px;
    text-align: center;
    line-height: 1.5;
    width: 100%; /* .lightbox-content is already the height-aware width */
    box-sizing: border-box;
}

/* TikTok video modal */
.tiktok-video-modal {
    position: fixed;
    inset: 0;
    z-index: 10002;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.tiktok-video-modal.open {
    display: flex;
}

.tiktok-video-modal-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 2;
}

.tiktok-video-modal-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.tiktok-video-modal-content {
    width: 370px;
    max-width: calc(100vw - 32px);
    height: calc(100vh - 80px);
    height: calc(100dvh - 80px); /* iOS: track the visible viewport, not the 100vh behind the URL bar */
    max-height: 750px;
    border-radius: 12px;
    overflow: hidden;
}

.tiktok-video-modal-content iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

.page-gallery-link-card[role="button"] {
    cursor: pointer;
}

/* Keyboard focus ring drawn inside the card (the desktop item clips overflow) */
.page-gallery-item [role="button"]:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -4px;
}

/* ===========================================
   Responsive
   =========================================== */

@media screen and (min-width: 768px) {
    /* Align modal header and body with generous, symmetrical padding */
    .page-modal-gallery .page-modal-header {
        padding: 24px 32px;
    }

    .page-modal-gallery .page-modal-body {
        padding: 24px 32px 32px 32px;
    }

    .page-gallery-album-tabs {
        margin-bottom: 21px; /* 21 + 3px padding = the 24px gap below the filter bar */
    }

    .page-gallery-grid {
        gap: 20px; /* Spacious gaps on larger screens */
    }

    /* Column count follows the item count (the modal width already does) — a lone item
       fills the 400px modal, two items don't leave an empty third column at ≥900px.
       (0,3,0) outranks both bare .page-gallery-grid column rules. */
    .page-modal-gallery[data-item-count="1"] .page-gallery-grid {
        grid-template-columns: 1fr;
    }

    .page-modal-gallery[data-item-count="2"] .page-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Desktop Hover Card styling - absolutely no border */
    .page-gallery-item {
        position: relative;
        border-radius: 12px;
        overflow: hidden;
        background: transparent; /* Solves browser subpixel bleeding of background color at rounded corners */
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
        
        /* Force GPU-accelerated subpixel clipping to eliminate anti-aliasing corner artifacts */
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        
        transition: box-shadow 0.25s ease, transform 0.25s ease;
    }

    /* The tile's own lift lives in the pointer-only block below, next to the
       caption reveal it belongs with — on a touch tablet it would stick. */

    /* Reset wrappers on desktop since the item container handles card styles.
       The video wrapper is kept out of this list: its link-card variant carries the
       JS-set thumbnail as a background-image, which `background: transparent !important`
       would wipe (white badge on white). Outlines stay so :focus-visible can draw. */
    .page-gallery-img-wrapper,
    .page-gallery-img {
        border-radius: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    .page-gallery-video-wrapper {
        border-radius: 0;
        box-shadow: none;
    }
}

/* Hover overlay caption — pointer devices only; touch tablets get the static caption below */
@media screen and (min-width: 768px) and (hover: hover) {
    .page-gallery-caption {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 28px 20px 20px 20px;
        font-size: 13.5px;
        line-height: 1.45;
        color: #ffffff;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.4) 65%, transparent 100%);
        opacity: 0;
        transform: translateY(8px);
        transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        pointer-events: none; /* Let clicks pass through to media elements underneath */
        z-index: 2;
        /* Clamp to 3 lines so a long caption can't outgrow the tile and clip its first lines */
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .page-gallery-item:hover {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        transform: translateY(-2px); /* Premium subtle lift on hover */
    }

    .page-gallery-item:hover .page-gallery-caption {
        opacity: 1;
        transform: translateY(0);
    }
}

@media screen and (min-width: 768px) and (hover: none) {
    .page-gallery-caption {
        padding: 8px 12px 10px; /* Static caption inside the card */
    }

    .page-gallery-grid {
        align-items: start; /* Image-only siblings don't stretch to a captioned tile's height */
    }
}

@media screen and (min-width: 900px) {
    .page-gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 24px; /* Spacious gaps for larger screens */
    }
}

@media screen and (max-width: 480px) {
    .page-gallery-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .page-gallery-lightbox {
        padding: 16px;
    }

    .lightbox-control-btn {
        width: 44px; /* Touch target; the 18px icon below keeps the visual size */
        height: 44px;
    }

    .lightbox-control-btn svg {
        width: 18px;
        height: 18px;
    }
}

