/*
 * Kachelgalerien – theme-neutrales Frontend
 *
 * Eigene Regeln nur für:
 * - Galerie-Raster
 * - Bilddarstellung
 * - Navigationsanordnung
 * - Lightbox
 *
 * Keine eigene Farbpalette für die Seitennavigation.
 */

/* ========================================
   Galerie
   ======================================== */

.kg-wrap {
    width: 100%;
    margin-block: 1.5em;
    scroll-margin-top: 100px;
    font: inherit;
    color: inherit;
}

.kg-wrap,
.kg-wrap * {
    box-sizing: border-box;
}

.kg-wrap .kg-gallery {
    display: grid;
    grid-template-columns:
        repeat(var(--kg-columns, 4), minmax(0, 1fr));
    gap: var(--kg-gap, 12px);
    width: 100%;
}

/* Kachelgröße und Seitenverhältnis aus den Einstellungen */

.kg-gallery > a.kg-tile {
    position: relative;
    display: block;
    float: none;
    width: 100%;
    min-width: 0;
    height: auto;
    aspect-ratio: var(--kg-ratio, 3 / 2);

    margin: 0 !important;
    padding: 0 !important;

    overflow: hidden;
    border: 0;
    border-radius: var(--kg-radius, 10px);
    background: transparent;
    box-shadow: none;
    text-decoration: none;
}

/* Bilder füllen die Kachel vollständig */

.kg-gallery > .kg-tile > img {
    position: absolute;
    inset: 0;

    display: block;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;

    margin: 0 !important;
    padding: 0 !important;

    border: 0;
    border-radius: 0;

    object-fit: cover;
    object-position: center;
}

.kg-gallery > .kg-tile:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
}

/* ========================================
   Seitennavigation
   ======================================== */

/*
 * Keine eigenen Linkfarben, Hintergründe,
 * Schriften oder Button-Rahmen.
 * Allgemeine Theme-Linkregeln bleiben wirksam.
 */

.kg-pagination {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75em;

    margin-block-start: 1.5em;

    font: inherit;
    color: inherit;
}

.kg-pagination .kg-pagination-info {
    margin: 0;
    font: inherit;
    color: inherit;
    text-align: center;
}

.kg-pagination ul.page-numbers {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5em;

    margin: 0;
    padding: 0;
    list-style: none;
}

.kg-pagination ul.page-numbers > li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.kg-pagination li > a.page-numbers,
.kg-pagination li > span.page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 2.5em;
    min-height: 2.5em;
    padding: 0.35em 0.65em;
}

/* Aktuelle Seite auch ohne Theme-Sonderregel erkennbar */

