/**
 * Patterns
 *
 * Loads on every page. Sections were separate files until the
 * October 2026 merge; their old names are kept in the section headers.
 */


/* ==========================================================================
   Card
   ========================================================================== */

/**
 * Card Component
 *
 * A linkable unit: an optional image plus a text group, usually repeated
 * in a grid. Colors come from the surrounding scheme (or a scheme class on
 * the card itself); padding comes from the shared --box-padding. The only
 * card-specific variables are:
 *
 *   --card-gap          space between image and text when inset or unboxed
 *   --card-text-gap     space between items in the text group
 *   --card-image-basis  image width in a row layout
 *   --card-small-image-basis  minimum width of a size-small image (.alignwide
 *                             sets it to one column of a four-column grid)
 *
 * Bleed (default): a boxed card (Fill, Outline, background or scheme) runs
 * the image to the edge and pads only the text group.
 * Inset: .has-outer-padding, or padding set in the editor, pads the whole
 * card, so the image sits inside the same margin as the text.
 *
 * @reference
 * - https://carbondesignsystem.com/components/tile/usage/
 * - https://playbook.ebay.com/design-system/components/card
 */

/* Defaults: zero specificity, so schemes, styles and modifiers win */
:where(.wp-block-group.card) {
	--card-gap:         var(--wp--custom--root--block-gap);
	--card-text-gap:    var(--wp--custom--spacing--small);
	--card-image-basis: 33.33%;

	background-color: transparent;
}

.wp-block-group.card {
	container-type: inline-size;
	position:       relative;

	/* Boxed cards clip their bleeding image to the box */
	&:is(.is-style-fill, .is-style-outline, .has-background, [class*="-scheme"]) {
		overflow: hidden;
	}

	/* Wide card: a small image takes one column of a four-column grid */
	&.alignwide {
		--card-small-image-basis: calc((100% - 3 * var(--wp--custom--root--block-gap)) / 4);
	}

	/* Wider padding on larger screens */
	&.has-wide-padding {
		--box-padding: var(--wp--custom--spacing--large);

		@media all and (min-width: 40rem) {
			--box-padding: var(--wp--custom--spacing--x-large);
		}
	}

	/* Outer group's Layout set to "Row" or "Stack" */
	&.is-layout-flex {
		align-items: stretch;
		gap:         var(--card-gap);

		/* "Row" with "Allow to wrap" off */
		&.is-nowrap > .wp-block-group {
			flex-grow: 1;
		}

		/* Pulls the image before the text */
		&.is-reverse > :is(.wp-block-image, .wp-block-post-featured-image) {
			order: -1;
		}
	}

	&.is-layout-flex.is-vertical > .wp-block-group {
		flex-grow: 1;
	}

	/* Boxed card: image bleeds, text group is padded */
	&:is(.is-style-fill, .is-style-outline, .has-background, [class*="-scheme"]) {
		gap: 0;

		> .wp-block-group {
			padding: var(--box-padding);
		}

		/* Inset: the whole card is padded instead */
		&:is(.has-outer-padding, [style*="padding"]) {
			gap: var(--card-gap);

			> .wp-block-group {
				padding: 0;
			}
		}

		&.has-outer-padding:not([style*="padding"]) {
			padding: var(--box-padding);
		}
	}

	/* Text group */
	> .wp-block-group {
		margin: 0;

		&.is-layout-flex {
			align-items: flex-start;
			gap:         var(--card-text-gap);
		}

		:is(.wp-block-paragraph, .wp-block-post-excerpt) {
			max-inline-size:     50ch;
			margin-inline-start: 0 !important;
		}
	}

	/* Linked heading or title: the whole card is the click target */
	&:has(:is(.wp-block-heading, .wp-block-post-title) > a) {
		@media (hover: hover) and (pointer: fine) {
			&:hover {
				color:        var(--fg-hover);
				border-color: var(--fg-hover);
			}

			&:has(img):hover img {
				filter: brightness(0.9);
			}
		}

		/* Outline the card when the linked heading has keyboard focus */
		&:focus-within {
			outline:        var(--wp--custom--root--thickness-hover) solid currentColor;
			outline-offset: var(--wp--custom--root--thickness-hover);
		}

		/* Keeps the image from trapping the ::before click target */
		> :is(.wp-block-image, .wp-block-post-featured-image) {
			position: static;
		}
	}

	:is(.wp-block-heading, .wp-block-post-title) > a {
		color: inherit;

		&:focus {
			outline: none;
		}

		&::before {
			content:  "";
			position: absolute;
			inset:    0;
			z-index:  1;
		}
	}

	/* Card image */
	> :is(.wp-block-image, .wp-block-post-featured-image) img {
		display:     block; /* kills the inline gap below the img */
		block-size:  auto;  /* natural aspect ratio when stacked */
		inline-size: 100%;
		object-fit:  cover;
	}

	/* Card image flex-basis by size, in a row layout */
	&.is-layout-flex:not(.is-vertical) {
		> .wp-block-group {
			flex:      1 1 0%;
			min-width: 0;
		}

		> :is(.wp-block-image, .wp-block-post-featured-image) {
			flex-grow:      0;
			flex-shrink:    0;
			display:        flex;
			flex-direction: column;
			flex-basis:     inherit;

			& img {
				flex-grow:      1;
				flex-shrink:    1;
				flex-basis:     auto;
				min-block-size: 0;
			}

			&.size-small {
				--card-image-basis: 12rem;
				flex-basis: max(var(--card-small-image-basis, 0px), calc(var(--card-image-basis) + (var(--box-padding, 0px) * 2)));
				align-self: flex-start;
				padding:    var(--box-padding, 0px);

				& img {
					flex-grow:  0;
					block-size: auto;
				}

				@container (max-width: 30rem) {
					flex-basis: 100%;

					& img {
						box-sizing:      content-box;
						max-inline-size: var(--card-image-basis);
					}
				}

				@container (min-width: 40rem) {
					--card-image-basis: 10rem;
				}
			}

			@container (min-width: 20rem) {
				flex-basis: var(--card-image-basis);
			}

			@container (min-width: 29rem) {
				&:is(.size-large, .size-full) {
					--card-image-basis: 50%;
				}
			}

			@container (min-width: 39rem) {
				&.size-full {
					--card-image-basis: 66.66%;
				}
			}
		}
	}
}


