/*
 * RahkarTheme — Add-to-Cart modal styles.
 *
 * Loaded only on shop / product / archive / cart pages (see
 * inc/cart-modal.php condition). No bytes ship to the blog, home, or
 * static pages.
 *
 * Layout model:
 *   - Mobile (< 768px): bottom sheet. Panel slides up from the bottom
 *     edge via translateY. A small "handle" hint sits at the top.
 *   - Desktop (≥ 768px): centered card. Panel scales 0.96 → 1 and fades.
 *
 * Animation model:
 *   - State toggled by a single `data-state` attribute on the container
 *     (managed by cart-modal.js). All transitions are GPU-only — transform
 *     + opacity, no width/height/margin animations → no layout thrash.
 *   - The panel uses `contain: layout paint` so internal repaints don't
 *     invalidate page layout.
 *
 * RTL: theme runs direction:rtl globally; nothing in this file uses a
 * directional `left`/`right` for content flow. The desktop centering uses
 * `left: 50%; translate(-50%, -50%)` which is physical and direction-
 * independent.
 *
 * Tokens: pulls from theme.json palette/spacing where possible, with
 * literal fallbacks so the modal still renders coherently if any palette
 * slug is later renamed.
 */

/* =====================================================================
 *  Container — full-viewport overlay; controls open/close
 * ===================================================================== */
.rh-atc {
	position: fixed;
	inset: 0;
	z-index: 1000;
	pointer-events: none;
}
.rh-atc[data-state="open"] {
	pointer-events: auto;
}

/* =====================================================================
 *  Backdrop
 * ===================================================================== */
.rh-atc__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(15, 17, 21, 0.45);
	opacity: 0;
	transition: opacity 200ms ease-out;
	cursor: pointer;
}
.rh-atc[data-state="open"] .rh-atc__backdrop {
	opacity: 1;
}

/* =====================================================================
 *  Panel — mobile (bottom sheet)
 * ===================================================================== */
