/*
 * Categories widget: a grid of business categories — home services, dental,
 * windshield replacement. Loads on top of shell.css, which owns the section
 * panel, the header and the header button.
 *
 * Deliberately the simplest grid in the plugin: a picture, a name, an optional
 * line and an optional link. Card padding is held in variables so the picture
 * can cancel it exactly and meet the card's own edges.
 */

.mcg {
	--mcg-col-gap: 24px;
	--mcg-row-gap: 24px;

	--mcg-card-pt: 0px;
	--mcg-card-pr: 20px;
	--mcg-card-pb: 20px;
	--mcg-card-pl: 20px;
	--mcg-card-radius: 20px;
	--mcg-card-lift: 6px;
	--mcg-card-speed: 0.35s;

	--mcg-media-radius: 0px;
	--mcg-media-space: 18px;
	--mcg-img-fit: cover;
	--mcg-img-pos: center center;
	--mcg-img-bg: transparent;

	--mcg-icon-box: 44px;
	--mcg-icon-size: 20px;
	--mcg-icon-space: 14px;

	--mcg-name-space: 8px;
	--mcg-text-space: 14px;

	--mcg-link-gap: 8px;
	--mcg-link-icon: 14px;

	--mcg-accent: #2f6bff;
	--mcg-scrim: rgba(8, 12, 22, 0.82);
	--mcg-scrim-size: 88%;
}

/* -------------------------------------------------------------------- grid */

.mcg__grid {
	--mcg-cols: 4;
	display: grid;
	grid-template-columns: repeat(var(--mcg-cols), minmax(0, 1fr));
	column-gap: var(--mcg-col-gap);
	row-gap: var(--mcg-row-gap);
}

/* -------------------------------------------------------------------- card */

.mcg-card {
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
	padding: var(--mcg-card-pt) var(--mcg-card-pr) var(--mcg-card-pb) var(--mcg-card-pl);
	border: 1px solid #e8ecf4;
	border-radius: var(--mcg-card-radius);
	/* Clips the picture to the card's own corners. */
	overflow: hidden;
	background-color: #ffffff;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
	transition: transform var(--mcg-card-speed) ease, box-shadow var(--mcg-card-speed) ease,
		background-color var(--mcg-card-speed) ease, border-color var(--mcg-card-speed) ease;
}

.mcg-card:hover,
.mcg-card:focus-within {
	transform: translateY(calc(var(--mcg-card-lift) * -1));
	box-shadow: 0 18px 40px rgba(15, 23, 42, 0.1);
}

.mcg-card__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-width: 0;
}

/* ------------------------------------------------------------------- media */

/*
 * The picture cancels the card's padding on the three sides it meets, so it
 * reaches the card's edges rather than sitting in a box inside them. Override
 * the padding variables, never the shorthand, or it will overhang by the
 * difference.
 */
.mcg-card__media {
	display: flex;
	flex: 0 0 auto;
	align-items: stretch;
	justify-content: center;
	height: var(--mcg-media-h, 190px);
	margin: var(--mcg-card-pt) calc(var(--mcg-card-pr) * -1) var(--mcg-media-space) calc(var(--mcg-card-pl) * -1);
	overflow: hidden;
	border-radius: var(--mcg-media-radius);
	background-color: var(--mcg-img-bg);
}

.mcg-card__media img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: var(--mcg-img-fit);
	object-position: var(--mcg-img-pos);
}

/* Picture below the copy instead. */
.mcg--media-bottom .mcg-card__media {
	order: 2;
	margin-top: var(--mcg-media-space);
	margin-bottom: calc(var(--mcg-card-pb) * -1);
}

.mcg--media-bottom .mcg-card {
	--mcg-card-pt: 20px;
}

/* -------------------------------------------------------------------- icon */

.mcg-card__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	align-self: flex-start;
	min-width: var(--mcg-icon-box);
	min-height: var(--mcg-icon-box);
	margin-bottom: var(--mcg-icon-space);
	border-radius: 14px;
	background-color: #eef3ff;
	color: var(--mcg-accent);
	line-height: 0;
}

.mcg-card__icon svg {
	width: var(--mcg-icon-size);
	height: var(--mcg-icon-size);
	fill: currentColor;
}

.mcg-card__icon i {
	font-size: var(--mcg-icon-size);
	line-height: 1;
}

.mcg-card__icon img {
	display: block;
	width: var(--mcg-icon-size);
	height: auto;
	max-width: 100%;
}

