/**
 * Add-to-cart modal: the order slip.
 *
 * A sheet that rises from the bottom on phones and sits centred on desktop:
 * photo (when the product has one), name in the condensed display face,
 * price in ink, one line of description, then the option groups and a
 * footer that always shows the quantity and the add action. Same rules,
 * same type, same price column as the menu. Depends on css/foodmaster-tokens.css.
 */

/* ---------- Shell ---------- */
.foodmaster-modern-modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 100000;
	font-family: var(--fm-font-body);
	font-size: 15px;
	line-height: 1.35;
	color: var(--fm-black);
}

.foodmaster-modern-modal.is-open,
.foodmaster-modern-modal[aria-hidden="false"] {
	display: block;
}

.foodmaster-modern-modal-overlay {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	background: rgba(20, 20, 20, 0.6);
	animation: fm-fade var(--fm-base) var(--fm-ease-out, var(--fm-ease)) both;
}

.foodmaster-modern-modal-container {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 100%;
	max-height: calc(100dvh - 32px);
	background: var(--fm-paper);
	color: var(--fm-black);
	border: var(--fm-rule-strong);
	border-bottom: 0;
	border-radius: var(--fm-radius) var(--fm-radius) 0 0;
	overflow: hidden;
	/* The sheet arrives: a longer travel on the standard ease, the fade settles first */
	animation: fm-sheet-in var(--fm-slow) var(--fm-ease-out, var(--fm-ease)) both;
	will-change: transform, opacity;
}

.foodmaster-modern-modal.is-closing .foodmaster-modern-modal-overlay {
	animation: fm-fade var(--fm-fast) var(--fm-ease-out, var(--fm-ease)) reverse both;
}

.foodmaster-modern-modal.is-closing .foodmaster-modern-modal-container {
	animation: fm-sheet-out var(--fm-fast) var(--fm-ease-out, var(--fm-ease)) both;
}

