/**
 * lpk-toast.css
 *
 * Styles for the toast notification system + the cart-counter bounce
 * animation used by Stage 3 optimistic add-to-cart UI.
 *
 * Loaded conditionally — only enqueued when lpk_enable_optimistic_ui = yes
 * (see functions.php). Stays out of the critical path entirely when the
 * feature flag is off.
 *
 * @phase 4-G stage 2 — optimistic UI helpers
 */

/* === Container (fixed bottom-right; stacks newest-on-top via reverse) === */
#lpk-toast-container {
	position: fixed;
	bottom: var(--space-4);
	right: var(--space-4);
	z-index: 9999;
	display: flex;
	flex-direction: column-reverse;
	gap: var(--space-2);
	pointer-events: none; /* container ignores clicks; toasts re-enable */
}

/* === Toast card === */
.lpk-toast {
	pointer-events: auto;
	min-width: 280px;
	max-width: 420px;
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-md);
	background: var(--color-bg-page);
	color: var(--color-text-primary);
	font-family: var(--font-body);
	font-size: var(--fs-body-sm);
	line-height: 1.45;
	cursor: pointer;
	border-left: 4px solid var(--color-border-strong);
	display: flex;
	align-items: flex-start;
	gap: var(--space-3);

	/* Resting state for slide animation */
	transform: translateY(0);
	opacity: 1;
	transition: transform 250ms ease, opacity 250ms ease;
}

.lpk-toast__message {
	flex: 1 1 auto;
	min-width: 0;
	word-wrap: break-word;
}

.lpk-toast__action {
	flex-shrink: 0;
	background: transparent;
	border: 0;
	padding: 0;
	margin: 0;
	color: var(--color-accent-mint-dark);
	font-family: inherit;
	font-size: inherit;
	font-weight: 600;
	cursor: pointer;
	text-decoration: none;
}
.lpk-toast__action:hover,
.lpk-toast__action:focus {
	text-decoration: underline;
	text-underline-offset: 2px;
	outline: none;
}

/* === Type variants — coloured left border === */
.lpk-toast--success { border-left-color: var(--color-success); }
.lpk-toast--error   { border-left-color: var(--color-error); }
.lpk-toast--warning { border-left-color: var(--color-warning); }
.lpk-toast--info    { border-left-color: var(--color-info); }

/* === Animation states === */
.lpk-toast.is-entering {
	transform: translateY(20px);
	opacity: 0;
}
.lpk-toast.is-leaving {
	transform: translateY(20px);
	opacity: 0;
}

/* === Mobile layout (≤ 600px): full width, bottom moves up to clear FAB === */
@media (max-width: 600px) {
	#lpk-toast-container {
		left: var(--space-4);
		right: var(--space-4);
		bottom: calc(var(--space-4) + 72px); /* clears WhatsApp FAB if present */
	}
	.lpk-toast {
		min-width: 0;
		max-width: none;
		width: 100%;
	}
}

/* ============================================================
 * Cart counter bounce — used by Stage 3 when an item is added
 * to cart with optimistic UI. Triggered by JS adding the
 * .lpk-cart-counter--bouncing class for the duration of the
 * animation, then removing it.
 * ============================================================ */
@keyframes lpk-bounce {
	0%   { transform: scale(1); }
	30%  { transform: scale(1.3); }
	60%  { transform: scale(0.9); }
	100% { transform: scale(1); }
}

.lpk-cart-counter--bouncing {
	animation: lpk-bounce 400ms ease-out;
}

/* ============================================================
 * Add-to-Cart pulse — Stage 3 hotfix. Visual-only confirmation
 * that a click registered, without disabling the button. The
 * scale-down + green ripple matches the bounce on the cart
 * counter so the two read as a single "added" gesture.
 *
 * Applied by pdp-page.js Path A (optimistic) only — classic
 * and fallback paths still use the locking button state.
 * ============================================================ */
