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

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

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

	--urlar-bg:    var(--wp--preset--color--base, light-dark(#fcfcfc, #0a0a0a));
	--urlar-bg-1:  var(--wp--preset--color--base-2, light-dark(#f7f7f7, #171717));
	--urlar-bg-2:  var(--wp--preset--color--neutral-100, light-dark(#f5f5f5, #171717));
	--urlar-bg-3:  var(--wp--preset--color--grey-200, light-dark(#e5e5e5, #262626));
	--urlar-line:   var(--wp--preset--color--grey-200, light-dark(#e5e5e5, #262626));
	--urlar-line-2: var(--wp--preset--color--grey-300, light-dark(#d4d4d4, #404040));
	--urlar-ink:    var(--wp--preset--color--contrast, light-dark(#191919, #f5f5f5));
	--urlar-ink-2:  var(--wp--preset--color--grey-600, light-dark(#525252, #a3a3a3));
	--urlar-ink-3:  var(--wp--preset--color--grey-500, light-dark(#737373, #737373));
	--urlar-accent:     var(--wp--preset--color--purple-500, light-dark(#874da2, #d05aff));
	--urlar-accent-2:   var(--wp--preset--color--purple-600, light-dark(#75448c, #d87aff));
	--urlar-accent-ink: light-dark(#ffffff, #0e0420);
	--urlar-accent-faint: var(--wp--preset--color--purple-100, light-dark(#f3e8f7, #41284a));
	--urlar-ok:    var(--wp--preset--color--green-500, light-dark(#16a34a, #4ade80));
	--urlar-r-2: 4px;
	--urlar-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(--urlar-bg);
	--drawer-color: var(--urlar-ink);
	--drawer-max-width: none;

	font-family: inherit;
}

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

.urlar-cartd .c-drawer {
	width: min(480px, calc(100vw - 24px));
	color: var(--urlar-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) {
	.urlar-cartd .c-drawer__handle-wrapper {
		display: none;
	}
}

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

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

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

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

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

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

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

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

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

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

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

.urlar-cartd__ship {
	flex: 0 0 auto;
	padding: 10px 20px 0;
}

.urlar-cartd__ship:empty {
	padding: 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.urlar-cartd__price {
	font-family: var(--urlar-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. */
.urlar-cartd__line-save {
	font-size: 0.68rem;
	font-weight: 600;
	color: var(--urlar-ok);
}

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

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

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

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

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

.urlar-cartd__qty.is-busy .urlar-cartd__qty-val::after,
.urlar-cartd__line.is-removing .urlar-cartd__remove::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	border: 2px solid var(--urlar-line-2);
	border-top-color: var(--urlar-accent);
	animation: urlar-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. */
.urlar-cartd__line.is-removing .urlar-cartd__remove {
	color: transparent;
	position: relative;
	opacity: 1;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.urlar-cartd__xsell-price del {
	color: var(--urlar-ink-3);
	margin-right: 4px;
}

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

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

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

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

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

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

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

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

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

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

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

/* Currency code after the amount — answers "is this AUD or USD?" at a glance. */
.urlar-cartd__subtotal-cur {
	font-family: var(--urlar-f-mono);
	font-size: 0.78rem;
	font-weight: 500;
	color: var(--urlar-ink-3);
}

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

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

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

/* ── Mobile: bottom sheet rising from the tab bar ──────────────────────
   Mirrors the .urlar-mnav__d pattern (urlar-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) {
	.urlar-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;
	}

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

	.urlar-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 */
		/* Fixed full height like the search/garage sheets (not content-sized) —
		   the items area owns the middle, footer pins to the bottom, so even a
		   small cart gets the full sheet. */
		height: calc(96dvh - var(--mnav-tab-h, 0px) - env(safe-area-inset-bottom));
		--drawer-max-height: calc(96dvh - 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. */
	.urlar-cartd .c-drawer__handle-wrapper {
		padding: 12px 0 6px;
	}

	/* Tighter chrome — the sheet competes with the tab bar for height. */
	.urlar-cartd__header {
		padding: 8px 16px 10px;
	}

	.urlar-cartd__ship {
		padding: 3px 16px 0;
	}

	/* Shipping bar sits tight to the items below — message baseline almost on
	   the track. Applies in every state, incl. the taller "$X to go" one. */
	.urlar-cartd__ship .urlar-cart-ship__head {
		margin-bottom: 2px;
	}

	.urlar-cartd__ship .urlar-cart-ship__msg {
		font-size: 0.74rem;
	}

	.urlar-cartd__items {
		padding: 2px 16px 8px;
	}

	.urlar-cartd__line {
		padding: 10px 0;
	}

	.urlar-cartd__footer {
		padding: 10px 16px 12px;
	}

	/* Cross-sells: one row, native scroll-snap slider — three stacked cards
	   were burying the cart lines on a phone. */
	.urlar-cartd__xsell {
		padding: 8px 0 0 16px;
	}

	.urlar-cartd__xsell-title {
		margin-bottom: 6px;
	}

	.urlar-cartd__xsell-list {
		display: flex;
		gap: 8px;
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		padding: 0 16px 8px 0;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
		touch-action: pan-x; /* browser owns the horizontal swipe (see gallery.css) */
	}

	.urlar-cartd__xsell-list::-webkit-scrollbar {
		display: none;
	}

	.urlar-cartd__xsell-item {
		flex: 0 0 auto;
		width: min(260px, 78vw);
		scroll-snap-align: start;
		padding: 8px 10px;
		border: 1px solid var(--urlar-line);
		border-radius: var(--urlar-r-2);
		background: var(--urlar-bg-1);
	}

	.urlar-cartd__xsell-thumb {
		flex-basis: 40px;
		width: 40px;
		height: 40px;
	}
}

/* ── Free shipping bar — borderless one-liner + brand-gradient track ──
   Gradient values mirror the brand red→purple in urlar-styles.css. Note:
   DESIGN.md reserves that gradient for marketing surfaces — used here on
   explicit request; swap the fill to a purple ramp for doctrine compliance. */

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

.urlar-cart-ship__msg {
	margin: 0;
	font-size: 0.78rem;
	font-weight: 600;
	color: var(--urlar-ink-2);
}

/* Unlocked: full-strength ink (black in light mode), not green — user call. */
.urlar-cart-ship.is-unlocked .urlar-cart-ship__msg {
	color: var(--urlar-ink);
}

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

/* The track IS the gradient, full width and uncompressed; the "fill" element
   is a neutral cover over the un-earned portion, retreating rightward as the
   subtotal grows (scaleX from the right — compositor-only, no repaints). */
.urlar-cart-ship__track {
	height: 4px;
	border-radius: 999px;
	background: linear-gradient(to right, #c43a30 0%, #874da2 100%);
	overflow: hidden;
}

.urlar-cart-ship__fill {
	height: 100%;
	width: 100%;
	background: var(--urlar-bg-3);
	transform-origin: right;
	transition: transform 0.4s ease;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@keyframes urlar-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) {
	.urlar-cartd__line--added {
		animation: none;
	}
	.urlar-cart-undo {
		animation: none;
	}
}
