/*
 * Feature hub_layout: the card list on the Resource Centre, search results and article archives.
 *
 * Loaded only while the switch is on and only on those pages, after base.css (inc/features/hub-layout.php). Every rule is
 * scoped under body.cc-feature-hub_layout, which inc/features.php adds while the switch is on, so nothing here can change a
 * page that has the switch off.
 *
 * The markup this styles (patterns/hub-all-resources.php, hub-all-resources-page.php, templates/archive.html, search.html,
 * index.html):
 *   .cc-listing > .wp-block-query > ul.wp-block-post-template.is-layout-grid (class cc-resource-grid on all but index.html)
 *     > li.wp-block-post > .cc-post-card > p.cc-resource-type (hub and archive only), h2 or h3.wp-block-post-title
 *       .has-xl-font-size, .wp-block-post-date (hub and archive only), .wp-block-post-excerpt.
 * The featured groups wrapper is div.cc-hub__groups in templates/home.html and page-hub.html. The plugin's own lists
 * (ul.cc-resources) are not a post template, so none of the grid rules below reach them.
 */

/*
 * Grid: as many columns as fit at 19rem each, never wider than the container (so a 320 px screen gets one column and no
 * sideways scroll). Inside the 1200 px container with 16 px gutters this gives one column at 320 and 375, two at 768 and
 * three at 1024, 1280 and 1440. The selector is longer than the class WordPress generates for the block's grid
 * (.wp-container-core-post-template-is-layout-...), so it wins without !important.
 */
body.cc-feature-hub_layout .cc-listing .wp-block-post-template.is-layout-grid {
	grid-template-columns: repeat(auto-fill, minmax(min(19rem, 100%), 1fr));
}

/* A long word in a card can never push its column wider than the track. */
body.cc-feature-hub_layout .cc-listing .wp-block-post-template.is-layout-grid > .wp-block-post {
	min-width: 0;
}

/*
 * Card titles use the "l" size instead of "xl". WordPress prints .has-xl-font-size with !important, so the override has to
 * be !important too; the longer selector makes it win. Only a card title is touched: the type label, date and excerpt keep
 * their sizes, and no heading outside a card changes.
 */
body.cc-feature-hub_layout .cc-post-card .wp-block-post-title.has-xl-font-size {
	font-size: var(--wp--preset--font-size--l, var(--cc-font-size-l)) !important;
}

/*
 * No blank band. When the core plugin is off the featured groups block prints nothing, but its wrapper keeps its padding and
 * leaves 97 to 120 px of empty space under the front door links. Hide the wrapper when it holds no featured groups. A
 * browser without :has() drops this rule and keeps today's gap, which is harmless.
 */
body.cc-feature-hub_layout .cc-hub__groups:not(:has(.cc-hub-groups)) {
	display: none;
}

/*
 * Type treatment: a short rule above the type label on a card, keyed on the data attribute that blocks/resource-type prints
 * while this switch is on. It is decoration only: a border on an empty pseudo element (no image, no extra markup, empty
 * generated text so it is not announced), in the action colour from the tokens. A border rather than a background so it
 * still draws in forced colours. The text label stays, so colour is never the only cue to the type.
 */
body.cc-feature-hub_layout .cc-post-card [data-cc-resource-type]::before {
	content: "";
	content: "" / "";
	display: block;
	width: 2rem;
	margin-bottom: var(--cc-space-xs);
	border-top: 2px solid var(--cc-color-action);
}

/*
 * Hub head: the intro paragraph stays readable over the banner picture. From 48em the open notebook in the picture sits under
 * the paragraph, so from 48em up to 63.99em (1023 px) the paragraph gets a near solid canvas panel. With the switch off the
 * worst pixel under the text measured 1.62:1 at 768 px, 2.45:1 at 900, 3.98:1 at 960 and 4.65:1 at 1000 (4.5:1 needed), so the
 * 4.5:1 line is crossed at about 993 px and the panel keeps a margin of about 30 px beyond it. Without the panel the paragraph
 * has 5.13:1 at 1023 and 5.17:1 at 1024, so from 64em a panel (it used to run to 1151 px) only put a hard vertical edge
 * across the notebook. The text does not move: the panel reaches into the gutter by its padding and takes the same amount
 * back from the margins. Below 48em the vertical gradient already gives 8.6:1 or better (measured from 320 to 767 px).
 */