.rh-atc__panel {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	max-height: 88vh;
	background: var(--wp--preset--color--base, #fff);
	color: var(--wp--preset--color--text, #1a1d23);
	border-radius: 16px 16px 0 0;
	box-shadow: 0 -8px 32px rgba(15, 17, 21, 0.14);
	transform: translateY(100%);
	transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
	contain: layout paint;
}
.rh-atc[data-state="open"] .rh-atc__panel {
	transform: translateY(0);
}

/* Drag handle indicator (mobile only) */
.rh-atc__handle {
	width: 36px;
	height: 4px;
	margin: 8px auto 0;
	border-radius: 2px;
	background: var(--wp--preset--color--border, #e2e4e9);
	flex: 0 0 auto;
}

/* =====================================================================
 *  Head
 * ===================================================================== */
.rh-atc__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--wp--preset--color--border, #e2e4e9);
	flex: 0 0 auto;
}
.rh-atc__title {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	font-size: 1rem;
	font-weight: 600;
	color: var(--wp--preset--color--contrast, #0f1115);
	line-height: 1.4;
}
.rh-atc__check {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: var(--wp--preset--color--success, #198754);
	color: #fff;
	flex: 0 0 auto;
}
@media (max-width: 767px) {
	.rh-atc__close { display: none; }
}
.rh-atc__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--text-muted, #5b6271);
	cursor: pointer;
	border-radius: 8px;
	transition: background-color 120ms, color 120ms;
	flex: 0 0 auto;
}
.rh-atc__close:hover,
.rh-atc__close:focus-visible {
	background: var(--wp--preset--color--surface, #f7f7f8);
	color: var(--wp--preset--color--contrast, #0f1115);
}

/* =====================================================================
 *  Body — scrollable when content exceeds remaining space
 * ===================================================================== */
.rh-atc__body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	-webkit-overflow-scrolling: touch;
}

/* Added item row */
.rh-atc__item {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	padding-bottom: 12px;
	border-bottom: 1px solid var(--wp--preset--color--border, #e2e4e9);
}
.rh-atc__img {
	width: 72px;
	height: 72px;
	object-fit: cover;
	border-radius: 8px;
	background: var(--wp--preset--color--surface, #f7f7f8);
	flex: 0 0 auto;
}
.rh-atc__item-text {
	flex: 1 1 auto;
	min-width: 0;
}
.rh-atc__item-name {
	margin: 0 0 4px;
	font-size: 0.9375rem;
	font-weight: 500;
	color: var(--wp--preset--color--contrast, #0f1115);
	line-height: 1.45;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.rh-atc__item-meta {
	margin: 0;
	font-size: 0.8125rem;
	color: var(--wp--preset--color--text-muted, #5b6271);
}
.rh-atc__times {
	margin: 0 4px;
	opacity: 0.7;
}

/* Cart subtotal row */
.rh-atc__summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 12px;
	padding-top: 12px;
	font-size: 0.9375rem;
}
.rh-atc__summary-label {
	color: var(--wp--preset--color--text-muted, #5b6271);
}
.rh-atc__summary-value {
	font-weight: 700;
	color: var(--wp--preset--color--contrast, #0f1115);
	font-size: 1rem;
}

/* =====================================================================
 *  Free-shipping progress bar (modal-scoped)
 * ---------------------------------------------------------------------
 *  WHY a modal-scoped class (not the same `.rh-ship-bar` the cart page
 *  uses): both stylesheets co-load on the cart page, and the modal needs
 *  tighter padding + smaller text than the standalone bar on /cart.
 *  Different visual contexts → different class names. No specificity
 *  battles, no duplicated rules across stylesheets.
 * ===================================================================== */
.rh-atc__ship-bar {
	margin-top: 12px;
	padding: 10px 12px;
	background: var(--wp--preset--color--surface, #f7f7f8);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 8px;
	contain: layout paint;
}
.rh-atc__ship-bar[hidden] {
	display: none;
}
.rh-atc__ship-label {
	margin: 0 0 8px;
	font-size: 0.8125rem;
	color: var(--wp--preset--color--text, #1a1d23);
}
.rh-atc__ship-label strong {
	color: var(--wp--preset--color--primary, #0a66c2);
}
.rh-atc__ship-track {
	height: 6px;
	background: var(--wp--preset--color--muted, #eceef1);
	border-radius: 9999px;
	overflow: hidden;
}
.rh-atc__ship-fill {
	height: 100%;
	width: 0;
	background: var(--wp--preset--color--primary, #0a66c2);
	border-radius: inherit;
	transition: width 400ms cubic-bezier(0.22, 0.61, 0.36, 1),
	            background-color 200ms;
}
.rh-atc__ship-bar.is-qualified .rh-atc__ship-fill {
	background: var(--wp--preset--color--success, #198754);
}
.rh-atc__ship-bar.is-qualified .rh-atc__ship-label {
	color: var(--wp--preset--color--success, #198754);
	font-weight: 600;
}
@media (prefers-reduced-motion: reduce) {
	.rh-atc__ship-fill {
		transition: none;
	}
}

/* =====================================================================
 *  Cross-sell strip — horizontal scroll on mobile
 * ===================================================================== */
.rh-atc__upsell {
	margin-top: 16px;
	padding-top: 12px;
	border-top: 1px solid var(--wp--preset--color--border, #e2e4e9);
}
.rh-atc__upsell-title {
	margin: 0 0 8px;
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--wp--preset--color--text-muted, #5b6271);
}
.rh-atc__upsell-list {
	display: flex;
	gap: 8px;
	margin: 0;
	padding: 2px 0;
	list-style: none;
	overflow-x: auto;
	scrollbar-width: thin;
	-webkit-overflow-scrolling: touch;
}
.rh-atc__upsell-item {
	flex: 0 0 132px;
	display: flex;
	flex-direction: column;
	padding: 8px;
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 8px;
	background: var(--wp--preset--color--base, #fff);
}
.rh-atc__upsell-link {
	display: block;
	text-decoration: none;
	color: inherit;
	margin-bottom: 6px;
}
.rh-atc__upsell-img {
	display: block;
	width: 100%;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 6px;
	background: var(--wp--preset--color--surface, #f7f7f8);
	margin-bottom: 6px;
}
.rh-atc__upsell-name {
	font-size: 0.8125rem;
	font-weight: 500;
	color: var(--wp--preset--color--contrast, #0f1115);
	line-height: 1.4;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	min-height: 2.3em;
}
.rh-atc__upsell-price {
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--wp--preset--color--primary, #0a66c2);
	margin-bottom: 6px;
}
.rh-atc__upsell-price ins {
	text-decoration: none;
}
.rh-atc__upsell-add {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 100%;
	min-height: var(--wp--custom--button--h--sm, 36px);
	padding: 0 var(--wp--custom--button--px--sm, 14px);
	border: 1px solid var(--wp--preset--color--primary, #0a66c2);
	border-radius: var(--wp--custom--button--radius, 10px);
	background: transparent;
	color: var(--wp--preset--color--primary, #0a66c2);
	font: inherit;
	font-size: var(--wp--custom--button--fs--sm, 0.875rem);
	font-weight: var(--wp--custom--button--fw, 600);
	cursor: pointer;
	text-decoration: none;
	transition: background-color 120ms, color 120ms;
	margin-top: auto;
}
.rh-atc__upsell-add:hover,
.rh-atc__upsell-add:focus-visible {
	background: var(--wp--preset--color--primary, #0a66c2);
	color: #fff;
}
.rh-atc__upsell-add[aria-busy="true"] {
	opacity: 0.6;
	pointer-events: none;
}
/* Outlined surface (transparent bg, primary border) — the global white
   spinner from loading.css would be invisible here, so re-ink it with the
   brand color. */
.rh-atc__upsell-add[aria-busy="true"]::after {
	border-color: rgba(15, 17, 21, 0.18);
	border-top-color: var(--wp--preset--color--primary, #0a66c2);
}

/* =====================================================================
 *  Actions — CTA cluster (all use the site-wide button tokens)
 * ---------------------------------------------------------------------
 *  Mobile: primary full-width, then a row with [outlined | text-link].
 *  Desktop: single row [primary | outlined | text-link].
 *  All three buttons share height/radius/weight with primary CTAs across
 *  the site so the modal feels visually consistent with the cart/checkout
 *  pages, not subordinate.
 * ===================================================================== */
.rh-atc__actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	padding: 12px 14px max(env(safe-area-inset-bottom, 0px), 12px);
	border-top: 1px solid var(--wp--preset--color--border, #e2e4e9);
	background: var(--wp--preset--color--base, #fff);
	flex: 0 0 auto;
}
.rh-atc__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--wp--custom--button--h--md, 44px);
	padding: 0 var(--wp--custom--button--px--md, 20px);
	border: 1px solid transparent;
	border-radius: var(--wp--custom--button--radius, 10px);
	font: inherit;
	font-size: var(--wp--custom--button--fs--md, 0.9375rem);
	font-weight: var(--wp--custom--button--fw, 600);
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 120ms, color 120ms, border-color 120ms;
}
.rh-atc__btn--primary {
	background: var(--wp--preset--color--primary, #0a66c2);
	color: #fff;
	grid-column: 1 / -1;
}
.rh-atc__btn--primary:hover,
.rh-atc__btn--primary:focus-visible {
	background: var(--wp--preset--color--primary-dark, #074a8d);
	color: #fff;
}
.rh-atc__btn--outlined {
	background: transparent;
	color: var(--wp--preset--color--primary, #0a66c2);
	border-color: var(--wp--preset--color--primary, #0a66c2);
}
.rh-atc__btn--outlined:hover,
.rh-atc__btn--outlined:focus-visible {
	background: var(--wp--preset--color--surface, #f7f7f8);
}
.rh-atc__btn--text {
	background: transparent;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--custom--button--fs--sm, 0.875rem);
	padding: 0 var(--wp--custom--button--px--sm, 14px);
}
.rh-atc__btn--text:hover,
.rh-atc__btn--text:focus-visible {
	color: var(--wp--preset--color--contrast, #0f1115);
	background: var(--wp--preset--color--surface, #f7f7f8);
}

/* =====================================================================
 *  Desktop — centered popup card
 * ===================================================================== */
@media (min-width: 768px) {
	.rh-atc__panel {
		left: 50%;
		top: 50%;
		right: auto;
		bottom: auto;
		width: min(520px, calc(100vw - 32px));
		max-height: 86vh;
		border-radius: 12px;
		box-shadow: 0 24px 60px rgba(15, 17, 21, 0.22);
		transform: translate(-50%, -48%) scale(0.96);
		opacity: 0;
		transition: transform 220ms ease-out, opacity 200ms ease-out;
	}
	.rh-atc[data-state="open"] .rh-atc__panel {
		transform: translate(-50%, -50%) scale(1);
		opacity: 1;
	}

	.rh-atc__handle {
		display: none;
	}

	/* Slightly larger image + tighter padding feel more "card" than "sheet". */
	.rh-atc__img {
		width: 80px;
		height: 80px;
	}

	/* Desktop actions: single row — primary + outlined + continue-link.
	   Primary uses a moderate 1.2:1 ratio over outlined; large enough to
	   read as the lead CTA, not so wide that it dominates the modal. */
	.rh-atc__actions {
		grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
		gap: 10px;
		padding: 14px 16px 16px;
	}
	.rh-atc__btn--primary {
		grid-column: auto;
	}
}

/* =====================================================================
 *  Header cart badge — pulse on count change
 * ---------------------------------------------------------------------
 *  WHY co-located: the animation belongs to the modal flow (it fires
 *  when the modal opens after a successful add). Keeping it next to the
 *  modal's other rules avoids hunting across files.
 * ===================================================================== */
.rh-cart__count {
	transition: transform 200ms ease-out;
}
.rh-cart__count.is-bumped {
	animation: rh-cart-bump 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes rh-cart-bump {
	0%   { transform: scale(1); }
	35%  { transform: scale(1.35); }
	100% { transform: scale(1); }
}

/* (The .rh-cart__count.is-empty { display:none } rule lives in header.css
 * alongside the rest of the base badge styling — no need to duplicate it
 * here. cart-modal.js still toggles the class on count change; CSS only
 * needs to define the hide behavior once.) */

/* Reduced-motion respect — skip all panel/backdrop animations. */
@media (prefers-reduced-motion: reduce) {
	.rh-atc__backdrop,
	.rh-atc__panel,
	.rh-cart__count {
		transition: none;
	}
	.rh-cart__count.is-bumped {
		animation: none;
	}
}
