/*
 * Presentation for the news gallery and EkorreGalleryLightbox.
 *
 * Three parts: the thumbnail grid in the layout the author picked, the
 * buttons of a strip, and the caption chrome. The caption rules belong
 * together because the per-thumbnail caption source is markup, not display, so
 * it stays hidden in the page; the lightbox copies its contents into its own
 * overlay, which is what this styles.
 */

/* The thumbnail grid.
 *
 * Its own layout rather than the framework's, because chunk_gallery.tpl is
 * included from the Bootstrap 3, 4 and 5 news templates alike and `img-fluid`,
 * `d-block`, `row g-3` and `col-6` all arrived in Bootstrap 4 or 5. On a
 * Bootstrap 3 site none of them applied, so nothing constrained the image and
 * every thumbnail rendered at its natural width -- a 2000px photo pushed the
 * whole page sideways. Found on kif, whose design carries `bootstrap` without a
 * `bootstrap_version`, which Theme::getBootstrapVersion() reads as 3.
 *
 * Flexbox and not CSS grid, which is not the obvious choice and was not the
 * first attempt: a grid container placed here measured **zero wide** on the kif
 * article page -- 730px of parent, `width:auto`, no rule setting a width, and
 * still `repeat(4, 1fr)` resolved to `0px 0px 0px 0px`, while a plain block in
 * the same position filled its 730px. Flex was measured working in exactly that
 * spot, and it is what chunk_files.tpl beside this already uses on the same
 * page. Percentage widths with negative side margins are also what these
 * themes' own `.row` does, so the result sits inside a Bootstrap 3 page the way
 * the rest of it does.
 *
 * The breakpoints are Bootstrap 5's md and lg and the counts are the ones the
 * old classes gave (2, then 3, then 4 across), so a site already rendering this
 * correctly sees no change.
 *
 * Sizes are px and not rem for the same reason the layout is not Bootstrap's:
 * Bootstrap 3 sets html{font-size:10px} and restores 16px on body, so one rem
 * is 10px on a Bootstrap 3 client and 16px on a Bootstrap 5 one -- the same
 * declaration rendering 37.5% smaller on four of the fourteen. Measured on kif,
 * where getComputedStyle(document.documentElement).fontSize is 10px.
 */
/* The heading over the photos, set by the author (chunk_gallery.tpl). An h4,
 * which Bootstrap 5 makes 24px - nearly the article's own title (KK,
 * 2026-11-22: too big). A section's label in the text's colour, a size above
 * the text; px for the reason chunk_files.tpl gives, and through the wrapper
 * so a theme's rule for h4 does not win. The attachments' heading in
 * chunk_files.tpl and the event's in chunk_event.tpl are the same, and the
 * three change together.
 */
.news_gallery_wrap .news_gallery_title {
    margin: 24px 0 10px;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
}

/* Justified rows, as Google Photos and Flickr lay out photos of mixed shapes
 * (KK, 2026-11-22): every photo in a row has the same height and its own
 * width, nothing is cropped, and the row fills the line. Each cell carries its
 * photo's width/height as --r (chunk_gallery.tpl); it starts at --r times the
 * row height and takes a share of the line's leftover in proportion to --r,
 * which grows every photo in the row by the same height. The ::after filler
 * soaks up the last row's leftover, so a last row of one or two keeps the row
 * height instead of stretching across the line. Replaced equal columns with
 * each photo's own height, where a portrait stood three times a landscape.
 */
.news_gallery_items {
    --news-gallery-row: 180px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 16px;
}

.news_gallery_items::after {
    content: "";
    flex-grow: 999999;
}

.news_gallery_cell {
    flex: var(--r, 1.3333) 1 calc(var(--r, 1.3333) * var(--news-gallery-row));
    min-width: 0;
    box-sizing: border-box;
}

/* A row only grows so far: one a very wide photo could not join would
   otherwise grow until it filled the line, two landscapes 60% over the row
   height. Capped, such a row stops short of the line's end. Not on a phone,
   where one photo across the column is what a row of one should be. */
