/**
 * Affiliate Directory
 *
 * The component sits inside an arbitrary host theme, so it inherits the
 * theme's typography and colour and derives every surface from `currentColor`.
 * All knobs are exposed as custom properties on `.affiliate-directory`, so a
 * theme can restyle it without fighting specificity.
 */

.affiliate-directory {
	/* Layout */
	--ad-columns: 3;
	--ad-card-gap: 1.75rem;
	--ad-card-padding: 1.5rem;
	--ad-card-radius: 0.5rem;
	--ad-row-gap: 1rem;
	--ad-logo-width: 12rem;
	--ad-logo-height: 8rem;

	/* Type. The affiliate name intentionally shares the description's size. */
	--ad-description-size: 16px;
	--ad-description-line-height: 1.6;
	--ad-meta-size: 15px;

	/* `none` lets the description fill its grid column. Set a value such as
	   68ch to cap line length instead. */
	--ad-description-max-width: none;

	/* Surfaces, derived from the inherited text colour. */
	--ad-rule: color-mix(in srgb, currentColor 14%, transparent);
	--ad-muted: color-mix(in srgb, currentColor 62%, transparent);
	--ad-accent: currentColor;

	container-type: inline-size;
	container-name: affiliate-directory;
}

/* Fallback for browsers without color-mix() support. */
@supports not (color: color-mix(in srgb, currentColor 50%, transparent)) {
	.affiliate-directory {
		--ad-rule: rgba(0, 0, 0, 0.14);
		--ad-muted: rgba(0, 0, 0, 0.62);
	}
}

/* ---------------------------------------------------------------------------
 * List and rows
 * ------------------------------------------------------------------------ */

.affiliate-directory__list {
	display: grid;
	grid-template-columns: repeat(var(--ad-columns, 3), minmax(0, 1fr));
	gap: var(--ad-card-gap);
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Grid items stretch to the tallest in their row by default; making the card a
   flex column lets its contents fill that height instead of leaving the border
   floating away from the content. */
.affiliate-directory__item {
	border: 1px solid var(--ad-rule);
	border-radius: var(--ad-card-radius);
	display: flex;
	padding: var(--ad-card-padding);
}

.affiliate-directory__row {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--ad-row-gap);
	width: 100%;
}

/* ---------------------------------------------------------------------------
 * Logo
 * ------------------------------------------------------------------------ */

.affiliate-directory__media {
	min-width: 0;
	text-align: center;
}

/* One link per row wrapping both the logo and the name, so screen reader users
   hear a single entry rather than two links to the same destination. */
.affiliate-directory .affiliate-directory__link {
	box-shadow: none;
	color: inherit;
	display: block;
	max-width: 100%;
	text-decoration: none;
}

.affiliate-directory__link:focus-visible {
	outline: 2px solid var(--ad-accent);
	outline-offset: 4px;
}

/* Offer and Shop lines, pinned to the bottom of the card so they line up
   across a row however long the descriptions run. */
.affiliate-directory__meta {
	display: flex;
	flex-direction: column;
	font-size: var(--ad-meta-size);
	gap: 0.35rem;
	line-height: var(--ad-description-line-height);
	margin-block-start: auto;
	text-align: left;
	width: 100%;
}

.affiliate-directory__offer,
.affiliate-directory__shop {
	margin: 0;
}

.affiliate-directory__meta-label {
	font-weight: 600;
}

.affiliate-directory__shop-link {
	color: inherit;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.15em;
}

.affiliate-directory__shop-link:focus-visible {
	outline: 2px solid var(--ad-accent);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
 * Description
 *
 * The size is set on the wrapper and inherited by the paragraphs wpautop()
 * generates. The paragraph rule exists because a bare `p { font-size }` in the
 * host theme would otherwise win on source order.
 * ------------------------------------------------------------------------ */

.affiliate-directory__description {
	font-size: var(--ad-description-size);
	line-height: var(--ad-description-line-height);
	max-width: var(--ad-description-max-width);
	min-width: 0;
	text-align: left;
	width: 100%;
}

.affiliate-directory__description p {
	font-size: inherit;
	line-height: inherit;
	margin: 0 0 0.75em;
}

.affiliate-directory__description p:last-child {
	margin-block-end: 0;
}

/* ---------------------------------------------------------------------------
 * Pager
 * ------------------------------------------------------------------------ */

.affiliate-directory__footer {
	align-items: center;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin-block-start: var(--ad-card-gap);
}

.affiliate-directory__load-more {
	background: none;
	border: 1px solid var(--ad-rule);
	border-radius: 999px;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: var(--ad-meta-size);
	line-height: 1.4;
	padding: 0.625rem 1.75rem;
	transition: border-color 200ms ease;
}

.affiliate-directory__load-more:hover:not(:disabled) {
	border-color: var(--ad-accent);
}

.affiliate-directory__load-more:focus-visible {
	outline: 2px solid var(--ad-accent);
	outline-offset: 2px;
}

.affiliate-directory__load-more[aria-busy='true'],
.affiliate-directory__load-more:disabled {
	cursor: default;
	opacity: 0.6;
}

.affiliate-directory__status {
	color: var(--ad-muted);
	font-size: 0.875rem;
	margin: 0;
}

@media (prefers-reduced-motion: reduce) {
	.affiliate-directory__load-more {
		transition: none;
	}
}

/* ---------------------------------------------------------------------------
 * Empty state
 * ------------------------------------------------------------------------ */

.affiliate-directory__empty {
	color: var(--ad-muted);
	margin: 0;
}

/* ---------------------------------------------------------------------------
 * Utilities
 * ------------------------------------------------------------------------ */

.affiliate-directory__screen-reader-text {
	border: 0;
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}

/* ---------------------------------------------------------------------------
 * Narrow containers
 * ------------------------------------------------------------------------ */

/* Column count steps down with the container, not the viewport, so the grid
   also adapts inside a narrow template or sidebar. */
@container affiliate-directory (max-width: 56rem) {
	.affiliate-directory__list {
		grid-template-columns: repeat(min(var(--ad-columns, 3), 2), minmax(0, 1fr));
	}
}

@container affiliate-directory (max-width: 34rem) {
	.affiliate-directory__list {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Same treatment for browsers without container query support. */
@supports not (container-type: inline-size) {
	@media (max-width: 60rem) {
		.affiliate-directory__list {
			grid-template-columns: repeat(min(var(--ad-columns, 3), 2), minmax(0, 1fr));
		}
	}

	@media (max-width: 38rem) {
		.affiliate-directory__list {
			grid-template-columns: minmax(0, 1fr);
		}
	}
}
