/**
 * EnableU Checkout Form Styles
 * Styles for the branded checkout shell to fix form field alignment
 *
 * @package EnableU
 */

/* ==========================================================================
   Checkout Card Container
   ========================================================================== */
.enableu-checkout__card {
	width: 100%;
}

/* Ensure PMPro form inside the card is properly contained */
.enableu-checkout__card .pmpro_form {
	width: 100%;
}

/* ==========================================================================
   Form Field Wrappers
   ========================================================================== */

/* Base field wrapper - creates positioning context for icons */
.enableu-checkout__field {
	position: relative;
	display: block;
	width: 100%;
}

/* Field with leading icon (email, name, password) - adds left padding */
.enableu-checkout__field--has-leading input,
.enableu-checkout__field--has-leading select {
	padding-left: 2.5rem !important;
}

/* Field with toggle button (password) - adds right padding */
.enableu-checkout__field--has-toggle input,
.enableu-checkout__field--has-toggle select {
	padding-right: 2.5rem !important;
}

/* Inline validation error (e.g. business-email guard on #bemail) */
.enableu-checkout__field-error {
	display: block;
	margin-top: 0.375rem;
	font-size: 0.8125rem;
	line-height: 1.25rem;
	color: #dc2626;
}

.enableu-checkout__field-error::before {
	content: "";
	display: inline-block;
	width: 0.5rem;
	height: 0.5rem;
	margin-right: 0.4rem;
	border-radius: 9999px;
	background: #dc2626;
	vertical-align: middle;
}

/* ==========================================================================
   Icon Positioning
   ========================================================================== */