@media (min-width: 577px) {
    .news_gallery_cell {
        max-width: calc(var(--r, 1.3333) * var(--news-gallery-row) * 1.3);
    }
}

@media (max-width: 576px) {
    .news_gallery_items {
        --news-gallery-row: 120px;
    }
}

/* A non-image item is a plain link, not a thumbnail, so it takes the row. */
.news_gallery_items .news_gallery_cell_wide {
    flex: 0 0 100%;
}

.news_gallery_link {
    display: block;
    text-decoration: none;
}

/* The photo fills its cell at its own shape. --r comes from the stored
   dimensions; a photo stored without them is cropped to 4:3 rather than
   left to set its own height. */
.news_gallery_img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: var(--r, 1.3333);
    object-fit: cover;
    border-radius: 4px;
}

.news_gallery_caption_title {
    margin-top: 4px;
    font-size: 14px;
}

.news_gallery_caption_desc {
    font-size: 14px;
    opacity: 0.75;
}

/* The other two layouts the author can pick for the gallery below the text
 * (NewsGallery::layouts(), KK 2026-11-22), drawn as the galleries in the text
 * draw them (text-gallery.css). Large, the justified rows above, is the default
 * and needs no rule of its own. Neither needs the filler that holds the last
 * justified row short; a strip would scroll on into it.
 */
.news_gallery--small .news_gallery_items::after,
.news_gallery--strip .news_gallery_items::after {
    content: none;
}

/* Small: square thumbnails, three to a line on a phone. */
.news_gallery--small .news_gallery_cell {
    flex: 0 0 120px;
    width: 120px;
    max-width: none;
}

.news_gallery--small .news_gallery_img {
    aspect-ratio: 1 / 1;
}

/* Strip: one line, every photo its height and as wide as its shape, moved by
   the buttons and the wheel of gallery-strip.js in place of a scroll bar. */
.news_gallery--strip {
    --gallery-strip-height: 160px;
}

.news_gallery--strip .news_gallery_items {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.news_gallery--strip .news_gallery_items::-webkit-scrollbar {
    display: none;
}

.news_gallery--strip .news_gallery_cell {
    flex: 0 0 auto;
    width: calc(var(--r, 1.3333) * var(--gallery-strip-height));
    max-width: none;
}

@media (max-width: 576px) {
    .news_gallery--small .news_gallery_cell {
        flex-basis: calc((100% - 16px) / 3);
        width: calc((100% - 16px) / 3);
    }

    .news_gallery--strip {
        --gallery-strip-height: 120px;
    }
}

/* A strip's previous and next buttons (gallery-strip.js), for the galleries in
 * the text and the one below it alike. They sit on the middle of the photos,
 * not of the captions under them: the strip gives its photos' height in
 * --gallery-strip-height.
 */
.gallery-strip {
    position: relative;
}

.gallery-strip > .gallery-strip-nav {
    position: absolute;
    top: calc(var(--gallery-strip-height, 160px) / 2 - 18px);
    z-index: 2;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 50%;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
    color: #212529;
    font-size: 16px;
    line-height: 34px;
    text-align: center;
    cursor: pointer;
}

.gallery-strip > .gallery-strip-nav:hover {
    background: #fff;
}

.gallery-strip > .gallery-strip-nav[hidden] {
    display: none;
}

.gallery-strip > .gallery-strip-nav--prev {
    left: 6px;
}

.gallery-strip > .gallery-strip-nav--next {
    right: 6px;
}

/* The caption source next to each thumbnail. Present for the lightbox to read,
   never shown in place. */
.pswp-caption-content {
    display: none;
}

.pswp__custom-caption {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 15px;
    line-height: 1.35;
    box-sizing: border-box;
}

.pswp__custom-caption strong {
    font-weight: 600;
}

.pswp__custom-caption .pswp-caption-desc {
    opacity: 0.85;
}

/* An item with captions turned off contributes nothing, so the bar should not
   appear as an empty strip over the image. */
.pswp__custom-caption:empty {
    display: none;
}
