/**
 * AFV Modular Forms - Base Styles
 * Sistema modular de formulários com suporte a blocos JSON
 * Mobile-first, responsive e acessível (WCAG 2.2 AA)
 *
 * @package AFV_Simple_Portal
 * @version 2.0.0
 */

/* ============================================
   1. DESIGN TOKENS E VARIÁVEIS
   ============================================ */

:root {
	/* Colors - Map to AFV Design System */
	--afvsp-primary: var(--afv-primary-start, #5A41F4);
	--afvsp-primary-dark: var(--afv-primary-end, #4631CC);
	--afvsp-primary-light: var(--afv-primary-middle, #7A65F6);
	--afvsp-success: var(--afv-success, #10B981);
	--afvsp-error: var(--afv-error, #EF4444);
	--afvsp-warning: var(--afv-warning, #F59E0B);
	--afvsp-info: var(--afv-info, #3B82F6);

	/* Typography */
	--afvsp-font-family: var(--afv-font-family, 'DM Sans', sans-serif);
	--afvsp-font-size-sm: var(--afv-font-size-sm, 0.875rem);
	--afvsp-font-size-base: var(--afv-font-size-base, 1rem);
	--afvsp-font-size-lg: var(--afv-font-size-lg, 1.125rem);
	--afvsp-font-size-xl: var(--afv-font-size-xl, 1.25rem);
	--afvsp-font-size-2xl: var(--afv-font-size-2xl, 1.5rem);

	/* Spacing - Map to AFV System */
	--afvsp-spacing-xs: var(--afv-space-xs, 0.25rem);
	--afvsp-spacing-sm: var(--afv-space-sm, 0.5rem);
	--afvsp-spacing-md: var(--afv-space-md, 1rem);
	--afvsp-spacing-lg: var(--afv-space-lg, 1.5rem);
	--afvsp-spacing-xl: var(--afv-space-xl, 2rem);
	--afvsp-spacing-2xl: var(--afv-space-2xl, 3rem);

	/* Border Radius */
	--afvsp-radius-sm: var(--afv-radius-md, 8px);
	--afvsp-radius-md: var(--afv-radius-lg, 12px);
	--afvsp-radius-lg: var(--afv-radius-xl, 16px);
	--afvsp-radius-xl: var(--afv-radius-2xl, 24px);

	/* Shadows */
	--afvsp-shadow-sm: var(--afv-shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.1));
	--afvsp-shadow-md: var(--afv-shadow-md, 0 4px 8px rgba(0, 0, 0, 0.08));
	--afvsp-shadow-lg: var(--afv-shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.1));

	/* Transitions */
	--afvsp-transition: var(--afv-transition-normal, all 0.2s ease);
	--afvsp-transition-slow: var(--afv-transition-slow, all 0.3s ease);
}

/* ============================================
   2. BASE FORM WRAPPER
   ============================================ */

.afvsp-form-wrapper {
	width: 100%;
	max-width: 100%;
	padding: 1rem;
	margin: 0 auto;
	font-family: var(--afvsp-font-family);
	font-size: var(--afvsp-font-size-base);
	line-height: 1.6;
	color: #1a1a1a;
}

@media (min-width: 768px) {
	.afvsp-form-wrapper {
		padding: 2rem;
		max-width: 1200px;
	}
}

/* ============================================
   3. FORM HEADER
   ============================================ */

.afvsp-form-header {
	margin-bottom: var(--afvsp-spacing-xl);
	text-align: center;
}

.afvsp-form-header h1 {
	font-size: 1.75rem;
	font-weight: 700;
	color: #1a1a1a;
	margin: 0 0 0.5rem 0;
	line-height: 1.2;
}

.afvsp-form-subtitle {
	font-size: 1rem;
	color: #64748b;
	margin: 0;
	line-height: 1.5;
}

@media (min-width: 768px) {
	.afvsp-form-header h1 {
		font-size: 2.25rem;
	}

	.afvsp-form-subtitle {
		font-size: 1.125rem;
	}
}

/* ============================================
   4. PROGRESS BAR
   ============================================ */

.afvsp-progress-bar-wrapper {
	margin-bottom: var(--afvsp-spacing-xl);
	padding: 1rem;
	background: #f8fafc;
	border-radius: var(--afvsp-radius-md);
}

.afvsp-progress-bar {
	width: 100%;
	height: 8px;
	background: #e2e8f0;
	border-radius: 999px;
	overflow: hidden;
	margin-bottom: 0.5rem;
}

.afvsp-progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--afvsp-primary), var(--afvsp-primary-light));
	border-radius: 999px;
	transition: width 0.3s ease;
	width: 0;
}

.afvsp-progress-text {
	font-size: 0.875rem;
	color: #475569;
	font-weight: 500;
	display: block;
	text-align: center;
}

/* ============================================
   5. TABS NAVIGATION (Mobile First)
   ============================================ */

.afvsp-form-tabs {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	margin-bottom: var(--afvsp-spacing-xl);
	padding: 0;
	list-style: none;
}

.afvsp-form-tab {
	flex: 1;
	min-width: 100%;
}

.afvsp-form-tab button {
	width: 100%;
	min-height: 48px;
	padding: 0.75rem 1rem;
	background: #f8fafc;
	border: 2px solid #e2e8f0;
	border-radius: var(--afvsp-radius-sm);
	font-size: 1rem;
	font-weight: 500;
	color: #475569;
	cursor: pointer;
	transition: var(--afvsp-transition);
	text-align: left;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.afvsp-form-tab button:hover {
	background: #f1f5f9;
	border-color: var(--afvsp-primary-light);
}

.afvsp-form-tab button.active {
	background: var(--afvsp-primary);
	border-color: var(--afvsp-primary);
	color: white;
	box-shadow: var(--afvsp-shadow-md);
}

.afvsp-form-tab button:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(90, 65, 244, 0.25);
}

@media (min-width: 768px) {
	.afvsp-form-tabs {
		flex-direction: row;
		flex-wrap: wrap;
	}

	.afvsp-form-tab {
		min-width: auto;
		flex: 1 1 160px;
	}

	.afvsp-form-tab button {
		text-align: center;
		justify-content: center;
	}
}

/* ============================================
   6. FORM BLOCKS
   ============================================ */

.afvsp-form-block {
	background: white;
	border: 1px solid #e2e8f0;
	border-radius: var(--afvsp-radius-md);
	padding: 1.5rem;
	margin-bottom: var(--afvsp-spacing-lg);
	box-shadow: var(--afvsp-shadow-sm);
}

.afvsp-form-block-title {
	font-size: 1.25rem;
	font-weight: 600;
	color: #1e293b;
	margin: 0 0 1.5rem 0;
	padding-bottom: 0.75rem;
	border-bottom: 2px solid #e2e8f0;
}

@media (min-width: 768px) {
	.afvsp-form-block {
		padding: 2.5rem;
		border: 1px solid var(--afv-border-color, #e2e8f0);
		box-shadow: var(--afvsp-shadow-md);
		transition: var(--afvsp-transition);
	}

	.afvsp-form-block:hover {
		box-shadow: var(--afvsp-shadow-lg);
		border-color: var(--afv-border-hover, #cbd5e1);
	}

	.afvsp-form-block-title {
		font-size: 1.75rem;
		margin-bottom: 2rem;
		color: var(--afv-text-primary);
	}
}

/* ============================================
   7. FORM FIELDS (Mobile First)
   ============================================ */

.afvsp-form-field {
	margin-bottom: 1.5rem;
}

.afvsp-form-field label {
	display: block;
	font-size: 1rem;
	font-weight: 600;
	color: var(--afv-text-primary, #334155);
	margin-bottom: 0.75rem;
}

.afvsp-form-field label.required::after {
	content: " *";
	color: var(--afvsp-error);
}

.afvsp-form-field input[type="text"],
.afvsp-form-field input[type="email"],
.afvsp-form-field input[type="tel"],
.afvsp-form-field input[type="date"],
.afvsp-form-field input[type="number"],
.afvsp-form-field select,
.afvsp-form-field textarea {
	width: 100%;
	min-height: 52px;
	/* Premium height */
	padding: 0.875rem 1.25rem;
	font-size: 1rem;
	font-family: var(--afvsp-font-family);
	color: var(--afv-text-primary, #1e293b);
	background: var(--afv-bg-surface, white);
	border: 1px solid var(--afv-border-color, #cbd5e1);
	border-radius: var(--afvsp-radius-sm);
	transition: var(--afvsp-transition);
	box-sizing: border-box;
}

.afvsp-form-field textarea {
	min-height: 120px;
	resize: vertical;
	line-height: 1.5;
}

/* Focus states - WCAG 2.2 AA */
.afvsp-form-field input:focus,
.afvsp-form-field select:focus,
.afvsp-form-field textarea:focus {
	outline: none;
	border-color: var(--afvsp-primary);
	box-shadow: 0 0 0 3px rgba(90, 65, 244, 0.15);
}

/* Error states */
.afvsp-form-field.has-error input,
.afvsp-form-field.has-error select,
.afvsp-form-field.has-error textarea {
	border-color: var(--afvsp-error);
}

.afvsp-form-field.has-error input:focus,
.afvsp-form-field.has-error select:focus,
.afvsp-form-field.has-error textarea:focus {
	box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Disabled states */
.afvsp-form-field input:disabled,
.afvsp-form-field select:disabled,
.afvsp-form-field textarea:disabled {
	background: #f1f5f9;
	color: #94a3b8;
	cursor: not-allowed;
}

/* Help text */
.afvsp-form-help {
	display: block;
	font-size: 0.875rem;
	color: #64748b;
	margin-top: 0.375rem;
	line-height: 1.4;
}

/* Error message */
.afvsp-form-error {
	display: block;
	font-size: 0.875rem;
	color: var(--afvsp-error);
	margin-top: 0.375rem;
	font-weight: 500;
}

/* ============================================
   8. GRID LAYOUTS (Mobile First)
   ============================================ */

.afvsp-form-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: 1rem;
}

@media (min-width: 768px) {
	.afvsp-form-grid-2 {
		grid-template-columns: repeat(2, 1fr);
	}

	.afvsp-form-grid-3 {
		grid-template-columns: repeat(3, 1fr);
	}

	.afvsp-form-grid .col-span-2 {
		grid-column: span 2;
	}

	.afvsp-form-grid .col-span-full {
		grid-column: 1 / -1;
	}
}

/* ============================================
   9. BUTTONS (Touch-optimized)
   ============================================ */

.afvsp-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 48px;
	padding: 0.75rem 1.5rem;
	font-size: 1rem;
	font-weight: 600;
	font-family: var(--afvsp-font-family);
	text-align: center;
	text-decoration: none;
	border: 2px solid transparent;
	border-radius: var(--afvsp-radius-sm);
	cursor: pointer;
	transition: var(--afvsp-transition);
	box-sizing: border-box;
	white-space: nowrap;
}

.afvsp-btn-primary {
	background: var(--afvsp-primary);
	color: white;
	border-color: var(--afvsp-primary);
}

.afvsp-btn-primary:hover {
	background: var(--afvsp-primary-dark);
	border-color: var(--afvsp-primary-dark);
	transform: translateY(-1px);
	box-shadow: var(--afvsp-shadow-md);
}

.afvsp-btn-secondary {
	background: white;
	color: var(--afvsp-primary);
	border-color: var(--afvsp-primary);
}

.afvsp-btn-secondary:hover {
	background: #f8fafc;
}

.afvsp-btn:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(90, 65, 244, 0.25);
}

.afvsp-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none !important;
}

/* ============================================
   10. FORM ACTIONS (Mobile First)
   ============================================ */

.afvsp-form-actions {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	margin-top: 2rem;
	padding-top: 2rem;
	border-top: 2px solid #e2e8f0;
}

.afvsp-form-actions .afvsp-btn {
	width: 100%;
}

@media (min-width: 768px) {
	.afvsp-form-actions {
		flex-direction: row;
		justify-content: flex-end;
	}

	.afvsp-form-actions .afvsp-btn {
		width: auto;
		min-width: 180px;
	}
}

/* ============================================
   11. ALERTS & NOTIFICATIONS
   ============================================ */

.afvsp-alert {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	padding: 1rem 1.25rem;
	border-radius: var(--afvsp-radius-sm);
	margin-bottom: var(--afvsp-spacing-lg);
	font-size: 0.9375rem;
	line-height: 1.5;
}

.afvsp-alert-icon {
	font-size: 1.25rem;
	flex-shrink: 0;
}

.afvsp-alert-success {
	background: #f0fdf4;
	border: 2px solid #86efac;
	color: #15803d;
}

.afvsp-alert-error {
	background: #fef2f2;
	border: 2px solid #fca5a5;
	color: #991b1b;
}

.afvsp-alert-info {
	background: #eff6ff;
	border: 2px solid #93c5fd;
	color: #1e40af;
}

.afvsp-alert-warning {
	background: #fffbeb;
	border: 2px solid #fde047;
	color: #92400e;
}

/* ============================================
   12. SAVE STATUS INDICATOR
   ============================================ */

.afvsp-save-status {
	position: fixed;
	bottom: 2rem;
	right: 2rem;
	padding: 0.75rem 1.25rem;
	background: white;
	border: 2px solid #e2e8f0;
	border-radius: var(--afvsp-radius-md);
	box-shadow: var(--afvsp-shadow-lg);
	display: none;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.875rem;
	font-weight: 500;
	z-index: 1000;
	transition: var(--afvsp-transition);
}

.afvsp-save-status.show {
	display: flex;
}

.afvsp-save-status.saving {
	border-color: var(--afvsp-info);
	color: var(--afvsp-info);
}

.afvsp-save-status.saved {
	border-color: var(--afvsp-success);
	color: var(--afvsp-success);
}

.afvsp-save-status.error {
	border-color: var(--afvsp-error);
	color: var(--afvsp-error);
}

@media (max-width: 767px) {
	.afvsp-save-status {
		bottom: 1rem;
		right: 1rem;
		left: 1rem;
		justify-content: center;
	}
}

/* ============================================
   13. CHECKBOX & RADIO INPUTS
   ============================================ */

.afvsp-checkbox-field,
.afvsp-radio-field {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	margin-bottom: 1rem;
}

.afvsp-checkbox-field input[type="checkbox"],
.afvsp-radio-field input[type="radio"] {
	min-width: 20px;
	min-height: 20px;
	margin-top: 0.125rem;
	cursor: pointer;
	flex-shrink: 0;
}

.afvsp-checkbox-field label,
.afvsp-radio-field label {
	cursor: pointer;
	margin: 0;
	font-weight: 400;
	line-height: 1.5;
}

/* ============================================
   14. CONDITIONAL FIELDS
   ============================================ */

.afvsp-conditional-field {
	display: none;
}

.afvsp-conditional-field.show {
	display: block;
	animation: slideIn 0.3s ease;
}

@keyframes slideIn {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ============================================
   15. REPEATER FIELDS
   ============================================ */

.afvsp-repeater-item {
	padding: 1.5rem;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: var(--afvsp-radius-sm);
	margin-bottom: 1rem;
	position: relative;
}

.afvsp-repeater-remove {
	position: absolute;
	top: 1rem;
	right: 1rem;
	padding: 0.5rem;
	background: white;
	border: 1px solid #e2e8f0;
	border-radius: var(--afvsp-radius-sm);
	cursor: pointer;
	font-size: 1.25rem;
	color: #64748b;
	transition: var(--afvsp-transition);
}

.afvsp-repeater-remove:hover {
	color: var(--afvsp-error);
	border-color: var(--afvsp-error);
}

.afvsp-repeater-add {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1.25rem;
	background: white;
	border: 2px dashed var(--afvsp-primary);
	border-radius: var(--afvsp-radius-sm);
	color: var(--afvsp-primary);
	font-weight: 600;
	cursor: pointer;
	transition: var(--afvsp-transition);
}

.afvsp-repeater-add:hover {
	background: #f8fafc;
	border-style: solid;
}

/* ============================================
   16. ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* High Contrast Mode */
@media (prefers-contrast: more),
(forced-colors: active) {

	.afvsp-form-field input,
	.afvsp-form-field select,
	.afvsp-form-field textarea {
		border-width: 2px;
	}

	.afvsp-btn {
		border-width: 3px;
	}
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
	* {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
	.afvsp-form-block {
		box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
	}
}

/* Screen Reader Only */
.afvsp-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border-width: 0;
}

/* ============================================
   17. LOADING STATES
   ============================================ */

.afvsp-loading {
	position: relative;
	pointer-events: none;
	opacity: 0.6;
}

.afvsp-loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 32px;
	height: 32px;
	margin: -16px 0 0 -16px;
	border: 3px solid #e2e8f0;
	border-top-color: var(--afvsp-primary);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* ============================================
   18. PRINT STYLES
   ============================================ */

@media print {

	.afvsp-form-actions,
	.afvsp-save-status,
	.afvsp-repeater-add,
	.afvsp-repeater-remove {
		display: none !important;
	}

	.afvsp-form-block {
		page-break-inside: avoid;
		box-shadow: none;
		border: 1px solid #000;
	}
}