/**
 * Earth Tribe Gallery — frontend.
 *
 * Everything is scoped to .etg-* and uses custom properties for colour and
 * spacing so a Divi child theme can restyle it without fighting specificity.
 */

.etg-gallery,
.etg-uploader,
.etg-browser,
.etg-notice {
	--etg-radius: 8px;
	--etg-border: rgba( 0, 0, 0, 0.12 );
	--etg-muted: #6b7280;
	--etg-accent: #2b6cb0;
	--etg-surface: #fff;
	--etg-columns: 4;
	--etg-gutter: 16px;

	box-sizing: border-box;
}

.etg-gallery *,
.etg-uploader *,
.etg-browser *,
.etg-notice * {
	box-sizing: border-box;
}

/* ---- Notices ----------------------------------------------------------- */

.etg-notice {
	padding: 28px 24px;
	border: 1px dashed var( --etg-border );
	border-radius: var( --etg-radius );
	text-align: center;
	color: var( --etg-muted );
}

.etg-notice p {
	margin: 0 0 12px;
}

.etg-notice p:last-child {
	margin-bottom: 0;
}

.etg-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 10px 20px;
	border: 1px solid var( --etg-accent );
	border-radius: 6px;
	background: var( --etg-accent );
	color: #fff;
	font-size: 15px;
	line-height: 1.4;
	text-decoration: none;
	cursor: pointer;
}

.etg-button:hover:not( :disabled ) {
	filter: brightness( 1.08 );
	color: #fff;
}

.etg-button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.etg-button--ghost {
	background: transparent;
	color: inherit;
	border-color: var( --etg-border );
}

.etg-empty {
	padding: 30px 10px;
	color: var( --etg-muted );
	text-align: center;
}

/* ---- Gallery ----------------------------------------------------------- */

.etg-gallery__grid {
	display: grid;
	grid-template-columns: repeat( var( --etg-columns ), minmax( 0, 1fr ) );
	gap: var( --etg-gutter );
}

.etg-gallery__item {
	margin: 0;
	overflow: hidden;
	border-radius: var( --etg-radius );
	background: rgba( 0, 0, 0, 0.04 );
}

.etg-gallery__trigger {
	display: block;
	width: 100%;
	padding: 0;
	border: 0;
	background: none;
	cursor: zoom-in;
	line-height: 0;
}

.etg-gallery__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.35s ease, opacity 0.25s ease;
}

/* Tile shapes. Masonry and justified keep each image's own proportions. */

.etg-gallery--ratio-square .etg-gallery__image {
	aspect-ratio: 1;
}

.etg-gallery--ratio-landscape .etg-gallery__image {
	aspect-ratio: 4 / 3;
}

.etg-gallery--ratio-portrait .etg-gallery__image {
	aspect-ratio: 3 / 4;
}

.etg-gallery--ratio-wide .etg-gallery__image {
	aspect-ratio: 16 / 9;
}

.etg-gallery--ratio-auto .etg-gallery__image {
	aspect-ratio: auto;
	height: auto;
}

/* Masonry: CSS columns keep natural heights without a layout library. */

.etg-gallery--masonry .etg-gallery__grid {
	display: block;
	column-count: var( --etg-columns );
	column-gap: var( --etg-gutter );
}

.etg-gallery--masonry .etg-gallery__item {
	break-inside: avoid;
	margin-bottom: var( --etg-gutter );
}

.etg-gallery--masonry .etg-gallery__image {
	aspect-ratio: auto;
	height: auto;
}

/* Justified: each tile is flex-weighted by its own aspect ratio. */

.etg-gallery--justified .etg-gallery__grid {
	display: flex;
	flex-wrap: wrap;
}

.etg-gallery--justified .etg-gallery__item {
	flex: var( --etg-ratio, 1 ) 1 calc( var( --etg-ratio, 1 ) * 180px );
	margin: 0 var( --etg-gutter ) var( --etg-gutter ) 0;
}

.etg-gallery--justified .etg-gallery__image {
	aspect-ratio: var( --etg-ratio, 1 );
}

/* Carousel: one scroll-snapping row. */

.etg-gallery--carousel .etg-gallery__grid {
	display: flex;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	padding-bottom: 8px;
}

