/**
 * HFM Gallery
 *
 * Native CSS scroll-snap gallery — replaces WooThumbs Premium.
 * The browser owns all drag/swipe/momentum; JS only handles click nav + active state.
 *
 * @package HFM.Parts
 * @copyright ùrlar – https://www.urlar.co/
 */

/* ─────────────────────────────────────────────────────────────────────────────
   Design tokens — light mode defaults
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery {
	--hfm-gallery-bg:           var(--wp--preset--color--grey-100, #f0f0f0);
	--hfm-gallery-thumb-border: #efefef;
	--hfm-gallery-thumb-bg:     #ffffff;
	--hfm-gallery-arrow-bg:     rgba(255, 255, 255, 0.78);
	--hfm-gallery-arrow-color:  #1a1a1a;
	--hfm-gallery-dot-color:    rgba(0, 0, 0, 0.70);
}

@media (prefers-color-scheme: dark) {
	.hfm-gallery {
		--hfm-gallery-bg:           #1e1e1e;
		--hfm-gallery-thumb-border: #333333;
		--hfm-gallery-thumb-bg:     #262626;
		--hfm-gallery-arrow-bg:     rgba(0, 0, 0, 0.55);
		--hfm-gallery-arrow-color:  rgba(255, 255, 255, 0.90);
		--hfm-gallery-dot-color:    rgba(255, 255, 255, 0.75);
	}
}

.dark .hfm-gallery {
	--hfm-gallery-bg:           #1e1e1e;
	--hfm-gallery-thumb-border: #333333;
	--hfm-gallery-thumb-bg:     #262626;
	--hfm-gallery-arrow-bg:     rgba(0, 0, 0, 0.55);
	--hfm-gallery-arrow-color:  rgba(255, 255, 255, 0.90);
	--hfm-gallery-dot-color:    rgba(255, 255, 255, 0.75);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Gallery wrapper
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Viewport — clips the scroll container, anchors the arrows
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__viewport {
	position: relative;
	width: 100%;
	border-radius: 14px;
	overflow: hidden;          /* clips off-screen slides + hides scrollbar track */
	background: var(--hfm-gallery-bg);
	aspect-ratio: 1 / 1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Main scroll container — the browser handles ALL drag/swipe/momentum
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__main {
	display: flex;
	width: 100%;
	height: 100%;
	overflow-x: scroll;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	touch-action: pan-x pan-y; /* allow vertical page scroll; browser still owns horizontal swipe */
	user-select: none;         /* prevent text selection while mouse-dragging */
}

.hfm-gallery__main::-webkit-scrollbar {
	display: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Individual slide
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__slide {
	flex: 0 0 100%;
	scroll-snap-align: start;
	width: 100%;
	height: 100%;
}

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

/* ─────────────────────────────────────────────────────────────────────────────
   Prev / Next arrows — frosted glass disc, always readable
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__arrow {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 34px;
	height: 34px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--hfm-gallery-arrow-bg) !important;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	border-radius: 50%;
	border: none;
	box-shadow: none !important;
	cursor: pointer;
	z-index: 10;
	padding: 0;
	color: var(--hfm-gallery-arrow-color);
	transition: opacity 150ms ease-out;
}

.hfm-gallery__arrow:hover,
.hfm-gallery__arrow:focus,
.hfm-gallery__arrow:active,
.hfm-gallery__arrow:focus-visible {
	background: var(--hfm-gallery-arrow-bg) !important;
	box-shadow: none !important;
	outline: none;
	opacity: 0.85;
}

.hfm-gallery__arrow svg {
	display: block;
	width: 9px;
	height: 16px;
	pointer-events: none;
	transition: transform 100ms ease-out;
}

.hfm-gallery__arrow--prev {
	left: 10px;
}

.hfm-gallery__arrow--prev:hover svg {
	transform: translateX(-2px);
}

.hfm-gallery__arrow--next {
	right: 10px;
}

.hfm-gallery__arrow--next:hover svg {
	transform: translateX(2px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Thumbnail strip (desktop)
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__thumbs {
	display: flex;
	flex-direction: row;
	gap: 6px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	padding-bottom: 2px;
}

.hfm-gallery__thumbs::-webkit-scrollbar {
	display: none;
}

.hfm-gallery__thumb {
	flex-shrink: 0;
	scroll-snap-align: start;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 72px;
	height: 60px;
	padding: 3px;
	border-radius: 8px;
	border: 1px solid var(--hfm-gallery-thumb-border);
	background: var(--hfm-gallery-thumb-bg);
	cursor: pointer;
	transition: border-color 0.15s ease, outline-color 0.15s ease;
	outline: 2px solid transparent;
	outline-offset: 0;
}

.hfm-gallery__thumb:hover {
	border-color: color-mix(in srgb, currentColor 30%, transparent);
}

.hfm-gallery__thumb--active {
	border-color: transparent;
	outline-color: currentColor;
}

.hfm-gallery__thumb-img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 6px;
	aspect-ratio: 1.2 / 1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Dot indicators (mobile) — growing pill, WooThumbs spec
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery__dots {
	display: none;
	justify-content: center;
	align-items: center;
	gap: 6px;
	padding: 4px 0;
}

.hfm-gallery__dot {
	width: 10px;
	height: 10px;
	border-radius: 100%;
	background: var(--hfm-gallery-dot-color);
	opacity: 0.35;
	border: none;
	padding: 0;
	cursor: pointer;
	transition: width 100ms ease-out, border-radius 100ms ease-out, opacity 100ms ease-out;
	overflow: hidden;
	text-indent: 250%;
	white-space: nowrap;
}

.hfm-gallery__dot:hover {
	opacity: 0.6;
}

.hfm-gallery__dot--active {
	width: 30px;
	border-radius: 68px;
	opacity: 1;
	cursor: default;
}

.hfm-gallery__dot--active:hover {
	opacity: 1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Single-image mode — hide chrome when there's nothing to navigate
───────────────────────────────────────────────────────────────────────────── */

.hfm-gallery--single .hfm-gallery__arrow,
.hfm-gallery--single .hfm-gallery__thumbs,
.hfm-gallery--single .hfm-gallery__dots {
	display: none;
}

.hfm-gallery--single .hfm-gallery__main {
	user-select: auto;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Responsive — swap thumbs ↔ dots at mobile breakpoint
───────────────────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
	.hfm-gallery__thumbs {
		display: none;
	}

	.hfm-gallery__dots {
		display: flex;
	}
}
