/**
 * Loading State Components
 * Spinners, skeleton screens, and progress bars
 * Implements specifications from TECHTRONIC_DESIGN_SYSTEM.md Section 7.9
 *
 * @package Techtronic_Learning
 * @since 1.0.0
 */

/* ==========================================================================
   Spinner Component
   ========================================================================== */

.spinner {
	/* Size */
	width: 40px;
	height: 40px;

	/* Appearance */
	border: 3px solid var(--gray-700);
	border-top-color: var(--accent-700);
	border-radius: 50%;

	/* Animation */
	animation: spin 0.8s linear infinite;
}

.spinner--small {
	width: 24px;
	height: 24px;
	border-width: 2px;
}

.spinner--large {
	width: 56px;
	height: 56px;
	border-width: 4px;
}

/* Spinner color variants */
.spinner--teal {
	border-top-color: var(--primary-500);
}

.spinner--white {
	border-color: rgba(255, 255, 255, 0.3);
	border-top-color: #ffffff;
}

.spinner--dark {
	border-color: rgba(0, 0, 0, 0.1);
	border-top-color: var(--gray-900);
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* Centered spinner */
.spinner--center {
	margin: 0 auto;
}

/* ==========================================================================
   Spinner Overlay (Full Page Loading)
   ========================================================================== */

.spinner-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 9998;

	display: flex;
	align-items: center;
	justify-content: center;

	background: rgba(10, 14, 20, 0.8);
	backdrop-filter: blur(4px);
}

.spinner-overlay .spinner {
	border-color: rgba(255, 255, 255, 0.2);
	border-top-color: var(--accent-700);
}

/* ==========================================================================
   Skeleton Screen Component
   ========================================================================== */

.skeleton {
	background: linear-gradient(
		90deg,
		var(--gray-700) 0%,
		var(--gray-600) 50%,
		var(--gray-700) 100%
	);
	background-size: 200% 100%;
	border-radius: 4px;

	animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
	0% {
		background-position: 200% 0;
	}

	100% {
		background-position: -200% 0;
	}
}

/* Skeleton variants */
.skeleton--text {
	height: 16px;
	margin-bottom: 8px;
}

.skeleton--title {
	height: 24px;
	margin-bottom: 12px;
	width: 70%;
}

.skeleton--heading {
	height: 32px;
	margin-bottom: 16px;
	width: 60%;
}

.skeleton--image {
	width: 100%;
	aspect-ratio: 16 / 9;
	border-radius: 8px;
}

.skeleton--avatar {
	width: 48px;
	height: 48px;
	border-radius: 50%;
}

.skeleton--avatar--small {
	width: 32px;
	height: 32px;
}

.skeleton--avatar--large {
	width: 64px;
	height: 64px;
}

.skeleton--button {
	width: 120px;
	height: 48px;
	border-radius: 6px;
}

.skeleton--input {
	width: 100%;
	height: 48px;
	border-radius: 6px;
	margin-bottom: 16px;
}

.skeleton--card {
	width: 100%;
	height: 300px;
	border-radius: 8px;
}

/* Skeleton on light surfaces */
.light-surface .skeleton {
	background: linear-gradient(
		90deg,
		var(--gray-200) 0%,
		var(--gray-100) 50%,
		var(--gray-200) 100%
	);
	background-size: 200% 100%;
}

/* ==========================================================================
   Progress Bar Component
   ========================================================================== */

.progress-bar {
	/* Container */
	width: 100%;
	height: 8px;
	background: var(--gray-700);
	border-radius: 2px;
	overflow: hidden;
	position: relative;
}

.progress-bar__fill {
	/* Fill */
	height: 100%;
	background: var(--accent-700);
	border-radius: 2px;
	transition: width 0.3s ease;
}

/* Progress bar sizes */
.progress-bar--thin {
	height: 4px;
}

.progress-bar--chunky {
	height: 12px;
	border-radius: 6px;
}

.progress-bar--chunky .progress-bar__fill {
	border-radius: 6px;
}

/* Progress bar color variants */
.progress-bar--success .progress-bar__fill {
	background: var(--success-500);
}

.progress-bar--teal .progress-bar__fill {
	background: var(--primary-600);
}

.progress-bar--warning .progress-bar__fill {
	background: var(--warning-500);
}

.progress-bar--error .progress-bar__fill {
	background: var(--error-500);
}

/* Progress bar on light surfaces */
.light-surface .progress-bar {
	background: var(--gray-200);
}

/* ==========================================================================
   Progress Bar with Label
   ========================================================================== */

