/**
 * @package     MarkTom.Module.Pa_Contentgallery
 * @copyright   (C) 2026 Mark Tomzig <https://joomla.marktom.net>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

.pa-contentgallery__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--pa-cg-size, 160px)), 1fr));
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Fixed size: thumbnails exactly as large as set in the module ("Raster an Breite anpassen" = Nein). */
.pa-contentgallery__grid--fixed {
    grid-template-columns: repeat(auto-fill, min(100%, var(--pa-cg-size, 160px)));
}

.pa-contentgallery__description {
    margin-top: 1rem;
}

.pa-contentgallery__description > :last-child {
    margin-bottom: 0;
}

.pa-contentgallery__figure {
    margin: 0;
}

.pa-contentgallery__thumb {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: zoom-in;
}

.pa-contentgallery__thumb img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0.25rem;
}

.pa-contentgallery__grid--crop .pa-contentgallery__thumb img {
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

/* Not cropped: same height for all thumbnails, width follows the aspect ratio. */
.pa-contentgallery__grid--row {
    display: flex;
    flex-wrap: wrap;
}

.pa-contentgallery__grid--row .pa-contentgallery__item {
    flex: 0 0 auto;
    max-width: 100%;
}

.pa-contentgallery__grid--row .pa-contentgallery__thumb img {
    width: auto;
    max-width: 100%;
    height: var(--pa-cg-size, 160px);
    object-fit: cover;
}

.pa-contentgallery__grid--row .pa-contentgallery__caption {
    width: 0;
    min-width: 100%;
}

.pa-contentgallery__thumb:hover img {
    opacity: 0.85;
}

.pa-contentgallery__thumb:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

/* Text below thumbnails: at most 3 lines, very long words are broken. */
.pa-contentgallery__caption {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    overflow-wrap: anywhere;
    hyphens: auto;
}

/* Background colour comes from the module settings (CSS variable on the container),
   text and controls adapt to it. Override in the template, e.g.
   .pa-contentgallery__modal .modal-content { background-color: #333; } */
.pa-contentgallery__modal .modal-content {
    background-color: var(--pa-cg-modal-bg, #20242c);
}

.pa-contentgallery__modal--dark .modal-content {
    color: #fff;
}

.pa-contentgallery__modal--dark .modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.15);
}

.pa-contentgallery__modal--light .modal-content {
    color: #212529;
}

.pa-contentgallery__modal--light .modal-header {
    border-bottom-color: rgba(0, 0, 0, 0.15);
}

.pa-contentgallery__modal--light .carousel-control-prev-icon,
.pa-contentgallery__modal--light .carousel-control-next-icon {
    filter: invert(1) grayscale(100);
}

.pa-contentgallery__modal .carousel:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: -3px;
}

/* Fixed size: the dialog keeps its height while browsing, whatever the image format.
   Height of the image area and the caption area can be changed in the template:
   .pa-contentgallery { --pa-cg-stage-height: 60vh; --pa-cg-caption-height: 6rem; } */
.pa-contentgallery__slide {
    display: flex;
    flex-direction: column;
    margin: 0;
    text-align: center;
}

.pa-contentgallery__stage {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--pa-cg-stage-height, min(70vh, 900px));
}

.pa-contentgallery__large {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Caption area: text on top (up to 3 lines without scrolling), counter always at the bottom. */
.pa-contentgallery__slide-caption {
    display: flex;
    flex-direction: column;
    height: var(--pa-cg-caption-height, 7.25rem);
    padding: 0.75rem 3rem 0;
}

.pa-contentgallery__text {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    line-height: 1.5;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.pa-contentgallery__counter {
    display: block;
    flex: 0 0 auto;
    margin-top: auto;
    padding-top: 0.25rem;
    font-size: 0.875rem;
    opacity: 0.75;
}

/* Phones in portrait: full-screen dialog, smaller image area, more room for text. */
@media (max-width: 575.98px) and (orientation: portrait) {
    .pa-contentgallery__stage {
        height: var(--pa-cg-stage-height-portrait, 50vh);
    }

    .pa-contentgallery__slide-caption {
        height: var(--pa-cg-caption-height-portrait, 30vh);
        padding: 0.75rem 0.5rem 0;
    }
}

.pa-contentgallery__modal .carousel-control-prev,
.pa-contentgallery__modal .carousel-control-next {
    width: 3rem;
}

/* Title hidden: close button keeps its normal distance from the edge, no separator line. */
.pa-contentgallery__modal--notitle .modal-header {
    justify-content: flex-end;
    border-bottom: 0;
}

.pa-contentgallery__modal--notitle .modal-header .btn-close {
    margin: 0;
}