@keyframes fm-fade {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes fm-rise {
	from { transform: translateY(24px); opacity: 0; }
	to { transform: none; opacity: 1; }
}

@keyframes fm-sheet-in {
	from { transform: translateY(var(--fm-rise)); opacity: 0; }
	40% { opacity: 1; }
	to { transform: none; opacity: 1; }
}

@keyframes fm-sheet-out {
	from { transform: none; opacity: 1; }
	to { transform: translateY(calc(var(--fm-rise) * 0.5)); opacity: 0; }
}

/* Inside the sheet, the content settles a beat after the sheet itself */
.foodmaster-modern-modal-container .foodmaster-modern-content-section {
	animation: fm-rise var(--fm-base) var(--fm-ease) both;
	animation-delay: calc(var(--fm-slow) * 0.25);
}

/* The photo fades in at its final size, whenever the product arrives */
.foodmaster-modern-modal-container .foodmaster-modern-image-section {
	animation: fm-fade var(--fm-base) var(--fm-ease-out, var(--fm-ease)) both;
}

/* While the sheet is open: no page scroll, no smooth-scroll hop, and the
   scrollbar's width stays reserved so nothing underneath shifts sideways */
html.foodmaster-modal-open {
	overflow: hidden;
	scroll-behavior: auto;
}

html.foodmaster-modal-open body {
	padding-inline-end: var(--fm-scrollbar-width, 0px);
}

/* Only elements fixed to the viewport need their own gutter; the sticky header
   lives inside the body and already has it. */
html.foodmaster-modal-open .foodmaster-mini-cart-wrapper.sticky-cart {
	padding-inline-end: var(--fm-scrollbar-width, 0px);
}

html.foodmaster-modal-open .foodmaster-notification {
	margin-inline-start: calc(var(--fm-scrollbar-width, 0px) / -2);
}

/* Header: just the close control, floating over the content */
.foodmaster-modern-modal-header {
	position: absolute;
	top: calc(var(--fm-m) * 1.5);
	inset-inline-end: calc(var(--fm-m) * 1.5);
	z-index: 3;
	display: flex;
	justify-content: flex-end;
	padding: 0;
	background: transparent;
	border: 0;
}

.foodmaster-modern-modal-close {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: calc(var(--fm-m) * 5);
	height: calc(var(--fm-m) * 5);
	padding: 0;
	background: var(--fm-paper);
	border: 1.5px solid var(--fm-black);
	border-radius: var(--fm-radius);
	color: var(--fm-black);
	font-size: 0;
	line-height: 0;
	cursor: pointer;
	transition: background var(--fm-fast) var(--fm-ease), color var(--fm-fast) var(--fm-ease);
}

.foodmaster-modern-modal-close svg {
	width: 18px;
	height: 18px;
}

.foodmaster-modern-modal-close:hover {
	background: var(--fm-black);
	color: var(--fm-paper);
}

.foodmaster-modern-modal-close:focus-visible {
	box-shadow: var(--fm-focus);
	outline: none;
}

/* Scrolling body */
.foodmaster-modern-modal-content {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	padding: 0;
	/* Keep the gutter from the first frame so the photo column never shifts when the list grows */
	scrollbar-gutter: stable;
	scrollbar-width: thin;
	scrollbar-color: var(--fm-n3) transparent;
}

.foodmaster-modern-modal-content::-webkit-scrollbar {
	width: 8px;
}

.foodmaster-modern-modal-content::-webkit-scrollbar-thumb {
	background: var(--fm-n3);
	border-radius: var(--fm-radius);
}

/* ---------- Content ---------- */
.foodmaster-modern-popup-container {
	display: flex;
	flex-direction: column;
}

.foodmaster-modern-image-section {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 10;
	background: var(--fm-n1);
	border-bottom: var(--fm-rule-strong);
	overflow: hidden;
}

.foodmaster-modern-image-section img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.foodmaster-modern-image-section:empty {
	display: none;
}

.foodmaster-modern-content-section {
	display: flex;
	flex-direction: column;
	padding: calc(var(--fm-m) * 2.5) calc(var(--fm-m) * 2) 0;
}

/* Name, rating, price, line */
.foodmaster-modern-title {
	margin: 0 calc(var(--fm-m) * 6) 0 0;
	font-family: var(--fm-font-display);
	font-weight: var(--fm-display-weight);
	font-size: 32px;
	line-height: 0.95;
	letter-spacing: calc(0.005em * var(--fm-tracking));
	text-transform: var(--fm-caps);
	color: var(--fm-black);
	overflow-wrap: break-word;
}

[dir="rtl"] .foodmaster-modern-title {
	margin: 0 0 0 calc(var(--fm-m) * 6);
}

.foodmaster-modern-image-section + .foodmaster-modern-content-section .foodmaster-modern-title {
	margin-inline-end: 0;
}

.foodmaster-modern-rating {
	display: flex;
	align-items: center;
	gap: var(--fm-m);
	margin-top: var(--fm-m);
	font-size: 13px;
	color: var(--fm-n6);
}

.foodmaster-rating-stars {
	display: inline-flex;
	gap: 2px;
	color: var(--fm-black);
}

.foodmaster-rating-stars svg {
	width: 14px;
	height: 14px;
	display: block;
}

.foodmaster-star-empty {
	color: var(--fm-n3);
}

.foodmaster-modern-price {
	margin-top: calc(var(--fm-m) * 1.5);
	font-family: var(--fm-font-display);
	font-weight: var(--fm-display-weight);
	font-size: 26px;
	line-height: 1;
	color: var(--fm-price-ink);
	font-variant-numeric: tabular-nums lining-nums;
}

.foodmaster-modern-price .woocommerce-Price-amount,
.foodmaster-modern-price .woocommerce-Price-currencySymbol {
	color: inherit;
	font-weight: inherit;
}

.foodmaster-modern-price del {
	margin-inline-end: var(--fm-m);
	font-family: var(--fm-font-body);
	font-weight: 500;
	font-size: 14px;
	color: var(--fm-n6);
	vertical-align: 0.2em;
}

.foodmaster-modern-price ins {
	text-decoration: none;
}

.foodmaster-modern-description {
	margin-top: var(--fm-m);
	max-width: 60ch;
	font-size: 15px;
	line-height: 1.4;
	color: var(--fm-n6);
}

.foodmaster-modern-description p {
	margin: 0;
}

.foodmaster-modern-description p + p {
	margin-top: 0.6em;
}

/* Stock line from WooCommerce */
.foodmaster-modern-content-section .stock {
	margin: var(--fm-m) 0 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--fm-success);
}

.foodmaster-modern-content-section .stock.out-of-stock {
	color: var(--fm-error);
}

/* Add-to-cart area: option groups scroll with the content, the footer stays */
.foodmaster-modern-add-to-cart {
	margin-top: calc(var(--fm-m) * 2.5);
}

/* Upsells and related: rows again */
.foodmaster-modern-upsells,
.foodmaster-modern-related {
	margin: calc(var(--fm-m) * 3) 0 0;
	padding-top: calc(var(--fm-m) * 2);
	border-top: var(--fm-rule-strong);
}

