/**
 * VR Studio Forms — Frontend Styles.
 *
 * Mobile-first base styles with CSS custom properties for theming.
 * Scoped to .vrsf-form to avoid Elementor container conflicts.
 *
 * @package VRStudioForms
 */

/* ─── Custom Properties (Theme API) ─── */
/* Base: "Inherit Theme" preset — inherits text/backgrounds from the
   surrounding theme so the form blends with the page. Interactive
   elements (button, focus, accents) use Gateway Orange for consistent
   brand presence regardless of the theme context. */
.vrsf-form {
	--vrsf-font-family: inherit;
	--vrsf-font-size: 16px;
	--vrsf-color-text: inherit;
	--vrsf-color-label: inherit;
	--vrsf-color-placeholder: color-mix(in srgb, currentColor 40%, transparent);
	--vrsf-color-border: color-mix(in srgb, currentColor 25%, transparent);
	--vrsf-color-border-focus: #FF6B35;
	--vrsf-color-bg: transparent;
	--vrsf-color-bg-input: transparent;
	--vrsf-color-error: #ff4d6a;
	--vrsf-color-success: #00e676;
	--vrsf-color-primary: #FF6B35;
	--vrsf-color-primary-hover: #FF8C5A;
	--vrsf-color-primary-text: #fff;
	--vrsf-border-radius: 8px;
	--vrsf-spacing: 20px;
	--vrsf-transition: 0.2s ease;
	--vrsf-shadow-glow: none;
}

/* ─── Preset: Dark Premium ─── */
.vrsf-form.vrsf-preset-dark {
	--vrsf-color-text: #ffffff;
	--vrsf-color-label: #b0b0b0;
	--vrsf-color-placeholder: #6b6b6b;
	--vrsf-color-border: #2d2d2d;
	--vrsf-color-border-focus: #FF6B35;
	--vrsf-color-bg: #0d0d0d;
	--vrsf-color-bg-input: #1a1a1a;
	--vrsf-color-primary: #FF6B35;
	--vrsf-color-primary-hover: #FF8C5A;
	--vrsf-color-primary-text: #fff;
	--vrsf-shadow-glow: 0 0 12px rgba(255, 107, 53, 0.2);
	color-scheme: dark;
}

/* ─── Preset: Light Premium ─── */
.vrsf-form.vrsf-preset-light {
	--vrsf-color-text: #1a1a1a;
	--vrsf-color-label: #4a4a4a;
	--vrsf-color-placeholder: #b0b0b0;
	--vrsf-color-border: #e0e0e0;
	--vrsf-color-border-focus: #FF6B35;
	--vrsf-color-bg: #ffffff;
	--vrsf-color-bg-input: #fafafa;
	--vrsf-color-primary: #FF6B35;
	--vrsf-color-primary-hover: #FF8C5A;
	--vrsf-color-primary-text: #fff;
	--vrsf-shadow-glow: 0 0 12px rgba(255, 107, 53, 0.12);
}

/* ─── Form Container ─── */
.vrsf-form {
	font-family: var(--vrsf-font-family);
	font-size: var(--vrsf-font-size);
	color: var(--vrsf-color-text);
	line-height: 1.5;
	max-width: 100%;
	background-color: var(--vrsf-color-bg);
	padding: 32px;
	border-radius: 12px;
	border: 1px solid var(--vrsf-color-border);
}

.vrsf-form *,
.vrsf-form *::before,
.vrsf-form *::after {
	box-sizing: border-box;
}

/* ─── Field Wrapper ─── */
.vrsf-field {
	margin-bottom: var(--vrsf-spacing);
}

/* ─── Labels ─── */
.vrsf-field > label {
	display: block;
	margin-bottom: 8px;
	font-weight: 600;
	font-size: 13px;
	color: var(--vrsf-color-label);
	text-transform: uppercase;
	letter-spacing: 1px;
}

