/*
 * Pot choice under a plant (knowledge-views.php, frontend/plant-container.js).
 * Built in the bouquet builder's language: native radios styled as choice
 * cards, an apricot selected state with an ink rim, and a paper order bar
 * with a 1px ink rim and 16px corners that pairs the plant with the chosen
 * pot, holds the running total and the one action. Flat surfaces, no
 * shadows; icons come from the theme set (zf_brand_icon).
 *
 * Motion follows docs/design/design.json: ease-out under 300ms, transform
 * and opacity only. The cards sprout into place once when the list arrives,
 * waiting is the garden sprout, and the total bumps once when it changes.
 * Reduced motion keeps opacity fades only.
 */

.zf-pot-fit {
	--pot-radius: 16px;
	--pot-fast: 140ms;
	--pot-base: 220ms;
	container: pot-fit / inline-size;
	display: grid;
	gap: clamp(1.25rem, 0.9rem + 1.4vw, 2rem);
	color: var(--ink);
}
.zf-pot-fit .zf-ui-icon {
	flex: none;
	inline-size: 1.25em;
	block-size: 1.25em;
}

/* ---- Heading --------------------------------------------------------------- */
.zf-pot-fit__head {
	display: flex;
	align-items: flex-start;
	gap: clamp(0.85rem, 0.6rem + 1vw, 1.25rem);
}
.zf-pot-fit__mark {
	flex: none;
	display: grid;
	place-items: center;
	inline-size: clamp(3rem, 2.6rem + 1.4vw, 3.75rem);
	aspect-ratio: 1;
	border: 1px solid var(--ink);
	border-radius: 12px;
	background: var(--leaf-tint);
}
.zf-pot-fit__mark .zf-ui-icon {
	inline-size: 62%;
	block-size: 62%;
}
.zf-pot-fit__heading {
	display: grid;
	gap: 0.4rem;
	min-inline-size: 0;
}
.zf-pot-fit__heading h2 {
	margin: 0;
	font-size: clamp(1.75rem, 1.2rem + 2vw, 2.75rem);
	line-height: 1.12;
	color: var(--forest);
	text-wrap: balance;
}
.zf-pot-fit__heading p {
	margin: 0;
	max-inline-size: 62ch;
	color: var(--muted);
	font-size: 1rem;
	line-height: 1.65;
	text-wrap: pretty;
}

/* ---- Form ------------------------------------------------------------------ */
.zf-pot-fit__form {
	display: grid;
	gap: 1rem;
	margin: 0;
}
.zf-pot-fit__options {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 14.5rem), 1fr));
	gap: 1rem;
}
.zf-pot-fit[data-state='empty'] .zf-pot-fit__options,
.zf-pot-fit[data-state='error'] .zf-pot-fit__options:empty {
	display: none;
}

/* ---- Choice card ----------------------------------------------------------- */
.zf-pot-card {
	position: relative;
	display: grid;
	grid-template-rows: 1fr auto;
	min-inline-size: 0;
	border: 1px solid var(--line);
	border-radius: var(--pot-radius);
	background: var(--card);
	overflow: clip;
	transition:
		border-color var(--pot-fast) ease,
		background-color var(--pot-fast) ease;
}
.zf-pot-card__choice {
	position: relative;
	display: grid;
	grid-template-rows: auto 1fr;
	gap: 0;
	font-size: 1rem;
	min-inline-size: 0;
	cursor: pointer;
	font-weight: 400;
	-webkit-tap-highlight-color: transparent;
}
/* The native radio stays real and covers the whole choice, so a tap anywhere
   on the picture or text selects it and assistive technology reads a radio. */
.zf-pot-card__input {
	position: absolute;
	inset: 0;
	z-index: 1;
	inline-size: 100%;
	block-size: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}
