/**
 * CDF Gallery - Frontend Styles.
 *
 * Scope strikt auf .cdfg-gallery und .cdfg-lightbox. Keine globalen Overrides.
 * Struktur (Grids, Abstaende, Aspect-Ratio) + dezentes Default-Design.
 * Bewusst keine Markenfarben, keine harten Schatten, keine starken Typografie-Overrides.
 */

/* ==========================================================================
 * Basis
 * ========================================================================== */

.cdfg-gallery,
.cdfg-gallery * {
	box-sizing: border-box;
}

.cdfg-gallery {
	margin: 0 0 2em 0;
	color: inherit;
	font-size: inherit;
	line-height: 1.5;
}

.cdfg-gallery img {
	max-width: 100%;
	height: auto;
	display: block;
}

/* <picture> ist nur ein Container fuer <source>+<img>. display: contents
 * sorgt dafuer, dass picture im Layout transparent ist (alle Childs
 * verhalten sich, als waere picture nicht da). Damit greifen alle
 * vorhandenen img-Selektoren (.cdfg-album-cover img, .cdfg-image-link img,
 * .cdfg-lightbox-img) wie zuvor.
 */
.cdfg-gallery picture,
.cdfg-lightbox picture {
	display: contents;
}

.cdfg-gallery .cdfg-empty {
	padding: 2em 1em;
	text-align: center;
	color: #6b6b6b;
	font-style: italic;
}

/* ==========================================================================
 * Notice (z.B. "Album nicht gefunden")
 * ========================================================================== */

.cdfg-notice {
	margin: 0 0 1.5em 0;
	padding: 0.75em 1em;
	border: 1px solid #e0cf8a;
	background: #fdf8e3;
	color: #5a4a00;
	border-radius: 2px;
}

.cdfg-notice p {
	margin: 0;
}

/* ==========================================================================
 * Uebersicht: Zickzack-Layout (2-Spalten 50:50 auf Desktop, Stack auf Mobile)
 *
 * Struktur: <li.cdfg-album-tile> enthaelt <a.cdfg-album-link> als Grid mit
 * zwei Children (.cdfg-album-info schwarz, .cdfg-album-cover Bild). Auf
 * jedem zweiten Listenelement (:nth-child(even)) werden die Children
 * ueber grid order vertauscht.
 * ========================================================================== */

.cdfg-album-grid {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0;
}

.cdfg-album-tile {
	margin: 0;
	padding: 0;
}

.cdfg-album-link {
	display: grid;
	grid-template-columns: 1fr 1fr;
	align-items: stretch;
	height: 420px;
	text-decoration: none;
	color: inherit;
	transition: opacity 0.15s ease;
}

.cdfg-album-link:hover,
.cdfg-album-link:focus {
	opacity: 0.95;
	text-decoration: none;
}

.cdfg-album-link:focus-visible {
	outline: 2px solid #3858e9;
	outline-offset: 2px;
}

/* Info-Block (links im Zickzack-Default).
 *
 * Hoehe = Tile-Hoehe. Overflow hidden, damit Text bei sehr langen
 * Beschreibungen nicht ausbricht (Zeichenlimit 350 im Admin soll das
 * in der Regel verhindern, aber defensiv schadet nicht).
 */
.cdfg-album-info {
	order: 1;
	background: #eef0f5;
	color: #525fab;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	padding: 2.5em 2em;
	overflow: hidden;
}

/* Responsive Typografie: clamp(min, preferred, max).
 * Max-Wert wird auf Desktop bei ca. 1280px Viewport erreicht, darueber
 * gedeckelt. Unter ca. 375px greift der Min-Wert (entspricht Mobile-
 * Default aus dem bisherigen Design).
 */
.cdfg-album-name {
	margin: 0 0 0.4em 0;
	font-size: clamp(1.4rem, 1.4rem + 2vw, 3rem);
	font-weight: 700;
	line-height: 1.1;
	color: inherit;
}

