/*
 *  ============================================================================
 * Briefly — balanced grids..
 *
 * The Hub's own classic themes never load the Premium
 * Suite's render-guards.css, so the identical rules live here too. That is a
 * duplicated STYLESHEET, not a duplicated RULE: both files are generated from
 * the same table, and a free-tier site would otherwise keep the three-across-
 * and-one-below layout this release exists to remove.
 * ==========================================================================
 */

/*
 *  ── 5. Balanced grids — never three across and one below ────────────────────
 *
 * He is right and it is systemic. All 236 grids in the library were written as
 *
 *     grid-template-columns: repeat(auto-fit, minmax(NNNpx, 1fr))
 *
 * which means the column count is whatever happens to fit the container. Nobody
 * ever chose it, and nothing ever consulted the number of items. Meanwhile the
 * generator's own JSON skeleton asks for exactly FOUR of nearly everything —
 * four features, four services, four stats, four FAQs — and four is the worst
 * number in that system:
 *
 *     46 Grids with a >=280px floor  ->  4 items render 3 + 1 on desktop
 *    131 grids at 220-260px          ->  4 items render 3 + 1 at tablet width
 *     55 grids at <=200px            ->  4 items render 3 + 1 on a small tablet
 *
 * So at some viewport width, essentially every group in every theme orphans an
 * Item. It reads as carelessness because it is carelessness — just nobody's in
 * particular.
 *
 * Why this is CSS and not PHP: the alternative was passing an item count out of
 * 236 call sites in 35 themes, which is 236 chances to miss one and a permanent
 * obligation on every future section. The container already knows how many
 * children it has. Let it.
 *
 * The whole block is inside @supports, so a browser without :has() gets exactly
 * today's behaviour rather than a broken one.
 * --------------------------------------------------------------------------
 */

.ewpk-g {
	display: grid;
	/*
	 * The pre-:has() fallback is today's behaviour, with each grid's own
	 * density floor carried across as a custom property — so a browser
	 * without :has() renders exactly what it renders now, never worse.
	 */
	grid-template-columns: repeat( auto-fit, minmax( var( --ewpk-min, 240px ), 1fr ) );
}