.zf-pot-card__media {
	position: relative;
	display: grid;
	place-items: center;
	aspect-ratio: 1;
	background: var(--tint);
	overflow: clip;
}
.zf-pot-card__media img {
	position: absolute;
	inset: 0;
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
	mix-blend-mode: multiply;
	transition: scale 300ms var(--ease-out);
}
.zf-pot-card__media .zf-pot-card__fallback {
	inline-size: 38%;
	block-size: 38%;
	opacity: 0.8;
}
.zf-pot-card__tick {
	position: absolute;
	inset-block-start: 0.75rem;
	inset-inline-end: 0.75rem;
	display: grid;
	place-items: center;
	inline-size: 2rem;
	block-size: 2rem;
	border: 1px solid var(--line-strong);
	border-radius: 8px;
	background: var(--paper);
	transition:
		background-color var(--pot-fast) ease,
		border-color var(--pot-fast) ease;
}
.zf-pot-card__tick .zf-ui-icon {
	inline-size: 1.3rem;
	block-size: 1.3rem;
	opacity: 0;
	scale: 0.4;
	--zf-icon-ink: var(--paper);
	--zf-icon-accent: var(--paper);
	--zf-icon-sage: var(--paper);
	transition:
		opacity var(--pot-fast) ease,
		scale var(--pot-base) var(--ease-out);
}
.zf-pot-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding: 0.9rem 1rem 1rem;
	min-inline-size: 0;
	transition: background-color var(--pot-fast) ease;
}
.zf-pot-card__badges {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
}
.zf-pot-card__badges:empty {
	display: none;
}
.zf-pot-card__badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.15rem 0.5rem;
	border-radius: 6px;
	font-size: 0.8rem;
	font-weight: 600;
	line-height: 1.5;
}
.zf-pot-card__badge .zf-ui-icon {
	inline-size: 1rem;
	block-size: 1rem;
}
.zf-pot-card__badge[data-badge='shop'] {
	background: var(--coral);
	color: var(--coral-ink);
	--zf-icon-ink: var(--coral-ink);
	--zf-icon-accent: var(--coral-ink);
	--zf-icon-sage: var(--coral-ink);
}
.zf-pot-card__badge[data-badge='measured'] {
	background: var(--leaf-tint);
	color: var(--forest);
}
.zf-pot-card__name {
	font-family: Fredoka, system-ui, sans-serif;
	font-size: 1.12rem;
	font-weight: 700;
	line-height: 1.3;
	text-wrap: balance;
}
.zf-pot-card__specs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.15rem 0.85rem;
	font-size: 0.85rem;
	color: var(--muted);
}
.zf-pot-card__spec {
	display: inline-flex;
	gap: 0.3rem;
}
.zf-pot-card__spec b {
	font-weight: 600;
	color: var(--ink);
}
.zf-pot-card__note {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	overflow: hidden;
	font-size: 0.875rem;
	line-height: 1.55;
	color: var(--muted);
}
.zf-pot-card__price {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.25rem 0.6rem;
	margin-block-start: auto;
	padding-block-start: 0.35rem;
}
.zf-pot-card__price bdi {
	font-size: 1.2rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}
.zf-pot-card__demo {
	font-size: 0.78rem;
	color: var(--muted);
}
.zf-pot-card__link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	min-block-size: 44px;
	padding: 0.55rem 1rem;
	border-block-start: 1px solid var(--line);
	color: var(--forest);
	font-size: 0.92rem;
	font-weight: 600;
	text-decoration: none;
	transition:
		background-color var(--pot-fast) ease,
		color var(--pot-fast) ease;
}
.zf-pot-card__link svg {
	flex: none;
	inline-size: 1.15rem;
	block-size: 1.15rem;
	transition: translate var(--pot-base) var(--ease-out);
}
.zf-pot-card__link:focus-visible {
	outline: 3px solid var(--ink);
	outline-offset: -3px;
}

