/*
 * Cart drawer (#cw-drawer-cart). The shell is printed by template-parts/header/drawer-cart.php and the rows are
 * rendered by assets/js/cart-drawer.js. Base drawer, overlay and panel behavior: drawer.css.
 * Desktop: 440px from the right, slide .26s. Mobile (< 900px): min(90vw, 400px) with rounded leading corners.
 */
.cw-drawer--cart {
	--cw-cart-width: 440px;
	--cw-cart-pad: 24px;
	--cw-cart-thumb: 64px;
	--cw-cart-stepper-w: 118px;
	width: min(var(--cw-cart-width), 100vw);
	transition: transform .26s ease-out;
}

/* Elements with a display value of their own must still honor [hidden]. */
.cw-drawer--cart [hidden] {
	display: none;
}

.cw-drawer--cart .cw-drawer__head {
	min-height: 0;
	gap: 12px;
	padding: 18px var(--cw-cart-pad);
	border-bottom-color: var(--cw-color-line-soft);
}

.cw-drawer--cart .cw-drawer__title {
	margin-right: auto;
	font-size: 20px;
	line-height: 1.2;
}

.cw-drawer--cart .cw-drawer__close {
	width: var(--cw-control-h-sm);
	height: var(--cw-control-h-sm);
	border-radius: var(--cw-radius);
	background: var(--cw-color-subtle);
}

.cw-drawer--cart .cw-drawer__close .cw-icon {
	width: 20px;
	height: 20px;
}

.cw-cart__messages {
	margin: 0;
}

.cw-cart__messages:not(:empty) {
	margin: 12px var(--cw-cart-pad) 0;
	padding: 10px 12px;
	border: 1px solid var(--cw-color-accent);
	border-radius: var(--cw-radius);
	background: var(--cw-color-accent-soft);
	color: var(--cw-color-accent-strong);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
}

.cw-cart__body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 0 var(--cw-cart-pad);
}

.cw-cart__unavailable {
	margin: 32px 0;
	color: var(--cw-color-muted);
	text-align: center;
}

.cw-cart__loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	margin: 0;
	padding: 48px 0;
	color: var(--cw-color-text-2);
	font-size: 14px;
}

.cw-cart__spinner {
	width: 24px;
	height: 24px;
	border: 3px solid var(--cw-color-line);
	border-top-color: var(--cw-color-button);
	border-radius: 50%;
	animation: cw-cart-spin .8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
	.cw-cart__spinner,
	.cw-cart-item.is-updating .cw-cart-item__thumb::after {
		animation-duration: 3s;
	}

	.cw-cart__progress.is-active::after {
		width: 100%;
		animation: none;
		transform: none;
	}
}

/* Thin indeterminate bar above the list while a mutation request runs (cart-drawer.js toggles .is-active). */
.cw-cart__progress {
	height: 3px;
	flex: 0 0 auto;
	overflow: hidden;
}

.cw-cart__progress::after {
	display: block;
	width: 40%;
	height: 100%;
	background: var(--cw-color-button);
	opacity: 0;
	content: "";
	transform: translateX(-100%);
}

.cw-cart__progress.is-active::after {
	opacity: 1;
	animation: cw-cart-progress 1s ease-in-out infinite;
}

@keyframes cw-cart-progress {
	to {
		transform: translateX(250%);
	}
}

/* Rows */
.cw-cart__items {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Mutation in flight: no scroll lock, the controls only show a progress cursor. */
.cw-cart__items.is-busy .cw-cart-item button {
	cursor: progress;
}

.cw-cart-item {
	display: grid;
	grid-template-columns: var(--cw-cart-thumb) minmax(0, 1fr);
	gap: 12px;
	padding: 14px 0;
	border-bottom: 1px solid var(--cw-color-line-soft);
}

.cw-cart-item__thumb {
	position: relative;
	display: grid;
	width: var(--cw-cart-thumb);
	height: var(--cw-cart-thumb);
	place-items: center;
	border-radius: var(--cw-radius);
	background: var(--cw-color-subtle);
}

/* Two classes: must beat `.woocommerce-page img` (0,1,1) of woocommerce-layout.css. */
.cw-drawer .cw-cart-item__image {
	width: 80%;
	height: 80%;
	object-fit: contain;
}

.cw-cart-item__info {
	display: flex;
	min-width: 0;
	flex-direction: column;
	gap: 6px;
}

.cw-cart-item__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
}

