/**
 * Simple PIN Modal - Frontend Styles
 * Dark mode with theme variable support
 */

/* Modal Overlay */
.sp-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.5);
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 999999;
	padding: 1rem;
	animation: sp-fade-in 0.3s ease-out;
}

/* When background image is set, add overlay tint */
.sp-modal-overlay.sp-has-background {
	background-blend-mode: darken;
}

.sp-modal-overlay.sp-has-background:before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  backdrop-filter: blur(80px);
}

@keyframes sp-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.sp-modal-overlay.sp-fade-out {
	animation: sp-fade-out 0.3s ease-out forwards;
}

@keyframes sp-fade-out {
	from {
		opacity: 1;
	}
	to {
		opacity: 0;
	}
}

/* Modal Card */
.sp-modal-card {
	background-color: #191a1b;
	border: 1px solid var(--cs-color-border, #414141);
	border-radius: 12px;
	padding: 2rem 3rem;
	max-width: 420px;
	width: 100%;
	box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
	animation: sp-slide-up 0.3s ease-out;
}

@keyframes sp-slide-up {
	from {
		transform: translateY(20px);
		opacity: 0;
	}
	to {
		transform: translateY(0);
		opacity: 1;
	}
}

@media (max-width: 480px) {
	.sp-modal-card {
		padding: 2rem 3rem;
	}
}

/* Icon Container */
.sp-modal-icon-container {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 80px;
	height: 80px;
	margin: 0 auto 1.5rem;
	background: linear-gradient(135deg, rgba(39, 129, 246, 0.2) 0%, rgba(39, 129, 246, 0.1) 100%);
	border-radius: 50%;
}

.sp-icon-svg {
	width: 40px;
	height: 40px;
	color: #2781f6;
}

.sp-icon-image {
	width: 80px;
	height: 80px;
	object-fit: contain;
}

/* Title */
.sp-modal-title {
	margin: 0 0 0.5rem;
	font-size: 1.75rem;
	font-weight: 700;
	text-align: center;
	color: var(--cs-color-primary, #FFFFFF);
	line-height: 1.2;
}

@media (max-width: 480px) {
	.sp-modal-title {
		font-size: 1.5rem;
	}
}

/* Subtitle */
.sp-modal-subtitle {
	margin: 0 0 2rem;
	font-size: 0.9375rem;
	text-align: center;
	color: var(--cs-color-secondary, #979797);
	line-height: 1.5;
}

/* Form */
.sp-modal-form {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

/* PIN Inputs Container */
.sp-pin-inputs {
	display: flex;
	gap: 12px;
	justify-content: center;
	align-items: center;
}

@media (max-width: 380px) {
	.sp-pin-inputs {
		gap: 8px;
	}
}

/* Individual PIN Input */
.sp-pin-input {
	width: 56px !important;
	height: 56px;
	font-size: 1.5rem;
	font-weight: 600;
	text-align: center;
	background-color: var(--cs-site-background, #212121) !important;
	color: var(--cs-color-primary, #FFFFFF);
	border: 2px solid var(--cs-color-border, #414141) !important;
	border-radius: 10px !important;
	outline: none;
	transition: all 0.2s ease;
	letter-spacing: 0.1em;
}

@media (max-width: 480px) {
	.sp-pin-input {
		width: 52px;
		height: 52px;
		font-size: 1.375rem;
	}
}

@media (max-width: 380px) {
	.sp-pin-input {
		width: 48px;
		height: 48px;
		font-size: 1.25rem;
	}
}

.sp-pin-input:focus {
	border-color: #2781f6 !important;
	box-shadow: 0 0 0 2px rgb(39 129 246) !important;
}

.sp-pin-input.sp-error {
	border-color: #e32c26;
	animation: sp-shake 0.4s ease;
}

@keyframes sp-shake {
	0%, 100% {
		transform: translateX(0);
	}
	25% {
		transform: translateX(-8px);
	}
	75% {
		transform: translateX(8px);
	}
}

/* Loading Indicators */
.sp-loading-indicator {
	display: none;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 40px;
	color: var(--cs-color-primary, #FFFFFF);
}

/* 1. Spinner with text */
.sp-loading-spinner {
	flex-direction: row;
}

.sp-spinner {
	width: 20px;
	height: 20px;
	border: 3px solid rgba(39, 129, 246, 0.2);
	border-top-color: #2781f6;
	border-radius: 50%;
	animation: sp-spin 0.8s linear infinite;
}

@keyframes sp-spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

.sp-loading-spinner span {
	font-size: 0.875rem;
	color: var(--cs-color-secondary, #979797);
}

/* 2. Animated dots */
.sp-loading-dots {
	flex-direction: row;
	gap: 6px;
}

.sp-dot {
	width: 8px;
	height: 8px;
	background-color: #2781f6;
	border-radius: 50%;
	animation: sp-bounce 1.4s infinite ease-in-out both;
}

.sp-dot:nth-child(1) { animation-delay: -0.32s; }
.sp-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes sp-bounce {
	0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
	40% { transform: scale(1); opacity: 1; }
}

/* 3. Progress bar */
.sp-loading-progress {
	width: 100%;
	max-width: 200px;
	height: 4px;
	background-color: rgba(39, 129, 246, 0.2);
	border-radius: 2px;
	overflow: hidden;
}

.sp-progress-bar {
	width: 30%;
	height: 100%;
	background-color: #2781f6;
	border-radius: 2px;
	animation: sp-progress 1.5s ease-in-out infinite;
}

@keyframes sp-progress {
	0% { width: 10%; margin-left: 0; }
	50% { width: 40%; margin-left: 30%; }
	100% { width: 10%; margin-left: 90%; }
}

/* 4. Checkmark animation */
.sp-loading-checkmark {
	width: 40px;
	height: 40px;
}

.sp-checkmark {
	width: 100%;
	height: 100%;
}

.sp-checkmark-circle {
	stroke: #2781f6;
	stroke-width: 2;
	stroke-dasharray: 166;
	stroke-dashoffset: 166;
	animation: sp-stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.sp-checkmark-check {
	stroke: #2781f6;
	stroke-width: 3;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 48;
	stroke-dashoffset: 48;
	animation: sp-stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.4s forwards;
}

@keyframes sp-stroke {
	100% { stroke-dashoffset: 0; }
}

/* Error Message */
.sp-error-message {
	display: none;
	padding: 0.75rem 1rem;
	background-color: rgba(227, 44, 38, 0.1);
	border: 1px solid rgba(227, 44, 38, 0.3);
	border-radius: 6px;
	color: #ff6b6b;
	font-size: 0.875rem;
	text-align: center;
	line-height: 1.4;
}

/* Submit Button */
.sp-submit-btn {
	width: 100%;
	padding: 0.875rem 1.5rem;
	font-size: 1rem;
	font-weight: 600;
	color: #FFFFFF;
	background-color: #2781f6;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: all 0.25s ease;
	outline: none;
	position: relative;
	overflow: hidden;
	display: none;
}

.sp-submit-btn::before {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: #1f70e0;
	transform: translateY(calc(100% + 1px));
	transition: transform 0s;
	z-index: -1;
}

.sp-submit-btn:hover:not(:disabled)::before {
	transform: none;
}

.sp-submit-btn:hover:not(:disabled) {
	background-color: #1f70e0;
	box-shadow: 0 4px 12px rgba(39, 129, 246, 0.3);
}

.sp-submit-btn:active:not(:disabled) {
	transform: translateY(0);
}

.sp-submit-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
	transform: none;
}

.sp-submit-btn:focus-visible {
	box-shadow: 0 0 0 3px rgba(39, 129, 246, 0.4);
}

/* Safe Box Design - 3 Part Background Structure */
.sp-safe-box-wrapper {
	position: relative;
	width: 100%;
	max-width: 500px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 3rem 2rem; /* Space for content */
	animation: sp-slide-up 0.3s ease-out; /* Slide up animation */
}

/* Background container - fills wrapper exactly */
.sp-safe-box-bg {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	z-index: 0;
	justify-content: center;
}

/* Top - Fixed natural height, NEVER stretches */
.sp-safe-box-top {
	position: relative; /* For success overlay positioning */
	width: 100%;
	flex: 0 0 auto; /* Fixed size, don't grow or shrink */
	aspect-ratio: 20/8; /* Adjust to match your actual image ratio */
	background-size: 100% 100%; /* Fill the aspect-ratio constrained area */
	background-position: top center;
	background-repeat: no-repeat;
}

/* Middle - Grows to fill space and keep top/bottom connected */
.sp-safe-box-middle {
	position: relative; /* For success overlay positioning */
	width: 100%;
	flex: 1 1 auto; /* Grows to fill all remaining space */
	min-height: 101px; /* Minimum height for content */
	background-size: 100% 100%; /* Stretches vertically - designed for this */
	background-position: center;
	background-repeat: no-repeat;
	z-index: 0; /* Ensure stacking context */
}

/* Bottom - Fixed natural height, NEVER stretches */
.sp-safe-box-bottom {
	position: relative; /* For success overlay positioning */
	width: 100%;
	flex: 0 0 auto; /* Fixed size, don't grow or shrink */
	aspect-ratio: 20/8; /* Adjust to match your actual image ratio */
	background-size: 100% 100%; /* Fill the aspect-ratio constrained area */
	background-position: bottom center;
	background-repeat: no-repeat;
}

/* Adjust modal card for safe box - sits above background */
.sp-safe-box-wrapper .sp-modal-card {
	position: relative;
	z-index: 1; /* Above background */
	background-color: transparent;
	border: none;
	box-shadow: none;
	max-width: 100%;
	animation: none !important;
	filter: none !important;
}

/* Adjust title for safe box */
.sp-safe-box-design .sp-modal-title {
	color: #FFFFFF;
	text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Adjust subtitle for safe box */
.sp-safe-box-design .sp-modal-subtitle {
	color: #E0E0E0;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@media (max-width: 768px) {
	.sp-safe-box {
		max-width: 90vw;
	}
	
	.sp-safe-box-top::before,
	.sp-safe-box-bottom::before {
		padding-top: 18%;
	}
	
	.sp-safe-box-middle {
		padding: 1.5rem;
	}
}

@media (max-width: 480px) {
	.sp-safe-box {
		max-width: 95vw;
		min-height: 350px;
	}
	
	.sp-safe-box-top::before,
	.sp-safe-box-bottom::before {
		padding-top: 16%;
	}
	
	.sp-safe-box-middle {
		padding: 1rem;
	}
	
	.sp-safe-box-design .sp-modal-subtitle {
		margin-bottom: 1.5rem;
	}
}
/* Success Overlay for Safe Box - Applied to each part */
.sp-safe-box-success-overlay {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-size: 100% 100%;
	background-position: center;
	background-repeat: no-repeat;
	opacity: 0;
	z-index: 10; /* Above normal state */
	pointer-events: none;
	animation: sp-led-flicker 0.6s ease-in-out forwards, sp-led-pulse 1.5s ease-in-out 0.6s infinite;
}

/* LED Flicker Animation - Quick blinks at start */
@keyframes sp-led-flicker {
	0% { opacity: 0; }
	10% { opacity: 1; }
	20% { opacity: 0; }
	30% { opacity: 1; }
	40% { opacity: 0.3; }
	50% { opacity: 1; }
	60% { opacity: 0.5; }
	70%, 100% { opacity: 1; }
}

/* LED Pulse Animation - Subtle glow */
@keyframes sp-led-pulse {
	0%, 100% { 
		opacity: 1;
	}
	50% { 
		opacity: 0.25;
	}
}
