/**
 * Shop Cart Component Styles
 *
 * Grocery cart surfaces (spec 2026-09-30-portal-shop-cart.md §5.2-§5.3):
 *   - the drawer (#gs-cart-drawer): right-anchored panel, bottom sheet <= 600 px;
 *   - the header entry point (.gs-cart-chip), in the nav rail and, under 900 px
 *     where the rail is off-canvas, floating top-right next to the hamburger;
 *   - the cart variant of the catalog sticky bar (.gs-sticky-price-bar--cart).
 *
 * Every colour, space, radius and z-index comes from design-tokens.css / the
 * theme tokens that portal.css remaps under .mphb-gs-shell[data-theme]. Vertical
 * rhythm uses the existing scale: header -> first line xl (20), line -> line lg
 * (16), last line -> footer xl (20), footer rows md (12).
 *
 * Buttons use .gs-btn on purpose: portal.css restyles every other
 * `.mphb-gs-shell button` through a selector no component rule can outweigh.
 * Neutral ones (icon buttons, chips) also carry .gs-btn-ghost: the injected
 * portal CSS forces `color: #fff !important` on every other .gs-btn, which made
 * their icons white on white. Primary CTAs keep that white-on-brand rule.
 *
 * @package MphbGuestServices
 */

/* Text on the brand colour: the portal's own CTAs are white on --gs-color-primary
 * (the admin-configurable brand, injected with !important), and the secondary
 * brand colour is not guaranteed to contrast with it, so it is not used here. */
.mphb-gs-shell {
	--gs-cart-on-primary: #fff;
}

/* ========================================
 * [hidden] must win over the display rules below (a stylesheet that fails to
 * load must never leave a full-screen layer over the page).
 * ======================================== */

.gs-cart-drawer[hidden],
.gs-cart-drawer__empty[hidden],
.gs-cart-drawer__footer[hidden],
.gs-cart-line__error[hidden],
.gs-cart-line__thumb[hidden],
.gs-nav-chip-cart[hidden],
.mphb-gs-shell .gs-cart-chip[hidden],
.gs-sticky-price-bar[hidden] {
	display: none;
}

/* ========================================
 * Drawer
 * ======================================== */

.gs-cart-drawer {
	--gs-cart-backdrop: rgba(0, 0, 0, 0.5);
	--gs-cart-enter-from: translateX(100%);
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: var(--gs-z-index-modal);
}

.gs-cart-drawer__backdrop {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: var(--gs-cart-backdrop);
}

.gs-cart-drawer__panel {
	position: absolute;
	top: 0;
	bottom: 0;
	right: 0; /* rtl.css anchors it left for Arabic. */
	display: flex;
	flex-direction: column;
	width: min(100%, 420px);
	box-sizing: border-box;
	background: var(--gs-color-surface);
	color: var(--gs-color-text);
	border-inline-start: 1px solid var(--gs-color-border);
	box-shadow: var(--gs-shadow-xl);
	animation: gs-cart-enter var(--gs-duration-base) var(--gs-ease-out);
}

.gs-cart-drawer__panel:focus {
	outline: none;
}

@keyframes gs-cart-enter {
	from {
		transform: var(--gs-cart-enter-from);
	}
}

@media (prefers-reduced-motion: reduce) {
	.gs-cart-drawer__panel {
		animation: none;
	}
}

/* Header */

.gs-cart-drawer__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--gs-space-md);
	flex-shrink: 0;
	padding: var(--gs-space-lg) var(--gs-space-xl);
	border-bottom: 1px solid var(--gs-color-border);
}

.gs-cart-drawer__title {
	margin: 0;
	font-size: var(--gs-font-size-xl);
	font-weight: var(--gs-font-weight-bold);
	line-height: var(--gs-line-height-tight);
	color: var(--gs-color-text);
}

.gs-cart-drawer .gs-cart-drawer__close {
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	padding: 0;
	background: transparent;
	color: var(--gs-color-text-soft);
	border: 0;
	border-radius: var(--gs-radius-full);
	box-shadow: none;
}

.gs-cart-drawer .gs-cart-drawer__close:hover {
	background: var(--gs-color-surface-hover);
	color: var(--gs-color-text);
	transform: none;
	box-shadow: none;
}

/* Keyboard focus ring (3:1 against both surfaces, unlike the soft default). */
.gs-cart-drawer .gs-btn:focus-visible,
.mphb-gs-shell .gs-cart-chip:focus-visible,
.gs-sticky-price-bar--cart .gs-btn:focus-visible {
	outline: 2px solid var(--gs-color-border-focus);
	outline-offset: 2px;
}

/* Body */

.gs-cart-drawer__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: var(--gs-space-xl);
}

.gs-cart-drawer__empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--gs-space-lg);
	padding: var(--gs-space-3xl) 0;
	text-align: center;
}

.gs-cart-drawer__empty-text {
	margin: 0;
	font-size: var(--gs-font-size-lg);
	color: var(--gs-color-text-soft);
}

