/**
 * Modal/Dialog Components
 * Overlay modals with animations and accessibility
 * Implements specifications from TECHTRONIC_DESIGN_SYSTEM.md Section 7.7
 *
 * @package Techtronic_Learning
 * @since 1.0.0
 */

/* ==========================================================================
   Modal Overlay
   ========================================================================== */

.modal-overlay {
	/* Position */
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 9999;

	/* Appearance */
	background: rgba(10, 14, 20, 0.85);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);

	/* Layout */
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;

	/* Initial state */
	opacity: 0;
	visibility: hidden;

	/* Transition */
	transition: all 0.3s ease;
}

.modal-overlay--active {
	opacity: 1;
	visibility: visible;
}

/* Prevent body scroll when modal is open */
body.modal-open {
	overflow: hidden;
}

/* ==========================================================================
   Modal Container
   ========================================================================== */

.modal {
	/* Size */
	width: 600px;
	max-width: calc(100vw - 48px);
	max-height: calc(100vh - 48px);

	/* Appearance */
	background: var(--surface-3);
	border: 1px solid var(--gray-600);
	border-radius: 12px;
	box-shadow: var(--shadow-2xl);

	/* Layout */
	display: flex;
	flex-direction: column;
	overflow: hidden;

	/* Initial state */
	opacity: 0;
	transform: scale(0.95) translateY(20px);

	/* Transition */
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay--active .modal {
	opacity: 1;
	transform: scale(1) translateY(0);
}

/* Modal sizes */
.modal--small {
	width: 480px;
}

.modal--large {
	width: 800px;
}

.modal--fullscreen {
	width: calc(100vw - 48px);
	height: calc(100vh - 48px);
}

/* ==========================================================================
   Modal Header
   ========================================================================== */

.modal__header {
	padding: 24px 24px 16px 24px;
	border-bottom: 1px solid var(--gray-600);

	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	flex-shrink: 0;
}

.modal__title {
	font-family: var(--font-display);
	font-size: 24px;
	font-weight: 600;
	color: var(--gray-50);
	line-height: 1.3;
	margin: 0;
}

.modal__subtitle {
	font-family: var(--font-body);
	font-size: 14px;
	color: var(--gray-300);
	line-height: 1.5;
	margin-top: 4px;
}

.modal__close {
	/* Size */
	width: 32px;
	height: 32px;
	padding: 0;
	flex-shrink: 0;

	/* Appearance */
	background: transparent;
	border: none;
	border-radius: 6px;
	color: var(--gray-300);

	/* Layout */
	display: flex;
	align-items: center;
	justify-content: center;

	/* Cursor */
	cursor: pointer;

	/* Transition */
	transition: all 0.2s ease;
}

.modal__close:hover {
	background: var(--surface-4);
	color: var(--gray-50);
}

.modal__close:focus-visible {
	outline: 2px solid var(--primary-500);
	outline-offset: 4px;
}

.modal__close svg {
	width: 20px;
	height: 20px;
}

/* ==========================================================================
   Modal Body
   ========================================================================== */

.modal__body {
	padding: 24px;
	overflow-y: auto;
	flex: 1;

	/* Custom scrollbar for better UX */
	scrollbar-width: thin;
	scrollbar-color: var(--gray-600) var(--surface-2);
}

.modal__body::-webkit-scrollbar {
	width: 8px;
}

.modal__body::-webkit-scrollbar-track {
	background: var(--surface-2);
	border-radius: 4px;
}

.modal__body::-webkit-scrollbar-thumb {
	background: var(--gray-600);
	border-radius: 4px;
}

.modal__body::-webkit-scrollbar-thumb:hover {
	background: var(--gray-500);
}

/* Body padding variants */
.modal__body--compact {
	padding: 16px 24px;
}

.modal__body--spacious {
	padding: 32px;
}

.modal__body--no-padding {
	padding: 0;
}

/* ==========================================================================
   Modal Footer
   ========================================================================== */

.modal__footer {
	padding: 16px 24px 24px 24px;
	border-top: 1px solid var(--gray-600);
	flex-shrink: 0;

	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 12px;
}

.modal__footer--space-between {
	justify-content: space-between;
}

.modal__footer--center {
	justify-content: center;
}

.modal__footer--stack {
	flex-direction: column;
	align-items: stretch;
}

.modal__footer--stack > * {
	width: 100%;
}

/* ==========================================================================
   Modal Variations
   ========================================================================== */

/* Confirmation modal */
.modal--confirmation .modal__body {
	text-align: center;
	padding: 32px 24px;
}

.modal--confirmation .modal__icon {
	width: 64px;
	height: 64px;
	margin: 0 auto 16px;
	color: var(--warning-500);
}

.modal--confirmation .modal__message {
	font-family: var(--font-body);
	font-size: 16px;
	color: var(--gray-200);
	line-height: 1.7;
}

/* Success modal */
.modal--success .modal__icon {
	color: var(--success-500);
}

/* Error modal */
.modal--error .modal__icon {
	color: var(--error-500);
}

/* Info modal */
.modal--info .modal__icon {
	color: var(--info-500);
}

/* ==========================================================================
   Modal with Image/Media
   ========================================================================== */

.modal__media {
	width: 100%;
	max-height: 400px;
	object-fit: cover;
	display: block;
}

.modal__media-container {
	position: relative;
	width: 100%;
	background: var(--gray-900);
}

/* ==========================================================================
   Modal Loading State
   ========================================================================== */

.modal--loading .modal__body {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 200px;
}

.modal--loading .modal__footer {
	pointer-events: none;
	opacity: 0.5;
}

/* ==========================================================================
   Responsive Modal
   ========================================================================== */

@media (max-width: 767px) {
	.modal-overlay {
		padding: 16px;
	}

	.modal {
		width: calc(100vw - 32px);
		max-width: none;
	}

	.modal--small,
	.modal--large {
		width: calc(100vw - 32px);
	}

	.modal__header {
		padding: 20px 16px 12px 16px;
	}

	.modal__title {
		font-size: 20px;
	}

	.modal__body {
		padding: 20px 16px;
	}

	.modal__footer {
		padding: 12px 16px 20px 16px;
		flex-direction: column;
		align-items: stretch;
	}

	.modal__footer > * {
		width: 100%;
	}

	/* Full-screen on very small screens */
	@media (max-width: 480px) {
		.modal-overlay {
			padding: 0;
		}

		.modal {
			width: 100vw;
			height: 100vh;
			max-width: 100vw;
			max-height: 100vh;
			border-radius: 0;
		}
	}
}

/* ==========================================================================
   Modal Animations
   ========================================================================== */

/* Fade in */
@keyframes modal-fade-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

/* Scale up */
@keyframes modal-scale-up {
	from {
		opacity: 0;
		transform: scale(0.9);
	}

	to {
		opacity: 1;
		transform: scale(1);
	}
}

/* Slide from bottom */
@keyframes modal-slide-up {
	from {
		opacity: 0;
		transform: translateY(50px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Animation modifiers */
.modal-overlay--fade {
	animation: modal-fade-in 0.3s ease;
}

.modal--scale {
	animation: modal-scale-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal--slide {
	animation: modal-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Stacked Modals (Multiple Modals Open)
   ========================================================================== */

.modal-overlay + .modal-overlay {
	z-index: 10000;
}

.modal-overlay + .modal-overlay + .modal-overlay {
	z-index: 10001;
}

/* ==========================================================================
   Modal Form Wrapper
   ========================================================================== */

.modal__form .form-field:last-child {
	margin-bottom: 0;
}

.modal__form-actions {
	display: flex;
	gap: 12px;
	margin-top: 24px;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.modal-overlay {
		position: static;
		background: none;
		backdrop-filter: none;
		padding: 0;
	}

	.modal {
		border: 2px solid #000;
		box-shadow: none;
		page-break-inside: avoid;
	}

	.modal__close {
		display: none;
	}

	.modal__footer {
		border-top: 2px solid #000;
	}
}