.etg-gallery--carousel .etg-gallery__item {
	flex: 0 0 calc( ( 100% - ( var( --etg-columns ) - 1 ) * var( --etg-gutter ) ) / var( --etg-columns ) );
	scroll-snap-align: start;
	margin-right: var( --etg-gutter );
}

.etg-gallery--carousel .etg-gallery__item:last-child {
	margin-right: 0;
}

/* Hover treatments. */

.etg-gallery--hover-zoom .etg-gallery__item:hover .etg-gallery__image {
	transform: scale( 1.06 );
}

.etg-gallery--hover-fade .etg-gallery__item:hover .etg-gallery__image {
	opacity: 0.72;
}

.etg-gallery--hover-lift .etg-gallery__item {
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.etg-gallery--hover-lift .etg-gallery__item:hover {
	transform: translateY( -5px );
	box-shadow: 0 10px 24px rgba( 0, 0, 0, 0.18 );
}

.etg-gallery__item {
	position: relative;
}

.etg-gallery__download {
	position: absolute;
	top: 8px;
	right: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.55 );
	color: #fff;
	opacity: 0;
	transition: opacity 0.18s ease, background 0.18s ease;
}

.etg-gallery__download svg {
	width: 18px;
	height: 18px;
}

.etg-gallery__item:hover .etg-gallery__download,
.etg-gallery__download:focus-visible {
	opacity: 1;
}

.etg-gallery__download:hover {
	background: rgba( 0, 0, 0, 0.78 );
	color: #fff;
}

/* Touch devices have no hover, so the affordance has to be permanent. */
@media ( hover: none ) {
	.etg-gallery__download {
		opacity: 1;
	}
}

.etg-gallery__caption {
	padding: 10px 12px 12px;
	font-size: 0.9em;
	line-height: 1.4;
}

.etg-gallery__title {
	display: block;
	font-weight: 600;
}

.etg-gallery__text {
	display: block;
	color: var( --etg-muted );
}

.etg-gallery__upload {
	margin: 18px 0 0;
	text-align: center;
}

.etg-browser__bar .etg-upload-link {
	flex: 0 0 auto;
	padding: 8px 16px;
	font-size: 0.9em;
}

/* ---- Lightbox ---------------------------------------------------------- */

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

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

.etg-lightbox[ hidden ] {
	display: none;
}

.etg-lightbox__backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 0, 0, 0, 0.9 );
}

.etg-lightbox__panel {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	height: 100%;
	padding: 5vh 4vw;
}

.etg-lightbox__figure {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	margin: 0;
	min-width: 0;
	min-height: 0;
}

.etg-lightbox__image {
	max-width: 100%;
	max-height: 80vh;
	object-fit: contain;
	border-radius: 4px;
}

.etg-lightbox__caption {
	max-width: 62ch;
	color: #fff;
	text-align: center;
	font-size: 0.95em;
	line-height: 1.5;
}

.etg-lightbox__caption strong {
	display: block;
	margin-bottom: 4px;
}

.etg-lightbox__caption span {
	color: rgba( 255, 255, 255, 0.75 );
}

.etg-lightbox__close,
.etg-lightbox__nav {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 46px;
	height: 46px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.12 );
	color: #fff;
	cursor: pointer;
	transition: background 0.15s ease;
}

.etg-lightbox__close:hover,
.etg-lightbox__nav:hover {
	background: rgba( 255, 255, 255, 0.25 );
}

.etg-lightbox__close {
	position: absolute;
	top: 3vh;
	right: 3vw;
	z-index: 2;
}

.etg-lightbox__close svg,
.etg-lightbox__nav svg {
	width: 22px;
	height: 22px;
}

.etg-lightbox__counter {
	position: absolute;
	left: 50%;
	bottom: 2vh;
	transform: translateX( -50% );
	color: rgba( 255, 255, 255, 0.65 );
	font-size: 0.85em;
	font-variant-numeric: tabular-nums;
}

/* ---- Uploader ---------------------------------------------------------- */

.etg-uploader__heading {
	margin: 0 0 14px;
}

