/**
 * Khaloghli full-page loader animations and non-critical styles.
 *
 * Critical overlay paint styles ship inline in the early head template.
 * This file enhances the cart animation and the orbiting loader mark.
 *
 * @package Khaloghli_Customizations\Modules\Loader
 * @version 1.0.8
 * @updated 1.0.8
 */

/* Invoice pages inherit a dedicated Persian UI font stack. */
body.kh-invoice-body .kh-loader-overlay {
	font-family: 'IRANSansWeb', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Centered loader stack. */
.kh-loader-container {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 25px;
}

/* Cart animation stage. */
.kh-cart-wrapper {
	position: relative;
	width: 200px;
	height: 180px;
}

/* Bouncing cart shell. */
.kh-shopping-cart {
	width: 120px;
	height: 100px;
	position: absolute;
	left: 50%;
	top: 50px;
	transform: translateX(-50%);
	animation: kh-bounce 0.6s ease-in-out infinite;
}

/* Vertical bounce for the cart. */
@keyframes kh-bounce {
	0%,
	100% {
		transform: translateX(-50%) translateY(0);
	}

	50% {
		transform: translateX(-50%) translateY(-10px);
	}
}

/* Cart basket outline. */
.kh-cart-body {
	width: 80px;
	height: 60px;
	border: 4px solid #fff;
	border-radius: 8px;
	position: absolute;
	left: 20px;
	top: 0;
}

/* Cart handle outline. */
.kh-cart-handle {
	width: 35px;
	height: 40px;
	border: 4px solid #fff;
	border-right: none;
	border-bottom: none;
	border-radius: 8px 0 0 0;
	position: absolute;
	left: -15px;
	top: 0;
}

/* Wheel row under the cart. */
.kh-cart-wheels {
	position: absolute;
	bottom: -20px;
	left: 30px;
	display: flex;
	gap: 40px;
}

/* Spinning wheel. */
.kh-wheel {
	width: 18px;
	height: 18px;
	background: #fff;
	border-radius: 50%;
	animation: kh-rotate 0.5s linear infinite;
}

/* Continuous wheel rotation. */
@keyframes kh-rotate {
	from {
		transform: rotate(0deg);
	}

	to {
		transform: rotate(360deg);
	}
}

/* Falling grocery items layer. */
.kh-items-container {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 99;
}

/* Shared item base. */
.kh-item {
	font-size: 22px;
	position: absolute;
	left: 50%;
	top: -50px;
	transform: translateX(-50%);
	opacity: 0;
}

/* Staggered fall timelines per item. */
.kh-item:nth-child(1) {
	animation: kh-item-fall-1 5s ease-in infinite;
	animation-delay: 0s;
}

.kh-item:nth-child(2) {
	animation: kh-item-fall-2 5s ease-in infinite;
	animation-delay: 0.5s;
}

.kh-item:nth-child(3) {
	animation: kh-item-fall-3 5s ease-in infinite;
	animation-delay: 1s;
}

.kh-item:nth-child(4) {
	animation: kh-item-fall-4 5s ease-in infinite;
	animation-delay: 1.5s;
}

.kh-item:nth-child(5) {
	animation: kh-item-fall-5 5s ease-in infinite;
	animation-delay: 2s;
}

.kh-item:nth-child(6) {
	animation: kh-item-fall-6 5s ease-in infinite;
	animation-delay: 2.5s;
}

.kh-item:nth-child(7) {
	animation: kh-item-fall-7 5s ease-in infinite;
	animation-delay: 3s;
}

.kh-item:nth-child(8) {
	animation: kh-item-fall-8 5s ease-in infinite;
	animation-delay: 3.5s;
}

/* Item 1 fall path. */
@keyframes kh-item-fall-1 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 45%;
		transform: translateX(-50%) rotate(-30deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(-30deg) scale(1.1);
	}

	20% {
		top: 62px;
		left: 58%;
		transform: translateX(-50%) rotate(5deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 62px;
		left: 58%;
		transform: translateX(-50%) rotate(5deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 62px;
		left: 58%;
		transform: translateX(-50%) rotate(15deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 2 fall path. */
@keyframes kh-item-fall-2 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 55%;
		transform: translateX(-50%) rotate(25deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(25deg) scale(1.1);
	}

	20% {
		top: 67px;
		left: 65%;
		transform: translateX(-50%) rotate(-10deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 67px;
		left: 65%;
		transform: translateX(-50%) rotate(-10deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 67px;
		left: 65%;
		transform: translateX(-50%) rotate(0deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 3 fall path. */
@keyframes kh-item-fall-3 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 50%;
		transform: translateX(-50%) rotate(-40deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(-40deg) scale(1.1);
	}

	20% {
		top: 72px;
		left: 50%;
		transform: translateX(-50%) rotate(15deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 72px;
		left: 50%;
		transform: translateX(-50%) rotate(15deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 72px;
		left: 50%;
		transform: translateX(-50%) rotate(25deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 4 fall path. */
@keyframes kh-item-fall-4 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 60%;
		transform: translateX(-50%) rotate(35deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(35deg) scale(1.1);
	}

	20% {
		top: 76px;
		left: 43%;
		transform: translateX(-50%) rotate(-8deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 76px;
		left: 43%;
		transform: translateX(-50%) rotate(-8deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 76px;
		left: 43%;
		transform: translateX(-50%) rotate(2deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 5 fall path. */
@keyframes kh-item-fall-5 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 40%;
		transform: translateX(-50%) rotate(-20deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(-20deg) scale(1.1);
	}

	20% {
		top: 65px;
		left: 55%;
		transform: translateX(-50%) rotate(12deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 65px;
		left: 55%;
		transform: translateX(-50%) rotate(12deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 65px;
		left: 55%;
		transform: translateX(-50%) rotate(22deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 6 fall path. */
@keyframes kh-item-fall-6 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 52%;
		transform: translateX(-50%) rotate(-35deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(-35deg) scale(1.1);
	}

	20% {
		top: 70px;
		left: 60%;
		transform: translateX(-50%) rotate(8deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 70px;
		left: 60%;
		transform: translateX(-50%) rotate(8deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 70px;
		left: 60%;
		transform: translateX(-50%) rotate(18deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 7 fall path. */
@keyframes kh-item-fall-7 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 48%;
		transform: translateX(-50%) rotate(30deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(30deg) scale(1.1);
	}

	20% {
		top: 68px;
		left: 47%;
		transform: translateX(-50%) rotate(-12deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 68px;
		left: 47%;
		transform: translateX(-50%) rotate(-12deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 68px;
		left: 47%;
		transform: translateX(-50%) rotate(-2deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Item 8 fall path. */
@keyframes kh-item-fall-8 {
	0%,
	90%,
	100% {
		top: -50px;
		left: 58%;
		transform: translateX(-50%) rotate(-25deg) scale(0.8);
		opacity: 0;
	}

	10% {
		opacity: 1;
		transform: translateX(-50%) rotate(-25deg) scale(1.1);
	}

	20% {
		top: 74px;
		left: 53%;
		transform: translateX(-50%) rotate(10deg) scale(1);
		opacity: 1;
	}

	80% {
		top: 74px;
		left: 53%;
		transform: translateX(-50%) rotate(10deg) scale(1);
		opacity: 1;
	}

	85% {
		top: 74px;
		left: 53%;
		transform: translateX(-50%) rotate(20deg) scale(0.9);
		opacity: 0.8;
	}
}

/* Brand text stack. */
.kh-brand-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	margin-top: 10px;
}

/* Brand name treatment. */
.kh-brand-name {
	color: #fff;
	font-size: 28px;
	font-weight: bold;
	letter-spacing: 1px;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
	opacity: 1 !important;
	visibility: visible !important;
}

/* Brand tagline treatment. */
.kh-brand-tagline {
	color: rgba(255, 255, 255, 0.95);
	font-size: 14px;
	letter-spacing: 0.5px;
	opacity: 1 !important;
	visibility: visible !important;
}

/* Loading label. */
.kh-loading-text {
	color: #fff;
	font-size: 16px;
	font-weight: bold;
	letter-spacing: 1px;
	margin-top: 8px;
	opacity: 1 !important;
	visibility: visible !important;
}

/* Animated dots wrapper. */
.kh-dots {
	display: inline-block;
}

/* Single pulsing dot. */
.kh-dot {
	animation: kh-dot-pulse 1.4s ease-in-out infinite;
	opacity: 0;
}

/* Dot pulse delays. */
.kh-dot:nth-child(1) {
	animation-delay: 0s;
}

.kh-dot:nth-child(2) {
	animation-delay: 0.2s;
}

.kh-dot:nth-child(3) {
	animation-delay: 0.4s;
}

/* Dot opacity pulse. */
@keyframes kh-dot-pulse {
	0%,
	100% {
		opacity: 0;
	}

	50% {
		opacity: 1;
	}
}

/* Orbit stage under the loading label. Motion is driven by kh-loader-orbit.js. */
.kh-orbit {
	position: relative;
	display: block;
	width: 150px;
	height: 76px;
	margin: 0 auto;
	overflow: visible;
	direction: ltr;
	flex-shrink: 0;
	perspective: 500px;
	transform-style: preserve-3d;
	will-change: transform;
}

/* Elliptical path the dots travel on. */
.kh-orbit-track {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 76px;
	height: 26px;
	border: 1px solid rgba(255, 255, 255, 0.24);
	border-radius: 50%;
	transform: translate(-50%, -50%) rotate(-16deg) skewY(-9deg);
	transform-origin: center;
	pointer-events: none;
}

/* Shared orbiting dot. Frame script updates transform, opacity, and glow. */
.kh-orbit-dot {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 16px;
	height: 16px;
	margin: 0;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: #fff;
	display: block;
	transform-origin: center;
	pointer-events: none;
	will-change: transform, opacity, filter;
}

/* Resting positions used before the script runs, and for reduced motion. */
.kh-orbit-dot:nth-child(2) {
	transform: translate(-50%, -50%) translate(34px, -4px) scale(0.9);
	opacity: 0.95;
}

.kh-orbit-dot:nth-child(3) {
	transform: translate(-50%, -50%) translate(-17px, 10px) scale(0.55);
	opacity: 0.55;
}

.kh-orbit-dot:nth-child(4) {
	transform: translate(-50%, -50%) translate(-17px, -12px) scale(0.4);
	opacity: 0.35;
}

@media (prefers-reduced-motion: reduce) {
	.kh-orbit {
		will-change: auto;
	}

	.kh-orbit-dot {
		will-change: auto;
	}
}