/* Selected: the builder's apricot choice with an ink rim and a filled tick. */
.zf-pot-card:has(.zf-pot-card__input:checked) {
	border-color: var(--ink);
}
.zf-pot-card:has(.zf-pot-card__input:checked) .zf-pot-card__body {
	background: var(--apricot-tint);
}
.zf-pot-card:has(.zf-pot-card__input:checked) .zf-pot-card__tick {
	background: var(--ink);
	border-color: var(--ink);
}
.zf-pot-card:has(.zf-pot-card__input:checked) .zf-pot-card__tick .zf-ui-icon {
	opacity: 1;
	scale: 1;
}
.zf-pot-card:has(.zf-pot-card__input:checked) .zf-pot-card__link {
	border-block-start-color: var(--ink);
}
.zf-pot-card:has(.zf-pot-card__input:focus-visible) {
	outline: 3px solid var(--ink);
	outline-offset: 4px;
}
.zf-pot-card:has(.zf-pot-card__input:disabled) .zf-pot-card__choice {
	cursor: progress;
}

@media (hover: hover) and (pointer: fine) {
	.zf-pot-card:hover {
		border-color: var(--line-strong);
	}
	.zf-pot-card:has(.zf-pot-card__input:checked):hover {
		border-color: var(--ink);
	}
	.zf-pot-card__choice:hover .zf-pot-card__media img {
		scale: 1.04;
	}
	.zf-pot-card__choice:hover .zf-pot-card__tick {
		border-color: var(--ink);
	}
	.zf-pot-card__link:hover {
		background: var(--leaf-tint);
	}
	.zf-pot-card__link:hover svg {
		translate: calc(-3px * var(--dir, 1)) 0;
	}
	.zf-pot-card__link:dir(ltr):hover svg {
		translate: 3px 0;
	}
}

/* Waiting placeholders, shown only until the list arrives. */
.zf-pot-card--waiting {
	display: grid;
	grid-template-rows: auto;
	align-content: start;
	gap: 0.6rem;
	padding-block-end: 1.1rem;
	pointer-events: none;
}
.zf-pot-card__line {
	block-size: 0.85rem;
	margin-inline: 1rem;
	border-radius: 4px;
	background: var(--tint);
}
.zf-pot-card__line--short {
	inline-size: 45%;
}

/* ---- Order bar ------------------------------------------------------------- */
.zf-pot-fit__bar {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.75rem 1rem;
	padding: 0.75rem;
	padding-inline-start: 1rem;
	border: 1px solid var(--line-strong);
	border-radius: var(--pot-radius);
	background: var(--paper);
	transition: border-color var(--pot-base) ease;
}
.zf-pot-fit__bar[hidden] {
	display: none;
}
.zf-pot-fit__bar[data-ready] {
	border-color: var(--ink);
}
.zf-pot-fit__pair {
	display: flex;
	align-items: center;
	gap: 0.4rem;
}
.zf-pot-fit__thumb {
	--thumb: 3.25rem;
	display: grid;
	place-items: center;
	inline-size: var(--thumb);
	block-size: var(--thumb);
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--tint);
	overflow: clip;
}
.zf-pot-fit__thumb img {
	grid-area: 1 / 1;
	inline-size: 100%;
	block-size: 100%;
	min-block-size: 0;
	object-fit: cover;
	mix-blend-mode: multiply;
}
.zf-pot-fit__thumb .zf-ui-icon {
	inline-size: 60%;
	block-size: 60%;
}
.zf-pot-fit__thumb--pot:not([data-filled]) {
	border: 1px dashed var(--line-strong);
	background: var(--card);
}
.zf-pot-fit__thumb--pot:not([data-filled]) .zf-ui-icon {
	opacity: 0.55;
}
.zf-pot-fit__thumb--pot[data-filled] {
	border-color: var(--ink);
}
.zf-pot-fit__join {
	display: grid;
	place-items: center;
	color: var(--muted);
}
.zf-pot-fit__join .zf-ui-icon {
	inline-size: 1.1rem;
	block-size: 1.1rem;
	--zf-icon-ink: var(--muted);
}
.zf-pot-fit__sum {
	margin: 0;
	min-inline-size: 0;
	line-height: 1.45;
}
.zf-pot-fit__total {
	display: inline-block;
	font-size: 1.05rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	transform-origin: var(--pot-origin, right) center;
}
.zf-pot-fit__total:dir(ltr) {
	--pot-origin: left;
}
.zf-pot-fit__hint {
	color: var(--muted);
	font-size: 0.95rem;
}
.zf-pot-fit__add {
	min-block-size: 48px;
	white-space: nowrap;
}
.zf-pot-fit__add .zf-ui-icon {
	--zf-icon-ink: currentColor;
	--zf-icon-accent: currentColor;
	--zf-icon-sage: currentColor;
}
.zf-pot-fit__add[aria-busy='true'] > .zf-ui-icon {
	display: none;
}
.zf-pot-fit__add:disabled:not([aria-busy='true']) {
	cursor: not-allowed;
}