/* -------------------------------------------------------------------- copy */

.mcg-card__name {
	margin: 0 0 var(--mcg-name-space);
	color: #0d1220;
	font-size: 18px;
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.3;
}

.mcg-card__text {
	margin: 0 0 var(--mcg-text-space);
	color: #5b6474;
	font-size: 14px;
	line-height: 1.6;
}

/* auto pins the link to the bottom, so every card in a row ends on one line. */
.mcg-card__link {
	display: inline-flex;
	align-items: center;
	align-self: flex-start;
	gap: var(--mcg-link-gap);
	margin-top: auto;
	color: var(--mcg-accent);
	font-size: 13px;
	font-weight: 600;
	line-height: 1.3;
	text-decoration: none;
}

.mcg-card__link-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
	transition: transform var(--mcg-card-speed) ease;
}

.mcg-card__link-icon svg {
	width: var(--mcg-link-icon);
	height: var(--mcg-link-icon);
	fill: currentColor;
}

.mcg-card:hover .mcg-card__link-icon {
	transform: translateX(3px);
}

/* ----------------------------------------------------------------- overlay */

/*
 * Overlay: the picture is the card and the copy rides on it. The scrim is a
 * var() fallback rather than a declaration, so the Style tab's own colour
 * replaces it and this default applies when nothing is set.
 */
.mcg--overlay .mcg-card {
	--mcg-card-pt: 20px;
	justify-content: flex-end;
	/* An overlay tile carries its copy, so it starts taller than a picture strip. */
	min-height: var(--mcg-media-h, 260px);
}

.mcg--overlay .mcg-card__media {
	position: absolute;
	inset: 0;
	z-index: 0;
	height: auto;
	margin: 0;
	border-radius: inherit;
}

.mcg--overlay .mcg-card__body {
	position: relative;
	z-index: 2;
	flex: 0 0 auto;
}

.mcg--overlay .mcg-card::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	border-radius: inherit;
	background-image: linear-gradient(to top, var(--mcg-scrim, rgba(8, 12, 22, 0.82)) 0%, transparent var(--mcg-scrim-size, 88%));
	pointer-events: none;
}

.mcg--overlay .mcg-card__name {
	color: #ffffff;
}

.mcg--overlay .mcg-card__text {
	color: rgba(255, 255, 255, 0.82);
}

.mcg--overlay .mcg-card__link {
	color: #ffffff;
}

.mcg--overlay .mcg-card__icon {
	background-color: rgba(255, 255, 255, 0.18);
	color: #ffffff;
}

/* --------------------------------------------------------------- card link */

.mcg-card__cover {
	position: absolute;
	inset: 0;
	z-index: 3;
	border-radius: inherit;
}

.mcg-card__cover:focus-visible {
	outline: 2px solid var(--mcg-accent);
	outline-offset: 3px;
}

.mcg-card__cover-label {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	border: 0;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* ------------------------------------------------------------- placeholder */

.mcg-ph {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 12px;
	color: #93a1ba;
	text-align: center;
	background-image: linear-gradient(
		160deg,
		rgba(47, 107, 255, 0.12) 0%,
		rgba(47, 107, 255, 0.04) 45%,
		rgba(148, 163, 184, 0.14) 100%
	);
}

.mcg--overlay .mcg-ph {
	background-image: linear-gradient( 160deg, #1e293b 0%, #0f172a 55%, #1e3a8a 100% );
	color: rgba(255, 255, 255, 0.5);
}

.mcg-ph__icon {
	width: 24px;
	height: 24px;
	fill: currentColor;
}

.mcg-ph__label {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1.3;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 1024px) {
	.mcg__grid {
		--mcg-cols: 2;
	}
}

@media (max-width: 600px) {
	/* Matches the Columns control's own phone default, so the two agree
	   whether or not the control has been touched. Each tile carries a line of
	   copy, and two across a phone leaves that copy wrapping every few words. */
	.mcg__grid {
		--mcg-cols: 1;
	}

	.mcg {
		--mcg-card-pr: 16px;
		--mcg-card-pb: 16px;
		--mcg-card-pl: 16px;
	}

	.mcg-card__name {
		font-size: 16px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.mcg-card,
	.mcg-card__link-icon {
		transition: none;
	}

	.mcg-card:hover,
	.mcg-card:focus-within {
		transform: none;
	}

	.mcg-card:hover .mcg-card__link-icon {
		transform: none;
	}
}