.etg-uploader__dropzone {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 42px 24px;
	border: 2px dashed var( --etg-border );
	border-radius: 12px;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.etg-uploader__dropzone:hover,
.etg-uploader__dropzone:focus-visible,
.etg-uploader__dropzone.is-dragover {
	border-color: var( --etg-accent );
	background: rgba( 43, 108, 176, 0.05 );
}

.etg-uploader__icon {
	width: 40px;
	height: 40px;
	color: var( --etg-accent );
}

.etg-uploader__prompt {
	margin: 0;
	font-weight: 600;
}

.etg-uploader__hint {
	margin: 0;
	color: var( --etg-muted );
	font-size: 0.85em;
}

.etg-uploader__input {
	display: none;
}

.etg-uploader__moderation {
	margin: 12px 0 0;
	padding: 10px 14px;
	border-radius: 6px;
	background: rgba( 180, 83, 9, 0.08 );
	color: #92400e;
	font-size: 0.9em;
}

.etg-uploader__help {
	margin-top: 14px;
	border-top: 1px solid var( --etg-border );
	padding-top: 12px;
	font-size: 0.9em;
}

.etg-uploader__help summary {
	cursor: pointer;
	color: var( --etg-accent );
	font-weight: 600;
}

.etg-uploader__help-body ul {
	margin: 10px 0 0;
	padding-left: 20px;
	color: var( --etg-muted );
	line-height: 1.6;
}

.etg-uploader__help-body li { margin-bottom: 5px; }

.etg-uploader__queue {
	margin: 16px 0 0;
	padding: 0;
	list-style: none;
}

.etg-queue__item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 0;
	border-bottom: 1px solid var( --etg-border );
}

.etg-queue__thumb {
	flex: 0 0 48px;
	width: 48px;
	height: 48px;
	border-radius: 6px;
	overflow: hidden;
	background: rgba( 0, 0, 0, 0.06 );
}

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

.etg-queue__thumb--heic {
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba( 43, 108, 176, 0.12 );
	color: var( --etg-accent );
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.04em;
}

.etg-queue__item--converting .etg-queue__fill {
	background: #7c3aed;
	width: 100%;
	animation: etg-pulse 1.1s ease-in-out infinite;
}

@keyframes etg-pulse {
	0%, 100% { opacity: 0.35; }
	50% { opacity: 1; }
}

@media ( prefers-reduced-motion: reduce ) {
	.etg-queue__item--converting .etg-queue__fill { animation: none; opacity: 0.7; }
}

.etg-queue__body {
	flex: 1;
	min-width: 0;
}

.etg-queue__name {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 500;
}

.etg-queue__meta {
	display: block;
	color: var( --etg-muted );
	font-size: 0.85em;
}

.etg-queue__item--error .etg-queue__meta {
	color: #b42318;
}

.etg-queue__bar {
	display: block;
	height: 4px;
	margin-top: 5px;
	border-radius: 999px;
	background: rgba( 0, 0, 0, 0.1 );
	overflow: hidden;
}

.etg-queue__fill {
	display: block;
	height: 100%;
	width: 0;
	background: var( --etg-accent );
	transition: width 0.2s ease;
}

.etg-queue__item--done .etg-queue__fill {
	background: #15803d;
}

.etg-queue__item--error .etg-queue__fill {
	background: #b42318;
}

.etg-queue__remove {
	flex: 0 0 auto;
	width: 26px;
	height: 26px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var( --etg-muted );
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
}

.etg-queue__remove:hover {
	background: rgba( 0, 0, 0, 0.08 );
}

.etg-uploader__actions {
	display: flex;
	gap: 10px;
	margin-top: 16px;
}

.etg-uploader__mine {
	margin-top: 32px;
	padding-top: 20px;
	border-top: 1px solid var( --etg-border );
}

.etg-uploader__mine-heading {
	margin: 0 0 14px;
}

.etg-uploader__mine-grid {
	display: grid;
	grid-template-columns: repeat( auto-fill, minmax( 120px, 1fr ) );
	gap: 12px;
}

.etg-mine__item {
	position: relative;
	margin: 0;
	border-radius: 6px;
	overflow: hidden;
	background: rgba( 0, 0, 0, 0.05 );
}

.etg-mine__item img {
	display: block;
	width: 100%;
	aspect-ratio: 1;
	object-fit: cover;
}

