/* Grid balance: one rule for every card grid on the site (2026-11-16 design
   cleanup, docs/design-refresh-2026-11/CLEANUP-PLAN.md, Phase 3).

   Rule: no single orphan card on any row at any width. A short last row
   stretches to fill instead of leaving a hole or one lonely card.

   How: the grid becomes 12 columns and each card spans a share of them,
   picked by card count with :has() quantity queries.

     Cards   Desktop (992+)          Tablet (768-991)        Phone (<768)
     3, 6, 9 3 per row               3 per row               1 per row
     4, 8    4 per row               2 per row               1 per row
     5       3 + 2 (the 2 widen)     3 + 2                   1 per row
     7, 10   3s, then 2 + 2          3s, then 2 + 2          1 per row
     2       2 halves                2 halves                1 per row

   Selectors carry `html body` so they outrank the per-template sheets, which
   load later in <body> at equal class specificity. Gaps stay whatever each
   grid family already sets. */

/* Specificity note: rules below are ordered and padded with :nth-child(n)
   (which matches every child) so that each later, more specific case wins
   over the general ones, and every rule outranks the page sheets' own grid
   rules (the strongest is .services-v1 .cards-5 > :nth-child(4), 0-3-0). */

/* ---------- The grids this covers ---------- */
html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):nth-child(n) {
	display: grid;
	grid-template-columns: repeat(12, minmax(0, 1fr));
	justify-content: stretch;
}
html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing) > :nth-child(n):nth-child(n) {
	/* Undo the flex sizing the flex-wrap families (sol, svc, cards-flow) used. */
	flex: none;
	width: auto;
	max-width: none;
	min-width: 0;
	margin-left: 0;
	margin-right: 0;
	grid-column: span 4;
}

@media (min-width: 768px) {
	/* Remainder of 2 (2, 5, 11): the last two take half a row each. */
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):has(> :last-child:nth-child(3n+2)) > :nth-last-child(-n+2) {
		grid-column: span 6;
	}
	/* Remainder of 1 with at least 4 cards (4, 7, 10): the last four run 2 + 2. */
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):has(> :nth-child(4)):has(> :last-child:nth-child(3n+1)) > :nth-last-child(-n+4) {
		grid-column: span 6;
	}
	/* A single card fills the row. */
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing) > :only-child:nth-child(n):nth-child(n):nth-child(n) {
		grid-column: 1 / -1;
	}
}

@media (min-width: 992px) {
	/* Exactly 4 or 8 cards: 4 per row. */
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):is(:has(> :nth-child(4):last-child), :has(> :nth-child(8):last-child)) > :nth-child(n):nth-child(n):nth-child(n) {
		grid-column: span 3;
	}
	/* Four cards in a narrow column stay 2 x 2: the four-card solution layout
	   (880px) and "How We Work", which shares its row with a heading column. */
	html body :is(.sol-grid--four, .work-grid):has(> :nth-child(4):last-child) > :nth-child(n):nth-child(n):nth-child(n):nth-child(n) {
		grid-column: span 6;
	}
	/* "Why" claim lists: three claims run one row (they sat 2 + 1). Below
	   992px they keep their existing single column. */
	html body .why-grid--flat .why-items:has(> :nth-child(3):last-child) {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

/* Location "Services Offered": five short label tiles fit one row once the
   container is full width (below 1200 they run 3 + 2). */
@media (min-width: 1200px) {
	html body .svc-grid:has(> :nth-child(5):last-child) {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}
	html body .svc-grid:has(> :nth-child(5):last-child) > :nth-child(n):nth-child(n):nth-child(n) {
		grid-column: auto;
	}
}

@media (min-width: 768px) and (max-width: 991px) {
	/* Exactly 8 cards: 2 per row on tablet. */
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):has(> :nth-child(8):last-child) > :nth-child(n):nth-child(n) {
		grid-column: span 6;
	}
}

/* Phone: every card grid is one column. */
@media (max-width: 767px) {
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing):nth-child(n) {
		grid-template-columns: minmax(0, 1fr);
	}
	html body :is(.cards-3, .stats-grid, .res-grid, .sol-grid, .work-grid, .cs-grid, .team-grid, .hub-grid, .svc-grid, .block-team-listing__listing) > :nth-child(n):nth-child(n) {
		grid-column: 1 / -1;
	}
}

/* Testimonial slider (slick): every card in the row matches the tallest one,
   and the reviewer line sits at the bottom of each card. */
html body .block-review .slick-track {
	display: flex;
}
html body .block-review .slick-slide {
	float: none;
	height: auto;
}
html body .block-review .slick-slide > div,
html body .block-review .block-review__item {
	height: 100%;
}
html body .block-review .block-review__copy {
	height: 100%;
	justify-content: space-between;
}