.vrsf-required {
	color: var(--vrsf-color-primary);
	margin-left: 2px;
}

/* ─── Inputs, Selects, Textareas ─── */
.vrsf-form .vrsf-field input[type="text"],
.vrsf-form .vrsf-field input[type="email"],
.vrsf-form .vrsf-field input[type="tel"],
.vrsf-form .vrsf-field input[type="number"],
.vrsf-form .vrsf-field input[type="date"],
.vrsf-form .vrsf-field select,
.vrsf-form .vrsf-field textarea {
	display: block;
	width: 100%;
	padding: 14px 16px;
	font-family: var(--vrsf-font-family);
	font-size: var(--vrsf-font-size);
	color: var(--vrsf-color-text);
	background-color: var(--vrsf-color-bg-input);
	border: 1px solid var(--vrsf-color-border);
	border-radius: var(--vrsf-border-radius);
	outline: 2px solid transparent;
	outline-offset: -2px;
	transition: border-color var(--vrsf-transition), box-shadow var(--vrsf-transition), outline-color var(--vrsf-transition);
	-webkit-appearance: none;
	appearance: none;
}

.vrsf-form .vrsf-field input::placeholder,
.vrsf-form .vrsf-field textarea::placeholder {
	color: var(--vrsf-color-placeholder);
	text-overflow: ellipsis;
	overflow: hidden;
	white-space: nowrap;
}

.vrsf-form .vrsf-field input:focus,
.vrsf-form .vrsf-field select:focus,
.vrsf-form .vrsf-field textarea:focus {
	border-color: var(--vrsf-color-border-focus);
	box-shadow: var(--vrsf-shadow-glow);
	outline-color: var(--vrsf-color-border-focus);
}

.vrsf-form .vrsf-field textarea {
	resize: vertical;
	min-height: 100px;
}

/* Select dropdown arrow — neutral gray works on both light/dark themes */
.vrsf-form .vrsf-field select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
	padding-right: 36px;
}

/* Preset-specific arrow colors */
.vrsf-form.vrsf-preset-dark .vrsf-field select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b0b0b0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.vrsf-form.vrsf-preset-light .vrsf-field select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a4a4a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

/* Select option colors — use hardcoded values because browsers often
   ignore CSS custom properties inside native dropdown popups. */
.vrsf-form .vrsf-field select option {
	background-color: var(--vrsf-color-bg-input);
	color: var(--vrsf-color-text);
}

.vrsf-form.vrsf-preset-dark .vrsf-field select option {
	background-color: #16213e;
	color: #e8e8f0;
}

.vrsf-form.vrsf-preset-light .vrsf-field select option {
	background-color: #f8f9fb;
	color: #1a1a1a;
}

/* ─── Date + Hour Row ─── */
.vrsf-date-hour-row {
	display: flex;
	gap: 10px;
}

.vrsf-date-col {
	flex: 1;
	min-width: 0;
}

.vrsf-hour-col {
	flex: 0 0 130px;
}

.vrsf-date-sublabel {
	display: block;
	font-size: 11px;
	font-weight: 600;
	color: var(--vrsf-color-placeholder);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	margin-bottom: 4px;
}

.vrsf-hour-select:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* iOS/Safari: date input shows empty — force visible placeholder color
   on the date text and show the picker chrome. */
.vrsf-date-input::-webkit-datetime-edit-text,
.vrsf-date-input::-webkit-datetime-edit-month-field,
.vrsf-date-input::-webkit-datetime-edit-day-field,
.vrsf-date-input::-webkit-datetime-edit-year-field {
	color: var(--vrsf-color-placeholder);
}

.vrsf-date-input.vrsf-has-value::-webkit-datetime-edit-text,
.vrsf-date-input.vrsf-has-value::-webkit-datetime-edit-month-field,
.vrsf-date-input.vrsf-has-value::-webkit-datetime-edit-day-field,
.vrsf-date-input.vrsf-has-value::-webkit-datetime-edit-year-field {
	color: var(--vrsf-color-text);
}