.etg-badge--pending {
	position: absolute;
	left: 6px;
	bottom: 6px;
	padding: 2px 7px;
	border-radius: 4px;
	background: #b45309;
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

/* ---- Browser ----------------------------------------------------------- */

.etg-browser {
	display: grid;
	grid-template-columns: 240px 1fr;
	gap: 24px;
}

.etg-browser--no-tree {
	grid-template-columns: 1fr;
}

.etg-browser__sidebar {
	min-width: 0;
}

.etg-browser__main {
	min-width: 0;
}

.etg-browser .etg-tree,
.etg-browser .etg-tree ul {
	margin: 0;
	padding: 0 0 0 12px;
	list-style: none;
}

.etg-browser > .etg-browser__sidebar > .etg-browser__tree > .etg-tree {
	padding-left: 0;
}

.etg-tree__row {
	display: flex;
	align-items: center;
	gap: 4px;
	border-radius: 6px;
}

.etg-tree__row.is-active {
	background: rgba( 43, 108, 176, 0.1 );
}

.etg-tree__toggle {
	width: 20px;
	height: 24px;
	border: 0;
	background: none;
	color: var( --etg-muted );
	cursor: pointer;
}

.etg-tree__spacer {
	display: inline-block;
	width: 20px;
}

.etg-tree__label {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	flex: 1;
	padding: 5px 8px;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.etg-tree__count {
	color: var( --etg-muted );
	font-size: 0.8em;
}

.etg-browser__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	flex-wrap: wrap;
	margin-bottom: 16px;
}

.etg-browser__crumbs {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
}

.etg-crumb {
	padding: 2px 4px;
	border: 0;
	background: none;
	color: var( --etg-accent );
	font: inherit;
	cursor: pointer;
	text-decoration: underline;
}

.etg-crumb__sep {
	color: var( --etg-muted );
}

.etg-browser__search {
	padding: 8px 12px;
	border: 1px solid var( --etg-border );
	border-radius: 6px;
	font: inherit;
	min-width: 200px;
}

.etg-browser__grid {
	display: grid;
	grid-template-columns: repeat( var( --etg-columns ), minmax( 0, 1fr ) );
	gap: var( --etg-gutter );
}

.etg-browser__item {
	margin: 0;
}

.etg-browser__trigger {
	display: block;
	width: 100%;
	padding: 0;
	border: 0;
	border-radius: var( --etg-radius );
	overflow: hidden;
	background: rgba( 0, 0, 0, 0.05 );
	cursor: zoom-in;
	line-height: 0;
}

.etg-browser__trigger img {
	display: block;
	width: 100%;
	aspect-ratio: 1;
	object-fit: cover;
	transition: transform 0.3s ease;
}

.etg-browser__item:hover .etg-browser__trigger img {
	transform: scale( 1.05 );
}

.etg-browser__item figcaption {
	padding-top: 7px;
	font-size: 0.85em;
	line-height: 1.35;
}

.etg-browser__loading {
	padding: 24px 8px;
	color: var( --etg-muted );
}

/* ---- Builder preview --------------------------------------------------- */

.etg-preview {
	min-height: 60px;
}

/* ---- Responsive -------------------------------------------------------- */

@media ( max-width: 980px ) {
	.etg-gallery__grid,
	.etg-browser__grid {
		grid-template-columns: repeat( min( var( --etg-columns ), 3 ), minmax( 0, 1fr ) );
	}

	.etg-gallery--masonry .etg-gallery__grid {
		column-count: min( var( --etg-columns ), 3 );
	}

	.etg-browser {
		grid-template-columns: 1fr;
	}
}

@media ( max-width: 640px ) {
	.etg-gallery__grid,
	.etg-browser__grid {
		grid-template-columns: repeat( min( var( --etg-columns ), 2 ), minmax( 0, 1fr ) );
	}

	.etg-gallery--masonry .etg-gallery__grid {
		column-count: min( var( --etg-columns ), 2 );
	}

	.etg-lightbox__panel {
		padding: 8vh 12px;
	}

	.etg-lightbox__nav {
		width: 38px;
		height: 38px;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.etg-gallery__image,
	.etg-browser__trigger img,
	.etg-gallery--hover-lift .etg-gallery__item,
	.etg-queue__fill {
		transition: none;
	}
}