.cdfg-album-description {
	margin: 0 0 0.6em 0;
	font-size: clamp(1rem, 1rem + 1.25vw, 2rem);
	line-height: 1.25;
	max-width: 32em;
}

.cdfg-album-description p {
	margin: 0 0 0.4em 0;
}

.cdfg-album-description p:last-child {
	margin-bottom: 0;
}

.cdfg-album-count {
	display: block;
	margin-top: 0.3em;
	font-size: clamp(0.85rem, 0.85rem + 0.7vw, 1.4rem);
	opacity: 0.7;
}

/* Cover-Block (rechts im Zickzack-Default). */
.cdfg-album-cover {
	order: 2;
	display: block;
	overflow: hidden;
	background: #f2f2f2;
	min-height: 0;
}

.cdfg-album-cover img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.cdfg-no-cover {
	display: block;
	width: 100%;
	height: 100%;
	background: #ececec;
}

/* Zickzack: jede gerade Zeile tauscht Reihenfolge per grid order. */
.cdfg-album-grid > .cdfg-album-tile:nth-child(even) .cdfg-album-info {
	order: 2;
}

.cdfg-album-grid > .cdfg-album-tile:nth-child(even) .cdfg-album-cover {
	order: 1;
}

/* Mobile: Single Column, Cover immer oben. Zickzack aufheben.
 *
 * Alle Alben sollen gleiche Hoehe haben, auch die Texte. Deswegen
 * feste Info-Hoehe (min-height) - die fixe Desktop-Hoehe am Link
 * wird hier aufgehoben, damit Cover + Info natuerliche Hoehen haben,
 * aber Info-Block ist zwischen den Tiles konsistent.
 */
@media (max-width: 768px) {
	.cdfg-album-link {
		grid-template-columns: 1fr;
		height: auto;
	}
	.cdfg-album-cover {
		aspect-ratio: 4 / 3;
	}
	@supports not (aspect-ratio: 4 / 3) {
		.cdfg-album-cover {
			height: 60vw;
			max-height: 420px;
		}
	}
	/* Cover oben, Info unten - auch bei :nth-child(even). */
	.cdfg-album-grid > .cdfg-album-tile .cdfg-album-cover,
	.cdfg-album-grid > .cdfg-album-tile:nth-child(even) .cdfg-album-cover {
		order: 1;
	}
	.cdfg-album-grid > .cdfg-album-tile .cdfg-album-info,
	.cdfg-album-grid > .cdfg-album-tile:nth-child(even) .cdfg-album-info {
		order: 2;
		padding: 1.75em 1.25em;
		min-height: 200px;
	}
}

/* ==========================================================================
 * Album-Detail: Header + Bildgrid
 * ========================================================================== */

.cdfg-album-nav {
	margin: 0 0 1em 0;
	font-size: 1.2rem;
}

.cdfg-back-link {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	color: inherit;
	text-decoration: none;
	padding: 0.2em 0;
}

.cdfg-back-link:hover,
.cdfg-back-link:focus {
	text-decoration: underline;
}

.cdfg-back-arrow {
	display: inline-block;
	line-height: 1;
}

.cdfg-album-header {
	margin: 0 0 1.5em 0;
}

.cdfg-album-title {
	margin: 0 0 0.5em 0;
	font-size: 1.6rem;
	line-height: 1.2;
}

.cdfg-album-description {
	margin: 0;
	color: inherit;
}

.cdfg-album-description p:first-child {
	margin-top: 0;
}

.cdfg-album-description p:last-child {
	margin-bottom: 0;
}

.cdfg-image-grid {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
	gap: 0;
}

.cdfg-image-item {
	margin: 0;
	padding: 0;
}

.cdfg-image-link {
	display: block;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	background: #f2f2f2;
	text-decoration: none;
	transition: opacity 0.15s ease;
}

