.cm-vehicle-gallery {
	--cm-gallery-background: #e8e8e8;
	--cm-gallery-control-background: rgb(255 255 255 / 78%);
	--cm-gallery-control-background-hover: rgb(255 255 255 / 94%);
	--cm-gallery-thumbnail-width: 138px;
	--cm-gallery-thumbnail-ratio: 3 / 2;
	--cm-gallery-transition: 180ms ease;

	position: relative;
	width: 100%;
	overflow: hidden;
	background: var(--cm-gallery-background);
}

.cm-vehicle-gallery__notice {
	margin: 1rem 0;
	padding: 1rem;
	border: 1px solid #dba617;
	background: #fff8e5;
	color: #4d3b00;
}

/*
 * Main image stage.
 */
.cm-vehicle-gallery__stage {
	position: relative;
	display: grid;
	place-items: center;
	min-height: clamp(420px, 50vw, 720px);
	padding: 2rem 6rem;
	overflow: hidden;
	touch-action: pan-y;
}

.cm-vehicle-gallery__stage:focus-visible {
	outline: 3px solid #222;
	outline-offset: -3px;
}

.cm-vehicle-gallery__viewport {
	position: relative;
	display: grid;
	place-items: center;
	width: min(100%, 1100px);
	height: clamp(370px, 44vw, 650px);
}

.cm-vehicle-gallery__main-image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	cursor: zoom-in;
	transition: opacity var(--cm-gallery-transition);
}

.cm-vehicle-gallery.is-main-loading
	.cm-vehicle-gallery__main-image {
	opacity: 0.38;
}

/*
 * Loading indicator.
 */
.cm-vehicle-gallery__loader {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 38px;
	aspect-ratio: 1;
	border: 3px solid rgb(0 0 0 / 18%);
	border-top-color: #222;
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, -50%);
	animation: cm-vehicle-gallery-spin 0.75s linear infinite;
	transition: opacity var(--cm-gallery-transition);
}

.cm-vehicle-gallery.is-main-loading
	.cm-vehicle-gallery__loader {
	opacity: 1;
}

@keyframes cm-vehicle-gallery-spin {
	to {
		transform: translate(-50%, -50%) rotate(360deg);
	}
}

/*
 * Expand control.
 */
.cm-vehicle-gallery__expand {
	position: absolute;
	z-index: 3;
	top: 0;
	right: 0;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	background: rgb(35 35 35 / 65%);
	color: #fff;
	cursor: pointer;
	transition: background-color var(--cm-gallery-transition);
}

.cm-vehicle-gallery__expand:hover {
	background: rgb(20 20 20 / 90%);
}

.cm-vehicle-gallery__expand svg {
	width: 23px;
	height: 23px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: square;
}

/*
 * Main previous and next buttons.
 */
.cm-vehicle-gallery__stage-nav {
	position: absolute;
	z-index: 2;
	top: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	width: 88px;
	min-height: 64px;
	padding: 0.5rem;
	border: 0;
	background: var(--cm-gallery-control-background);
	color: #444;
	font: inherit;
	text-transform: uppercase;
	transform: translateY(-50%);
	cursor: pointer;
	transition:
		background-color var(--cm-gallery-transition),
		color var(--cm-gallery-transition);
}

.cm-vehicle-gallery__stage-nav:hover {
	background: var(--cm-gallery-control-background-hover);
	color: #111;
}

.cm-vehicle-gallery__stage-nav--previous {
	left: 0;
}

.cm-vehicle-gallery__stage-nav--next {
	right: 0;
}

.cm-vehicle-gallery__stage-nav-icon {
	font-size: 1.7rem;
	line-height: 1;
}

.cm-vehicle-gallery__stage-nav-text {
	font-size: 0.72rem;
	font-weight: 600;
}

.cm-vehicle-gallery__stage-nav:disabled,
.cm-vehicle-gallery__reel-nav:disabled {
	opacity: 0.25;
	cursor: default;
}

/*
 * Thumbnail reel.
 */
.cm-vehicle-gallery__reel-shell {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: stretch;
	border-top: 1px solid #d5d5d5;
	background: #fff;
}

.cm-vehicle-gallery__reel {
	display: flex;
	gap: 12px;
	min-width: 0;
	padding: 12px 4px;
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-inline: contain;
	scroll-behavior: smooth;
	scroll-snap-type: inline proximity;
	scrollbar-width: thin;
	-webkit-overflow-scrolling: touch;
	position: relative;
}

.cm-vehicle-gallery__reel-nav {
	width: 46px;
	padding: 0;
	border: 0;
	background: #fff;
	color: #444;
	font-size: 1.8rem;
	cursor: pointer;
}

.cm-vehicle-gallery__reel-nav:hover:not(:disabled) {
	background: #f1f1f1;
	color: #111;
}

.cm-vehicle-gallery__reel-nav[hidden] {
	display: none;
}

.cm-vehicle-gallery__thumbnail {
	flex: 0 0 var(--cm-gallery-thumbnail-width);
	width: var(--cm-gallery-thumbnail-width);
	aspect-ratio: var(--cm-gallery-thumbnail-ratio);
	padding: 0;
	overflow: hidden;
	border: 2px solid transparent;
	background: #111;
	opacity: 0.52;
	scroll-snap-align: center;
	cursor: pointer;
	transition:
		opacity var(--cm-gallery-transition),
		border-color var(--cm-gallery-transition),
		transform var(--cm-gallery-transition);
}