.gs-cart-group__title {
	margin: 0 0 var(--gs-space-md);
	font-size: var(--gs-font-size-sm);
	font-weight: var(--gs-font-weight-bold);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--gs-color-text-soft);
}

.gs-cart-line + .gs-cart-group__title,
.gs-cart-drawer__lines > * + .gs-cart-group__title {
	margin-top: var(--gs-space-2xl);
}

/* Line */

.gs-cart-line {
	display: flex;
	align-items: flex-start;
	gap: var(--gs-space-lg);
}

.gs-cart-line + .gs-cart-line {
	margin-top: var(--gs-space-lg);
	padding-top: var(--gs-space-lg);
	border-top: 1px solid var(--gs-color-border);
}

.gs-cart-line__thumb {
	flex: 0 0 64px;
	width: 64px;
	height: 64px;
	object-fit: cover;
	background: var(--gs-color-surface-alt);
	border: 1px solid var(--gs-color-border);
	border-radius: var(--gs-radius-sm);
}

.gs-cart-line__main {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--gs-space-sm);
}

.gs-cart-line__main p {
	margin: 0;
}

.gs-cart-line__name {
	font-size: var(--gs-font-size-lg);
	font-weight: var(--gs-font-weight-medium);
	line-height: var(--gs-line-height-normal);
	color: var(--gs-color-text);
	overflow-wrap: anywhere;
}

.gs-cart-line__variant,
.gs-cart-line__note {
	font-size: var(--gs-font-size-base);
	line-height: var(--gs-line-height-normal);
	color: var(--gs-color-text-soft);
	overflow-wrap: anywhere;
}

.gs-cart-line__variant:empty,
.gs-cart-line__note:empty,
.gs-cart-line__chip:empty {
	display: none;
}

.gs-cart-line__note {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.gs-cart-line__meta {
	display: flex;
	flex-wrap: wrap;
	gap: var(--gs-space-sm);
}

.gs-cart-line__meta:not(:has(.gs-cart-line__chip:not(:empty))) {
	display: none;
}

.gs-cart-line__chip {
	padding: var(--gs-space-xs) var(--gs-space-md);
	font-size: var(--gs-font-size-sm);
	line-height: var(--gs-line-height-normal);
	color: var(--gs-color-text);
	background: var(--gs-color-surface-alt);
	border: 1px solid var(--gs-color-border);
	border-radius: var(--gs-radius-full);
}

/* Quantity + line total */

.gs-cart-line__buy {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--gs-space-md);
}

.gs-cart-stepper {
	display: inline-flex;
	align-items: center;
	background: var(--gs-color-surface-alt);
	border: 1px solid var(--gs-color-border);
	border-radius: var(--gs-radius-full);
}

.gs-cart-drawer .gs-cart-stepper__btn {
	width: 44px;
	height: 44px;
	padding: 0;
	background: transparent;
	color: var(--gs-color-text);
	border: 0;
	border-radius: var(--gs-radius-full);
	box-shadow: none;
}

.gs-cart-drawer .gs-cart-stepper__btn:hover:not(:disabled) {
	background: var(--gs-color-surface-hover);
	transform: none;
	box-shadow: none;
}

.gs-cart-drawer .gs-cart-stepper__btn:disabled {
	background: transparent;
	color: var(--gs-color-text-muted);
	opacity: 0.5;
}

.gs-cart-stepper__qty {
	min-width: 32px;
	text-align: center;
	font-size: var(--gs-font-size-lg);
	font-weight: var(--gs-font-weight-bold);
	font-variant-numeric: tabular-nums;
	color: var(--gs-color-text);
}

.gs-cart-line__total {
	font-size: var(--gs-font-size-lg);
	font-weight: var(--gs-font-weight-bold);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	color: var(--gs-color-text);
}

/* Edit / Remove */

.gs-cart-line__actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--gs-space-md);
}

.gs-cart-drawer .gs-cart-line__action {
	width: 44px; /* meal-section.css makes .gs-btn full width under 768 px. */
	height: 44px;
	padding: 0;
	background: transparent;
	color: var(--gs-color-text);
	border: 1px solid var(--gs-color-border);
	border-radius: var(--gs-radius-full);
	box-shadow: none;
}

.gs-cart-drawer .gs-cart-line__action:hover {
	background: var(--gs-color-surface-hover);
	border-color: var(--gs-color-border-active);
	transform: none;
	box-shadow: none;
}

/* Per-line server error (checkout refused this line) */

.gs-cart-line__error {
	padding: var(--gs-space-sm) var(--gs-space-md);
	font-size: var(--gs-font-size-base);
	line-height: var(--gs-line-height-normal);
	color: var(--gs-color-text);
	background: var(--gs-color-error-bg);
	border: 1px solid var(--gs-color-error-border);
	border-inline-start: 3px solid var(--gs-color-error);
	border-radius: var(--gs-radius-sm);
}

/* State classes set by the cart script */

.gs-cart-line.has-error .gs-cart-line__name {
	color: var(--gs-color-error);
}

.gs-cart-drawer .gs-cart-drawer__checkout.is-busy {
	cursor: progress;
	opacity: 0.7;
}

