/* Reusable components: CTAs, fields, chips, dialog shell and carousel. */

/* CTA */

.cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
	/*
	 * The node draws its stroke inside a 52px box. The border is kept for the colour
	 * transitions, so the height is fixed instead, and the 1px it renders at 1x comes out
	 * of the side padding (desktop-fidelity G2).
	 */
	min-height: 52px;
	padding: 0 calc(var(--space-4) - 1px);
	border: 1.4px solid transparent;
	border-radius: var(--radius-pill);
	font-family: var(--font-body);
	font-size: var(--font-cta);
	font-weight: 500;
	line-height: 24px;
	letter-spacing: var(--ls-body);
	text-align: center;
	cursor: pointer;
	/* DISSOLVE EASE_OUT 300ms in the prototype. */
	transition: background-color var(--duration-base) var(--ease-out),
		border-color var(--duration-base) var(--ease-out),
		color var(--duration-base) var(--ease-out);
}

.cta__icon {
	flex: none;
	width: 20px;
	height: 20px;
}

.cta--primary {
	border-color: var(--color-cta-primary-bg);
	background-color: var(--color-cta-primary-bg);
	color: var(--color-cta-primary-text);
}

/* Provisional: the Figma v4 gives the red CTA no hover, so it darkens to Dark Red. */
.cta--primary:hover {
	border-color: var(--color-cta-primary-hover-bg);
	background-color: var(--color-cta-primary-hover-bg);
}

.cta--secondary {
	border-color: var(--color-cta-secondary);
	background-color: transparent;
	color: var(--color-cta-secondary);
}

/* Stroke Dark on hover fills and loses the border. */
.cta--secondary:hover {
	border-color: var(--color-cta-secondary-hover-bg);
	background-color: var(--color-cta-secondary-hover-bg);
	color: var(--color-cta-secondary-hover-text);
}

.cta--light {
	border-color: var(--color-cta-light-bg);
	background-color: var(--color-cta-light-bg);
	color: var(--color-cta-light-text);
}

.cta--light:hover {
	border-color: var(--color-cta-light-hover-bg);
	background-color: var(--color-cta-light-hover-bg);
}

.cta--dark {
	border-color: var(--color-cta-dark-bg);
	background-color: var(--color-cta-dark-bg);
	color: var(--color-cta-dark-text);
}

.cta--dark:hover {
	border-color: var(--color-cta-dark-hover-bg);
	background-color: var(--color-cta-dark-hover-bg);
}

.cta-group {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
}

@media (max-width: 479px) {
	.cta-group {
		flex-direction: column;
		align-items: stretch;
	}

	.cta-group > .cta {
		width: 100%;
	}
}

/*
 * Revealed underline. Where a link component carries a "Line 1" layer, the hover fades it
 * from opacity 0 to 1 with DISSOLVE EASE_OUT 300ms instead of toggling text-decoration.
 * The pseudo element reproduces the fade, which text-decoration cannot.
 *
 * The line is as wide as the text, never as wide as the box: apply the class to the text
 * itself, not to a container that also holds an icon or padding.
 */
.has-underline {
	position: relative;
}

.has-underline::after {
	position: absolute;
	right: 0;
	bottom: var(--underline-offset, 0);
	left: 0;
	height: var(--underline-thickness, 1.4px);
	background-color: currentColor;
	opacity: 0;
	transition: opacity var(--duration-base) var(--ease-out);
	content: '';
}

/* The class sits on the label, so the trigger is the link or the button around it. */
a:hover > .has-underline::after,
a:focus-visible > .has-underline::after,
button:hover > .has-underline::after,
button:focus-visible > .has-underline::after {
	opacity: 1;
}

/* Form field */

.field {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
}

.field__label {
	color: var(--color-text);
	font-size: var(--font-p2);
	font-weight: 500;
	line-height: 1.4;
}

.field__control {
	position: relative;
	display: flex;
	align-items: center;
}

.field__input,
.field__select {
	width: 100%;
	height: 52px;
	padding: 14px var(--space-3);
	border: 2px solid var(--color-surface-muted);
	border-radius: var(--radius-pill);
	background-color: var(--color-surface-muted);
	color: var(--color-text);
	font-size: var(--font-p2);
	font-weight: 400;
	line-height: 1.4;
	transition: border-color var(--duration-fast) var(--ease-out);
}

.field__select {
	appearance: none;
	padding-inline-end: 48px;
	cursor: pointer;
}

.field__input::placeholder {
	color: var(--color-text-placeholder);
	opacity: 0.64;
}

/* An empty select shows the placeholder option, which must look like a placeholder. */
.field__select[data-empty='true'] {
	color: var(--color-text-placeholder);
}

.field__input:focus-visible,
.field__select:focus-visible {
	border-color: var(--color-focus-ring);
	outline: 2px solid var(--color-focus-ring);
	outline-offset: 2px;
}