@supports selector(:has(*)) {

	/* Phone: one column, always. Two columns of anything meaningful below
	   640px produces a card too narrow to read, and the orphan question does
	   not arise in a single column. */
	.ewpk-g, [class*="briefly-"] [class*="-grid-2"], [class*="briefly-"] [class*="-grid-3"], [class*="briefly-"] [class*="-grid-4"], [class*="briefly-"] [class*="-grid-5"] {
		grid-template-columns: minmax(0, 1fr);
	}

	@media (min-width: 640px) {
		/* Tablet */
		.ewpk-g:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(1):last-child) {
			grid-template-columns: repeat(1, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(2):last-child) {
			grid-template-columns: repeat(2, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(3):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(4):last-child) {
			grid-template-columns: repeat(2, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(5):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(6):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(7):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(7):last-child) > :last-child,
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(7):last-child) > :last-child,
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(7):last-child) > :last-child,
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(7):last-child) > :last-child,
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(7):last-child) > :last-child {
			grid-column: 1 / -1;
		}
		.ewpk-g:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(8):last-child) {
			grid-template-columns: repeat(2, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(9):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(10):last-child) {
			grid-template-columns: repeat(2, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(11):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(12):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
	}

	@media (min-width: 1024px) {
		/* Desktop */
		.ewpk-g:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(1):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(1):last-child) {
			grid-template-columns: repeat(1, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(2):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(2):last-child) {
			grid-template-columns: repeat(2, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(3):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(3):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(4):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(4):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(5):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(5):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(6):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(6):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(7):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(7):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(8):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(8):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(9):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(9):last-child) {
			grid-template-columns: repeat(3, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(10):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(10):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(11):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(11):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
		.ewpk-g:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-2"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-3"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-4"]:has(> :nth-child(12):last-child),
		[class*="briefly-"] [class*="-grid-5"]:has(> :nth-child(12):last-child) {
			grid-template-columns: repeat(4, minmax(0, 1fr));
		}
	}
}

/*
 *  ── 6. Inline fixed columns — the layouts §5 could never reach ──────────────
 *
 * Section §5 above governs .ewpk-g and the -grid-N classes, which is 236 of
 * the library's grids. It reaches none of the remaining 14, because those
 * write their track list as an INLINE STYLE:
 *
 *     <div style="display:grid;grid-template-columns:1fr 1fr;gap:3rem">
 *
 * An inline declaration beats every stylesheet rule that is not !important,
 * so these fourteen are the only layouts in the suite immune to all of the
 * responsive work — pr_hero_split, pr_product_detail, pr_private_enquiry,
 * pr_footer_full, cl_hero_clinical, cl_booking_location, cl_footer,
 * dr_chef_profile, dr_location, dr_footer, me_about_heritage (x2), me_footer.
 * They are the classic themes, and almost all of them are an IMAGE in one
 * track and TEXT in the other. At 1fr 1fr a phone gives each half the
 * viewport, so the copy sets in a ~180px column beside a photo and reads as
 * broken alignment. The footers are worse: 2fr 1fr 1fr never stops being
 * three columns.
 *
 * The tell that this was already known and half-fixed: pr_footer_full carries
 * its own inline <style> block with exactly this rule and an !important, for
 * that one section. The rule below covers every other section.
 *
 * Why this is CSS and not fourteen EDITS: the track lists are frozen into
 * post_content on every page already built. Editing the renderers fixes pages
 * built afterwards and nothing that is live today — the same reason the
 * anchor resolver runs at render time. The renderers are worth fixing too,
 * but second, and this is the half that reaches your site tonight.
 *
 * The selector is exact, not a guess. It requires all three of: a Briefly
 * theme wrapper, an inline `display:grid`, and a track list containing "fr "
 * — a space after a track unit, which a fixed list always has ("1fr 1fr")
 * and a responsive one never does ("minmax(240px,1fr))" ends the unit on a
 * bracket). So auto-fit grids are untouched and keep §5's behaviour.
 *
 * 760px to match .ewpk-grid, so a page never reflows at two
 * different widths.
 * --------------------------------------------------------------------------
 */

@media (max-width: 760px) {
	[class*="briefly-"][style*="display:grid"][style*="fr "],
	[class*="briefly-"] [style*="display:grid"][style*="fr "] {
		grid-template-columns: minmax(0, 1fr) !important;
	}
}

/* Tablet: a four-track footer is still four tracks at 900px. Two is the most
   a footer column list can carry legibly before the desktop layout applies. */
@media (min-width: 761px) and (max-width: 900px) {
	[class*="briefly-"][style*="display:grid"][style*="fr 1fr 1fr"],
	[class*="briefly-"] [style*="display:grid"][style*="fr 1fr 1fr"] {
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
	}
}

/*
 * The figures band's dividers and side padding are drawn for four
 * across. Below 1024px the grid is two-by-two or one column, and the same
 * padding stepped each figure further in than the last ("staircase" on a
 * phone). Below that width the figures sit flush, with space between rows.
 */
@media (max-width: 1023px) {
	.ewpk-statband { row-gap: 2rem !important; column-gap: 2rem !important; }
	.ewpk-statband > div { padding-left: 0 !important; padding-right: 0 !important; border-right: 0 !important; }
}

/*
 * An empty photo card never shows as a blank box, in any design.
 * Visitors see an unfilled photo space as .bfy-img-empty (owners, logged in,
 * still see the "add a photo" prompt). Lumen's hero already hid its empty
 * media column (hero-shapes.css); other designs wrap the space in their own
 * card — Keystone's hero card, a Terrace bento tile — which showed as a white
 * box beside the headline. A wrapper whose only content is the empty space
 * is hidden, and a grid that loses its photo column gives the text the row.
 */
[data-briefly-section] :is(div, figure, a, li)[class]:has(> .bfy-img-empty:only-child):not(.bfy-hero__media) {
	display: none !important;
}
[data-briefly-section] :is(div, section)[class]:has(> :is(div, figure)[class] > .bfy-img-empty:only-child) {
	grid-template-columns: minmax(0, 1fr) !important;
}

/*
 * The same rule, one level deeper. Atlas, and other designs, wrap the photo
 * twice: column > frame > photo (at-case-media > at-frame > empty).
 */
[data-briefly-section] :is(div, figure)[class]:has(> :is(div, figure, picture, span)[class]:only-child > .bfy-img-empty:only-child):not(.bfy-hero__media) {
	display: none !important;
}
[data-briefly-section] :is(div, section)[class]:has(> :is(div, figure)[class] > :is(div, figure, picture, span)[class]:only-child > .bfy-img-empty:only-child) {
	grid-template-columns: minmax(0, 1fr) !important;
}
/* A two-part split (photo + copy) that lost its photo: the copy keeps a
   reading measure instead of running the full container width. */
[data-briefly-section] :is(div, section)[class]:has(> :nth-child(2):last-child):has(> :is(div, figure)[class] > :is(div, figure, picture, span)[class]:only-child > .bfy-img-empty:only-child) > :not(:has(.bfy-img-empty)),
[data-briefly-section] :is(div, section)[class]:has(> :nth-child(2):last-child):has(> :is(div, figure)[class] > .bfy-img-empty:only-child) > :not(:has(.bfy-img-empty)) {
	max-width: 52rem;
}

/*
 * A figure with no number is not shown.
 * Pages built before 4.2.0 can hold a stat whose number was left blank
 * (Briefly never invents one): an empty <strong> above its label. New builds
 * drop these when the section is drawn; this covers pages already built.
 */
[data-briefly-section] :is(div, li):has(> strong:first-child:empty + :is(span, small, em, p)) {
	display: none !important;
}
