/**
 * Retreat gallery — Elementor-style justified layout (pure CSS)
 *
 * Each item gets flex-grow AND flex-basis proportional to its own aspect
 * ratio, so every item in a row ends up with the exact same height while
 * keeping its original proportions — that is what "justified" means.
 */

/* ---------- heading ---------- */

.ws-rgal-title {
    margin: 0 0 14px;
    font-size: 1.4em;
    line-height: 1.3;
}

/* ---------- container ---------- */

.ws-rgal {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ws-rgal-gap, 10px);
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ---------- items ---------- */

.ws-rgal .ws-rgal__item {
    position: relative;
    margin: 0;
    padding: 0;
    min-width: 0;
    overflow: hidden;
    border-radius: var(--ws-rgal-radius, 0);
    background: rgba(0, 0, 0, .04);
}

.ws-rgal .ws-rgal__link {
    position: absolute;
    inset: 0;
    display: block;
    line-height: 0;
}

/* Two-selector specificity so a theme's `img { height: auto }` can't win */
.ws-rgal .ws-rgal__img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    object-fit: cover;
    transition: transform .45s ease, opacity .3s ease;
}

/* ---------- justified ---------- */

/* flex-grow AND flex-basis both scale with the aspect ratio, so every item in
   a row lands on the exact same height: h = row + free / Σ(ratios).
   flex-basis is a plain custom property written by PHP — no calc(). */
.ws-rgal--justified {
    align-items: flex-start;
}

.ws-rgal--justified .ws-rgal__item {
    flex-grow: var(--ws-rgal-ar, 1.5);
    flex-shrink: 1;
    flex-basis: var(--ws-rgal-b, 300px);
}

/* The image flows normally and its own proportions give the item its height.
   Deriving that height from the width instead — via aspect-ratio or a
   percentage-padding box — renders correctly inside the gallery but does NOT
   propagate to Elementor's widget wrapper: the wrapper stayed 15px tall while
   holding a 195px gallery, and the next section was drawn on top of it. */
.ws-rgal--justified .ws-rgal__link {
    position: static;
    display: block;
    line-height: 0;
}

.ws-rgal--justified .ws-rgal__img {
    position: static;
    width: 100%;
    height: auto;
    object-fit: fill;
}

/* Invisible filler — absorbs the free space of the last row so the
   remaining images keep their row height instead of stretching. */
.ws-rgal--justified .ws-rgal__filler {
    flex: 999999 1 0;
    height: 0;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* ---------- masonry (testimonial screenshots) ---------- */

.ws-rgal--masonry {
    display: block;
    column-count: var(--ws-rgal-cols, 3);
    column-gap: var(--ws-rgal-gap, 10px);
}

.ws-rgal--masonry .ws-rgal__item {
    display: block;
    width: 100%;
    margin-bottom: var(--ws-rgal-gap, 10px);
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

/* Everything stays in normal flow here: the image's own proportions give the
   item its height, so nothing is absolutely positioned. WebKit misplaces
   absolutely positioned elements inside a multi-column container, and a
   screenshot must never be cropped anyway. */
.ws-rgal--masonry .ws-rgal__link {
    position: static;
    display: block;
    line-height: 0;
}

.ws-rgal--masonry .ws-rgal__img {
    position: static;
    width: 100%;
    height: auto;
    object-fit: fill;
}

/* ---------- grid fallback ---------- */

.ws-rgal--grid {
    display: grid;
    grid-template-columns: repeat(var(--ws-rgal-cols, 3), minmax(0, 1fr));
}

.ws-rgal--grid .ws-rgal__item::before {
    content: '';
    display: block;
    padding-top: 100%;
}

/* ---------- hover ---------- */

.ws-rgal--hover-zoom .ws-rgal__item:hover .ws-rgal__img {
    transform: scale(1.06);
}

.ws-rgal--hover-fade .ws-rgal__item:hover .ws-rgal__img {
    opacity: .78;
}

/* ---------- caption ---------- */

.ws-rgal__caption {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding: 26px 12px 10px;
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    text-align: start;
    background: linear-gradient(to top, rgba(0, 0, 0, .65), rgba(0, 0, 0, 0));
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .3s ease, transform .3s ease;
    pointer-events: none;
}

.ws-rgal__item:hover .ws-rgal__caption {
    opacity: 1;
    transform: none;
}

/* ---------- responsive ---------- */

@media (max-width: 1024px) {
    .ws-rgal--justified .ws-rgal__item {
        flex-basis: var(--ws-rgal-b-t, var(--ws-rgal-b, 300px));
    }
    .ws-rgal--grid {
        grid-template-columns: repeat(var(--ws-rgal-cols-t, 2), minmax(0, 1fr));
    }
    .ws-rgal--masonry {
        column-count: var(--ws-rgal-cols-t, 2);
    }
}

@media (max-width: 767px) {
    .ws-rgal--justified .ws-rgal__item {
        flex-basis: var(--ws-rgal-b-m, var(--ws-rgal-b-t, var(--ws-rgal-b, 300px)));
    }
    .ws-rgal--grid {
        grid-template-columns: repeat(var(--ws-rgal-cols-m, 2), minmax(0, 1fr));
    }
    .ws-rgal--masonry {
        column-count: var(--ws-rgal-cols-m, 2);
    }
}
