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

/* Justiertes („blockartiges") Layout wie EasyDNNGallery: jede Reihe füllt die volle Breite,
   die Bilder behalten ihr Seitenverhältnis (kein Beschnitt), saubere Kanten links UND rechts.
   Die exakten Kachelmasse setzt justify.js pro Reihe; hier nur Grundgerüst + Fallback. */
/* clear:both → die Galerie beginnt UNTER einer rechts gefloateten Box-Pane (.topic-box) und
   nutzt die volle Breite (sonst quetscht der Float die Reihen schmal/„eingerissene Mauer"). */
.tgf-galerie-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    clear: both;
    margin: 0;
}

/* Hinweis: Galerie-Kacheln sind <figure> und liegen im .prose-Container. Deshalb alle Regeln
   mit .tgf-galerie-grid präfixen, damit sie ".prose figure { margin }" und ".prose figure img
   { width:100%; height:auto }" (höhere Spezifität) sicher überstimmen. */
.tgf-galerie-grid .tgf-galerie-item {
    display: block;
    position: relative;   /* Anker für das Titel-Overlay (figcaption) */
    flex: 0 0 auto;
    margin: 0;
    line-height: 0;
    /* Fallback-Masse, bis justify.js die Reihe vermessen hat (verhindert Riesenbilder beim
       ersten Paint); width/height werden danach inline überschrieben. */
    width: 240px;
    height: 180px;
}

.tgf-galerie-zoom {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    width: 100%;
    height: 100%;
    background: #f0ece3;
    padding: 0;
    border: 0;
    cursor: pointer;
}

.tgf-galerie-grid .tgf-galerie-item img {
    width: 100%;
    height: 100%;
    /* Kachel-Ratio = Bild-Ratio (justify.js) → cover passt exakt, quasi ohne Beschnitt. */
    object-fit: cover;
    border-radius: 0;
    display: block;
    transition: transform .25s ease;
}

.tgf-galerie-zoom:hover img {
    transform: scale(1.04);
}

/* Titel als Overlay unten auf dem Thumbnail (bricht die Reihenhöhe NICHT; erscheint nur, wenn
   ein Titel gesetzt ist). Dezenter Verlauf für Lesbarkeit, lange Titel auf 2 Zeilen gekürzt. */
.tgf-galerie-grid .tgf-galerie-item figcaption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 16px 8px 6px;
    color: #fff;
    font-size: .78rem;
    line-height: 1.2;
    text-transform: none;
    letter-spacing: normal;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
    background: linear-gradient(to top, rgba(0, 0, 0, .72), rgba(0, 0, 0, 0));
    border-radius: 0 0 4px 4px;
    pointer-events: none;   /* Klick geht an den Zoom-Button darunter */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Video-Kachel ohne Poster: füllt die berechnete Kachel (16:9-Fallback via Ratio). */
.tgf-galerie-video .tgf-galerie-video-ph {
    display: block;
    width: 100%;
    height: 100%;
    background: #2a2016;
}

@media (max-width: 575.98px) {
    .tgf-galerie-grid .tgf-galerie-item { width: 150px; height: 120px; }
}

.tgf-galerie-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
    background: rgba(0, 0, 0, .18);
    transition: background .2s ease;
}

.tgf-galerie-video:hover .tgf-galerie-play {
    background: rgba(0, 0, 0, .32);
}

/* ===== Verwaltung ===== */
.tgf-galerie-admin {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 2px dashed #d8cdb8;
}

.tgf-galerie-admin-h {
    color: #2a2016;
    font-size: 1.1rem;
}

.tgf-galerie-admin-box {
    background: #f7f0e3;
    border: 1px solid #e4d9c2;
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.tgf-galerie-liste {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.tgf-galerie-liste-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid #e4d9c2;
}

.tgf-galerie-liste-thumb {
    flex: 0 0 80px;
    width: 80px;
    height: 60px;
    border-radius: 3px;
    overflow: hidden;
    background: #f0ece3;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tgf-galerie-liste-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.tgf-galerie-liste-felder {
    flex: 1 1 auto;
    min-width: 0;
}

.tgf-galerie-liste-aktionen {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: flex-start;
}

/* Admin-Umschalter */
.tgf-galerie-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

/* Drag & Drop */
.tgf-galerie-liste-griff {
    flex: 0 0 auto;
    align-self: center;
    cursor: grab;
    color: #b8a888;
    font-size: 1.3rem;
    line-height: 1;
    padding: 0 2px;
    user-select: none;
}

.tgf-galerie-liste-item {
    cursor: default;
}

.tgf-galerie-liste-item.tgf-dragging {
    opacity: .45;
}

/* ===== Lightbox ===== */
.tgf-galerie-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, .88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.tgf-galerie-lightbox-inhalt {
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tgf-galerie-lightbox-inhalt img {
    max-width: 92vw;
    max-height: 84vh;
    object-fit: contain;
    border-radius: 4px;
}

.tgf-galerie-lightbox-video {
    width: min(90vw, 1280px);
    aspect-ratio: 16 / 9;
}

.tgf-galerie-lightbox-video iframe {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 4px;
}

.tgf-galerie-lightbox-cap {
    margin-top: 10px;
    color: #f3ead6;
    text-align: center;
    max-width: 90vw;
}

.tgf-galerie-lightbox-cap strong {
    display: block;
    font-size: 1.05rem;
}

.tgf-galerie-lightbox-cap span {
    font-size: .9rem;
    opacity: .85;
}

.tgf-galerie-lightbox-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: 0;
    color: #fff;
    font-size: 2.4rem;
    line-height: 1;
    cursor: pointer;
    opacity: .8;
}

.tgf-galerie-lightbox-close:hover {
    opacity: 1;
}

.tgf-galerie-lightbox:focus {
    outline: none;
}

/* Blätter-Pfeile */
.tgf-galerie-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, .3);
    border: 0;
    color: #fff;
    font-size: 2.6rem;
    line-height: 1;
    width: 52px;
    height: 72px;
    border-radius: 6px;
    cursor: pointer;
    opacity: .75;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tgf-galerie-lightbox-nav:hover {
    opacity: 1;
    background: rgba(0, 0, 0, .5);
}

.tgf-galerie-lightbox-nav.tgf-prev {
    left: 14px;
}

.tgf-galerie-lightbox-nav.tgf-next {
    right: 14px;
}

@media (max-width: 575.98px) {
    .tgf-galerie-lightbox-nav {
        width: 40px;
        height: 56px;
        font-size: 2rem;
    }
}