/* Cards in a Query Loop grid fill the row height */
.wp-block-post-template.is-layout-grid > li:has(> .wp-block-group.card) {
	display:        flex;
	flex-direction: column;

	> .wp-block-group.card {
		flex-grow: 1;
	}
}

/* Card Variants */

.card-grid.cards-have-arrow-right-icons :is(.wp-block-heading, .wp-block-post-title) > a {
	display: flex;
	align-content: center;
	justify-content: space-between;
}

.tile-card,
.tile-card-grid > .wp-block-group {
	.wp-block-group {
		min-block-size: 12rem;
	}
	.wp-block-group:has(:is(h2,.wp-block-heading.has-x-large-font-size)) {
		min-block-size: 18rem;
	}
}

.card-grid.profile-grid {
	.wp-block-group {
		font-size: var(--wp--custom--font-size--small);

		& h4 {
			font-size: inherit;
		}
	}

	.wp-block-group > .wp-block-group.is-vertical {
		gap: 0;
	}
}


/* ==========================================================================
   Feature
   ========================================================================== */

/**
 * Feature Component
 *
 * A section-like box: padded, holding columns, Show/Hide disclosures and
 * accordions. Laid out, not clicked. Colors come from the scheme; padding
 * is the shared --box-padding, larger than a card's by default.
 *
 * @reference https://playbook.ebay.com/design-system/components/banner
 */

/* Defaults: zero specificity, so modifiers win */
:where(.feature, .is-feature) {
	--box-padding: var(--wp--custom--spacing--large);

	@media all and (min-width: 40rem) {
		--box-padding: var(--wp--custom--spacing--x-large);
	}
}