@media (min-width: 48em) and (max-width: 63.99em) {
	body.cc-feature-hub_layout .cc-hub__head > p:not(.cc-kicker) {
		box-sizing: border-box;
		width: fit-content;
		max-width: calc(40rem + 2 * var(--cc-space-m));
		margin-top: calc(var(--cc-space-m) + -1 * var(--cc-space-s));
		margin-bottom: calc(-1 * var(--cc-space-s));
		margin-inline-start: calc(-1 * var(--cc-space-m));
		padding: var(--cc-space-s) var(--cc-space-m);
		background: color-mix(in srgb, var(--cc-color-canvas) 92%, transparent);
	}
}

/*
 * Breadcrumb: the separator is drawn at the end of the item before it (::after), not at the start of the item after it
 * (::before), so a trail that wraps never starts a line with "/". Same character, colour and spacing as base.css.
 */
body.cc-feature-hub_layout .cc-breadcrumbs__item + .cc-breadcrumbs__item::before {
	content: none;
}

body.cc-feature-hub_layout .cc-breadcrumbs__item:not(:last-child)::after {
	content: "/" / "";
	margin-left: var(--cc-space-xs);
	color: var(--cc-color-line-strong);
}

/*
 * Card title links: a target at least 44 px tall (--cc-target-min); a one line title link was 23 to 26 px. The link becomes a
 * block that shrinks to its text, with padding above and below (--cc-hl-pad) and an equal negative margin that takes it back,
 * so the title text stays exactly where it was and the card does not grow. The padding is what one line of text lacks (the
 * same for a longer title, which keeps the layout unchanged for any line count); min-height is the floor against rounding.
 *
 * Two steps for --cc-hl-pad, because a declaration that holds var() is never dropped at parse time: in a browser that does not
 * know the lh unit, a value that uses it would be thrown out only when the value is computed, and the property would then be
 * unset (0). So the first rule sets the plain 12 px (0.75rem) on its own, and the exact lh based value (the 44 px target less
 * one line, halved) is set inside @supports (height: 1lh), which a browser without the unit skips. A browser with lh gets the
 * second rule (same selector, later, so it wins) and the result is the same as before.
 *
 * Focus ring: the padding that makes the box 44 px tall also pushes the 2 px ring (offset 2 px) out around the whole box, so
 * it ran through the lower part of the type label above the title. While the link has keyboard focus the ring is pulled back
 * onto the title text. An outline offset applies to all four sides, so the offset becomes the 2 px gap minus the padding (a
 * negative number) and the box is given the padding the offset takes away: the same amount is added to the left and right,
 * with an equal negative margin (max-width allows for it, so the title never wraps differently), and the text stays where it
 * was while the ring sits 2 px outside it at the sides and at the bottom.
 *
 * At the top the ring may not reach above the bottom of the type label box, and that box ends exactly where the title's first
 * line box begins, so a ring 2 px outside the text would still start 4 px (gap plus ring width) above it, inside the empty
 * space under the label letters. The ring top has to move down by --cc-hl-lift (gap 2 px, ring 2 px and 1.5 px for the
 * browser dropping the fraction of an outline offset and snapping the ring to whole pixels). The outline offset cannot be
 * different at the top, so while focused the box is moved down by half of that: the top padding is cut and the bottom padding
 * grows by --cc-hl-lift / 2, the margins give the same amounts back, and the offset takes in that much more. The box keeps its
 * height (so the target stays as tall as at rest and the space around the heading does not change) and the text does not
 * move; the ring top lands on the label box bottom or just inside the title's first line box (still above the letters).
 * All of it applies only while focused, so the link box at rest is exactly as above. Colour and width stay with the global
 * focus rule in base.css (including Highlight in forced colours); only the offset and these box sizes change.
 */