/* ─── Checkbox ─── */
.vrsf-field-checkbox {
	margin-bottom: var(--vrsf-spacing);
}

.vrsf-checkbox-label {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	cursor: pointer;
	font-weight: 400;
	font-size: 0.9em;
	line-height: 1.4;
}

.vrsf-checkbox-label input[type="checkbox"] {
	flex-shrink: 0;
	width: 18px;
	height: 18px;
	margin-top: 2px;
	accent-color: var(--vrsf-color-primary);
	cursor: pointer;
}

.vrsf-checkbox-text {
	flex: 1;
	color: var(--vrsf-color-label);
}

.vrsf-checkbox-text a {
	color: var(--vrsf-color-primary);
	text-decoration: underline;
}

.vrsf-checkbox-text a:hover {
	color: var(--vrsf-color-primary-hover);
}

/* ─── Field Errors ─── */
.vrsf-field-error {
	font-size: 0.85em;
	color: var(--vrsf-color-error);
	margin-top: 4px;
	min-height: 0;
	overflow: hidden;
	animation: vrsf-slide-down 0.2s ease-out;
}

.vrsf-field-error:empty {
	display: none;
}

@keyframes vrsf-slide-down {
	from {
		opacity: 0;
		transform: translateY(-4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Smooth border transition for error state */
.vrsf-form .vrsf-field input,
.vrsf-form .vrsf-field select,
.vrsf-form .vrsf-field textarea {
	transition: border-color var(--vrsf-transition), box-shadow var(--vrsf-transition);
}

.vrsf-form .vrsf-field.vrsf-has-error input,
.vrsf-form .vrsf-field.vrsf-has-error select,
.vrsf-form .vrsf-field.vrsf-has-error textarea {
	border-color: var(--vrsf-color-error);
}

.vrsf-form .vrsf-field.vrsf-has-error input:focus,
.vrsf-form .vrsf-field.vrsf-has-error select:focus,
.vrsf-form .vrsf-field.vrsf-has-error textarea:focus {
	box-shadow: 0 0 12px rgba(255, 77, 106, 0.2);
	outline-color: var(--vrsf-color-error);
}

/* ─── Turnstile Widget ─── */
.vrsf-turnstile-wrapper {
	margin-top: var(--vrsf-spacing);
}

.vrsf-turnstile-error {
	font-size: 0.85em;
	color: var(--vrsf-color-error);
	margin-top: 4px;
}

.vrsf-turnstile-error:empty {
	display: none;
}

/* ─── Submit Button ─── */
.vrsf-form-actions {
	margin-top: calc(var(--vrsf-spacing) * 1.25);
}

.vrsf-form .vrsf-submit-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 16px 32px;
	font-family: var(--vrsf-font-family);
	font-size: var(--vrsf-font-size);
	font-weight: 700;
	color: var(--vrsf-color-primary-text);
	background: var(--vrsf-color-primary);
	border: none;
	border-radius: var(--vrsf-border-radius);
	cursor: pointer;
	transition: background var(--vrsf-transition), box-shadow var(--vrsf-transition), transform var(--vrsf-transition), opacity var(--vrsf-transition);
	min-width: 160px;
	text-transform: uppercase;
	letter-spacing: 1px;
}

.vrsf-form .vrsf-submit-btn:hover {
	background: var(--vrsf-color-primary-hover);
	box-shadow: var(--vrsf-shadow-glow);
}

/* Gradient button for dark/light presets */
.vrsf-form.vrsf-preset-dark .vrsf-submit-btn,
.vrsf-form.vrsf-preset-light .vrsf-submit-btn {
	background: linear-gradient(135deg, var(--vrsf-color-primary), #E55A25);
}

.vrsf-form.vrsf-preset-dark .vrsf-submit-btn:hover,
.vrsf-form.vrsf-preset-light .vrsf-submit-btn:hover {
	background: linear-gradient(135deg, var(--vrsf-color-primary-hover), #FF6B35);
}

.vrsf-form .vrsf-submit-btn:active {
	transform: scale(0.98);
}

.vrsf-form .vrsf-submit-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	pointer-events: none;
}

.vrsf-form .vrsf-submit-btn:focus-visible {
	outline: 2px solid var(--vrsf-color-primary);
	outline-offset: 2px;
}

/* Spinner for loading state */
.vrsf-submit-btn .vrsf-btn-spinner {
	display: none;
	width: 16px;
	height: 16px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: #fff;
	border-radius: 50%;
	animation: vrsf-spin 0.6s linear infinite;
}

.vrsf-submit-btn.vrsf-loading .vrsf-btn-spinner {
	display: inline-block;
}

@keyframes vrsf-spin {
	to { transform: rotate(360deg); }
}

/* ─── Form Messages ─── */
.vrsf-form-messages {
	margin-top: var(--vrsf-spacing);
}

.vrsf-message {
	display: flex;
	align-items: flex-start;
	gap: 0;
	padding: 14px 18px;
	border-radius: var(--vrsf-border-radius);
	font-size: 0.95em;
	line-height: 1.4;
	animation: vrsf-fade-in 0.3s ease-out;
}

@keyframes vrsf-fade-in {
	from {
		opacity: 0;
		transform: translateY(-6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.vrsf-message-success {
	background-color: rgba(0, 230, 118, 0.1);
	border: 1px solid rgba(0, 230, 118, 0.3);
	border-left: 4px solid var(--vrsf-color-success);
	color: var(--vrsf-color-success);
}

.vrsf-message-error {
	background-color: rgba(255, 77, 106, 0.1);
	border: 1px solid rgba(255, 77, 106, 0.3);
	border-left: 4px solid var(--vrsf-color-error);
	color: var(--vrsf-color-error);
}

/* ─── Success Checkmark Icon ─── */
.vrsf-message-success::before {
	content: '';
	flex-shrink: 0;
	width: 18px;
	height: 18px;
	margin-right: 8px;
	margin-top: 1px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300e676' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
	background-size: contain;
	background-repeat: no-repeat;
}

.vrsf-message-error::before {
	content: '';
	flex-shrink: 0;
	width: 18px;
	height: 18px;
	margin-right: 8px;
	margin-top: 1px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ff4d6a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='15' y1='9' x2='9' y2='15'/%3E%3Cline x1='9' y1='9' x2='15' y2='15'/%3E%3C/svg%3E");
	background-size: contain;
	background-repeat: no-repeat;
}

/* ─── Success Fade-out ─── */
.vrsf-form.vrsf-success-fadeout .vrsf-field,
.vrsf-form.vrsf-success-fadeout .vrsf-form-actions {
	opacity: 0;
	transform: translateY(-8px);
	transition: opacity 0.4s ease, transform 0.4s ease;
	pointer-events: none;
}

/* ─── Loading Overlay ─── */
.vrsf-form.vrsf-submitting .vrsf-field,
.vrsf-form.vrsf-submitting .vrsf-form-actions {
	opacity: 0.5;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

/* ─── Layout Modifiers (Elementor widget) ─── */

/* Inline labels: label + input on the same row */
.vrsf-labels-inline .vrsf-field {
	display: flex;
	align-items: flex-start;
	gap: 12px;
}

.vrsf-labels-inline .vrsf-field > label {
	flex: 0 0 30%;
	max-width: 30%;
	padding-top: 10px;
	margin-bottom: 0;
}

.vrsf-labels-inline .vrsf-field > .vrsf-field-input-wrap {
	flex: 1;
	min-width: 0;
}

/* On mobile, inline labels revert to stacked */
@media (max-width: 767px) {
	.vrsf-labels-inline .vrsf-field {
		flex-direction: column;
		gap: 0;
	}

	.vrsf-labels-inline .vrsf-field > label {
		flex: unset;
		max-width: 100%;
		padding-top: 0;
		margin-bottom: 6px;
	}
}

/* Hidden labels: visually hidden but accessible */
.vrsf-labels-hidden .vrsf-field > label {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Full-width button */
.vrsf-btn-full .vrsf-submit-btn {
	display: flex;
	width: 100%;
}

/* Button alignment (only applies when not full-width) */
.vrsf-btn-align-center .vrsf-form-actions {
	text-align: center;
}

.vrsf-btn-align-right .vrsf-form-actions {
	text-align: right;
}

/* ─── Two-column Layout ─── */
@media (min-width: 768px) {
	.vrsf-form--two-col .vrsf-field-text,
	.vrsf-form--two-col .vrsf-field-email,
	.vrsf-form--two-col .vrsf-field-phone,
	.vrsf-form--two-col .vrsf-field-number,
	.vrsf-form--two-col .vrsf-field-date,
	.vrsf-form--two-col .vrsf-field-select {
		display: inline-block;
		width: calc(50% - var(--vrsf-spacing) / 2);
		vertical-align: top;
	}

	.vrsf-form--two-col .vrsf-field-text:nth-child(odd),
	.vrsf-form--two-col .vrsf-field-email:nth-child(odd),
	.vrsf-form--two-col .vrsf-field-phone:nth-child(odd),
	.vrsf-form--two-col .vrsf-field-number:nth-child(odd),
	.vrsf-form--two-col .vrsf-field-date:nth-child(odd),
	.vrsf-form--two-col .vrsf-field-select:nth-child(odd) {
		margin-right: var(--vrsf-spacing);
	}

	/* Full-width fields remain full width in 2-col mode */
	.vrsf-form--two-col .vrsf-field-textarea,
	.vrsf-form--two-col .vrsf-field-checkbox {
		display: block;
		width: 100%;
	}
}

/* ─── Form Title ─── */
.vrsf-form .vrsf-form-title {
	margin: 0 0 var(--vrsf-spacing) 0;
	font-family: var(--vrsf-font-family);
	color: var(--vrsf-color-text);
	line-height: 1.3;
}

/* ─── Honeypot (hidden) ─── */
.vrsf-hp-field {
	position: absolute;
	left: -9999px;
	top: -9999px;
	height: 0;
	width: 0;
	overflow: hidden;
}

/* ─── Responsive ─── */

/* Small screens: tighter spacing, touch-friendly targets */
@media (max-width: 767px) {
	.vrsf-form {
		--vrsf-spacing: 16px;
		padding: 24px;
		border-radius: 8px;
	}

	/* Ensure 48px minimum touch target (WCAG 2.1 AA) */
	.vrsf-form .vrsf-field input[type="text"],
	.vrsf-form .vrsf-field input[type="email"],
	.vrsf-form .vrsf-field input[type="tel"],
	.vrsf-form .vrsf-field input[type="number"],
	.vrsf-form .vrsf-field input[type="date"],
	.vrsf-form .vrsf-field select,
	.vrsf-form .vrsf-field textarea {
		min-height: 48px;
		font-size: 14px;
		padding: 12px 14px;
	}

	.vrsf-form .vrsf-submit-btn {
		min-height: 52px;
		width: 100%;
	}
}

/* ─── Forced Colors (Windows High Contrast) ─── */
@media (forced-colors: active) {
	.vrsf-form .vrsf-field input:focus,
	.vrsf-form .vrsf-field select:focus,
	.vrsf-form .vrsf-field textarea:focus {
		outline: 2px solid Highlight;
		outline-offset: 1px;
	}

	.vrsf-message-success::before,
	.vrsf-message-error::before {
		forced-color-adjust: none;
	}
}

/* ─── Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
	.vrsf-form *,
	.vrsf-form *::before,
	.vrsf-form *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