.field__input[aria-invalid='true'],
.field__select[aria-invalid='true'] {
	border-color: var(--color-error);
}

.field__chevron {
	position: absolute;
	right: var(--space-3);
	/* A 24 box with a 12x6 glyph in 714:6668. */
	width: 24px;
	height: 24px;
	pointer-events: none;
	color: var(--color-icon-accent);
}

.field__suffix {
	position: absolute;
	right: var(--space-3);
	color: var(--color-text-muted);
	font-size: var(--font-p2);
	pointer-events: none;
}

.field__hint {
	color: var(--color-text-muted);
	font-size: var(--font-p4);
	font-weight: 500;
	line-height: 18px;
}

/* A field without hint is label, 8, control: 85 in 714:6582. The empty hint stays for aria-describedby. */
.field__hint:empty {
	display: none;
}

/* The hints of the profit tab are Regular 14 Gray 10 (714:6760), against the Medium Gray BRAND of the yield tab. */
[data-calculator-form='profit'] .field__hint {
	color: var(--color-text);
	font-weight: 400;
}

.field__hint--error {
	color: var(--color-error);
}

/* Filter chip */

.chip {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 44px;
	padding: var(--space-1) var(--space-3);
	border-radius: var(--radius-pill);
	background-color: var(--color-surface-muted);
	color: var(--color-text);
	font-size: var(--font-p3);
	font-weight: 500;
	line-height: 1.3;
	white-space: nowrap;
	transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.chip[aria-selected='true'] {
	background-color: var(--color-selected);
	color: var(--color-text-on-brand);
}

.chip-list {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-1);
}

/*
 * Close button of the full width overlays. The circle is CSS, not part of the asset, so
 * the hover from 8% to 24% white is a plain background transition.
 */
.overlay-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	border-radius: var(--radius-pill);
	background-color: var(--color-hairline-light);
	backdrop-filter: blur(4px);
	color: var(--color-text-on-brand);
	transition: background-color var(--duration-base) var(--ease-out);
}

.overlay-close:hover {
	background-color: var(--color-hairline-light-hover);
}

.overlay-close svg {
	width: 19px;
	height: 19px;
}

/* Dialog shell */

.dialog {
	max-width: none;
	max-height: none;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	overflow: hidden;
}

.dialog:not([open]) {
	display: none;
}

.dialog__viewport {
	display: flex;
	justify-content: center;
	/*
	 * flex-start, not the default stretch: the viewport is as tall as the window, so
	 * stretch inflated the box to the full height and left a large band of dead white
	 * below short content. The spec asks for a content driven height.
	 */
	align-items: flex-start;
	width: 100%;
	height: 100%;
	padding-inline: var(--space-4);
	overflow-y: auto;
	overscroll-behavior: contain;
}

.dialog__box {
	position: relative;
	background-color: var(--color-surface);
	border-radius: var(--radius-modal);
	box-shadow: var(--shadow-modal);
}

.dialog__close {
	position: absolute;
	top: var(--space-5);
	right: var(--space-5);
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	/* Without it the UA padding of <button> squeezes the 48px glyph boxes. */
	padding: 0;
	border-radius: var(--radius-pill);
	background-color: transparent;
	color: var(--color-icon-accent);
	transition: background-color var(--duration-fast) var(--ease-out);
}

.dialog__close:hover {
	background-color: var(--color-hover-surface);
}

.dialog__close svg {
	width: 32px;
	height: 32px;
}

/* Carousel */

/*
 * The inactive dot is white in the Home carousels, which sit on Light Gray and on photos, and
 * Gray 20 in the recipes carousel, which sits on Gray 30. One variable, one modifier.
 */
.carousel {
	position: relative;
	--carousel-dot-inactive: var(--color-indicator-inactive);
}

.carousel--dots-gray {
	--carousel-dot-inactive: var(--color-indicator-inactive-muted);
}

.carousel__track {
	display: flex;
	gap: 20px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-ms-overflow-style: none;
	padding-inline: var(--container-gutter);
	scroll-padding-inline: var(--container-gutter);
}

.carousel__track::-webkit-scrollbar {
	display: none;
}

/*
 * Measured: under reduced motion the arrow still animated the track. carousel.js passes
 * behavior: 'auto' to scrollTo, and 'auto' means "use the computed scroll-behavior of the
 * element", which was smooth. The CSS has to be the one to give way.
 */
@media (prefers-reduced-motion: reduce) {
	.carousel__track {
		scroll-behavior: auto;
	}
}

.carousel__track[data-dragging='true'] {
	scroll-snap-type: none;
	scroll-behavior: auto;
	cursor: grabbing;
	user-select: none;
}

/*
 * While carousel.js owns the snapping, which is the whole time a carousel has an autoplay,
 * the browser must not pull the track to the nearest card: it fights the slide, and being
 * handed control back mid position re-anchors the track under the pointer. The script
 * aligns to a card at the end of every gesture instead.
 */
