/* ============================================================================
   Gallery Component
   Used by: includes/gallery.php (templates/page_with_galleries.php), js/gallery.js
   Plutonium CMS 6.2

   Index view  - .gallery-index   card per gallery
   Detail view - .gallery-detail  image grid for one gallery
   Lightbox    - extends the shared .gallery-lightbox / .lightbox-* rules in theme.css
   ============================================================================ */

.theme-galleries {
    --GalleryAccent: var(--ColorBrand2);
    width: 100%;
}

.theme-galleries .gallery-view {
    transition: opacity 0.2s ease;
}

.theme-galleries.is-loading .gallery-view {
    opacity: 0.35;
    pointer-events: none;
}

/* ============================================================================
   Index - card grid
   ============================================================================ */

.gallery-card-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: var(--Space8, 2rem);
}

.gallery-card {
    margin: 0;
    line-height: inherit;
    background: hsla(var(--White), 1);
    color: hsla(var(--ColorTextPrimary), 1);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-card:hover,
.gallery-card:focus-within {
    transform: translateY(-4px);
    box-shadow: 0 10px 28px hsla(var(--White), 0.14);
}

.gallery-card-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

.gallery-card-link:hover {
    color: inherit;
    text-decoration: none;
}

.gallery-card-link:focus {
    outline: none;
}

.gallery-card-link:focus-visible {
    outline: 3px solid hsla(var(--GalleryAccent), 1);
    outline-offset: 3px;
}

.gallery-card-image {
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: hsla(var(--ColorBrand), 0.12);
    flex-shrink: 0;
}

.gallery-card-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.gallery-card:hover .gallery-card-image img,
.gallery-card:focus-within .gallery-card-image img {
    transform: scale(1.04);
}

.gallery-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--Space2, 0.5rem);
    padding: var(--Space4, 1rem) var(--Space4, 1rem) var(--Space3, 0.75rem);
}

.gallery-card-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
    color: hsla(var(--GalleryAccent), 1);
}

.gallery-card-excerpt {
    font-size: var(--FontSizeBase, 1rem);
    line-height: 1.5;
    color: hsla(var(--ColorTextPrimary), 0.8);
}

.gallery-card-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--Space2, 0.5rem);
    padding: var(--Space3, 0.75rem) var(--Space4, 1rem) var(--Space4, 1rem);
    border-top: 1px solid hsla(var(--ColorBrand), 0.2);
}

.gallery-card-count {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: hsla(var(--ColorBrand), 1);
    background: hsla(var(--ColorBrand), 0.1);
    padding: 2px var(--Space2, 0.5rem);
    border-radius: 4px;
}

.gallery-card-cta {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: hsla(var(--GalleryAccent), 1);
}

/* ============================================================================
   Detail - header
   ============================================================================ */

.gallery-back {
    display: inline-flex;
    align-items: center;
    gap: var(--Space2, 0.5rem);
    margin-bottom: var(--Space6, 1.5rem);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    color: hsla(var(--White), 1);
    border-bottom: 2px solid hsla(var(--GalleryAccent), 1);
    padding-bottom: 2px;
}

.gallery-back:hover {
    color: hsla(var(--GalleryAccent), 1);
    text-decoration: none;
}

.gallery-back:focus {
    outline: none;
}

.gallery-back:focus-visible {
    outline: 2px solid hsla(var(--White), 1);
    outline-offset: 4px;
}

.gallery-detail-header {
    margin-bottom: var(--Space8, 2rem);
}

.gallery-detail-title {
    margin: 0 0 var(--Space2, 0.5rem);
}

.gallery-detail-title:focus {
    outline: none;
}

.gallery-detail-count {
    margin-bottom: var(--Space4, 1rem);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: hsla(var(--GalleryAccent), 1);
}

.gallery-detail-description {
    max-width: 80ch;
}

.gallery-detail-description > :last-child {
    margin-bottom: 0;
    padding-bottom: 0;
}

/* ============================================================================
   Detail - image grid
   ============================================================================ */

.gallery-image-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
    gap: var(--Space6, 1.5rem);
}