@supports not (aspect-ratio: 1 / 1) {
	.cdfg-image-link {
		padding-bottom: 100%;
		height: 0;
		position: relative;
	}
	.cdfg-image-link img {
		position: absolute;
		inset: 0;
	}
}

.cdfg-image-link:hover,
.cdfg-image-link:focus {
	opacity: 0.9;
}

.cdfg-image-link:focus-visible {
	outline: 2px solid #3858e9;
	outline-offset: 2px;
}

.cdfg-image-link img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Responsive Tweaks */
@media (max-width: 600px) {
	.cdfg-image-grid {
		grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	}
	.cdfg-album-title {
		font-size: 1.3rem;
	}
}

/* Mobile UX (<= 678px): Grid-Uebersicht im Album-Detail wird ausgeblendet.
 * JS oeffnet die Lightbox automatisch beim ersten Bild. Close in der
 * Lightbox redirected zur Album-Uebersicht (siehe gallery.js). Damit
 * entfaellt der unklare Zwischenschritt "Album-Cover -> Bild-Grid".
 *
 * Empty-State (cdfg-empty) bleibt sichtbar, damit Alben ohne Bilder
 * trotzdem etwas anzeigen.
 */
@media (max-width: 678px) {
	.cdfg-gallery-album .cdfg-image-grid {
		display: none;
	}
}

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

body.cdfg-lightbox-open {
	overflow: hidden;
}

.cdfg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	background: rgba(0, 0, 0, 0.92);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 2vh 2vw;
}

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

.cdfg-lightbox-stage {
	position: relative;
	max-width: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75em;
}

/* Bild + Caption-Overlay als zusammenhaengender Block, damit die Folie
 * am unteren Bildrand klebt und nicht am Viewport.
 *
 * max-height: dvh statt vh, damit auf mobilem Safari die Browser-Chrome
 * (untere Toolbar im Querformat) nicht in das Bild schneidet. vh bleibt
 * als Fallback fuer aeltere Browser.
 */
.cdfg-lightbox-media {
	position: relative;
	max-width: 92vw;
	max-height: 82vh;
	max-height: 82dvh;
	display: inline-block;
	line-height: 0;
}

.cdfg-lightbox-img {
	max-width: 92vw;
	max-height: 82vh;
	max-height: 82dvh;
	width: auto;
	height: auto;
	display: block;
	background: #000;
}

/* Caption liegt wie eine Folie am unteren Bildrand. Per Klick auf den
 * Toggle-Button ein-/ausblendbar (.is-hidden). Pointer-Events bleiben
 * auf dem Overlay aktiv, damit der Text selektierbar ist.
 */
.cdfg-lightbox-caption {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	margin: 0;
	padding: 0.9em 1.2em;
	background: rgba(0, 0, 0, 0.65);
	color: #fff;
	font-size: 0.95rem;
	line-height: 1.4;
	text-align: center;
	transition: opacity 0.15s ease, transform 0.2s ease;
}

.cdfg-lightbox-caption:empty,
.cdfg-lightbox-caption.is-hidden {
	opacity: 0;
	pointer-events: none;
	transform: translateY(100%);
}

.cdfg-lightbox-btn {
	position: absolute;
	appearance: none;
	background: rgba(0, 0, 0, 0.5);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, 0.4);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	cursor: pointer;
	font-size: 1.3rem;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
}

.cdfg-lightbox-btn:hover,
.cdfg-lightbox-btn:focus {
	background: rgba(0, 0, 0, 0.75);
}

.cdfg-lightbox-btn:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.cdfg-lightbox-close {
	top: 1vh;
	right: 1vh;
}

.cdfg-lightbox-prev {
	left: 1vh;
	top: 50%;
	transform: translateY(-50%);
}

.cdfg-lightbox-next {
	right: 1vh;
	top: 50%;
	transform: translateY(-50%);
}

