/**
 * Ecomgo Instagram Feed — frontend
 *
 * Wszystkie liczby i kolory wchodzą przez custom properties ustawiane
 * inline przez StyleBuilder. Dzięki temu nie generujemy klas typu .col-4
 * ani nie liczymy wymiarów w JS — robi to CSS Grid i aspect-ratio.
 */

.egif {
	--egif-cols: 4;
	--egif-cols-tablet: 3;
	--egif-cols-mobile: 2;
	--egif-gap: 8px;
	--egif-radius: 0px;
	--egif-aspect: 1 / 1;
	--egif-highlight-span: 2;
	--egif-color-bg: transparent;
	--egif-color-text: inherit;
	--egif-color-accent: #0095f6;

	/*
	 * Kolor napisu na tle akcentu. Domyślnie biel, bo domyślny akcent jest
	 * ciemny. Przy własnym kolorze z panelu wartość liczy StyleBuilder (PHP)
	 * i wystawia ją inline — nie zgadujemy jej tutaj i nie liczymy w JS.
	 */
	--egif-color-accent-contrast: #fff;

	position: relative;
	box-sizing: border-box;
	background: var(--egif-color-bg);
	color: var(--egif-color-text);
}

.egif *,
.egif *::before,
.egif *::after {
	box-sizing: inherit;
}

/* ── Lista ────────────────────────────────────────────────────────── */

.egif__items {
	display: grid;
	grid-template-columns: repeat(var(--egif-cols-mobile), minmax(0, 1fr));
	gap: var(--egif-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (min-width: 600px) {
	.egif__items {
		grid-template-columns: repeat(var(--egif-cols-tablet), minmax(0, 1fr));
	}
}

@media (min-width: 900px) {
	.egif__items {
		grid-template-columns: repeat(var(--egif-cols), minmax(0, 1fr));
	}
}

/* ── Kafelek ──────────────────────────────────────────────────────── */

.egif__item {
	position: relative;
	margin: 0;
	overflow: hidden;
	border-radius: var(--egif-radius);
}

.egif__link {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	line-height: 0;
	text-decoration: none;
}

.egif__img {
	display: block;
	width: 100%;
	height: 100%;
	aspect-ratio: var(--egif-aspect);
	object-fit: cover;
	transition: transform .35s ease, opacity .25s ease;
}

/* Proporcje „auto" — obraz zachowuje własne wymiary (potrzebne w masonry). */
.egif--masonry .egif__img,
.egif__item--auto .egif__img {
	height: auto;
	aspect-ratio: auto;
}

.egif__link:focus-visible {
	outline: 2px solid var(--egif-color-accent);
	outline-offset: 2px;
}

/* ── Efekty najechania ────────────────────────────────────────────── */

.egif--hover-zoom .egif__link:hover .egif__img,
.egif--hover-zoom .egif__link:focus-visible .egif__img {
	transform: scale(1.06);
}

.egif--hover-fade .egif__link:hover .egif__img,
.egif--hover-fade .egif__link:focus-visible .egif__img {
	opacity: .78;
}

.egif--hover-overlay .egif__link::after {
	content: "";
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .38);
	opacity: 0;
	transition: opacity .25s ease;
}

.egif--hover-overlay .egif__link:hover::after,
.egif--hover-overlay .egif__link:focus-visible::after {
	opacity: 1;
}

/* ── Plakietki typu materiału ─────────────────────────────────────── */

.egif__badge {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	color: #fff;
	filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .55));
	pointer-events: none;
}

/* ── Układ: masonry ───────────────────────────────────────────────── */

.egif--masonry .egif__items {
	display: block;
	column-count: var(--egif-cols-mobile);
	column-gap: var(--egif-gap);
}

@media (min-width: 600px) {
	.egif--masonry .egif__items { column-count: var(--egif-cols-tablet); }
}

@media (min-width: 900px) {
	.egif--masonry .egif__items { column-count: var(--egif-cols); }
}

.egif--masonry .egif__item {
	margin-bottom: var(--egif-gap);
	/* Bez tego przeglądarka rozcina kafelek między kolumnami. */
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
}

/* ── Układ: wyróżnienie ───────────────────────────────────────────── */

.egif--highlight .egif__item--wide {
	grid-column: span var(--egif-highlight-span);
	grid-row: span var(--egif-highlight-span);
}

/* ── Układ: karuzela ──────────────────────────────────────────────── */