.cm-vehicle-gallery__thumbnail:hover {
	opacity: 0.82;
	transform: translateY(-1px);
}

.cm-vehicle-gallery__thumbnail.is-active {
	border-color: #111;
	opacity: 1;
}

.cm-vehicle-gallery__thumbnail img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

/*
 * Generic focus handling.
 */
.cm-vehicle-gallery button:focus-visible {
	outline: 3px solid currentColor;
	outline-offset: 3px;
}

/*
 * Fullscreen dialog.
 */
.cm-vehicle-gallery__lightbox {
	width: 100vw;
	max-width: none;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	background: #000;
	color: #fff;
}

.cm-vehicle-gallery__lightbox::backdrop {
	background: #000;
}

.cm-vehicle-gallery__lightbox-stage {
	position: relative;
	display: grid;
	place-items: center;
	width: 100%;
	height: calc(100dvh - 64px);
	padding:
		max(3rem, env(safe-area-inset-top))
		max(1rem, env(safe-area-inset-right))
		1.5rem
		max(1rem, env(safe-area-inset-left));
	overflow: hidden;
	touch-action: pan-y;
}

.cm-vehicle-gallery__lightbox-image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	transition: opacity var(--cm-gallery-transition);
}

.cm-vehicle-gallery__lightbox.is-loading
	.cm-vehicle-gallery__lightbox-image {
	opacity: 0.28;
}

.cm-vehicle-gallery__lightbox-stage::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 42px;
	aspect-ratio: 1;
	border: 3px solid rgb(255 255 255 / 22%);
	border-top-color: #fff;
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, -50%);
	animation: cm-vehicle-gallery-spin 0.75s linear infinite;
	transition: opacity var(--cm-gallery-transition);
}

.cm-vehicle-gallery__lightbox.is-loading
	.cm-vehicle-gallery__lightbox-stage::after {
	opacity: 1;
}

/*
 * Rounded close control matching the older gallery.
 */
.cm-vehicle-gallery__lightbox-close {
	position: fixed;
	z-index: 5;
	top: 0;
	right: 0;
	display: grid;
	place-items: center;
	width: 50px;
	height: 50px;
	padding: 0 0 8px 8px;
	border: 0;
	border-radius: 0 0 0 100%;
	background: #fff;
	color: #111;
	font-size: 1.7rem;
	line-height: 1;
	cursor: pointer;
}

/*
 * Split previous and next bar.
 */
.cm-vehicle-gallery__lightbox-controls {
	position: fixed;
	z-index: 4;
	right: 0;
	bottom: 0;
	left: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	height: 64px;
	padding-bottom: env(safe-area-inset-bottom);
	background: #252525;
}

.cm-vehicle-gallery__lightbox-controls button {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.65rem;
	min-width: 0;
	padding: 0 1.25rem;
	border: 0;
	background: transparent;
	color: #fff;
	font: inherit;
	text-transform: uppercase;
	cursor: pointer;
	transition: background-color var(--cm-gallery-transition);
}

.cm-vehicle-gallery__lightbox-controls button:hover {
	background: rgb(255 255 255 / 9%);
}

.cm-vehicle-gallery__lightbox-controls button:first-child {
	border-right: 1px solid #000;
}

.cm-vehicle-gallery__lightbox-controls button:last-child {
	border-left: 1px solid #000;
}

.cm-vehicle-gallery__counter {
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 90px;
	padding-inline: 0.75rem;
	color: #bbb;
	font-size: 0.82rem;
}

.cm-vehicle-lightbox-open {
	overflow: hidden;
}

/*
 * Accessible hidden content.
 */
.cm-vehicle-gallery__visually-hidden {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/*
 * Tablet and mobile.
 */
@media (max-width: 800px) {
	.cm-vehicle-gallery {
		--cm-gallery-thumbnail-width: 116px;
	}

	.cm-vehicle-gallery__stage {
		min-height: 410px;
		padding: 1.25rem 0.75rem 4rem;
	}

	.cm-vehicle-gallery__viewport {
		height: 350px;
		padding-inline: 1rem;
	}

	.cm-vehicle-gallery__stage-nav {
		top: auto;
		bottom: 0;
		width: 50%;
		min-height: 50px;
		transform: none;
	}

	.cm-vehicle-gallery__stage-nav--previous {
		left: 0;
		border-right: 1px solid rgb(0 0 0 / 12%);
	}

	.cm-vehicle-gallery__stage-nav--next {
		right: 0;
	}

	.cm-vehicle-gallery__reel-nav {
		display: none;
	}

	.cm-vehicle-gallery__reel-shell {
		display: block;
	}
}

@media (max-width: 520px) {
	.cm-vehicle-gallery {
		--cm-gallery-thumbnail-width: 98px;
	}

	.cm-vehicle-gallery__stage {
		min-height: 340px;
	}

	.cm-vehicle-gallery__viewport {
		height: 290px;
	}

	.cm-vehicle-gallery__lightbox-stage {
		height: calc(100dvh - 58px);
		padding-inline: 0.5rem;
	}

	.cm-vehicle-gallery__lightbox-controls {
		height: 58px;
	}

	.cm-vehicle-gallery__counter {
		min-width: 58px;
		padding-inline: 0.35rem;
	}

	.cm-vehicle-gallery__lightbox-controls button {
		padding-inline: 0.5rem;
		font-size: 0.85rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cm-vehicle-gallery *,
	.cm-vehicle-gallery *::before,
	.cm-vehicle-gallery *::after {
		scroll-behavior: auto !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}