/**
 * Sterling Millwork — Photo Gallery
 *
 * 5-wide masonry-style grid with tag filtering, lazy load, lightbox.
 * Brand: #1a1a1a (dark), #c9a84c (gold), #f5f2ed (warm gray)
 *
 * @package Sterling_Millwork
 * @since 1.0.0
 */

/* ==========================================================================
   Filter Bar
   ========================================================================== */

.sterling-gallery-filters {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-bottom: 40px;
}

.sterling-gallery-filters button {
	background: none;
	border: 1px solid #ddd;
	padding: 8px 20px;
	font-family: 'Inter', sans-serif;
	font-size: 11px;
	font-weight: 400;
	letter-spacing: 2px;
	text-transform: uppercase;
	color: #3a3a3a;
	cursor: pointer;
	transition: all 0.3s ease;
}

.sterling-gallery-filters button:hover {
	border-color: #c9a84c;
	color: #c9a84c;
}

.sterling-gallery-filters button.active {
	background-color: #1a1a1a;
	border-color: #1a1a1a;
	color: #c9a84c;
}

/* ==========================================================================
   Project Description (shown on filter)
   ========================================================================== */

.sterling-gallery-desc {
	max-width: 700px;
	margin: 0 auto 36px;
	text-align: center;
	font-family: 'Inter', sans-serif;
	font-size: 15px;
	line-height: 1.8;
	color: #3a3a3a;
	opacity: 0;
	max-height: 0;
	overflow: hidden;
	transition: opacity 0.4s ease, max-height 0.4s ease;
}

.sterling-gallery-desc.visible {
	opacity: 1;
	max-height: 200px;
}

/* ==========================================================================
   Gallery Grid — 5 Wide
   ========================================================================== */

.sterling-gallery-grid {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	gap: 6px;
}

/* 4-wide variant (used on the corporate-facilities "Our Facility & Team" gallery) */
.sterling-gallery-grid--facility {
	grid-template-columns: repeat(4, 1fr);
	gap: 8px;
}

/* Facility gallery uses native lazy-load (loading="lazy"), not the JS data-src
   approach used by the portfolio. Show images by default; the JS still adds
   .loaded once the load event fires for the fade-in. */
.sterling-gallery-grid--facility .sterling-gallery-item img {
	opacity: 1;
}

/* The image inside the fallback <a> needs to behave the same as the bare img */
.sterling-gallery-item a {
	display: block;
	width: 100%;
	height: 100%;
	color: inherit;
	text-decoration: none;
}

.sterling-gallery-item a:focus-visible {
	outline: 2px solid #c9a84c;
	outline-offset: -2px;
}

.sterling-gallery-item {
	position: relative;
	overflow: hidden;
	aspect-ratio: 1;
	cursor: pointer;
	background-color: #f0f0f0;
}

.sterling-gallery-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.4s ease, opacity 0.4s ease;
	opacity: 0;
}

.sterling-gallery-item img.loaded {
	opacity: 1;
}

.sterling-gallery-item:hover img {
	transform: scale(1.05);
}

/* Overlay on hover */
.sterling-gallery-item::after {
	content: '';
	position: absolute;
	inset: 0;
	background: rgba(26, 26, 26, 0);
	transition: background 0.3s ease;
	pointer-events: none;
}

.sterling-gallery-item:hover::after {
	background: rgba(26, 26, 26, 0.15);
}

/* Hidden by filter */
.sterling-gallery-item.hidden {
	display: none;
}

/* Lazy load placeholder */
.sterling-gallery-item.not-loaded img {
	opacity: 0;
}

/* ==========================================================================
   Load More / Lazy Load
   ========================================================================== */

.sterling-gallery-sentinel {
	height: 1px;
	width: 100%;
}

.sterling-gallery-loading {
	text-align: center;
	padding: 40px 0;
	color: #999;
	font-size: 12px;
	letter-spacing: 2px;
	text-transform: uppercase;
	font-family: 'Inter', sans-serif;
}

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

.sterling-lightbox {
	position: fixed;
	inset: 0;
	z-index: 10000;
	background: rgba(0, 0, 0, 0.92);
	display: none;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 0.3s ease;
}

.sterling-lightbox.open {
	display: flex;
	opacity: 1;
}

.sterling-lightbox img {
	max-width: 90vw;
	max-height: 90vh;
	width: auto;
	height: auto;
	object-fit: contain;
	user-select: none;
	box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
	opacity: 0;
	transition: opacity 0.25s ease;
	-webkit-user-drag: none;
}

.sterling-lightbox img.loaded {
	opacity: 1;
}

