/**
 * Staff Gallery – public gallery (component view and module).
 * Asset: com_staffgallery.gallery
 *
 * Settings arrive as custom properties on the gallery root (see layouts/staffgallery/gallery.php):
 *   --sg-cols-lg / --sg-cols-md / --sg-cols-sm   columns at >= 992px / 576-991px / < 576px
 *   --sg-gap                                     gap between cards
 *   --sg-bg / --sg-bg-text                       image frame background and its text colour
 * The colours below can be overridden by a template (e.g. `.staffgallery { --sg-accent: #800; }`).
 *
 * Display rules (ARCHITECTURE.md 6.4): an image is always shown completely (object-fit: contain)
 * on the frame background. "cover" exists only in fill mode (.staffgallery--fill), where the
 * server already delivers a crop of the frame's own shape, so cover loses nothing.
 * No CSS reordering: the DOM order is the visual order.
 */

.staffgallery {
    --sg-cols-lg: 4;
    --sg-cols-md: 3;
    --sg-cols-sm: 2;
    --sg-gap: 16px;
    --sg-bg: #f2f2f2;
    --sg-bg-text: #1a1a1a;
    --sg-accent: #1f3b5c;
    --sg-accent-text: #ffffff;
    --sg-chip-bg: #ffffff;
    --sg-chip-hover-bg: #e8eef5;
    --sg-chip-text: #1f2937;
    --sg-chip-border: #6b7280;
    --sg-focus: #0b57d0;

    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.staffgallery *,
.staffgallery *::before,
.staffgallery *::after {
    box-sizing: border-box;
}

/* ---------- Group filter ---------- */

.staffgallery__filter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
}