.progress-bar-wrapper {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.progress-bar__label {
	display: flex;
	justify-content: space-between;
	align-items: center;

	font-family: var(--font-body);
	font-size: 14px;
	font-weight: 500;
	color: var(--gray-200);
	line-height: 1.4;
}

.progress-bar__label-text {
	flex: 1;
}

.progress-bar__label-value {
	font-family: var(--font-display);
	font-weight: 600;
	color: var(--accent-700);
}

/* Label on light surfaces */
.light-surface .progress-bar__label {
	color: var(--gray-700);
}

/* ==========================================================================
   Indeterminate Progress Bar (Animated)
   ========================================================================== */

.progress-bar--indeterminate .progress-bar__fill {
	width: 30% !important;
	animation: progress-indeterminate 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes progress-indeterminate {
	0% {
		transform: translateX(-100%);
	}

	50% {
		transform: translateX(350%);
	}

	100% {
		transform: translateX(-100%);
	}
}

/* ==========================================================================
   Circular Progress (Alternative Spinner)
   ========================================================================== */

.progress-circle {
	width: 64px;
	height: 64px;
	position: relative;
}

.progress-circle svg {
	width: 100%;
	height: 100%;
	transform: rotate(-90deg);
}

.progress-circle__background {
	fill: none;
	stroke: var(--gray-700);
	stroke-width: 4;
}

.progress-circle__fill {
	fill: none;
	stroke: var(--accent-700);
	stroke-width: 4;
	stroke-linecap: round;
	transition: stroke-dashoffset 0.3s ease;
}

.progress-circle__text {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);

	font-family: var(--font-display);
	font-size: 16px;
	font-weight: 600;
	color: var(--gray-200);
}

/* Circular progress sizes */
.progress-circle--small {
	width: 48px;
	height: 48px;
}

.progress-circle--small .progress-circle__text {
	font-size: 14px;
}

.progress-circle--large {
	width: 80px;
	height: 80px;
}

.progress-circle--large .progress-circle__text {
	font-size: 20px;
}

/* ==========================================================================
   Dots Loader (Alternative Loading Indicator)
   ========================================================================== */

.dots-loader {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.dots-loader__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--accent-700);
	animation: dots-bounce 1.4s infinite ease-in-out both;
}

.dots-loader__dot:nth-child(1) {
	animation-delay: -0.32s;
}

.dots-loader__dot:nth-child(2) {
	animation-delay: -0.16s;
}

@keyframes dots-bounce {
	0%,
	80%,
	100% {
		transform: scale(0);
		opacity: 0.5;
	}

	40% {
		transform: scale(1);
		opacity: 1;
	}
}

/* Dots loader variants */
.dots-loader--small .dots-loader__dot {
	width: 6px;
	height: 6px;
	gap: 6px;
}

.dots-loader--large .dots-loader__dot {
	width: 12px;
	height: 12px;
	gap: 10px;
}

.dots-loader--teal .dots-loader__dot {
	background: var(--primary-500);
}

.dots-loader--white .dots-loader__dot {
	background: #ffffff;
}

/* ==========================================================================
   Pulse Loader (Subtle Alternative)
   ========================================================================== */

.pulse-loader {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--accent-700);
	animation: pulse 1.2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.pulse-loader--small {
	width: 24px;
	height: 24px;
}

.pulse-loader--large {
	width: 56px;
	height: 56px;
}

.pulse-loader--teal {
	background: var(--primary-500);
}

@keyframes pulse {
	0%,
	100% {
		opacity: 1;
		transform: scale(0.8);
	}

	50% {
		opacity: 0.5;
		transform: scale(1.2);
	}
}

/* ==========================================================================
   Loading State Container
   ========================================================================== */

.loading-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 48px 24px;
	text-align: center;
}

.loading-container__text {
	font-family: var(--font-body);
	font-size: 16px;
	color: var(--gray-300);
	line-height: 1.5;
}

.loading-container__subtext {
	font-family: var(--font-body);
	font-size: 14px;
	color: var(--gray-400);
	line-height: 1.5;
}

/* ==========================================================================
   Inline Loading (Within Content)
   ========================================================================== */

.loading-inline {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.loading-inline .spinner {
	width: 16px;
	height: 16px;
	border-width: 2px;
}

.loading-inline__text {
	font-family: var(--font-body);
	font-size: 14px;
	color: var(--gray-300);
}

/* ==========================================================================
   Button Loading State (See buttons.css for .btn-loading)
   ========================================================================== */

/* Additional helper for button context */
.btn.is-loading {
	position: relative;
	color: transparent !important;
	pointer-events: none;
}

.btn.is-loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 20px;
	height: 20px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: #ffffff;
	border-radius: 50%;
	animation: spin 0.6s linear infinite;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 767px) {
	.spinner {
		width: 32px;
		height: 32px;
	}

	.spinner--large {
		width: 48px;
		height: 48px;
	}

	.loading-container {
		padding: 32px 16px;
	}

	.progress-circle {
		width: 56px;
		height: 56px;
	}

	.progress-circle--large {
		width: 64px;
		height: 64px;
	}
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.spinner,
	.spinner-overlay,
	.skeleton,
	.progress-bar,
	.progress-circle,
	.dots-loader,
	.pulse-loader,
	.loading-container,
	.loading-inline {
		display: none;
	}
}