.egif--carousel .egif__items {
	display: flex;
	grid-template-columns: none;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.egif--carousel .egif__items::-webkit-scrollbar {
	display: none;
}

.egif--carousel .egif__item {
	flex: 0 0 calc((100% - (var(--egif-cols-mobile) - 1) * var(--egif-gap)) / var(--egif-cols-mobile));
	scroll-snap-align: start;
}

@media (min-width: 600px) {
	.egif--carousel .egif__item {
		flex-basis: calc((100% - (var(--egif-cols-tablet) - 1) * var(--egif-gap)) / var(--egif-cols-tablet));
	}
}

@media (min-width: 900px) {
	.egif--carousel .egif__item {
		flex-basis: calc((100% - (var(--egif-cols) - 1) * var(--egif-gap)) / var(--egif-cols));
	}
}

.egif__nav {
	position: absolute;
	top: 50%;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	transform: translateY(-50%);
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .92);
	color: #111;
	box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
	cursor: pointer;
	transition: opacity .2s ease;
}

.egif__nav--prev { left: 6px; }
.egif__nav--next { right: 6px; }

.egif__nav[disabled] {
	opacity: .35;
	cursor: default;
}

.egif__dots {
	display: flex;
	gap: 6px;
	justify-content: center;
	margin-top: 12px;
}

.egif__dot {
	width: 8px;
	height: 8px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: currentColor;
	opacity: .28;
	cursor: pointer;
	transition: opacity .2s ease, transform .2s ease;
}

.egif__dot[aria-selected="true"] {
	background: var(--egif-color-accent);
	opacity: 1;
	transform: scale(1.25);
}

/* Edytorialny pasek: wybieralny wariant istniejącej karuzeli. */
.egif--carousel-editorial .egif__header {
	justify-content: center;
	margin: 0 0 clamp(20px, 3vw, 40px);
	text-align: center;
}

.egif--carousel-editorial .egif__avatar,
.egif--carousel-editorial .egif__count,
.egif--carousel-editorial .egif__bio {
	display: none;
}

.egif--carousel-editorial .egif__username {
	font-family: Georgia, 'Times New Roman', serif;
	font-size: clamp(18px, 1.5vw, 25px);
	font-weight: 500;
	letter-spacing: .015em;
	text-transform: uppercase;
}

.egif--carousel-editorial .egif__item,
.egif--carousel-editorial .egif__img {
	border-radius: 0;
}

.egif--carousel-editorial .egif__nav {
	width: 40px;
	height: 40px;
	box-shadow: none;
	border: 1px solid rgba(35, 51, 43, .2);
	background: rgba(255, 255, 255, .94);
	color: #23332b;
}

.egif--carousel-editorial .egif__nav--prev { left: 14px; }
.egif--carousel-editorial .egif__nav--next { right: 14px; }

@media (max-width: 599px) {
	.egif--carousel-editorial .egif__nav {
		width: 36px;
		height: 36px;
	}
}

/* ── Nagłówek i stopka ────────────────────────────────────────────── */

.egif__header {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 16px;
}

.egif__avatar {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	object-fit: cover;
}

.egif__header-text { min-width: 0; }

.egif__username {
	font-weight: 700;
	text-decoration: none;
	color: inherit;
}

.egif__count {
	margin-left: 8px;
	font-size: .85em;
	opacity: .7;
}

.egif__bio {
	margin: 2px 0 0;
	font-size: .9em;
	opacity: .8;
}

.egif__footer {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	justify-content: center;
	margin-top: 16px;
}

.egif__btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 20px;
	border: 0;
	border-radius: 999px;
	background: var(--egif-color-accent);
	color: var(--egif-color-accent-contrast, #fff);
	font: inherit;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
}

.egif__btn:focus-visible,
.egif__nav:focus-visible,
.egif__dot:focus-visible {
	outline: 2px solid var(--egif-color-accent);
	outline-offset: 2px;
}

.egif__btn--more {
	background: transparent;
	border: 1.5px solid currentColor;
	color: inherit;
}

.egif__btn[disabled] {
	opacity: .55;
	cursor: default;
}

.egif__spinner {
	display: none;
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: egif-spin .7s linear infinite;
}

.egif__btn.is-loading .egif__spinner { display: inline-block; }

.egif__empty {
	margin: 0;
	padding: 24px 0;
	text-align: center;
	opacity: .7;
}

@keyframes egif-spin {
	to { transform: rotate(360deg); }
}

