/**
 * Cart drawer (mini-carrinho lateral).
 *
 * Side-sheet fixo à direita + backdrop. Estado controlado por .is-open (o JS
 * também usa o atributo [hidden] para tirar da árvore quando fechado). Só tokens
 * de tokens.css — nada hard-coded além de valores estruturais.
 */

.cart-drawer {
	position: fixed;
	inset: 0;
	/* Acima de tudo, inclusive widgets de terceiros (WhatsApp etc.). O JS ainda
	   re-append o drawer ao fim do body ao abrir, para vencer no empate de z-index. */
	z-index: 2147483647;
}

.cart-drawer[hidden] {
	display: none;
}

.cart-drawer__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.42);
	opacity: 0;
	transition: opacity var(--duration-normal) var(--ease-default);
}

.cart-drawer.is-open .cart-drawer__backdrop {
	opacity: 1;
}

.cart-drawer__panel {
	position: absolute;
	top: 0;
	right: 0;
	height: 100%;
	width: min(420px, 100%);
	display: flex;
	flex-direction: column;
	background: var(--color-panel, var(--color-bg));
	color: var(--color-fg);
	box-shadow: var(--shadow-lg);
	transform: translateX(100%);
	transition: transform var(--duration-normal) var(--ease-out);
	will-change: transform;
	overscroll-behavior: contain;
}

.cart-drawer.is-open .cart-drawer__panel {
	transform: translateX(0);
}

.cart-drawer__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-4);
	padding: var(--space-6);
	border-bottom: 1px solid var(--color-border);
}

.cart-drawer__title {
	margin: 0;
	font-family: var(--font-heading);
	font-size: var(--text-h5);
	font-weight: var(--font-semibold);
}

.cart-drawer__close {
	appearance: none;
	border: 0;
	background: transparent;
	color: var(--color-fg-subtle);
	font-size: 28px;
	line-height: 1;
	cursor: pointer;
	padding: 0 var(--space-2);
	border-radius: var(--radius-sm);
}

.cart-drawer__close:hover {
	color: var(--color-fg);
}

.cart-drawer__body {
	flex: 1;
	overflow-y: auto;
	padding: var(--space-4) var(--space-6);
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
}

.cart-drawer__empty {
	margin: auto 0;
	text-align: center;
	color: var(--color-fg-subtle);
	font-family: var(--font-body);
	font-size: var(--text-p);
}

/* Item = mesma arquitetura do resumo do pedido do checkout (.bc-summary__item). */
.cart-drawer__item {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	column-gap: var(--space-3);
	row-gap: var(--space-2);
	padding-bottom: var(--space-4);
	border-bottom: 1px solid var(--color-divider, var(--color-border));
}

.cart-drawer__item:last-child {
	border-bottom: 0;
	padding-bottom: 0;
}

/* Thumb: capa inteira (object-fit: contain) sobre fundo pastel derivado da cor
   predominante (aplicado inline pelo JS), + badge de quantidade. */
.cart-drawer__thumb {
	position: relative;
	width: 56px;
	height: 56px;
	flex: none;
}

.cart-drawer__thumb-inner {
	width: 100%;
	height: 100%;
	overflow: hidden;
	background: #fff;
	border-radius: var(--radius-md, 8px);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 5px;
	transition: background-color 0.3s ease;
}

.cart-drawer__thumb-inner img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	display: block;
}

.cart-drawer__badge {
	position: absolute;
	top: -8px;
	right: -8px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: var(--radius-full, 999px);
	background: var(--color-cta);
	color: var(--color-cta-fg);
	font-family: var(--font-ui);
	font-size: 12px;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 0 0 2px var(--color-panel, var(--color-bg));
}