/* Loading spinner */
.sterling-lightbox-spinner {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 44px;
	height: 44px;
	margin: -22px 0 0 -22px;
	border: 2px solid rgba(255, 255, 255, 0.2);
	border-top-color: #c9a84c;
	border-radius: 50%;
	animation: sterling-lightbox-spin 0.8s linear infinite;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

.sterling-lightbox.loading .sterling-lightbox-spinner {
	opacity: 1;
}

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

.sterling-lightbox-close {
	position: absolute;
	top: 24px;
	right: 32px;
	background: none;
	border: none;
	color: #fff;
	font-size: 32px;
	cursor: pointer;
	opacity: 0.7;
	transition: opacity 0.2s ease;
	line-height: 1;
	padding: 8px;
	font-family: 'Inter', sans-serif;
}

.sterling-lightbox-close:hover {
	opacity: 1;
}

.sterling-lightbox-prev,
.sterling-lightbox-next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	background: none;
	border: none;
	color: #fff;
	font-size: 48px;
	cursor: pointer;
	opacity: 0.5;
	transition: opacity 0.2s ease;
	padding: 20px;
	line-height: 1;
	font-family: 'Inter', sans-serif;
}

.sterling-lightbox-prev:hover,
.sterling-lightbox-next:hover {
	opacity: 1;
}

.sterling-lightbox-prev {
	left: 16px;
}

.sterling-lightbox-next {
	right: 16px;
}

.sterling-lightbox-caption {
	position: absolute;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	color: #ccc;
	font-size: 12px;
	letter-spacing: 2px;
	text-transform: uppercase;
	font-family: 'Inter', sans-serif;
	white-space: nowrap;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1200px) {
	.sterling-gallery-grid {
		grid-template-columns: repeat(4, 1fr);
	}
	.sterling-gallery-grid--facility {
		grid-template-columns: repeat(3, 1fr);
	}
}

@media (max-width: 900px) {
	.sterling-gallery-grid {
		grid-template-columns: repeat(3, 1fr);
	}
	.sterling-gallery-grid--facility {
		grid-template-columns: repeat(3, 1fr);
	}
}

@media (max-width: 600px) {
	.sterling-gallery-grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.sterling-gallery-grid--facility {
		grid-template-columns: repeat(2, 1fr);
	}

	.sterling-lightbox-close {
		top: 12px;
		right: 12px;
		font-size: 28px;
		width: 44px;
		height: 44px;
		display: flex;
		align-items: center;
		justify-content: center;
		opacity: 0.85;
	}

	.sterling-lightbox-prev,
	.sterling-lightbox-next {
		font-size: 32px;
		padding: 12px;
		min-width: 44px;
		min-height: 44px;
		opacity: 0.7;
	}

	.sterling-lightbox-prev {
		left: 4px;
	}

	.sterling-lightbox-next {
		right: 4px;
	}

	.sterling-lightbox img {
		max-width: 94vw;
		max-height: 80vh;
	}

	.sterling-lightbox-caption {
		bottom: 12px;
		font-size: 11px;
		white-space: normal;
		max-width: 90vw;
		text-align: center;
	}
}

/* Safety: ensure touch targets are always at least 44px even on desktop */
.sterling-lightbox-close,
.sterling-lightbox-prev,
.sterling-lightbox-next {
	min-width: 44px;
	min-height: 44px;
}

/* ==========================================================================
   Gallery Scroll Window (corporate-facilities top gallery)
   Wraps a tall grid in a fixed-height scrollable container so the page
   does not stretch indefinitely. The lightbox must remain a sibling of
   this container — never a child — so it can overlay fullscreen.
   ========================================================================== */

