/*
 * Serviço photo mosaic ([textual_servico_mosaico]).
 *
 * The band sits at content width between the article and the footer. Vertical
 * spacing belongs to the Elementor container around it, so this file only lays
 * out the tiles.
 *
 * Two shapes stack: a lead block whose arrangement depends on how many of the
 * first three photos exist, and rows of up to three below it. Row tiles take a
 * fixed height rather than an aspect ratio, because a lone trailing photo at
 * 3:2 across the full column would tower over everything above it.
 *
 * The tile widths quoted in inc/servico-mosaico.php assume the single-serviço
 * template's 1260px content column; change them together.
 */

.tsm {
	--tsm-gap: 24px;
	--tsm-linha-altura: 280px;
	--tsm-radius: 30px;
	--tsm-media-bg: #e9e9e9;
	--tsm-focus: #fbb118;

	display: flex;
	flex-direction: column;
	gap: var(--tsm-gap);
}

.tsm__item {
	position: relative;
	min-width: 0;
	min-height: 0;
	margin: 0;
	overflow: hidden;
	border-radius: var(--tsm-radius);
	background-color: var(--tsm-media-bg);
}

/*
 * Taking the image out of flow is what lets the grid size tiles rather than
 * the other way round: an in-flow image contributes its intrinsic height to
 * the row track, so tall photos would outgrow the lead tile they are meant to
 * sit beside. Out of flow, each tile's height comes from its own aspect-ratio
 * or from the row track, and the image simply fills it.
 *
 * The selector carries two classes on purpose: Elementor ships
 * `.elementor img { height: auto }`, which outranks a single class and, on a
 * replaced element, resolves to the photo's intrinsic height instead of
 * stretching between top and bottom — leaving a strip of the tile's
 * background showing beneath every photo.
 */
.tsm .tsm__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.4s ease;
}

/*
 * The link has to fill the tile itself. Its only child is the out-of-flow
 * image, so an inline anchor would compute to zero area and nothing would be
 * clickable; stretching it also makes the whole tile the target rather than
 * whatever sliver of text-line the anchor would otherwise occupy.
 */
.tsm .tsm__link {
	position: absolute;
	inset: 0;
	display: block;
	border-radius: inherit;
}

.tsm .tsm__link:focus-visible {
	outline: 3px solid var(--tsm-focus);
	outline-offset: 3px;
}

.tsm .tsm__link:hover .tsm__img,
.tsm .tsm__link:focus-visible .tsm__img {
	transform: scale(1.05);
}

@media (prefers-reduced-motion: reduce) {
	.tsm .tsm__img {
		transition: none;
	}

	.tsm .tsm__link:hover .tsm__img,
	.tsm .tsm__link:focus-visible .tsm__img {
		transform: none;
	}
}

/* Lead block --------------------------------------------------------------- */

.tsm__bloco {
	display: grid;
	gap: var(--tsm-gap);
}

/* A single photo reads as a banner; 3:2 across the full column is too tall. */
.tsm__bloco--1 {
	grid-template-columns: 1fr;
}

.tsm__bloco--1 .tsm__item {
	aspect-ratio: 12 / 5;
}

.tsm__bloco--2 {
	grid-template-columns: 1fr 1fr;
}

.tsm__bloco--2 .tsm__item {
	aspect-ratio: 3 / 2;
}

/*
 * The mock's arrangement. Only the lead tile carries an aspect ratio: it sets
 * the block's height, and the two equal rows divide that height between the
 * stacked tiles, which lands them at 3:2 as well at content width.
 */
.tsm__bloco--3 {
	grid-template-columns: 2fr 1fr;
	grid-template-rows: 1fr 1fr;
}

.tsm__bloco--3 .tsm__item--lead {
	grid-area: 1 / 1 / 3 / 2;
	aspect-ratio: 3 / 2;
}

/* Rows below the lead block ------------------------------------------------ */

.tsm__linha {
	display: grid;
	gap: var(--tsm-gap);
}

.tsm__linha--1 {
	grid-template-columns: 1fr;
}

.tsm__linha--2 {
	grid-template-columns: repeat(2, 1fr);
}

.tsm__linha--3 {
	grid-template-columns: repeat(3, 1fr);
}

.tsm__linha .tsm__item {
	height: var(--tsm-linha-altura);
}

/* Tablet ------------------------------------------------------------------- */

@media (max-width: 1024px) {
	.tsm {
		--tsm-gap: 20px;
		--tsm-linha-altura: 220px;
	}
}

/* Mobile ------------------------------------------------------------------- */

/*
 * The lead tile goes full width and everything else pairs up beneath it. A
 * lone trailing photo keeps the full width instead of leaving a hole beside it.
 */
@media (max-width: 767px) {
	.tsm {
		--tsm-gap: 16px;
	}

	.tsm__bloco--1 .tsm__item {
		aspect-ratio: 3 / 2;
	}

	.tsm__bloco--2 {
		grid-template-columns: 1fr;
	}

	.tsm__bloco--3 {
		grid-template-columns: 1fr 1fr;
		grid-template-rows: auto;
	}

	.tsm__bloco--3 .tsm__item--lead {
		grid-area: auto;
		grid-column: 1 / -1;
	}

	.tsm__bloco--3 .tsm__item {
		aspect-ratio: 3 / 2;
	}

	.tsm__linha--2,
	.tsm__linha--3 {
		grid-template-columns: repeat(2, 1fr);
	}

	/*
	 * A row of three wraps to 2 + 1 in two columns, which would leave the last
	 * tile beside a hole. Let it take the whole width instead.
	 */
	.tsm__linha .tsm__item:last-child:nth-child(odd) {
		grid-column: 1 / -1;
	}

	.tsm__linha .tsm__item {
		height: auto;
		aspect-ratio: 3 / 2;
	}
}