@keyframes lpk-atc-pulse {
	0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
	50%  { transform: scale(0.97); box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
	100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.lpk-atc--just-clicked {
	animation: lpk-atc-pulse 600ms ease-out;
}

/* ============================================================
 * Inline ATC confirmation card — Stage 4 (hotfix v2 layout).
 * Flex layout with width:100%, flex:0 0 auto so the card cannot
 * be compressed by a parent flex container (e.g. when inserted
 * adjacent to a flex button row). Single-line ellipsis on text
 * rows so long product names don't blow the card up.
 * ============================================================ */
.lpk-atc-confirm {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: var(--space-3, 14px);
	width: 100%;
	flex: 0 0 auto;
	min-width: 0;
	box-sizing: border-box;
	margin-top: var(--space-3, 16px);
	padding: var(--space-3, 14px) var(--space-4, 18px);
	background: var(--color-surface, #f4faf6);
	border: 1px solid var(--color-success, #22c55e);
	border-left: 4px solid var(--color-success, #22c55e);
	border-radius: var(--radius-md, 8px);
	box-shadow: 0 4px 14px rgba(34, 197, 94, 0.12);
	animation: lpk-atc-confirm-in 250ms ease-out;
	font: var(--font-body, 15px/1.45 system-ui);
}
.lpk-atc-confirm.is-leaving { animation: lpk-atc-confirm-out 350ms ease-in forwards; }

.lpk-atc-confirm__check {
	flex: 0 0 28px;
	display: inline-flex; align-items: center; justify-content: center;
	width: 28px; height: 28px;
	background: var(--color-success, #22c55e); color: #fff;
	border-radius: 50%; font-weight: bold; font-size: 16px;
}
.lpk-atc-confirm__text { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.lpk-atc-confirm__line1 {
	font-weight: 600; color: #14532d;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lpk-atc-confirm__line2 {
	font-size: 0.92em; color: #166534; opacity: 0.85;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
	margin-top: 2px;
}
.lpk-atc-confirm__line3 {
	font-size: 0.85em; color: #16a34a; margin-top: 2px;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lpk-atc-confirm__link {
	flex: 0 0 auto;
	color: var(--color-success, #16a34a);
	font-weight: 600; font-size: 0.92em;
	text-decoration: none; padding: 6px 10px; border-radius: 6px;
	transition: background 150ms;
	white-space: nowrap;
}
.lpk-atc-confirm__link:hover { background: rgba(34, 197, 94, 0.08); }

@keyframes lpk-atc-confirm-in {
	from { opacity: 0; transform: translateY(-6px); }
	to   { opacity: 1; transform: translateY(0); }
}
@keyframes lpk-atc-confirm-out {
	from { opacity: 1; max-height: 200px; }
	to   { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin-top: 0; }
}

@media (max-width: 600px) {
	.lpk-atc-confirm { flex-wrap: wrap; }
	.lpk-atc-confirm__link {
		flex: 1 1 100%; text-align: center; margin-top: var(--space-2, 8px);
	}
}

/* ============================================================
 * Cart-item leaving animation — Stage 4. Applied by cart-page.js
 * when Remove is clicked (optimistic). On error, the class is
 * removed and the row springs back into place.
 * ============================================================ */
.lpk-cart__item.is-leaving {
	transition: opacity 200ms ease, transform 200ms ease, max-height 250ms ease, padding 250ms ease, margin 250ms ease;
	opacity: 0;
	transform: translateX(-8px);
	max-height: 0;
	overflow: hidden;
	padding-top: 0;
	padding-bottom: 0;
	margin-top: 0;
	margin-bottom: 0;
}

/* Cart-item pending state — subtle green tint while the optimistic
 * UI waits for the server to confirm the qty change. */
.lpk-cart__item.is-pending {
	transition: background 150ms;
	background: rgba(34, 197, 94, 0.03);
}