.cdfg-lightbox-counter {
	position: absolute;
	top: 1vh;
	left: 1vh;
	color: #ededed;
	background: rgba(0, 0, 0, 0.4);
	padding: 0.25em 0.6em;
	font-size: 0.8rem;
	border-radius: 2px;
	pointer-events: none;
}

/* Caption-Toggle: rechts unten, gespiegelt zum Counter links oben. */
.cdfg-lightbox-cap-toggle {
	right: 1vh;
	bottom: 1vh;
	font-family: Georgia, "Times New Roman", serif;
	font-style: italic;
	font-weight: 700;
}

.cdfg-lightbox-cap-toggle[aria-pressed="false"] {
	opacity: 0.55;
}

/* Ab 601px (Smartphone quer + groesser): Buttons und Counter am
 * Viewport-Rand heften statt am Stage-Rand, damit sie _neben_ dem
 * Bild sitzen, nicht drauf. Im Hochkant-Smartphone bleibt alles
 * wie es ist.
 */
@media (min-width: 601px) {
	.cdfg-lightbox-btn,
	.cdfg-lightbox-counter {
		position: fixed;
	}
	/* Bildbeschriftung im Desktop/Querformat etwas groesser fuer Lesbarkeit. */
	.cdfg-lightbox-caption {
		font-size: 1.25rem;
	}
	.cdfg-lightbox-close {
		top: 1vh;
		right: 1vh;
	}
	.cdfg-lightbox-prev {
		left: 1vh;
		top: 50%;
		transform: translateY(-50%);
	}
	.cdfg-lightbox-next {
		right: 1vh;
		top: 50%;
		transform: translateY(-50%);
	}
	.cdfg-lightbox-cap-toggle {
		right: 1vh;
		bottom: 1vh;
	}
	.cdfg-lightbox-counter {
		top: 1vh;
		left: 1vh;
	}
}

@media (max-width: 600px) {
	.cdfg-lightbox-img {
		max-height: 70vh;
		max-height: 70dvh;
	}
	.cdfg-lightbox-btn {
		width: 38px;
		height: 38px;
		font-size: 1.1rem;
	}

	/* Mobile hochkant: Prev, Next und Caption-Toggle unterhalb des
	 * Bilds in einer Reihe. Close und Counter bleiben absolute an
	 * den oberen Ecken der Stage.
	 *
	 * Stage wird zur Grid: Media fuellt die erste Zeile, Buttons
	 * verteilen sich in der zweiten Zeile (prev links, toggle
	 * mittig, next rechts).
	 */
	.cdfg-lightbox-stage {
		display: grid;
		grid-template-columns: 1fr auto 1fr;
		grid-template-rows: auto auto;
		justify-items: center;
		align-items: center;
		gap: 0.75em;
	}
	.cdfg-lightbox-media {
		grid-column: 1 / -1;
		grid-row: 1;
	}
	.cdfg-lightbox-prev,
	.cdfg-lightbox-next,
	.cdfg-lightbox-cap-toggle {
		position: static;
		top: auto;
		right: auto;
		bottom: auto;
		left: auto;
		transform: none;
	}
	.cdfg-lightbox-prev {
		grid-column: 1;
		grid-row: 2;
		justify-self: start;
	}
	.cdfg-lightbox-cap-toggle {
		grid-column: 2;
		grid-row: 2;
	}
	.cdfg-lightbox-next {
		grid-column: 3;
		grid-row: 2;
		justify-self: end;
	}
	/* Close + Counter bleiben aus dem Grid-Flow raus - ueber absolute
	 * Positionierung an der Stage verankert (Close oben rechts,
	 * Counter oben links, jeweils ueber dem Bild). */
	.cdfg-lightbox-close,
	.cdfg-lightbox-counter {
		position: absolute;
	}
	.cdfg-lightbox-close {
		top: 0.5em;
		right: 0.5em;
	}
	.cdfg-lightbox-counter {
		top: 0.5em;
		left: 0.5em;
	}
}