/* Footer */

.gs-cart-drawer__footer {
	display: flex;
	flex-direction: column;
	gap: var(--gs-space-md);
	flex-shrink: 0;
	padding: var(--gs-space-xl);
	background: var(--gs-color-surface);
	border-top: 1px solid var(--gs-color-border);
}

.gs-cart-drawer__total-row {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--gs-space-md);
}

.gs-cart-drawer__total-label {
	font-size: var(--gs-font-size-base);
	font-weight: var(--gs-font-weight-medium);
	color: var(--gs-color-text-soft);
}

.gs-cart-drawer__total {
	font-size: var(--gs-font-size-2xl);
	font-weight: var(--gs-font-weight-bold);
	font-variant-numeric: tabular-nums;
	color: var(--gs-color-text);
}

.gs-cart-drawer__note {
	margin: 0;
	font-size: var(--gs-font-size-sm);
	line-height: var(--gs-line-height-normal);
	color: var(--gs-color-text-soft);
}

.gs-cart-drawer .gs-cart-drawer__checkout,
.gs-cart-drawer .gs-cart-drawer__continue,
.gs-cart-drawer .gs-cart-drawer__empty-action {
	min-height: 48px;
	width: 100%;
}

.gs-cart-drawer .gs-cart-drawer__empty-action {
	width: auto;
	padding-inline: var(--gs-space-2xl);
}

/* Bottom sheet on phones */
@media (max-width: 600px) {
	.gs-cart-drawer {
		--gs-cart-enter-from: translateY(100%);
	}

	.gs-cart-drawer__panel {
		top: auto;
		right: 0;
		left: 0;
		width: 100%;
		max-height: 85vh;
		max-height: 85dvh;
		border-inline-start: 0;
		border-top: 1px solid var(--gs-color-border);
		border-radius: var(--gs-radius-xl) var(--gs-radius-xl) 0 0;
	}
}

/* ========================================
 * Header entry point (chip)
 * ======================================== */

.gs-nav-header--has-cart {
	grid-auto-flow: column;
	grid-template-columns: none;
	grid-auto-columns: minmax(0, 1fr);
}

/* Same box as .gs-theme-button so the chips line up (height measured, not guessed). */
.mphb-gs-shell .gs-cart-chip {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--gs-space-sm);
	box-sizing: border-box;
	min-height: 30px;
	padding: 8px 12px;
	background: var(--gs-nav-item-bg);
	color: var(--gs-nav-text);
	border: 1px solid var(--gs-nav-border);
	border-radius: 999px;
	font-size: var(--gs-font-size-base);
	cursor: pointer;
}

.mphb-gs-shell .gs-cart-chip--nav {
	width: 100%;
	min-width: 50px;
}

.mphb-gs-shell .gs-cart-chip:hover {
	background: var(--gs-nav-item-bg-hover);
	color: var(--gs-nav-text);
	transform: none;
	box-shadow: none;
}

.gs-cart-chip__icon {
	flex-shrink: 0;
}

.gs-cart-chip__count {
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	box-sizing: border-box;
	font-size: var(--gs-font-size-sm);
	font-weight: var(--gs-font-weight-bold);
	line-height: 20px;
	text-align: center;
	font-variant-numeric: tabular-nums;
	color: var(--gs-cart-on-primary);
	background: var(--gs-color-primary);
	border-radius: 10px;
}

.gs-cart-chip__count:empty {
	display: none;
}

/* Floating twin (mirrors the hamburger, top-right). Desktop shows the nav chip. */
.mphb-gs-shell .gs-cart-chip--floating {
	display: none;
}

@media (max-width: 900px) {
	.gs-nav-chip-cart:not([hidden]) {
		display: none;
	}

	.mphb-gs-shell .gs-cart-chip--floating:not([hidden]) {
		display: inline-flex;
		position: fixed;
		width: auto;
		top: 12px;
		right: 12px; /* rtl.css mirrors it. */
		z-index: var(--gs-z-index-sticky);
		height: 56px;
		min-width: 56px;
		padding: 0 14px;
		background: var(--gs-nav-bg);
		border: 2px solid var(--gs-color-primary);
		border-radius: var(--gs-radius-xl);
		box-shadow: var(--gs-shadow-md);
	}
}

@media (max-width: 480px) {
	.mphb-gs-shell .gs-cart-chip--floating:not([hidden]) {
		top: 10px;
		right: 10px;
		height: 48px;
		min-width: 48px;
		padding: 0 10px;
	}
}

/* ========================================
 * Catalog sticky bar, cart variant
 * ======================================== */

.gs-sticky-price-bar--cart .gs-sticky-bar-total {
	color: var(--gs-color-text);
}

.gs-sticky-price-bar--cart .gs-sticky-bar-row > .gs-cart-bar__open {
	order: 3; /* after the summary, like the other bar actions */
	flex-shrink: 0;
	width: auto;
	min-height: 44px;
	padding: 0 var(--gs-space-lg);
	font-size: var(--gs-font-size-base);
	white-space: nowrap;
}