.cw-drawer .cw-cart-item__name {
	min-width: 0;
	color: var(--cw-color-ink);
	font-size: 14px;
	font-weight: 700;
	line-height: 1.3;
	overflow-wrap: anywhere;
}

.cw-drawer .cw-cart-item__name:hover,
.cw-drawer .cw-cart-item__name:focus-visible {
	text-decoration: underline;
}

.cw-cart-item__remove {
	display: grid;
	width: 30px;
	height: 30px;
	flex: 0 0 auto;
	margin: 0;
	padding: 0;
	place-items: center;
	border: 0;
	border-radius: var(--cw-radius);
	background: var(--cw-color-bg);
	color: var(--cw-color-muted);
	cursor: pointer;
}

.cw-cart-item__remove:hover,
.cw-cart-item__remove:focus-visible {
	color: var(--cw-color-ink);
}

.cw-cart-item__remove .cw-icon {
	width: 16px;
	height: 16px;
}

.cw-cart-item__meta,
.cw-cart-item__discount {
	margin: 0;
	color: var(--cw-color-muted);
	font-size: 12px;
	line-height: 1.4;
}

.cw-cart-item__sku:not([hidden])::after {
	content: " \00b7 ";
}

.cw-cart-item__regular {
	margin-right: 4px;
}

.cw-cart-item__foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.cw-cart-item__foot .cw-stepper {
	width: var(--cw-cart-stepper-w);
	flex: 0 0 auto;
}

.cw-cart-item__qty {
	color: var(--cw-color-text-2);
	font-size: 13px;
	font-weight: 600;
}

.cw-cart-item__total {
	margin-left: auto;
	color: var(--cw-color-ink);
	font-size: 15px;
	text-align: right;
}

/* Row with the request in flight: dimmed thumbnail and a small spinner over it. */
.cw-cart-item.is-updating .cw-cart-item__image {
	opacity: .4;
}

.cw-cart-item.is-updating .cw-cart-item__thumb::after {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 22px;
	height: 22px;
	margin: -11px 0 0 -11px;
	border: 3px solid var(--cw-color-line);
	border-top-color: var(--cw-color-button);
	border-radius: 50%;
	animation: cw-cart-spin .8s linear infinite;
	content: "";
}

/* Controls at their quantity limit (aria-disabled keeps the focus in place). */
.cw-cart-item [aria-disabled="true"] {
	cursor: not-allowed;
	opacity: .45;
}

.cw-cart-item .cw-stepper__button[aria-disabled="true"]:hover {
	background: var(--cw-color-surface);
}

/* Empty state */
.cw-cart-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding: 32px 0;
	text-align: center;
}

.cw-cart-empty__icon {
	display: grid;
	width: 72px;
	height: 72px;
	place-items: center;
	border-radius: var(--cw-radius);
	background: var(--cw-color-subtle);
	color: var(--cw-color-text-2);
}

.cw-cart-empty__title,
.cw-cart-empty__text {
	margin: 0;
}

.cw-cart-empty__title {
	color: var(--cw-color-ink);
	font-size: 18px;
	font-weight: 700;
}

.cw-cart-empty__text {
	color: var(--cw-color-text-2);
	font-size: 14px;
}

/* Footer */
.cw-cart__footer {
	display: grid;
	gap: 10px;
	padding: 16px var(--cw-cart-pad) 20px;
	border-top: 1px solid var(--cw-color-line);
	background: var(--cw-color-bg);
}

.cw-cart__row {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin: 0;
}

.cw-cart__row--saving {
	color: var(--cw-color-success);
	font-size: 14px;
	font-weight: 600;
}

.cw-cart__row--subtotal > span {
	color: var(--cw-color-text-2);
	font-size: 15px;
}

.cw-cart__row--subtotal > strong {
	color: var(--cw-color-ink);
	font-size: 24px;
	letter-spacing: -.02em;
}

.cw-cart__note {
	margin: 0;
	color: var(--cw-color-muted);
	font-size: 12px;
	line-height: 1.4;
}

.cw-drawer--cart .cw-cart__footer .cw-button {
	color: var(--cw-button-color);
}

@media (max-width: 899px) {
	.cw-drawer--cart {
		--cw-cart-width: min(90vw, 400px);
		--cw-cart-pad: 16px;
		border-radius: var(--cw-radius) 0 0 var(--cw-radius);
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-drawer--cart {
		transition: none;
	}
}
