/**
 * ENHANCED FORMS & FIELDS STYLING
 * Fichier: public/css/enhanced-forms.css
 * Améliorations des formulaires et champs de saisie
 */

/* =============================================
   GLOBAL FORM STYLES
   ============================================= */

form {
    animation: fadeInUp 0.6s ease-out;
}

form.was-validated .form-control:valid,
.form-control.is-valid {
    border-color: #28a745;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
    padding-right: calc(1.5em + 0.75rem);
}

form.was-validated .form-control:invalid,
.form-control.is-invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
    padding-right: calc(1.5em + 0.75rem);
}

/* =============================================
   INPUT FIELDS
   ============================================= */

.form-control,
.form-select {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: #fff;
}

.form-control:focus,
.form-select:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    background-color: #fff;
    transform: translateY(-2px);
}

.form-control::placeholder {
    color: #999;
    font-weight: 500;
}

/* Floating labels */
.form-floating > label {
    color: #666;
    font-weight: 500;
}

.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
    color: #007bff;
    font-weight: 600;
}

/* =============================================
   TEXTAREAS
   ============================================= */

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    max-height: 400px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

textarea.form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* =============================================
   FORM GROUPS & LABELS
   ============================================= */

.form-group,
.mb-3 {
    animation: fadeInUp 0.6s ease-out;
}

label,
.form-label {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

label .required,
.form-label .required {
    color: #dc3545;
    font-weight: bold;
}

/* Help text */
.form-text,
.invalid-feedback,
.valid-feedback {
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
    animation: slideInUp 0.3s ease-out;
}

.form-text {
    color: #6c757d;
}

.invalid-feedback {
    color: #dc3545;
    display: block !important;
}

.valid-feedback {
    color: #28a745;
    display: block !important;
}

/* =============================================
   CHECKBOXES & RADIOS
   ============================================= */

.form-check {
    padding-left: 0;
    margin-bottom: 0.75rem;
}

.form-check-input {
    width: 1.25em;
    height: 1.25em;
    margin-top: 0.3em;
    margin-right: 0.75rem;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    background-color: white;
}

.form-check-input:hover {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.1);
}

.form-check-input:checked {
    background-color: #007bff;
    border-color: #007bff;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 6l4 4 8-8'/%3e%3c/svg%3e");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.form-check-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.form-check-label {
    cursor: pointer;
    user-select: none;
    color: #333;
    font-weight: 500;
}

/* Radio buttons */
.form-check-input[type="radio"] {
    border-radius: 50%;
}

/* =============================================
   SELECT DROPDOWNS
   ============================================= */

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23007bff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.75rem;
    cursor: pointer;
}

.form-select:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* =============================================
   FILE INPUTS
   ============================================= */

.form-control[type="file"]::file-selector-button {
    padding: 0.375rem 0.75rem;
    margin: -0.75rem -1rem;
    margin-inline-end: 0.75rem;
    color: white;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    border-color: inherit;
    border-radius: 0;
    transition: all 0.3s ease;
    cursor: pointer;
    font-weight: 600;
}

.form-control[type="file"]::file-selector-button:hover {
    background: linear-gradient(135deg, #0056b3 0%, #003d82 100%);
    box-shadow: 0 5px 15px rgba(0, 123, 255, 0.4);
}

/* =============================================
   FORM GROUPS WITH ICONS
   ============================================= */

.input-group .form-control,
.input-group .form-select {
    border-radius: 8px 0 0 8px;
}

.input-group .btn {
    border-radius: 0 8px 8px 0;
}

.input-group-text {
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-right: none;
    border-radius: 8px 0 0 8px;
    color: #007bff;
    font-weight: 600;
    transition: all 0.3s ease;
}

.input-group:focus-within .input-group-text {
    border-color: #007bff;
    background: white;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.1);
}

/* =============================================
   FORM ANIMATIONS
   ============================================= */

@keyframes formPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7); }
    50% { box-shadow: 0 0 0 10px rgba(0, 123, 255, 0); }
}

.form-control.focus-pulse {
    animation: formPulse 1.5s infinite;
}

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

@media (max-width: 768px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Évite le zoom sur iOS */
    }

    label,
    .form-label {
        font-size: 0.95rem;
    }

    .form-text,
    .invalid-feedback,
    .valid-feedback {
        font-size: 0.8rem;
    }
}

/* =============================================
   DARK MODE SUPPORT
   ============================================= */

@media (prefers-color-scheme: dark) {
    /* In dark mode, keep input backgrounds light and readable when focused
       to ensure consistent visibility during data entry. Colors for labels
       and surrounding UI remain adjusted for dark theme. */
    .form-control,
    .form-select,
    .input-group-text {
        background-color: #2b2b2b;
        color: #e0e0e0;
        border-color: #444;
    }

    /* Keep focused input fields visually light/clear for data entry */
    .form-control:focus,
    .form-select:focus {
        background-color: #ffffff;
        color: #000000;
        border-color: #007bff;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.15);
    }

    label,
    .form-label {
        color: #e0e0e0;
    }

    .form-text {
        color: #b0b0b0;
    }

    .form-check-input {
        background-color: #2b2b2b;
        border-color: #555;
    }

    .form-check-label {
        color: #e0e0e0;
    }

    .input-group-text {
        background: #333;
        border-color: #444;
    }
}

/* =============================================
   FORM VALIDATION STATES
   ============================================= */

.was-validated .form-control:valid {
    border-color: #28a745;
}

.was-validated .form-control:invalid {
    border-color: #dc3545;
}

.was-validated textarea.form-control:valid {
    border-color: #28a745;
}

.was-validated textarea.form-control:invalid {
    border-color: #dc3545;
}

/* =============================================
   SUBMIT BUTTON STATES
   ============================================= */

button[type="submit"],
.btn-submit {
    position: relative;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
}

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

button[type="submit"].loading::after,
.btn-submit.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #f3f3f3;
    border-radius: 50%;
    border-top: 2px solid #007bff;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
