/**
 * GDC Modal Component
 *
 * 3 sizes:    sm (400px) | md (600px) | lg (800px)
 * 3 states:   hidden | visible | closing
 *
 * All animations use GPU-safe properties (transform, opacity).
 * Tokens sourced from tokens.css (layer 1 + 2).
 *
 * @package GDC
 * @since   1.0.0
 */

/* ==========================================================
   KEYFRAMES — GPU-safe (transform + opacity only)
   ========================================================== */

@keyframes gdc-modal-fade-in {
	0%   { opacity: 0; }
	100% { opacity: 1; }
}

@keyframes gdc-modal-fade-out {
	0%   { opacity: 1; }
	100% { opacity: 0; }
}

@keyframes gdc-modal-scale-in {
	0%   { opacity: 0; transform: scale(0.9) translateZ(0); }
	100% { opacity: 1; transform: scale(1) translateZ(0); }
}

@keyframes gdc-modal-scale-out {
	0%   { opacity: 1; transform: scale(1) translateZ(0); }
	100% { opacity: 0; transform: scale(0.9) translateZ(0); }
}

/* ==========================================================
   BACKDROP
   ========================================================== */

.gdc-modal-backdrop {
	position: fixed;
	inset: 0;
	z-index: 1000;

	display: flex;
	align-items: center;
	justify-content: center;

	background: rgba(0, 0, 0, 0.7);

	animation: gdc-modal-fade-in 300ms var(--gdc-ease-out) forwards;

	/* GPU layer promotion */
	will-change: opacity;
	transform: translateZ(0);
}

/* Hidden state */
.gdc-modal-backdrop[data-state="hidden"] {
	display: none;
}

/* Closing state */
.gdc-modal-backdrop[data-state="closing"] {
	animation: gdc-modal-fade-out 150ms var(--gdc-ease-out) forwards;
}

/* ==========================================================
   MODAL CONTAINER
   ========================================================== */

.gdc-modal {
	position: relative;

	background: var(--gdc-bg-surface);
	border-radius: 12px;
	box-shadow: var(--gdc-shadow-lg);

	width: 90vw;
	max-width: 600px;
	max-height: 85vh;

	display: flex;
	flex-direction: column;

	animation: gdc-modal-scale-in 300ms var(--gdc-ease-out) forwards;

	/* GPU layer promotion */
	will-change: transform, opacity;
	transform: translateZ(0);
}

/* Closing state */
.gdc-modal-backdrop[data-state="closing"] .gdc-modal {
	animation: gdc-modal-scale-out 150ms var(--gdc-ease-out) forwards;
}

/* ==========================================================
   SIZE VARIANTS
   ========================================================== */

.gdc-modal[data-size="sm"] {
	max-width: 400px;
}

.gdc-modal[data-size="md"] {
	max-width: 600px;
}

.gdc-modal[data-size="lg"] {
	max-width: 800px;
}

/* ==========================================================
   HEADER
   ========================================================== */

.gdc-modal__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;

	padding: 20px 24px 0;

	flex-shrink: 0;
}

.gdc-modal__title {
	margin: 0;

	font-family: var(--gdc-font-sans);
	font-size: var(--gdc-text-lg, 1.125rem);
	font-weight: var(--gdc-font-semibold);
	line-height: var(--gdc-leading-normal);
	color: var(--gdc-text-primary);
}

.gdc-modal__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;

	min-width: 44px;
	min-height: 44px;
	width: 44px;
	height: 44px;

	padding: 0;
	border: none;
	border-radius: 8px;
	background: transparent;
	cursor: pointer;

	color: var(--gdc-text-secondary, #A0A0A0);

	transition:
		background-color var(--gdc-duration-fast) var(--gdc-ease-out),
		color var(--gdc-duration-fast) var(--gdc-ease-out);

	flex-shrink: 0;
}

.gdc-modal__close:hover {
	background-color: var(--gdc-bg-hover);
	color: var(--gdc-text-primary);
}

.gdc-modal__close:focus-visible {
	outline: 2px solid var(--gdc-accent-cta);
	outline-offset: 2px;
}

.gdc-modal__close svg {
	width: 18px;
	height: 18px;
}

/* ==========================================================
   BODY
   ========================================================== */

.gdc-modal__body {
	padding: 16px 24px;

	overflow-y: auto;
	-webkit-overflow-scrolling: touch;

	flex: 1 1 auto;
	min-height: 0;

	font-family: var(--gdc-font-sans);
	font-size: var(--gdc-text-base);
	line-height: var(--gdc-leading-relaxed, 1.6);
	color: var(--gdc-text-secondary, #A0A0A0);
}

/* ==========================================================
   FOOTER
   ========================================================== */

.gdc-modal__footer {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;

	padding: 0 24px 20px;

	flex-shrink: 0;
}

/* ==========================================================
   REDUCED MOTION
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
	.gdc-modal-backdrop,
	.gdc-modal {
		animation-duration: 1ms !important;
	}
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */

@media (max-width: 480px) {
	.gdc-modal {
		width: 100vw;
		max-width: 100vw;
		max-height: 100vh;
		border-radius: 0;
	}

	.gdc-modal__header {
		padding: 16px 16px 0;
	}

	.gdc-modal__body {
		padding: 12px 16px;
	}

	.gdc-modal__footer {
		padding: 0 16px 16px;
	}
}