.kg-pagination [aria-current="page"] {
    font-weight: bold;
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.kg-pagination .page-numbers.dots {
    min-width: auto;
    padding-inline: 0.25em;
}

.kg-pagination a:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

/* ========================================
   Lightbox
   ======================================== */

dialog.kg-lightbox {
    position: fixed;
    inset: 0;

    box-sizing: border-box;

    width: 100vw;
    max-width: none;

    height: 100vh;
    height: 100dvh;
    max-height: none;

    margin: 0;
    padding: 64px 70px 24px;

    overflow: auto;
    border: 0;

    background: rgb(0 0 0 / 95%);
    color: #fff;
    font: inherit;
}

dialog.kg-lightbox[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

dialog.kg-lightbox::backdrop {
    background: rgb(0 0 0 / 85%);
}

.kg-lightbox,
.kg-lightbox * {
    box-sizing: border-box;
}

.kg-lightbox .kg-lightbox-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75em;

    width: 100%;
    margin: 0;
    padding: 0;

    text-align: center;
}

.kg-lightbox .kg-lightbox-image {
    display: block;

    width: auto;
    height: auto;
    max-width: 100%;

    max-height: 70vh;
    max-height: 70dvh;

    margin: 0;
    padding: 0;

    border: 0;
    border-radius: 0;
    box-shadow: none;

    object-fit: contain;
}

.kg-lightbox .kg-lightbox-caption {
    max-width: 60em;
    margin: 0;
    padding: 0;

    font: inherit;
    color: inherit;
    line-height: 1.5;
    white-space: pre-line;
}

.kg-lightbox .kg-lightbox-counter,
.kg-lightbox .kg-lightbox-status {
    margin: 0;
    padding: 0;
    font: inherit;
    color: inherit;
}

/* Bedienelemente unabhängig vom Theme lesbar halten */

.kg-lightbox button {
    position: fixed;
    z-index: 2;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 46px;
    height: 46px;
    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    border: 1px solid currentColor;
    border-radius: 50%;

    background: rgb(0 0 0 / 50%);
    color: #fff;
    box-shadow: none;

    font-family: inherit;
    font-size: 28px;
    font-weight: normal;
    line-height: 1;
    letter-spacing: normal;
    text-decoration: none;
    text-transform: none;

    cursor: pointer;
}

.kg-lightbox button:hover {
    background: #fff;
    color: #000;
}

.kg-lightbox button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

.kg-lightbox .kg-lightbox-close {
    top: 15px;
    right: 18px;
}

.kg-lightbox .kg-lightbox-prev {
    top: calc(50% - 23px);
    left: 12px;
}

.kg-lightbox .kg-lightbox-next {
    top: calc(50% - 23px);
    right: 12px;
}

.kg-lightbox [hidden] {
    display: none !important;
}

/* ========================================
   Hilfsklasse
   ======================================== */

.kg-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Tablet
   ======================================== */

@media (max-width: 900px) {
    .kg-wrap .kg-gallery {
        grid-template-columns:
            repeat(var(--kg-tablet-columns, 3), minmax(0, 1fr));
    }
}

/* ========================================
   Smartphone
   ======================================== */

@media (max-width: 600px) {
    .kg-wrap .kg-gallery {
        grid-template-columns:
            repeat(var(--kg-mobile-columns, 2), minmax(0, 1fr));
    }

    dialog.kg-lightbox {
        padding: 65px 48px 20px;
    }

    .kg-lightbox button {
        width: 36px;
        height: 36px;
        font-size: 24px;
    }

    .kg-lightbox .kg-lightbox-prev {
        top: calc(50% - 18px);
        left: 5px;
    }

    .kg-lightbox .kg-lightbox-next {
        top: calc(50% - 18px);
        right: 5px;
    }
}

/* Seitennavigation im Stil des Elmos-Modern-Themes */
.kg-wrap .kg-pagination {
    margin-top: 40px;
    text-align: center;
}

.kg-wrap .kg-pagination .nav-links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.kg-wrap .kg-pagination a,
.kg-wrap .kg-pagination .current {
    display: inline-block;
    padding: 9px 14px;
    border-radius: 8px;
    color: var(--color-blue, #0879c9);
    background: var(--color-light, #f5f8fa);
    text-decoration: none;
}

.kg-wrap .kg-pagination .current {
    color: var(--color-white, #fff);
    background: var(--color-blue, #0879c9);
}

.kg-wrap .kg-pagination a:hover {
    color: var(--color-blue-dark, #075a98);
}

/* Zufälliges Vorschaubild */
.kg-random-thumbnail {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    border-radius: 10px;
    line-height: 0;
}

.kg-random-thumbnail-image {
    display: block;
    width: 160px;
    height: 110px;
    max-width: 100%;
    object-fit: cover;
}

/* Zufälliges, seitenbreites Banner */
.kg-random-banner {
    position: relative;
    left: 50%;
    display: block;
    width: 100vw;
    height: var(--kg-banner-height, 220px);
    margin-left: -50vw;
    overflow: hidden;
    line-height: 0;
}

.kg-random-banner-image {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    object-position: center;
}