.gallery-image-item {
    margin: 0;
    line-height: inherit;
}

.gallery-image-figure {
    margin: 0;
}

.gallery-image-button {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    cursor: zoom-in;
    background: hsla(var(--White), 0.08);
}

.gallery-image-button:hover {
    background: hsla(var(--White), 0.08);
}

.gallery-image-button:focus-visible {
    outline: 3px solid hsla(var(--GalleryAccent), 1);
    outline-offset: 3px;
}

.gallery-image-button img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.gallery-image-button:hover img,
.gallery-image-button:focus-visible img {
    transform: scale(1.05);
    opacity: 0.9;
}

.gallery-image-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: var(--Space2, 0.5rem);
    line-height: 1.4;
}

.gallery-image-caption {
    font-size: 0.95rem;
    color: hsla(var(--White), 1);
}

.gallery-image-description {
    font-size: 0.85rem;
    color: hsla(var(--White), 0.7);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

/* ============================================================================
   Lightbox
   ============================================================================ */

.theme-gallery-lightbox[hidden],
.theme-gallery-lightbox [hidden] {
    display: none !important;
}

.theme-gallery-lightbox .lightbox-content {
    flex-direction: column;
    padding: 4.5rem 5rem 4rem;
}

.theme-gallery-lightbox .lightbox-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--Space3, 0.75rem);
    max-width: 100%;
    margin: 0;
}

.theme-gallery-lightbox .lightbox-image-container {
    max-width: 100%;
    max-height: none;
    flex-shrink: 0;
}

.theme-gallery-lightbox .lightbox-image {
    display: block;
    max-width: 100%;
    /* Image + caption area together never exceed the padded viewport:
       17rem = 8.5rem vertical padding + 0.75rem gap + 7.75rem caption area. */
    max-height: calc(100vh - 17rem);
    max-height: calc(100dvh - 17rem);
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 50px hsla(var(--Black), 0.5);
    transition: opacity 0.15s ease;
}

.theme-gallery-lightbox .lightbox-image.is-loading {
    opacity: 0.3;
}

.theme-gallery-lightbox .lightbox-meta {
    max-width: 70ch;
    max-height: 7.75rem;
    /* Padding keeps tall glyphs inside the box so short captions never show a scrollbar. */
    padding: 0.25rem 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: hsla(var(--White), 0.4) transparent;
    text-align: center;
    line-height: 1.5;
    color: hsla(var(--White), 1);
}

.theme-gallery-lightbox .lightbox-meta-caption {
    font-size: 1rem;
}

.theme-gallery-lightbox .lightbox-meta-description {
    margin-top: 2px;
    font-size: 0.9rem;
    color: hsla(var(--White), 0.75);
}

.theme-gallery-lightbox .lightbox-close,
.theme-gallery-lightbox .lightbox-prev,
.theme-gallery-lightbox .lightbox-next {
    margin: 0;
    padding: 0;
}

.theme-gallery-lightbox .lightbox-close:focus-visible,
.theme-gallery-lightbox .lightbox-prev:focus-visible,
.theme-gallery-lightbox .lightbox-next:focus-visible {
    outline: 2px solid hsla(var(--White), 1);
    outline-offset: 2px;
}

.theme-gallery-lightbox .lightbox-counter {
    bottom: 1rem;
}

@media screen and (max-width: 768px) {
    .theme-gallery-lightbox .lightbox-content {
        padding: 4rem 1rem 3.5rem;
    }

    .theme-gallery-lightbox .lightbox-image {
        max-height: calc(100vh - 16rem);
        max-height: calc(100dvh - 16rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .theme-galleries .gallery-view,
    .gallery-card,
    .gallery-card-image img,
    .gallery-image-button img,
    .theme-gallery-lightbox .lightbox-image {
        transition: none;
    }

    .gallery-card:hover,
    .gallery-card:focus-within,
    .gallery-card:hover .gallery-card-image img,
    .gallery-card:focus-within .gallery-card-image img,
    .gallery-image-button:hover img,
    .gallery-image-button:focus-visible img {
        transform: none;
    }
}
