/**
 * Native cart drawer — styles for js/hfm-cart.js rendering into the
 * modules/drawer shell (#hfm-cart-drawer). Token-driven via hfm-styles.
 *
 * @package HFM.Parts
 * @copyright ùrlar — https://www.urlar.co/
 */

/* ── Tokens ────────────────────────────────────────────────────────────
   Theme tokens are scoped per component (see product-card.css, blog.css) —
   this block mirrors the .hfm-cart-drawer set so the drawer is self-reliant
   and dark-mode aware via light-dark(). */

.hfm-cartd {
	color-scheme: light dark;

	--hfm-bg:    var(--wp--preset--color--base, light-dark(#fcfcfc, #0a0a0a));
	--hfm-bg-1:  var(--wp--preset--color--base-2, light-dark(#f7f7f7, #171717));
	--hfm-bg-2:  var(--wp--preset--color--neutral-100, light-dark(#f5f5f5, #171717));
	--hfm-bg-3:  var(--wp--preset--color--grey-200, light-dark(#e5e5e5, #262626));
	--hfm-line:   var(--wp--preset--color--grey-200, light-dark(#e5e5e5, #262626));
	--hfm-line-2: var(--wp--preset--color--grey-300, light-dark(#d4d4d4, #404040));
	--hfm-ink:    var(--wp--preset--color--contrast, light-dark(#191919, #f5f5f5));
	--hfm-ink-2:  var(--wp--preset--color--grey-600, light-dark(#525252, #a3a3a3));
	--hfm-ink-3:  var(--wp--preset--color--grey-500, light-dark(#737373, #737373));
	--hfm-accent:     var(--wp--preset--color--purple-500, light-dark(#874da2, #d05aff));
	--hfm-accent-2:   var(--wp--preset--color--purple-600, light-dark(#75448c, #d87aff));
	--hfm-accent-ink: light-dark(#ffffff, #0e0420);
	--hfm-accent-faint: var(--wp--preset--color--purple-100, light-dark(#f3e8f7, #41284a));
	--hfm-ok:    var(--wp--preset--color--green-500, light-dark(#16a34a, #4ade80));
	--hfm-r-2: 4px;
	--hfm-f-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

	/* Feed the drawer module's own surface vars from the token set. The module
	   defaults --drawer-max-width to 24rem for side drawers — none, or it caps
	   the width rule below. */
	--drawer-bg: var(--hfm-bg);
	--drawer-color: var(--hfm-ink);
	--drawer-max-width: none;

	font-family: inherit;
}

/* ── Shell ─────────────────────────────────────────────────────────── */

.hfm-cartd .c-drawer {
	width: min(480px, calc(100vw - 24px));
	color: var(--hfm-ink);
}

/* Grab handle is a bottom-sheet affordance — mobile only. On desktop the
   right drawer still drags (swipe right to dismiss), just without the bar. */
@media (min-width: 968px) {
	.hfm-cartd .c-drawer__handle-wrapper {
		display: none;
	}
}

/* Neutralise global theme button styling inside the drawer — every control
   here styles itself. */
.hfm-cartd button {
	appearance: none;
	-webkit-appearance: none;
	font: inherit;
	box-shadow: none;
	text-transform: none;
	letter-spacing: normal;
}

.hfm-cartd .c-drawer__body {
	display: flex;
	flex-direction: column;
	height: 100%;
	padding: 0;
}

/* ── Header ────────────────────────────────────────────────────────── */

.hfm-cartd__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid var(--hfm-line);
}

.hfm-cartd__title {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
}

.hfm-cartd__countwrap {
	color: var(--hfm-ink-3);
	font-weight: 500;
}

.hfm-cartd__close {
	border: 0;
	background: none;
	color: var(--hfm-ink-2);
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	padding: 2px 8px;
	border-radius: var(--hfm-r-2);
}

.hfm-cartd__close:hover {
	color: var(--hfm-ink);
	background: var(--hfm-bg-2);
}

/* ── Notice ────────────────────────────────────────────────────────── */

.hfm-cartd__notice {
	margin: 12px 20px 0;
	padding: 10px 12px;
	border: 1px solid var(--hfm-line-2);
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
	font-size: 0.85rem;
	color: var(--hfm-ink-2);
}

/* ── Items ─────────────────────────────────────────────────────────── */

.hfm-cartd__ship {
	flex: 0 0 auto;
	padding: 12px 20px 0;
}

.hfm-cartd__items {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 8px 20px 16px;
}

.hfm-cartd__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.hfm-cartd__line {
	display: flex;
	gap: 12px;
	padding: 14px 0;
	border-bottom: 1px solid var(--hfm-line);
	transition: opacity 0.25s ease;
}

.hfm-cartd__line.is-removing {
	opacity: 0.35;
	pointer-events: none;
}

.hfm-cartd__line--added {
	animation: hfm-cartd-added 2.2s ease;
}

@keyframes hfm-cartd-added {
	0%, 40% { background: var(--hfm-accent-faint); }
	100%    { background: transparent; }
}

.hfm-cartd__thumb {
	flex: 0 0 64px;
	width: 64px;
	height: 64px;
	object-fit: cover;
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
	border: 1px solid var(--hfm-line);
}

.hfm-cartd__body {
	flex: 1 1 auto;
	min-width: 0;
}

.hfm-cartd__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
}

.hfm-cartd__name {
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.3;
	color: var(--hfm-ink);
	text-decoration: none;
}

.hfm-cartd__name:hover {
	color: var(--hfm-accent);
}

.hfm-cartd__remove {
	flex: 0 0 auto;
	border: 0;
	background: none;
	color: var(--hfm-ink-3);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
}

.hfm-cartd__remove:hover {
	color: var(--hfm-ink);
}

.hfm-cartd__variation {
	margin: 2px 0 0;
	font-size: 0.78rem;
	color: var(--hfm-ink-3);
}

.hfm-cartd__special {
	display: inline-block;
	margin-top: 4px;
	font-family: var(--hfm-f-mono);
	font-size: 0.7rem;
	color: var(--hfm-accent-2);
	border: 1px solid var(--hfm-accent-faint);
	border-radius: var(--hfm-r-2);
	padding: 2px 6px;
}

.hfm-cartd__includes {
	list-style: none;
	margin: 6px 0 0;
	padding: 6px 0 0 10px;
	border-left: 2px solid var(--hfm-line-2);
	font-size: 0.78rem;
	color: var(--hfm-ink-2);
}

.hfm-cartd__includes li {
	margin: 2px 0;
}

.hfm-cartd__row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 10px;
	gap: 8px;
}

.hfm-cartd__price {
	font-family: var(--hfm-f-mono);
	font-size: 0.9rem;
	font-weight: 600;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 1px;
}

/* Subtle per-line sale indicator. */
.hfm-cartd__line-save {
	font-size: 0.68rem;
	font-weight: 600;
	color: var(--hfm-ok);
}

/* ── Busy spinners (qty save, line remove) ─────────────────────────── */

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

/* Number → spinner while the debounced save is in flight. */
.hfm-cartd__qty.is-busy {
	pointer-events: none;
}

.hfm-cartd__qty.is-busy .hfm-cartd__qty-btn {
	opacity: 0.4;
}

.hfm-cartd__qty.is-busy .hfm-cartd__qty-val {
	color: transparent;
	position: relative;
}

.hfm-cartd__qty.is-busy .hfm-cartd__qty-val::after,
.hfm-cartd__line.is-removing .hfm-cartd__remove::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	border: 2px solid var(--hfm-line-2);
	border-top-color: var(--hfm-accent);
	animation: hfm-cartd-spin 0.6s linear infinite;
}

/* × → spinner while the remove request runs (line itself dims via
   .is-removing). Kept at full opacity against the dimmed line. */
.hfm-cartd__line.is-removing .hfm-cartd__remove {
	color: transparent;
	position: relative;
	opacity: 1;
}

.hfm-cartd__subtotal.is-busy .hfm-cartd__subtotal-val {
	opacity: 0.45;
	transition: opacity 0.15s ease;
}

/* ── Quantity stepper ──────────────────────────────────────────────── */

.hfm-cartd__qty {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	border: 1px solid var(--hfm-line);
	border-radius: var(--hfm-r-2);
	overflow: hidden;
}

.hfm-cartd__qty--fixed {
	border-style: dashed;
	color: var(--hfm-ink-3);
	font-size: 0.78rem;
	padding: 5px 10px;
	cursor: help;
}

.hfm-cartd__qty-btn {
	border: 0;
	background: var(--hfm-bg-2);
	color: var(--hfm-ink);
	width: 30px;
	height: 30px;
	font-size: 15px;
	line-height: 1;
	cursor: pointer;
}

.hfm-cartd__qty-btn:hover {
	background: var(--hfm-bg-3);
}

.hfm-cartd__qty-val {
	min-width: 28px;
	text-align: center;
	font-size: 0.85rem;
	font-weight: 600;
}

/* ── Cross-sells ───────────────────────────────────────────────────── */

.hfm-cartd__xsell {
	flex: 0 0 auto;
	padding: 10px 20px 4px;
	border-top: 1px solid var(--hfm-line);
}

.hfm-cartd__xsell-title {
	margin: 0 0 8px;
	font-family: var(--hfm-f-mono);
	font-size: 0.68rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--hfm-ink-3);
}

.hfm-cartd__xsell-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.hfm-cartd__xsell-item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 0;
}

.hfm-cartd__xsell-thumb {
	flex: 0 0 48px;
	width: 48px;
	height: 48px;
	object-fit: cover;
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
	border: 1px solid var(--hfm-line);
}

.hfm-cartd__xsell-body {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.hfm-cartd__xsell-name {
	font-size: 0.8rem;
	font-weight: 600;
	line-height: 1.25;
	color: var(--hfm-ink);
	text-decoration: none;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.hfm-cartd__xsell-name:hover {
	color: var(--hfm-accent);
}

.hfm-cartd__xsell-price {
	font-family: var(--hfm-f-mono);
	font-size: 0.78rem;
	color: var(--hfm-ink-2);
}

.hfm-cartd__xsell-chip {
	align-self: flex-start;
	font-family: var(--hfm-f-mono);
	font-size: 0.65rem;
	color: var(--hfm-accent-2);
	background: var(--hfm-accent-faint);
	border-radius: var(--hfm-r-2);
	padding: 1px 6px;
}

.hfm-cartd__xsell-add {
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	border: 1px solid var(--hfm-line-2);
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
	color: var(--hfm-ink);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	position: relative;
}

.hfm-cartd__xsell-add:hover {
	background: var(--hfm-accent);
	border-color: var(--hfm-accent);
	color: var(--hfm-accent-ink);
}

.hfm-cartd__xsell-add.is-busy {
	color: transparent;
	pointer-events: none;
}

.hfm-cartd__xsell-add.is-busy::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	border: 2px solid var(--hfm-line-2);
	border-top-color: var(--hfm-accent);
	animation: hfm-cartd-spin 0.6s linear infinite;
}

/* ── Footer ────────────────────────────────────────────────────────── */

.hfm-cartd__footer {
	flex: 0 0 auto;
	padding: 14px 20px 18px;
	border-top: 1px solid var(--hfm-line);
	background: var(--hfm-bg-1);
}

.hfm-cartd__savings {
	display: flex;
	justify-content: space-between;
	font-size: 0.8rem;
	margin-bottom: 6px;
	color: var(--hfm-ink-2);
}

.hfm-cartd__savings-val {
	font-family: var(--hfm-f-mono);
	font-weight: 600;
	color: var(--hfm-ok);
}

.hfm-cartd__subtotal {
	display: flex;
	justify-content: space-between;
	font-size: 0.9rem;
	font-weight: 600;
	margin-bottom: 12px;
}

.hfm-cartd__subtotal-val {
	font-family: var(--hfm-f-mono);
}

.hfm-cartd__checkout {
	display: block;
	text-align: center;
	padding: 13px 16px;
	border-radius: var(--hfm-r-2);
	background: var(--hfm-accent);
	color: var(--hfm-accent-ink);
	font-weight: 700;
	text-decoration: none;
	transition: opacity 0.15s ease;
}

.hfm-cartd__checkout:hover {
	background: var(--hfm-accent-2);
}

.hfm-cartd__checkout.is-busy {
	opacity: 0.55;
	pointer-events: none;
}

/* ── Mobile: bottom sheet rising from the tab bar ──────────────────────
   Mirrors the .hfm-mnav__d pattern (hfm-mobile-nav.css): sheet + bar read
   as one surface, bar stays visible/interactive below the sheet.
   --mnav-tab-h is defined on :root for exactly this cross-component use. */

@media (max-width: 967px) {
	.hfm-cartd {
		--drawer-z: 9980; /* under the 9990 tab bar */
		--drawer-overlay-color: rgba(0, 0, 0, 0.55);
		--drawer-inset: 0;
		--drawer-max-width: none;
		--drawer-radius: 20px;
	}

	.hfm-cartd .c-drawer__overlay {
		bottom: calc(var(--mnav-tab-h, 0px) + env(safe-area-inset-bottom));
	}

	.hfm-cartd .c-drawer[data-direction="bottom"] {
		width: auto;
		bottom: calc(var(--mnav-tab-h, 0px) + env(safe-area-inset-bottom));
		padding-bottom: 0; /* the bar below owns the safe area */
		--drawer-max-height: calc(92dvh - var(--mnav-tab-h, 0px) - env(safe-area-inset-bottom));
		overflow: hidden;
		box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
	}

	/* Same grab-handle spacing as the shop/search sheets. */
	.hfm-cartd .c-drawer__handle-wrapper {
		padding: 12px 0 6px;
	}
}

/* ── Free shipping bar (same visual language as legacy drawer) ─────── */

.hfm-cart-ship {
	border: 1px solid var(--hfm-line);
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-1);
	overflow: hidden;
}

.hfm-cart-ship__inner {
	padding: 10px 12px 8px;
}

.hfm-cart-ship__eyebrow {
	margin: 0;
	font-family: var(--hfm-f-mono);
	font-size: 0.68rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--hfm-ink-3);
}

.hfm-cart-ship__head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 8px;
}

.hfm-cart-ship__msg {
	margin: 2px 0 0;
	font-size: 0.85rem;
	font-weight: 600;
}

.hfm-cart-ship__target {
	font-family: var(--hfm-f-mono);
	font-size: 0.75rem;
	color: var(--hfm-ink-3);
}

.hfm-cart-ship__track {
	height: 5px;
	background: var(--hfm-bg-3);
}

.hfm-cart-ship__fill {
	height: 100%;
	width: 100%;
	background: var(--hfm-accent);
	transform-origin: left;
	transition: transform 0.4s ease;
}

.hfm-cart-ship.is-unlocked .hfm-cart-ship__fill {
	background: var(--hfm-accent-2);
}

/* ── Empty state ───────────────────────────────────────────────────── */

.hfm-cart-empty {
	text-align: center;
	padding: 40px 8px 24px;
}

.hfm-cart-empty__title {
	margin: 0 0 8px;
	font-size: 1.05rem;
	font-weight: 700;
}

.hfm-cart-empty__lede {
	margin: 0 0 20px;
	font-size: 0.88rem;
	color: var(--hfm-ink-2);
}

.hfm-cart-empty__trust {
	margin: 16px 0 0;
	font-size: 0.75rem;
	color: var(--hfm-ink-3);
}

.hfm-cartd__shop-btn {
	display: inline-block;
	padding: 12px 28px;
}

/* ── Skeleton (initial SSR state, replaced by first render) ────────── */

.hfm-cart-skeleton__row {
	display: flex;
	gap: 12px;
	padding: 14px 0;
}

.hfm-cart-skeleton__thumb {
	flex: 0 0 64px;
	height: 64px;
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
}

.hfm-cart-skeleton__body {
	flex: 1;
}

.hfm-cart-skeleton__line {
	height: 12px;
	border-radius: var(--hfm-r-2);
	background: var(--hfm-bg-2);
	margin-bottom: 8px;
}

.hfm-cart-skeleton__line--short {
	width: 55%;
}

.hfm-cartd.is-loading .hfm-cart-skeleton__thumb,
.hfm-cartd.is-loading .hfm-cart-skeleton__line {
	animation: hfm-cartd-pulse 1.2s ease-in-out infinite;
}

@keyframes hfm-cartd-pulse {
	0%, 100% { opacity: 1; }
	50%      { opacity: 0.45; }
}

/* ── Undo snackbar (ported class names) ────────────────────────────── */

.hfm-cart-undo {
	position: fixed;
	left: 50%;
	bottom: 24px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 14px;
	background: var(--hfm-ink);
	color: var(--hfm-bg);
	padding: 10px 16px;
	border-radius: var(--hfm-r-2);
	font-size: 0.85rem;
	z-index: 10010;
	animation: hfm-cartd-undo-in 0.22s ease;
}

.hfm-cart-undo.is-leaving {
	opacity: 0;
	transition: opacity 0.2s ease;
}

.hfm-cart-undo__action {
	border: 0;
	background: none;
	color: var(--hfm-accent);
	font-weight: 700;
	cursor: pointer;
	padding: 2px 4px;
}

@keyframes hfm-cartd-undo-in {
	from { transform: translate(-50%, 12px); opacity: 0; }
	to   { transform: translate(-50%, 0);   opacity: 1; }
}

/* Decorative motion off for reduced-motion users. Spinners stay — they are
   status indicators, not decoration (drawer.css already stills the panel). */
@media (prefers-reduced-motion: reduce) {
	.hfm-cartd__line--added {
		animation: none;
	}
	.hfm-cart-undo {
		animation: none;
	}
}