/* ---- Note: waiting, nothing fits, error, added -------------------------- */
.zf-pot-fit__note {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}
.zf-pot-fit__note[data-tone=''] {
	display: contents;
}
.zf-pot-fit__note-icon {
	display: none;
	flex: none;
	place-items: center;
}
.zf-pot-fit__note-icon .zf-ui-icon {
	inline-size: 1.75rem;
	block-size: 1.75rem;
}
.zf-pot-fit__note[data-tone='empty'] [data-tone-icon='empty'],
.zf-pot-fit__note[data-tone='error'] [data-tone-icon='error'],
.zf-pot-fit__note[data-tone='added'] [data-tone-icon='added'] {
	display: grid;
}
.zf-pot-fit__status {
	margin: 0;
	line-height: 1.55;
}
.zf-pot-fit__status:empty {
	display: none;
}
.zf-pot-fit__note[data-tone='loading'] {
	color: var(--muted);
}
.zf-pot-fit__note[data-tone='loading']::before {
	content: '';
	flex: none;
	inline-size: 1.4rem;
	block-size: 1.4rem;
	background: var(--leaf);
	-webkit-mask: var(--sprout) center / contain no-repeat;
	mask: var(--sprout) center / contain no-repeat;
}
.zf-pot-fit__note[data-tone='empty'],
.zf-pot-fit__note[data-tone='error'],
.zf-pot-fit__note[data-tone='added'] {
	padding: 0.9rem 1.1rem;
	border: 1px solid var(--line);
	border-radius: var(--pot-radius);
	background: var(--card);
}
.zf-pot-fit__note[data-tone='empty'] {
	background: var(--leaf-tint);
	border-color: transparent;
}
.zf-pot-fit__note[data-tone='error'] {
	border-color: var(--danger);
	background: color-mix(in oklch, var(--danger) 6%, var(--paper));
}
.zf-pot-fit__note[data-tone='error'] .zf-ui-icon {
	--zf-icon-ink: var(--danger);
	--zf-icon-accent: var(--danger);
}
.zf-pot-fit__note[data-tone='added'] {
	border-color: var(--forest);
	background: var(--leaf-tint);
}
.zf-pot-fit__note .text-link {
	font-weight: 700;
	white-space: nowrap;
}