/* Leading icon (mail, lock, user) - positioned left inside input */
.enableu-checkout__icon--leading {
	position: absolute;
	left: 0.875rem;
	top: 50%;
	transform: translateY(-50%);
	color: var(--muted-foreground, #6b7280);
	pointer-events: none;
	z-index: 2;
}

/* Password toggle button - positioned right inside input */
.enableu-checkout__toggle {
	position: absolute;
	right: 0.875rem;
	top: 50%;
	transform: translateY(-50%);
	background: none;
	border: none;
	padding: 0;
	margin: 0;
	cursor: pointer;
	color: var(--muted-foreground, #6b7280);
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.5rem;
	height: 1.5rem;
}

.enableu-checkout__toggle:hover {
	color: var(--foreground, #111827);
}

/* ==========================================================================
   PMPro Form Field Overrides
   ========================================================================== */

/* Ensure all PMPro form fields are full width */
.enableu-checkout__card .pmpro_form_field {
	width: 100%;
	margin-bottom: 1rem;
}

/* Fix the Account Information section layout */
.enableu-checkout__card .pmpro_form_field-text {
	width: 100%;
}

/* Ensure inputs are full width within their containers */
.enableu-checkout__card .pmpro_form_field-text input[type="text"],
.enableu-checkout__card .pmpro_form_field-text input[type="email"],
.enableu-checkout__card .pmpro_form_field-text input[type="password"],
.enableu-checkout__card .pmpro_form_field-text select {
	width: 100%;
	max-width: 100%;
}

/* Email field - ensure it spans full width */
.enableu-checkout__card input[name="bemail"],
.enableu-checkout__card input#bemail,
.enableu-checkout__card .pmpro_form_field-bemail {
	width: 100%;
	max-width: 100%;
}

/* ==========================================================================
   Two-Column Layout Fix (First Name / Last Name, Password / Confirm Password)
   ========================================================================== */

/* Container for side-by-side fields */
.enableu-checkout__card .pmpro_form_fields {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem;
	width: 100%;
}

/* Default: all fields take full width */
.enableu-checkout__card .pmpro_form_field {
	flex: 1 1 100%;
	min-width: 0;
}

/* Side-by-side fields (First Name/Last Name, Password/Confirm Password) */
/* These should appear in pairs and share the row */
.enableu-checkout__card .pmpro_form_field.pmpro_form_field-first_name,
.enableu-checkout__card .pmpro_form_field.pmpro_form_field-last_name,
.enableu-checkout__card .pmpro_form_field:has(input[name="first_name"]),
.enableu-checkout__card .pmpro_form_field:has(input[name="last_name"]),
.enableu-checkout__card .pmpro_form_field:has(input[name="password"]),
.enableu-checkout__card .pmpro_form_field:has(input[name="password2"]),
.enableu-checkout__card .pmpro_form_field:has(input#password),
.enableu-checkout__card .pmpro_form_field:has(input#password2) {
	flex: 1 1 calc(50% - 0.5rem);
	min-width: 0; /* Prevent flex item overflow and allow proper shrinking */
}

/* Fallback for browsers without :has() support - target by common patterns */
@supports not selector(:has(*)) {
	/* First name / Last name row, Password / Confirm Password row */
	.enableu-checkout__card .pmpro_form_field:nth-child(1):not(.pmpro_form_field-bemail):not(.pmpro_form_field-busername),
	.enableu-checkout__card .pmpro_form_field:nth-child(2):not(.pmpro_form_field-bemail):not(.pmpro_form_field-busername),
	.enableu-checkout__card .pmpro_form_field:nth-child(3),
	.enableu-checkout__card .pmpro_form_field:nth-child(4) {
		flex: 1 1 calc(50% - 0.5rem);
		min-width: 0;
	}
}

/* ==========================================================================
   Input Styling Consistency
   ========================================================================== */

/* Ensure consistent input appearance */
.enableu-checkout__card input[type="text"],
.enableu-checkout__card input[type="email"],
.enableu-checkout__card input[type="password"],
.enableu-checkout__card select {
	width: 100%;
	padding: 0.75rem 1rem;
	border: 1px solid var(--border, #e5e7eb);
	border-radius: 0.5rem;
	background-color: var(--background, #ffffff);
	color: var(--foreground, #111827);
	font-size: 0.9375rem;
	line-height: 1.5;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.enableu-checkout__card input[type="text"]:focus,
.enableu-checkout__card input[type="email"]:focus,
.enableu-checkout__card input[type="password"]:focus,
.enableu-checkout__card select:focus {
	outline: none;
	border-color: var(--primary, #3b82f6);
	box-shadow: 0 0 0 3px color-mix(in oklch, var(--primary, #3b82f6) 20%, transparent);
}

/* ==========================================================================
   Labels
   ========================================================================== */

/* Ensure label text is visible and asterisk stays inline */
.enableu-checkout__card .pmpro_form_label {
	display: block;
	margin-bottom: 0.375rem;
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--foreground, #111827);
}

/* Asterisk should stay inline with the last word of the label */
.enableu-checkout__card .pmpro_form_label .pmpro_asterisk {
	display: inline;
	color: var(--destructive, #ef4444);
	margin-left: 0.25rem;
	white-space: nowrap;
}

/* ==========================================================================
   Submit Button
   ========================================================================== */

.enableu-checkout__card .pmpro_submit {
	margin-top: 1.5rem;
}

.enableu-checkout__card input[type="submit"],
.enableu-checkout__card .pmpro_btn-submit {
	width: 100%;
	padding: 0.875rem 1.5rem;
	background-color: var(--primary, #2563eb);
	color: var(--primary-foreground, #ffffff);
	border: none;
	border-radius: 0.5rem;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.enableu-checkout__card input[type="submit"]:hover,
.enableu-checkout__card .pmpro_btn-submit:hover {
	background-color: color-mix(in oklch, var(--primary, #2563eb) 90%, black);
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 640px) {
	/* Stack all fields on small screens */
	.enableu-checkout__card .pmpro_form_field.pmpro_form_field-first_name,
	.enableu-checkout__card .pmpro_form_field.pmpro_form_field-last_name,
	.enableu-checkout__card .pmpro_form_field:has(input[name="first_name"]),
	.enableu-checkout__card .pmpro_form_field:has(input[name="last_name"]),
	.enableu-checkout__card .pmpro_form_field:has(input[name="password"]),
	.enableu-checkout__card .pmpro_form_field:has(input[name="password2"]),
	.enableu-checkout__card .pmpro_form_field:has(input#password),
	.enableu-checkout__card .pmpro_form_field:has(input#password2) {
		flex: 1 1 100%;
	}

	@supports not selector(:has(*)) {
		.enableu-checkout__card .pmpro_form_field:nth-child(1):not(.pmpro_form_field-bemail):not(.pmpro_form_field-busername),
		.enableu-checkout__card .pmpro_form_field:nth-child(2):not(.pmpro_form_field-bemail):not(.pmpro_form_field-busername),
		.enableu-checkout__card .pmpro_form_field:nth-child(3),
		.enableu-checkout__card .pmpro_form_field:nth-child(4) {
			flex: 1 1 100%;
		}
	}
}