.sterling-gallery-scroll-window {
	max-height: 500px;
	overflow-y: auto;
	overflow-x: hidden;
	padding-right: 4px;
	/* Firefox scrollbar */
	scrollbar-width: thin;
	scrollbar-color: #c9a84c rgba(255, 255, 255, 0.05);
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
.sterling-gallery-scroll-window::-webkit-scrollbar {
	width: 8px;
}
.sterling-gallery-scroll-window::-webkit-scrollbar-track {
	background: rgba(255, 255, 255, 0.05);
	border-radius: 4px;
}
.sterling-gallery-scroll-window::-webkit-scrollbar-thumb {
	background: #c9a84c;
	border-radius: 4px;
}
.sterling-gallery-scroll-window::-webkit-scrollbar-thumb:hover {
	background: #d6b85f;
}

/* Mobile: disable the scroll window — let the grid flow naturally so
   users do not have to scroll inside a scrolling page. */
@media (max-width: 600px) {
	.sterling-gallery-scroll-window {
		max-height: none;
		overflow: visible;
		padding-right: 0;
	}
}

/* ==========================================================================
   Filmstrip Gallery (Netflix-row style horizontal scroll)
   Used on corporate-facilities for the top "Our Facility" gallery and the
   bottom "Behind the Shop" gallery. Wraps a single horizontal row of large
   thumbs, with chevron buttons overlayed on left/right edges and a soft
   gradient mask hinting at additional offscreen content.

   Structure:
     .sterling-gallery-filmstrip-wrap (outer, holds chevrons + edge masks)
       .sterling-gallery-filmstrip   (the scrollable horizontal flex row)
         .sterling-gallery-item       (each large thumb)
       .sterling-filmstrip-chevron --prev / --next  (absolute buttons)

   The lightbox stays a sibling of .sterling-gallery-filmstrip-wrap.
   ========================================================================== */

.sterling-gallery-filmstrip-wrap {
	position: relative;
	width: 100%;
}

.sterling-gallery-filmstrip {
	display: flex;
	flex-wrap: nowrap;
	gap: 18px;
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	padding: 4px 4px 12px 4px;
	scrollbar-width: none; /* Firefox */
	-ms-overflow-style: none; /* IE/Edge legacy */
}

.sterling-gallery-filmstrip::-webkit-scrollbar {
	display: none;
}

/* Each item: fixed width, fixed aspect, snap to start. Override the
   inherited 1:1 aspect from the grid rules. */
.sterling-gallery-filmstrip .sterling-gallery-item {
	flex: 0 0 360px;
	width: 360px;
	height: 240px;
	aspect-ratio: auto;
	scroll-snap-align: start;
	border-radius: 2px;
}

.sterling-gallery-filmstrip .sterling-gallery-item a {
	display: block;
	width: 100%;
	height: 100%;
}

.sterling-gallery-filmstrip .sterling-gallery-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 1;
}

/* Edge fade hints — gradient masks on left and right edges of the wrap.
   Pointer-events: none so they don't intercept clicks. The chevrons sit
   on top of these. */
.sterling-gallery-filmstrip-wrap::before,
.sterling-gallery-filmstrip-wrap::after {
	content: '';
	position: absolute;
	top: 0;
	bottom: 0;
	width: 56px;
	pointer-events: none;
	z-index: 2;
	transition: opacity 0.25s ease;
}

.sterling-gallery-filmstrip-wrap::before {
	left: 0;
	background: linear-gradient(to right, rgba(26, 26, 26, 0.85), rgba(26, 26, 26, 0));
}

.sterling-gallery-filmstrip-wrap::after {
	right: 0;
	background: linear-gradient(to left, rgba(26, 26, 26, 0.85), rgba(26, 26, 26, 0));
}

/* Hide the corresponding edge fade when at the start/end of the strip */
.sterling-gallery-filmstrip-wrap.is-at-start::before {
	opacity: 0;
}

.sterling-gallery-filmstrip-wrap.is-at-end::after {
	opacity: 0;
}

/* Chevron buttons */
.sterling-filmstrip-chevron {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 48px;
	height: 48px;
	border-radius: 50%;
	border: 1px solid rgba(201, 168, 76, 0.4);
	background: rgba(26, 26, 26, 0.78);
	color: #c9a84c;
	font-family: 'Inter', sans-serif;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	z-index: 3;
	transition: background 0.2s ease, border-color 0.2s ease, opacity 0.25s ease, transform 0.25s ease;
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

.sterling-filmstrip-chevron:hover {
	background: rgba(26, 26, 26, 0.92);
	border-color: #c9a84c;
	color: #ffffff;
}

.sterling-filmstrip-chevron:focus-visible {
	outline: 2px solid #c9a84c;
	outline-offset: 2px;
}

.sterling-filmstrip-chevron--prev {
	left: 8px;
}

.sterling-filmstrip-chevron--next {
	right: 8px;
}

/* Hide the prev chevron when at start, next chevron when at end */
.sterling-gallery-filmstrip-wrap.is-at-start .sterling-filmstrip-chevron--prev,
.sterling-gallery-filmstrip-wrap.is-at-end .sterling-filmstrip-chevron--next {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-50%) scale(0.85);
}

/* Tablet */
@media (max-width: 900px) {
	.sterling-gallery-filmstrip {
		gap: 14px;
	}
	.sterling-gallery-filmstrip .sterling-gallery-item {
		flex: 0 0 280px;
		width: 280px;
		height: 180px;
	}
}

/* Phone — smaller thumbs, hide chevrons on touch */
@media (max-width: 600px) {
	.sterling-gallery-filmstrip {
		gap: 12px;
	}
	.sterling-gallery-filmstrip .sterling-gallery-item {
		flex: 0 0 240px;
		width: 240px;
		height: 160px;
	}
	.sterling-gallery-filmstrip-wrap::before,
	.sterling-gallery-filmstrip-wrap::after {
		width: 32px;
	}
}

/* Touch devices: hide chevrons — swipe is natural. */
@media (hover: none) {
	.sterling-filmstrip-chevron {
		display: none;
	}
}
