/**
 * Form Optimization CSS
 * Stili per ottimizzare l'aspetto e la performance dei form
 */

/* 🚀 Form Critical Styles - Caricamento immediato */
.newsletter-form,
.contact-form {
    opacity: 1 !important;
    transition: opacity 0.3s ease;
}

.newsletter-form.loading,
.contact-form.loading {
    opacity: 0.7;
}

/* Form Ready State */
.form-ready {
    opacity: 1 !important;
}

.component-ready {
    opacity: 1 !important;
}

/* 🎯 Button States */
button[type="submit"] {
    position: relative;
    overflow: hidden;
}

button[type="submit"].loading {
    pointer-events: none;
}

button[type="submit"] .button-text {
    transition: opacity 0.3s ease;
}

button[type="submit"] .button-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

button[type="submit"].loading .button-text {
    opacity: 0;
}

button[type="submit"].loading .button-loading {
    opacity: 1;
}

/* 🔄 Loading Animation */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* 📝 Field Validation */
input.error,
textarea.error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.field-error {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* ✅ Success Messages */
.form-success {
    background-color: #dcfce7;
    border: 1px solid #16a34a;
    color: #15803d;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.form-success svg {
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* ❌ Error Messages */
.form-error {
    background-color: #fef2f2;
    border: 1px solid #ef4444;
    color: #dc2626;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.form-error svg {
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* 🔄 Form Loading Overlay */
.form-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 0.5rem;
}

/* 📱 Mobile Optimizations */
@media (max-width: 640px) {
    .newsletter-form .flex {
        flex-direction: column;
    }
    
    .newsletter-form button[type="submit"] {
        margin-top: 0.5rem;
        width: 100%;
    }
}

/* 🎨 Focus States */
input:focus,
textarea:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    border-color: #3b82f6;
}

/* ⚡ Performance Optimizations */
.newsletter-component,
.contact-component {
    will-change: opacity;
    transform: translateZ(0); /* Force hardware acceleration */
}

/* 🔧 Debug Styles (solo in modalità debug) */
.wp-debug .form-ready::after {
    content: "✅ Form Ready";
    position: absolute;
    top: -20px;
    right: 0;
    background: #10b981;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}

.wp-debug .newsletter-form::before {
    content: "🚀 Critical JS Loaded";
    position: absolute;
    top: -20px;
    left: 0;
    background: #3b82f6;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}