.carousel__track[data-manual-snap='true'] {
	scroll-snap-type: none;
	scroll-behavior: auto;
}

.carousel__item {
	flex: none;
	scroll-snap-align: start;
	-webkit-user-drag: none;
	/* Keyboard focus inside a clipped track must scroll the track, not the body. */
	scroll-margin-inline: var(--container-gutter);
}

/*
 * A row that fits the window is centred on the page (client round 1, item 2): the auto
 * margins share the free space between the two gutters. They resolve to 0 when the track
 * overflows, so a scrolling carousel still starts at the container edge. Not
 * justify-content: center, which clips the start of an overflowing scroll container.
 */
.carousel__item:first-child {
	margin-inline-start: auto;
}

.carousel__item:last-child {
	margin-inline-end: auto;
}

.carousel__nav {
	position: absolute;
	top: calc(50% - 26px);
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-between;
	padding-inline: var(--space-5);
	pointer-events: none;
}

.carousel__arrow {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	padding: 0;
	border-radius: var(--radius-pill);
	background-color: var(--color-arrow-bg);
	backdrop-filter: blur(7px);
	color: var(--color-text);
	pointer-events: auto;
}

/* The chevron of 680:29287 is drawn on the arrow's own 52px box. */
.carousel__arrow svg {
	flex: none;
	width: 52px;
	height: 52px;
}

/* 680:29290: white circle, Dark Red chevron. */
.carousel__arrow:hover {
	background-color: var(--color-surface);
	color: var(--color-icon-accent);
}

.carousel__arrow--prev svg {
	transform: rotate(180deg);
}

/*
 * At an end the arrow that has nowhere to go leaves: state 1 of 680:28026 and 702:95567
 * shows "next" only, and state 2 shows both. It keeps aria-disabled for the carousel.js
 * contract and goes out of the tab order with visibility.
 */
.carousel__arrow[aria-disabled='true'] {
	visibility: hidden;
	opacity: 0;
	cursor: default;
}

/*
 * Pendency 7: the Figma variant hides the arrows, but acceptance criterion 5 requires
 * arrow navigation. They stay in the DOM and are revealed on hover or focus, and are
 * always visible on touch devices.
 */
.carousel--reveal-arrows .carousel__nav {
	opacity: 0;
	transition: opacity var(--duration-base) var(--ease-out);
}

.carousel--reveal-arrows .carousel__nav .carousel__arrow {
	pointer-events: none;
}

.carousel--reveal-arrows:hover .carousel__nav,
.carousel--reveal-arrows:focus-within .carousel__nav {
	opacity: 1;
}

.carousel--reveal-arrows:hover .carousel__nav .carousel__arrow,
.carousel--reveal-arrows:focus-within .carousel__nav .carousel__arrow {
	pointer-events: auto;
}

@media (hover: none) {
	.carousel--reveal-arrows .carousel__nav {
		opacity: 1;
	}

	.carousel--reveal-arrows .carousel__nav .carousel__arrow {
		pointer-events: auto;
	}
}

.carousel__nav[hidden],
.carousel__dots[hidden] {
	display: none;
}

/*
 * The gap is 16px and not the 4px of the Figma frame. With the 4px of the drawing the
 * pitch between two dots is 12px, and no touch area of 24px can fit in it without
 * covering the neighbour: hit testing in the middle of a dot returned the next one, so
 * every dot navigated to the wrong page. 16px puts the pitch at exactly 24px.
 */
.carousel__dots {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-3);
	/* 702:95567 and 680:28026: the dots sit at y=432 of a carousel whose cards are 400 tall. */
	margin-block-start: var(--space-5);
}

@media (max-width: 1023px) {
	.carousel__dots {
		margin-block-start: var(--space-4);
	}
}

.carousel__dot {
	position: relative;
	width: 8px;
	height: 8px;
	/* Without it the 6px side padding of the UA button made the inactive dot 12x8. */
	padding: 0;
	border-radius: var(--radius-pill);
	background-color: var(--carousel-dot-inactive);
	transition: width var(--duration-base) var(--ease-out), background-color var(--duration-base) var(--ease-out);
}

/*
 * The dot of the Figma frame is 8x8, well under the 24x24 of WCAG 2.5.8, and it cannot be
 * grown without redrawing it. The pseudo element carries the touch area instead, which
 * keeps the drawing untouched. It is exactly 24x24, the pitch allowed by the gap above:
 * anything larger overlaps the neighbouring dot and steals its clicks.
 */
.carousel__dot::before {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 24px;
	height: 24px;
	transform: translate(-50%, -50%);
	content: '';
}

.carousel__dot[aria-current='true'] {
	width: 28px;
	background-color: var(--color-indicator);
}
