/* ==========================================================================
   Slider and Carousel tags (mgtags/mgcarousel.cfm) - the content listings'
   strip, drawn for images.  Linked by the tag itself rather than built into
   the site's stylesheet, so a slider draws correctly before a rebuild.  The
   script is the listings' own (includes/js/common.js initStrip).

   Themes style their header banner through FlexSlider's class names, which
   the markup keeps (.flexslider, ul li, .slide_text, .slide_title), so the
   rules here are kept low enough for those to win.
   ========================================================================== */

.mg-carousel {
	--mg-item-gap: 0px;
	--mg-per-view: 1;
	--mg-fade-ms: 600ms;
	--mg-item-accent: var(--mg-primary, var(--mg-theme-color, var(--bs-primary, var(--primary, #015c6e))));
	--mg-item-accent-text: var(--mg-primary-contrast, #fff);
	--mg-item-border: var(--mg-border, rgba(128, 128, 128, .35));
	container-type: inline-size;
	position: relative;
	clear: both;
	width: 100%;
	margin: 0;
}
.mg-carousel-viewport {
	position: relative;
	overflow: hidden;
	margin: 0;
	padding: 0;
}

/* The strip: one row that snaps to each slide */
.mg-carousel .mg-listing-items {
	display: flex;
	position: relative;
	gap: var(--mg-item-gap);
	margin: 0;
	padding: 0;
	list-style: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
}
.mg-carousel .mg-listing-items::-webkit-scrollbar {
	display: none;
}
.mg-carousel .mg-carousel-slide {
	position: relative;
	flex: 0 0 calc((100% - (var(--mg-per-view) - 1) * var(--mg-item-gap)) / var(--mg-per-view));
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
	scroll-snap-align: start;
}
.mg-carousel .mg-carousel-slide > a {
	display: block;
}
.mg-carousel .mg-carousel-slide img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0 auto;
}

/* Fade: the slides share one place and the shown one fades in.  The class is
   set by the script, so without it the strip still scrolls. */
.mg-carousel.is-fade .mg-listing-items {
	display: grid;
	overflow: hidden;
	scroll-snap-type: none;
}
.mg-carousel.is-fade .mg-carousel-slide {
	grid-area: 1 / 1;
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--mg-fade-ms) ease, visibility 0s linear var(--mg-fade-ms);
}
.mg-carousel.is-fade .mg-carousel-slide.is-active {
	z-index: 1;
	opacity: 1;
	visibility: visible;
	transition: opacity var(--mg-fade-ms) ease, visibility 0s;
}

/* Captions across the foot of the image, as FlexSlider drew them */
.mg-carousel .slide_text {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 1;
	padding: 5px 10px;
	background-color: rgba(0, 0, 0, .5);
	color: #fff;
}
.mg-carousel .slide_text a,
.mg-carousel .slide_text a:hover {
	color: #fff;
}
.mg-carousel .slide_title {
	font-size: 1.2em;
	text-transform: uppercase;
}

/* Previous and next, over the image */
.mg-carousel-nav {
	position: absolute;
	top: 50%;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, .45);
	color: #fff;
	cursor: pointer;
	opacity: .85;
	transform: translateY(-50%);
	transition: background-color .2s ease, color .2s ease, opacity .2s ease;
}
.mg-carousel-nav.mg-listing-prev {
	left: .75rem;
}
.mg-carousel-nav.mg-listing-next {
	right: .75rem;
}
.mg-carousel-nav:hover,
.mg-carousel-nav:focus-visible {
	background: var(--mg-item-accent);
	color: var(--mg-item-accent-text);
	opacity: 1;
}
@container (max-width: 480px) {
	.mg-carousel-nav {
		width: 2.1rem;
		height: 2.1rem;
		font-size: .85rem;
	}
	.mg-carousel-nav.mg-listing-prev {
		left: .4rem;
	}
	.mg-carousel-nav.mg-listing-next {
		right: .4rem;
	}
}

/* Dots, under the image */
.mg-carousel .mg-listing-controls {
	display: flex;
	justify-content: center;
	margin: .75rem 0 0;
}
.mg-carousel .mg-listing-dots {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: .4rem;
	margin: 0;
}
.mg-carousel .mg-listing-dot {
	width: .6rem;
	height: .6rem;
	padding: 0;
	border: 0;
	border-radius: 1rem;
	background: var(--mg-item-border);
	cursor: pointer;
	transition: width .2s ease, background-color .2s ease;
}
.mg-carousel .mg-listing-dot[aria-current="true"] {
	width: 1.5rem;
	background: var(--mg-item-accent);
}

/* Thumbnails, under the image.  The auto margins centre a short row and still
   let a long one scroll from its first thumbnail. */
.mg-listing-thumbs {
	position: relative;
	display: flex;
	gap: .5rem;
	margin: .5rem 0 0;
	padding: 2px;
	overflow-x: auto;
	scrollbar-width: thin;
}
.mg-listing-thumb {
	flex: 0 0 min(140px, calc((100% - 1.5rem) / 4));
	padding: 0;
	border: 2px solid transparent;
	border-radius: .375rem;
	background: none;
	cursor: pointer;
	overflow: hidden;
	opacity: .6;
	transition: opacity .2s ease, border-color .2s ease;
}
.mg-listing-thumb:first-child {
	margin-left: auto;
}
.mg-listing-thumb:last-child {
	margin-right: auto;
}
.mg-listing-thumb img {
	display: block;
	width: 100%;
	aspect-ratio: 16 / 9;
	object-fit: cover;
}
.mg-listing-thumb:hover,
.mg-listing-thumb:focus-visible,
.mg-listing-thumb[aria-current="true"] {
	border-color: var(--mg-item-accent);
	opacity: 1;
}

/* Everything fits: no controls */
.mg-carousel.mg-listing--static .mg-carousel-nav,
.mg-carousel.mg-listing--static .mg-listing-controls {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.mg-carousel .mg-listing-items {
		scroll-behavior: auto;
	}
	.mg-carousel.is-fade .mg-carousel-slide,
	.mg-carousel.is-fade .mg-carousel-slide.is-active,
	.mg-carousel-nav,
	.mg-carousel .mg-listing-dot,
	.mg-listing-thumb {
		transition: none;
	}
}