/* ---- Narrow column: list rows instead of tall cards ---------------------- */
@container pot-fit (max-inline-size: 34rem) {
	.zf-pot-fit__options {
		grid-template-columns: minmax(0, 1fr);
		gap: 0.75rem;
	}
	.zf-pot-card__choice {
		grid-template-columns: 6.5rem minmax(0, 1fr);
		grid-template-rows: auto;
	}
	.zf-pot-card__media {
		aspect-ratio: auto;
		min-block-size: 100%;
	}
	.zf-pot-card__tick {
		inset-block-start: 0.6rem;
		inset-inline-end: 0.6rem;
		inline-size: 1.75rem;
		block-size: 1.75rem;
	}
	.zf-pot-card__body {
		padding: 0.75rem 0.85rem 0.85rem;
		padding-inline-end: 2.9rem;
	}
	.zf-pot-card__note {
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}
	.zf-pot-card--waiting {
		grid-template-columns: 6.5rem minmax(0, 1fr);
		grid-template-rows: 0.85rem 0.85rem;
		align-content: center;
		padding-block: 0;
		min-block-size: 6.5rem;
	}
	.zf-pot-card--waiting .zf-pot-card__media {
		grid-row: 1 / span 2;
		align-self: stretch;
		margin-block: -1px;
	}
	.zf-pot-card--waiting {
		align-items: center;
	}
	.zf-pot-fit__bar {
		grid-template-columns: auto minmax(0, 1fr);
		padding: 0.75rem;
	}
	.zf-pot-fit__add {
		grid-column: 1 / -1;
		inline-size: 100%;
	}
	.zf-pot-fit__thumb {
		--thumb: 2.85rem;
	}
}

/* ---- Motion ---------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
	.zf-pot-fit[data-state='ready'] .zf-pot-card {
		animation: zf-pot-in 260ms var(--ease-out) backwards;
		animation-delay: calc(var(--i, 0) * 45ms);
	}
	.zf-pot-card:active:not(:has(.zf-pot-card__link:active)) {
		scale: 0.985;
	}
	.zf-pot-card {
		transition:
			border-color var(--pot-fast) ease,
			background-color var(--pot-fast) ease,
			scale var(--pot-fast) var(--ease-out);
	}
	.zf-pot-fit__bar:not([hidden]) {
		animation: zf-pot-rise var(--pot-base) var(--ease-out) backwards;
	}
	.zf-pot-fit__thumb--pot[data-filled] img {
		animation: zf-pot-pop var(--pot-base) var(--ease-out);
	}
	.zf-pot-fit__total.is-bumped {
		animation: zf-pot-bump 180ms var(--ease-out);
	}
	.zf-pot-fit__note[data-tone='empty'],
	.zf-pot-fit__note[data-tone='error'],
	.zf-pot-fit__note[data-tone='added'] {
		animation: zf-pot-rise var(--pot-base) var(--ease-out) backwards;
	}
	.zf-pot-fit__note[data-tone='loading']::before {
		animation: sprout-rise 1150ms var(--ease-out) infinite;
	}
	.zf-pot-card--waiting {
		animation: zf-pot-breathe 1400ms ease-in-out infinite alternate;
	}
	@keyframes zf-pot-in {
		from {
			opacity: 0;
			transform: translateY(0.6rem);
		}
	}
	@keyframes zf-pot-rise {
		from {
			opacity: 0;
			transform: translateY(0.35rem);
		}
	}
	@keyframes zf-pot-pop {
		from {
			opacity: 0;
			transform: scale(0.82);
		}
	}
	@keyframes zf-pot-bump {
		50% {
			transform: scale(1.05);
		}
	}
	@keyframes zf-pot-breathe {
		from {
			opacity: 0.55;
		}
	}
}
@media (prefers-reduced-motion: reduce) {
	.zf-pot-fit[data-state='ready'] .zf-pot-card,
	.zf-pot-fit__bar:not([hidden]),
	.zf-pot-fit__note[data-tone='added'] {
		animation: zf-pot-fade 160ms ease backwards;
	}
	.zf-pot-card__tick .zf-ui-icon {
		scale: 1;
	}
	@keyframes zf-pot-fade {
		from {
			opacity: 0;
		}
	}
}

/* ---- Forced colours -------------------------------------------------------- */
@media (forced-colors: active) {
	.zf-pot-card:has(.zf-pot-card__input:checked) {
		outline: 3px solid Highlight;
		outline-offset: -3px;
	}
	.zf-pot-card:has(.zf-pot-card__input:checked) .zf-pot-card__tick {
		background: Highlight;
	}
	.zf-pot-fit__note[data-tone='loading']::before {
		background: CanvasText;
	}
}