/* ── Lightbox ─────────────────────────────────────────────────────── */

/*
 * Powłoka lightboxa stoi w stopce strony, poza elementem `.egif`, więc NIE
 * dziedziczy jego custom properties. Zmienne akcentu przepisuje na nią skrypt
 * przy otwarciu — bierze je z inline'owego stylu klikniętego feedu, czyli
 * z wartości policzonej i zsanityzowanej w PHP.
 *
 * Dopóki tego nie zrobi, działa fallback w `var()`. Jest jaśniejszy od
 * domyślnego akcentu feedu (#0095f6), bo tło lightboxa jest czarne — dlatego
 * NIE deklarujemy tu `--egif-color-accent` na sztywno.
 */

.egif-lb[hidden] { display: none; }

.egif-lb {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
}

.egif-lb__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .88);
}

.egif-lb__dialog {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	max-width: 1100px;
	max-height: 92vh;
	padding: 0 8px;
}

.egif-lb__stage {
	flex: 1 1 auto;
	min-width: 0;
	max-height: 92vh;
	overflow: hidden;
	border-radius: 8px;
	background: #000;
}

.egif-lb__media {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 220px;
	max-height: 78vh;
}

.egif-lb__media img,
.egif-lb__media video {
	display: block;
	max-width: 100%;
	max-height: 78vh;
	width: auto;
	height: auto;
	object-fit: contain;
}

/* Reels są pionowe — bez tego zajmowałyby całą wysokość ekranu. */
.egif-lb__media--portrait video,
.egif-lb__media--portrait img {
	max-height: 78vh;
	width: auto;
}

.egif-lb__close,
.egif-lb__nav {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	border-radius: 50%;
	cursor: pointer;
	transition: background .2s ease;
}

.egif-lb__close:hover,
.egif-lb__nav:hover {
	background: rgba(255, 255, 255, .25);
}

.egif-lb__close:focus-visible,
.egif-lb__nav:focus-visible,
.egif-lb__unmute:focus-visible,
.egif-lb__permalink:focus-visible {
	outline: 2px solid var(--egif-color-accent, #5bb0ff);
	outline-offset: 2px;
}

.egif-lb__close {
	position: absolute;
	top: -44px;
	right: 8px;
	width: 36px;
	height: 36px;
}

.egif-lb__nav {
	flex: 0 0 44px;
	width: 44px;
	height: 44px;
}

.egif-lb__nav[disabled] {
	opacity: .3;
	cursor: default;
}

.egif-lb__meta {
	padding: 12px 16px;
	background: #111;
	color: #eee;
}

.egif-lb__caption[hidden] { display: none; }

.egif-lb__caption {
	margin: 0 0 6px;
	font-size: .92rem;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.egif-lb__permalink {
	color: var(--egif-color-accent, #5bb0ff);
	font-size: .85rem;
	text-decoration: none;
}

.egif-lb__spinner {
	position: absolute;
	width: 34px;
	height: 34px;
	border: 3px solid rgba(255, 255, 255, .35);
	border-right-color: transparent;
	border-radius: 50%;
	animation: egif-spin .7s linear infinite;
}

.egif-lb__unmute {
	position: absolute;
	right: 12px;
	bottom: 12px;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 7px 12px;
	border: 0;
	border-radius: 999px;
	background: rgba(0, 0, 0, .68);
	color: #fff;
	font: inherit;
	font-size: .8rem;
	cursor: pointer;
}

.egif-lb__error {
	padding: 32px 20px;
	color: #fff;
	text-align: center;
}

@media (max-width: 640px) {
	.egif-lb__dialog { flex-direction: column; padding: 0; }
	.egif-lb__nav { position: absolute; top: 50%; transform: translateY(-50%); }
	.egif-lb__nav--prev { left: 4px; }
	.egif-lb__nav--next { right: 4px; }
	.egif-lb__close { top: 8px; right: 8px; z-index: 4; background: rgba(0,0,0,.55); }
	.egif-lb__stage { border-radius: 0; }
}

/* ── Szacunek dla ustawień dostępności ────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
	.egif__img,
	.egif__link::after,
	.egif__nav,
	.egif-lb__close,
	.egif-lb__nav {
		transition: none;
	}

	.egif__spinner,
	.egif-lb__spinner {
		animation-duration: 2s;
	}

	.egif--carousel .egif__items {
		scroll-behavior: auto;
	}
}

.egif .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}