body.cc-feature-hub_layout .cc-post-card .wp-block-post-title a {
	--cc-hl-pad: 0.75rem;
	display: block;
	box-sizing: border-box;
	width: fit-content;
	max-width: 100%;
	min-width: var(--cc-target-min);
	min-height: var(--cc-target-min);
	padding-block: var(--cc-hl-pad);
	margin-block: calc(-1 * var(--cc-hl-pad));
}

@supports (height: 1lh) {
	body.cc-feature-hub_layout .cc-post-card .wp-block-post-title a {
		--cc-hl-pad: max(0px, calc((var(--cc-target-min) - 1lh) / 2));
	}
}

body.cc-feature-hub_layout .cc-post-card .wp-block-post-title a:focus-visible {
	--cc-hl-lift: calc(var(--cc-focus-offset) + var(--cc-focus-width) + 1.5px);
	--cc-hl-half: calc(var(--cc-hl-lift) / 2);
	--cc-hl-wide: calc(var(--cc-hl-pad) + var(--cc-hl-half));
	--cc-hl-top: max(0px, calc(var(--cc-hl-pad) + -1 * var(--cc-hl-half)));
	max-width: calc(100% + 2 * var(--cc-hl-wide));
	padding-block-start: var(--cc-hl-top);
	padding-block-end: var(--cc-hl-wide);
	padding-inline: var(--cc-hl-wide);
	margin-block-start: calc(-1 * var(--cc-hl-top));
	margin-block-end: calc(-1 * var(--cc-hl-wide));
	margin-inline: calc(-1 * var(--cc-hl-wide));
	outline-offset: calc(var(--cc-focus-offset) + -1 * var(--cc-hl-wide));
}

/*
 * Hub search field: the whole placeholder ("Search guides, articles and pages", about 257 px) shows on a phone. In a row with
 * the Search button the field was 179 px wide at 320 and 229 px at 375 and the text was cut to "Search guides, ar". Below 30em
 * the button goes under the field, both full width, and the side padding drops from 16 to 12 px, which is enough from about
 * 330 px up. Chromium keeps about 15 px of an empty search field for its clear button, so below 330 px the placeholder steps
 * down from 16 px (15 px at 320) just far enough to fit; typed text keeps 16 px. The ellipsis marks the end if a large text
 * size or zoom still leaves too little room. From 30em the row layout is unchanged.
 *
 * Placeholder colour: the browser default grey (117, 117, 117) on the field (35, 35, 35) is 3.41:1, short of the 4.5:1 that
 * small text needs. The placeholder takes the secondary token (226, 226, 226), 12.1:1 on the field, with full opacity, the same
 * as the product search placeholder on the range page. The typed text colour is not touched.
 */
body.cc-feature-hub_layout .cc-hub__search .wp-block-search__input {
	text-overflow: ellipsis;
}

body.cc-feature-hub_layout .cc-hub__search .wp-block-search__input::placeholder {
	color: var(--cc-color-secondary);
	opacity: 1;
}

@media (max-width: 29.99em) {
	body.cc-feature-hub_layout .cc-hub__search .wp-block-search__inside-wrapper {
		flex-direction: column;
		align-items: stretch;
	}

	body.cc-feature-hub_layout .cc-hub__search .wp-block-search__input {
		flex: none;
		min-width: 0;
		padding-inline: var(--cc-space-s);
	}

	body.cc-feature-hub_layout .cc-hub__search .wp-block-search__input::placeholder {
		font-size: min(1em, calc((100vw - 5rem) / 16));
	}

	body.cc-feature-hub_layout .cc-hub__search .wp-block-search__button {
		flex: none;
		margin: 0;
	}
}