.foodmaster-modern-upsells h3,
.foodmaster-modern-related h3 {
	margin: 0 0 var(--fm-m);
	font-family: var(--fm-font-display);
	font-weight: var(--fm-display-weight);
	font-size: 20px;
	line-height: 1;
	letter-spacing: calc(0.02em * var(--fm-tracking));
	text-transform: var(--fm-caps);
}

/* Loading state while the content fetches */
.foodmaster-modern-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: var(--fm-m);
	min-height: 240px;
	padding: calc(var(--fm-m) * 4);
	color: var(--fm-n6);
	font-size: 15px;
}

.foodmaster-modern-spinner {
	width: 24px;
	height: 24px;
	border: 2px solid var(--fm-n2);
	border-top-color: var(--fm-ink);
	border-radius: 50%;
	animation: foodmaster-spin 0.8s linear infinite;
}

.foodmaster-modern-loading-text {
	margin: 0;
	font-weight: 600;
	color: var(--fm-black);
}

.foodmaster-modern-loading-subtext {
	margin: 0;
	font-size: 13px;
}

@keyframes foodmaster-spin {
	to { transform: rotate(360deg); }
}

/* Toast after adding */
/* Requirement errors from the option validator */
.wf_requiremnts_error {
	margin: var(--fm-m) 0 0;
	padding: var(--fm-m) calc(var(--fm-m) * 1.5);
	border: 1.5px solid var(--fm-error);
	border-radius: var(--fm-radius);
	color: var(--fm-error);
	font-size: 14px;
	font-weight: 600;
}

/* ---------- Desktop: centred sheet with the photo beside the content ---------- */
@media (min-width: 768px) {
	.foodmaster-modern-modal-overlay {
		align-items: center;
		padding: calc(var(--fm-m) * 3);
	}

	/* Centred on wide screens: a shorter rise. No scale: the product arrives mid-animation
	   and a scaling sheet would show the photo growing into place. */
	@keyframes fm-sheet-in {
		from { transform: translateY(calc(var(--fm-rise) * 0.5)); opacity: 0; }
		40% { opacity: 1; }
		to { transform: none; opacity: 1; }
	}

	@keyframes fm-sheet-out {
		from { transform: none; opacity: 1; }
		to { transform: translateY(calc(var(--fm-rise) * 0.25)); opacity: 0; }
	}

	.foodmaster-modern-modal-container {
		width: min(100%, 880px);
		max-height: min(calc(100dvh - 48px), 820px);
		border-bottom: var(--fm-rule-strong);
		border-radius: var(--fm-radius);
	}

	.foodmaster-modern-popup-container {
		flex-direction: row;
		align-items: stretch;
		min-height: 100%;
	}

	/* The photo keeps its square and stays in view while a long option list scrolls */
	.foodmaster-modern-image-section {
		flex: 0 0 40%;
		aspect-ratio: 1;
		min-height: 0;
		height: auto;
		align-self: flex-start;
		position: sticky;
		top: 0;
		border-bottom: 0;
		border-inline-end: var(--fm-rule-strong);
	}

	.foodmaster-modern-modal .foodmaster-modern-image-section img {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
		max-width: none;
	}

	.foodmaster-modern-content-section {
		flex: 1 1 auto;
		min-width: 0;
		padding: calc(var(--fm-m) * 3) calc(var(--fm-m) * 3) 0;
	}

	.foodmaster-modern-title {
		font-size: 36px;
		margin-inline-end: calc(var(--fm-m) * 6);
	}

	.foodmaster-modern-image-section + .foodmaster-modern-content-section .foodmaster-modern-title {
		margin-inline-end: calc(var(--fm-m) * 6);
	}

	.foodmaster-modern-modal-header {
		top: calc(var(--fm-m) * 2);
		inset-inline-end: calc(var(--fm-m) * 2);
	}
}

@media (prefers-reduced-motion: reduce) {
	.foodmaster-modern-modal-overlay,
	.foodmaster-modern-modal-container,
	.foodmaster-modern-modal-container .foodmaster-modern-image-section,
	.foodmaster-modern-modal.is-closing .foodmaster-modern-modal-overlay,
	.foodmaster-modern-modal.is-closing .foodmaster-modern-modal-container {
		animation: none;
	}

	.foodmaster-modern-modal-close {
		transition: none;
	}

	.foodmaster-modern-spinner {
		animation: none;
	}
}