.cart-drawer__info {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.cart-drawer__name {
	font-family: var(--font-body);
	font-size: var(--text-p);
	line-height: 1.35;
}

.cart-drawer__controls {
	display: flex;
	align-items: center;
	gap: var(--space-3);
}

.cart-drawer__qty {
	display: inline-flex;
	align-items: center;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
}

.cart-drawer__qty button {
	appearance: none;
	width: 28px;
	height: 28px;
	border: 0;
	background: transparent;
	color: var(--color-fg);
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
}

.cart-drawer__qty button:hover {
	color: var(--color-secondary);
}

.cart-drawer__qty-val {
	min-width: 24px;
	text-align: center;
	font-family: var(--font-ui);
	font-size: var(--text-p);
	font-variant-numeric: tabular-nums;
}

.cart-drawer__remove {
	appearance: none;
	border: 0;
	background: transparent;
	padding: 0;
	color: var(--color-fg-subtle);
	font-family: var(--font-ui);
	font-size: var(--text-small);
	text-decoration: underline;
	cursor: pointer;
}

.cart-drawer__remove:hover {
	color: var(--color-error, var(--color-fg));
}

.cart-drawer__price {
	margin-left: auto;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 1px;
	font-family: var(--font-ui);
	font-size: var(--text-p);
	font-variant-numeric: tabular-nums;
}

.cart-drawer__price-old {
	font-size: var(--text-small);
	color: var(--color-fg-subtle);
	text-decoration: line-through;
}

.cart-drawer__price-new {
	color: var(--color-fg);
	font-weight: var(--font-semibold);
}

.cart-drawer__footer {
	padding: var(--space-6);
	border-top: 1px solid var(--color-border);
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
}

.cart-drawer--empty .cart-drawer__footer {
	display: none;
}

.cart-drawer__subtotal {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	font-family: var(--font-ui);
	font-size: var(--text-body);
	font-weight: var(--font-semibold);
}

.cart-drawer__checkout {
	width: 100%;
	justify-content: center;
	text-align: center;
}

/* Enquanto uma mutação está em voo, evita cliques repetidos. */
.cart-drawer.is-busy .cart-drawer__body {
	opacity: 0.6;
	pointer-events: none;
}

/* ------------------------------------------------------------------ *
 * Feedback do add-to-cart: botão → sucesso (✓) + pop no badge.
 * O botão de compra (.book-buy__cta) é do tema; aqui só adicionamos os
 * estados transitórios que o cart-drawer.js liga/desliga.
 * ------------------------------------------------------------------ */

.book-buy__cta.is-loading,
.book-buy__cta.is-added {
	position: relative;
}

/* Loading: esconde o rótulo e mostra um spinner centralizado. */
.book-buy__cta.is-loading {
	pointer-events: none;
	color: transparent;
}

.book-buy__cta.is-loading::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 18px;
	height: 18px;
	margin: -9px 0 0 -9px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: #fff;
	border-radius: 50%;
	animation: bc-cta-spin 0.6s linear infinite;
}

/* Sucesso: vira "Adicionado ✓" em verde por um instante. */
.book-buy__cta.is-added {
	color: transparent;
	background-color: var(--color-success, #16a34a);
}

.book-buy__cta.is-added::after {
	content: "Adicionado ✓";
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	font-weight: var(--font-semibold);
	animation: bc-cta-pop 0.28s var(--ease-out, ease);
}

@keyframes bc-cta-spin {
	to {
		transform: rotate(360deg);
	}
}

@keyframes bc-cta-pop {
	0% {
		transform: scale(0.92);
		opacity: 0;
	}
	100% {
		transform: scale(1);
		opacity: 1;
	}
}

/* Fly-to-cart: capa voa até o ícone do carrinho com arco suave. */
.bc-fly {
	position: fixed;
	z-index: 2147483647;
	pointer-events: none;
	border-radius: var(--radius-md, 8px);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
	object-fit: contain;
	background: #fff;
	padding: 3px;
	opacity: 1;
}

.bc-fly.is-flying {
	transition:
		left 0.65s ease,
		top 0.65s cubic-bezier(0.2, 0, 0, 1),
		width 0.65s ease,
		height 0.65s ease,
		opacity 0.55s ease-in 0.1s;
}

/* Badge do carrinho: "pop" quando o número sobe. */
.site-header__cart-count.is-bump {
	animation: bc-badge-pop 0.42s var(--ease-out, ease);
}

@keyframes bc-badge-pop {
	0% {
		transform: scale(1);
	}
	30% {
		transform: scale(1.35);
	}
	60% {
		transform: scale(0.95);
	}
	100% {
		transform: scale(1);
	}
}

@media (prefers-reduced-motion: reduce) {
	.cart-drawer__backdrop,
	.cart-drawer__panel {
		transition: none;
	}
	.book-buy__cta.is-loading::after,
	.book-buy__cta.is-added::after,
	.site-header__cart.is-flash::before {
		animation: none;
	}
	.site-header__cart-count.is-bump {
		animation: none;
	}
	.bc-fly.is-flying {
		transition: none;
	}
}