.staffgallery__filter-list > li {
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.staffgallery .staffgallery__chip {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    min-height: 2.5rem;
    padding: 0.25rem 1rem;
    border: 2px solid var(--sg-chip-border);
    border-radius: 999px;
    background: var(--sg-chip-bg);
    color: var(--sg-chip-text);
    font-size: 0.95rem;
    line-height: 1.3;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.staffgallery .staffgallery__chip:hover {
    background: var(--sg-chip-hover-bg);
    text-decoration: underline;
}

/* The current filter is also marked by weight, not by colour alone. */
.staffgallery .staffgallery__chip[aria-current="true"] {
    border-color: var(--sg-accent);
    background: var(--sg-accent);
    color: var(--sg-accent-text);
    font-weight: 700;
}

.staffgallery a:focus-visible {
    outline: 3px solid var(--sg-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px #ffffff;
}

@media (prefers-reduced-motion: no-preference) {
    .staffgallery .staffgallery__chip {
        transition: background-color 0.15s ease-out;
    }
}

/* ---------- Status and empty message ---------- */

.staffgallery__status {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    line-height: 1.4;
}

.staffgallery__empty {
    margin: 0 0 1rem;
    line-height: 1.5;
}

.staffgallery__empty p {
    margin: 0 0 0.5rem;
}

/* ---------- Grid ---------- */

.staffgallery .staffgallery__grid {
    display: grid;
    grid-auto-flow: row; /* never "dense": DOM order = visual order */
    grid-template-columns: repeat(var(--sg-cols-sm), minmax(0, 1fr));
    gap: var(--sg-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

@media (min-width: 576px) {
    .staffgallery .staffgallery__grid {
        grid-template-columns: repeat(var(--sg-cols-md), minmax(0, 1fr));
    }
}

@media (min-width: 992px) {
    .staffgallery .staffgallery__grid {
        grid-template-columns: repeat(var(--sg-cols-lg), minmax(0, 1fr));
    }
}

.staffgallery .staffgallery__item {
    display: flex;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.staffgallery .staffgallery__item::marker {
    content: none;
}

.staffgallery .staffgallery__card {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* ---------- Image frame ---------- */

.staffgallery .staffgallery__frame {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    overflow: hidden;
    aspect-ratio: 2 / 3;
    background: var(--sg-bg);
    color: var(--sg-bg-text);
}

.staffgallery--square .staffgallery__frame {
    aspect-ratio: 1 / 1;
}

/* Mosaic: the frame follows the image's own shape (--sg-ratio, set per card) and grows to the
   height of its grid area, so neighbours in a row stay flush; the image remains whole inside. */
.staffgallery--mosaic .staffgallery__frame {
    flex: 1 0 auto;
    aspect-ratio: var(--sg-ratio, 0.6667);
}

/* The frame decides the size: the image is positioned inside it and the site template's global
   `img { max-width: 100%; height: auto }` cannot interfere. */
.staffgallery .staffgallery__frame .staffgallery__img {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    object-fit: contain;
    object-position: center;
}

/* upscale = 0: never display an image larger than its own pixels. */
.staffgallery--noupscale .staffgallery__frame .staffgallery__img {
    object-fit: scale-down;
}

/* fill mode: the delivered file is already cropped to the frame's shape. */
.staffgallery--fill .staffgallery__frame .staffgallery__img {
    object-fit: cover;
}

/* fill mode, but the delivered file is not a crop of the frame's shape (crop not generated yet):
   show it whole instead of letting the browser crop around the centre. */
.staffgallery--fill .staffgallery__frame .staffgallery__img.staffgallery__img--contain {
    object-fit: contain;
}

/* Members without an image: initials in the frame (the member exists, so no placeholder card). */
.staffgallery .staffgallery__initials {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 8vw, 3rem);
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ---------- Text ---------- */

.staffgallery .staffgallery__body {
    min-width: 0;
    padding: 0.5rem 0 0;
}

.staffgallery .staffgallery__name {
    margin: 0;
    padding: 0;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    text-transform: none;
    overflow-wrap: anywhere;
}

.staffgallery .staffgallery__position,
.staffgallery .staffgallery__subjects,
.staffgallery .staffgallery__description {
    margin: 0.125rem 0 0;
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

/* ---------- Search ---------- */

.staffgallery__search {
    margin: 0 0 1rem;
}

.staffgallery .staffgallery__search-label {
    display: block;
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.staffgallery__search-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.staffgallery .staffgallery__search-input {
    flex: 1 1 12rem;
    min-width: 0;
    max-width: 24rem;
    min-height: 2.5rem;
    margin: 0;
    padding: 0.25rem 0.75rem;
    border: 2px solid var(--sg-chip-border);
    border-radius: 0.5rem;
    background: var(--sg-chip-bg);
    color: var(--sg-chip-text);
    font: inherit;
}

.staffgallery .staffgallery__search-submit,
.staffgallery .staffgallery__dialog button {
    min-height: 2.5rem;
    margin: 0;
    padding: 0.25rem 1rem;
    border: 2px solid var(--sg-accent);
    border-radius: 0.5rem;
    background: var(--sg-accent);
    color: var(--sg-accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.staffgallery .staffgallery__search-reset {
    color: inherit;
    overflow-wrap: anywhere;
}

.staffgallery input:focus-visible,
.staffgallery button:focus-visible {
    outline: 3px solid var(--sg-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px #ffffff;
}

/* ---------- Pagination (own markup, see layouts/staffgallery/pagination.php) ---------- */

.staffgallery__pagination {
    max-width: 100%;
    margin-top: 1.5rem;
}

.staffgallery .staffgallery__pages {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.375rem;
    max-width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
}

.staffgallery .staffgallery__pages > li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.staffgallery .staffgallery__page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.25rem 0.5rem;
    border: 2px solid var(--sg-chip-border);
    border-radius: 0.5rem;
    background: var(--sg-chip-bg);
    color: var(--sg-chip-text);
    line-height: 1;
    text-decoration: none;
}

.staffgallery .staffgallery__page:hover {
    background: var(--sg-chip-hover-bg);
}

.staffgallery .staffgallery__page--current {
    border-color: var(--sg-accent);
    background: var(--sg-accent);
    color: var(--sg-accent-text);
    font-weight: 700;
}

.staffgallery .staffgallery__page--step {
    font-size: 1.5rem;
}

/* Text for assistive technology only. */
.staffgallery .staffgallery__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Lightbox (progressive enhancement, see media/js/gallery.js) ---------- */

/* Without JavaScript the link simply opens the large image. */
.staffgallery .staffgallery__frame > .staffgallery__zoom {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
}

/* Focus ring of the photo link: drawn ABOVE the image (the image covers the link, so a box-shadow or
   outline of the link itself would be hidden or sit on the photo). Two colours - a blue outer ring
   and a white inner ring - so at least one of them contrasts with any photo (SC 1.4.11). */
.staffgallery .staffgallery__zoom:focus-visible {
    outline: none;
    box-shadow: none;
}

.staffgallery .staffgallery__zoom:focus-visible::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    outline: 4px solid var(--sg-focus);
    outline-offset: -4px;
    box-shadow: inset 0 0 0 8px #ffffff;
    pointer-events: none;
}

.staffgallery .staffgallery__dialog {
    box-sizing: border-box;
    width: min(96vw, 64rem);
    max-width: 96vw;
    max-height: 96vh;
    margin: auto;
    padding: 0;
    overflow: auto;
    border: 0;
    border-radius: 0.5rem;
    background: #ffffff;
    color: #1a1a1a;
}

.staffgallery .staffgallery__dialog::backdrop {
    background: rgba(0, 0, 0, 0.78);
}

.staffgallery .staffgallery__dialog-inner {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
}

.staffgallery .staffgallery__dialog-media {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    background: var(--sg-bg);
}

.staffgallery .staffgallery__dialog-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 62vh;
    margin: 0 auto;
}

.staffgallery .staffgallery__dialog-title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.3;
    color: inherit;
    overflow-wrap: anywhere;
}

.staffgallery .staffgallery__dialog-text p {
    margin: 0.25rem 0 0;
    overflow-wrap: anywhere;
}

.staffgallery .staffgallery__dialog-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
}

.staffgallery .staffgallery__dialog-bar button {
    flex: 1 1 auto;
}

@keyframes sg-dialog-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .staffgallery .staffgallery__dialog[open] {
        animation: sg-dialog-in 0.15s ease-out;
    }
}

/* ---------- Mosaic: big cards (2 x 2 cells), per breakpoint, only inside the media query ---------- */

@media (max-width: 575.98px) {
    .staffgallery--mosaic .staffgallery__item[data-mosaic-sm="big"] {
        grid-column: span 2;
        grid-row: span 2;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .staffgallery--mosaic .staffgallery__item[data-mosaic-md="big"] {
        grid-column: span 2;
        grid-row: span 2;
    }
}

@media (min-width: 992px) {
    .staffgallery--mosaic .staffgallery__item[data-mosaic-lg="big"] {
        grid-column: span 2;
        grid-row: span 2;
    }
}