:is(.feature, .is-feature) {
	padding-block: var(--box-padding);

	&.has-narrow-padding {
		--box-padding: var(--wp--custom--spacing--medium);

		@media all and (min-width: 40rem) {
			--box-padding: var(--wp--custom--spacing--large);
		}
	}

	&:is(.is-style-fill, .is-style-outline, [class*="-scheme"]) {
		padding-inline: var(--box-padding);
	}

	&.is-vertical {
		gap: 0;
	}


	.wp-block-columns.has-wide-column-gap,
	&.alignfull .wp-block-columns {
		column-gap: var(--wp--custom--spacing--x-large);
	}

	> details {
		inline-size:        100%;
		margin-block:       0;
		margin-block-start: var(--box-padding);
		border-block-start: 1px solid var(--border);

		> :is(.wp-block-group, .wp-block-columns) {
			margin-block:      0;
			padding-block-end: var(--box-padding);
		}

		> .wp-block-columns + .wp-block-columns {
			margin-block-start:  var(--box-padding);
			padding-block-start: var(--box-padding);
			border-block-start:  1px solid var(--border);
		}

		&.has-summary-at-end {
			display:        flex;
			flex-direction: column;

			> :is(.wp-block-group, .wp-block-columns) {
				padding-block-end: 0;
			}

			& summary {
				order: 2;
			}
		}
	}

	& summary {
		display:                   inline-block;
		padding-block:             var(--box-padding);
		padding-inline-end:        var(--box-padding);
		font-weight:               600;
		line-height:               1;
		text-decoration:           var(--wp--custom--root--text-decoration);
		text-decoration-thickness: var(--wp--custom--root--thickness);
		text-underline-offset:     var(--wp--custom--root--underline-offset);

		&::before {
			content: "Show ";
		}

		@media (hover: hover) {
			&:hover {
				text-decoration-thickness: var(--wp--custom--root--thickness-hover);
			}
		}
	}

	& details[open] {
		padding-block-start: var(--box-padding);

		& summary::before {
			content: "Hide ";
		}
	}

	.wp-block-image img {
		inline-size: 100%;
		block-size:  auto;
	}
}


:is(main, div:where(.wp-block-post-content.is-root-container)) > aside:has(.feature) {
	padding: 0;

	.feature {
		padding: 0;
		margin:  0;
	}

	.wp-block-accordion-item {
		padding-block-end: 0;
		border-top:        none;
	}

	.wp-block-accordion-heading {
		padding:   0;
		font-size: var(--wp--custom--font-size--medium);
	}

	.wp-block-accordion-heading__toggle {
		margin-block:   0;
		padding-block:  var(--wp--custom--spacing--large);
		padding-inline: var(--box-padding);
	}

	.is-open .wp-block-accordion-heading__toggle {
		padding-block-start: var(--box-padding);
		padding-block-end:   var(--wp--custom--spacing--medium);
	}

	.is-open .wp-block-accordion-panel {
		margin:            0;
		padding-inline:    var(--box-padding);
		padding-block-end: var(--box-padding);
	}
}


/* ==========================================================================
   Page Header
   ========================================================================== */

/* --- Page Header --- */

:root :is(main, div:where(.wp-block-post-content.is-root-container)) > header {
	+ * {
		margin-block-start: var(--wp--custom--spacing--x-large);
	}
}


:is(.page, .post-type-page, .blog, .archive) :is(main, div:where(.wp-block-post-content.is-root-container)) > header {
	:is(.wp-block-heading, .wp-block-post-title, .wp-block-query-title) {
		@media screen and (min-width: 40rem) {
			font-size: var(--wp--custom--font-size--xxx-large);
		}
	}
}


.wp-block-template-part:has(.site-breadcrumbs) {
	& a {
		color: inherit;
	}
}


/* ==========================================================================
   Table Of Contents
   ========================================================================== */

/**
 * Table of contents
 */
.is-table-of-contents {
	margin-block: var(--wp--custom--spacing--large);
	font-size: var(--wp--custom--font-size--small);

	& summary {
		display: inline-block;
		list-style: none;
		padding-block:  var(--wp--custom--button--padding-block);
		padding-inline: var(--wp--custom--button--padding-inline);
		border:         1px solid currentColor;
		border-radius:  var(--wp--custom--spacing--medium);
		background:     transparent;
		color: 	        var(--wp--custom--color--brand);

		&:hover {
			color: var(--wp--custom--color--brand--dark);
			text-decoration: var(--wp--custom--root--text-decoration);
			text-decoration-thickness: var(--wp--custom--root--thickness-hover);
			text-underline-offset: var(--wp--custom--root--underline-offset);
			text-decoration-skip-ink: none;
		}
	}

	&[open] summary {
		border-radius: var(--wp--custom--spacing--medium) var(--wp--custom--spacing--medium) 0 0;
		border-bottom: 0;
	}

	.wp-block-group {
		padding: var(--wp--custom--spacing--large);
		padding-block-start: var(--wp--custom--spacing--medium);
		margin-block-start: 0 !important;
		border: 1px solid var(--wp--custom--color--brand);
		border-radius: 0 var(--wp--custom--spacing--medium) var(--wp--custom--spacing--medium) var(--wp--custom--spacing--medium);
		background: var(--wp--custom--color--background);

		& ul {
			list-style: none;
			padding-inline-start: 0;

			& li + li {
				margin-block-start: var(--wp--custom--spacing--small);
			}
		}
	}
}
