/**
 * Système de modales UMOA
 * Design moderne et responsive
 */

/* ==================== BASE MODAL ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-container {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.7);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-sizing: border-box; /* Évite les débordements */
}

.modal-overlay.active .modal-container {
    transform: scale(1);
    opacity: 1;
}

/* ==================== TAILLES MODALES ==================== */
.modal-sm { max-width: 400px; }
.modal-md { max-width: 600px; }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }

/* ==================== HEADER MODAL ==================== */
.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 2px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #7B2CBF; /* Violet UMOA - couleur unie */
    color: white;
}

.modal-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 24px;
    color: white;
    cursor: pointer;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    opacity: 0.9;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
    transform: rotate(90deg);
}

/* ==================== BODY MODAL ==================== */
.modal-body {
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden; /* Empêche le débordement horizontal */
    max-height: calc(90vh - 160px);
    box-sizing: border-box; /* Évite les débordements */
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ==================== FOOTER MODAL ==================== */
.modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background: #f8f9fa;
}

/* ==================== FORMULAIRES DANS MODAL ==================== */
.modal-form .form-group {
    margin-bottom: 1.5rem;
}

.modal-form label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.modal-form .form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-form .form-control:focus {
    outline: none;
    border-color: #7B2CBF; /* Violet UMOA */
    box-shadow: 0 0 0 3px rgba(123, 44, 191, 0.1);
}

.modal-form .form-text {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.35rem;
    display: block;
}

.modal-form .form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* ==================== BOUTONS DANS MODAL ==================== */
.modal-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-btn-primary {
    background: #7B2CBF; /* Violet UMOA - couleur unie */
    color: white;
    box-shadow: 0 4px 10px rgba(123, 44, 191, 0.3);
}

.modal-btn-primary:hover {
    background: #9D4EDD; /* Violet UMOA clair */
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(123, 44, 191, 0.4);
}

.modal-btn-secondary {
    background: #6c757d;
    color: white;
}

.modal-btn-secondary:hover {
    background: #5a6268;
}

.modal-btn-danger {
    background: #dc3545;
    color: white;
}

.modal-btn-danger:hover {
    background: #c82333;
}

/* ==================== LOADER MODAL ==================== */
.modal-loader {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    align-items: center;
    justify-content: center;
}

.modal-loader.active {
    display: flex;
}

.modal-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==================== MESSAGES DANS MODAL ==================== */
.modal-alerts-container {
    margin-bottom: 1.5rem;
}

.modal-alert {
    padding: 1rem 1.25rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    z-index: 10001;
}

.modal-alert-success {
    background: #d4edda;
    border-left: 4px solid #28a745;
    color: #155724;
}

.modal-alert-error {
    background: #f8d7da;
    border-left: 4px solid #dc3545;
    color: #721c24;
}

.modal-alert-warning {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    color: #856404;
}

.modal-alert-info {
    background: #d1ecf1;
    border-left: 4px solid #17a2b8;
    color: #0c5460;
}

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(-50px); opacity: 0; }
}

/* ==================== TYPES DE MODALES ==================== */

/* Modal Connexion/Inscription */
.modal-auth {
    max-width: 450px;
}

.modal-auth .modal-body {
    padding: 2.5rem;
}

/* Modal Formulaire */
.modal-form-container {
    max-width: 700px;
}

/* Modal Confirmation */
.modal-confirm {
    max-width: 400px;
    text-align: center;
}

.modal-confirm .modal-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* Modal Info/Aide */
.modal-info {
    max-width: 600px;
}

/* ==================== RESPONSIVE MOBILE-FIRST ==================== */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end; /* Modale depuis le bas sur mobile */
        padding: 0;
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); /* Espace pour navbar bottom + safe area */
    }
    
    .modal-container {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - calc(64px + env(safe-area-inset-bottom, 0px))); /* Hauteur totale moins navbar */
        margin: 0;
        border-radius: 16px 16px 0 0; /* Coins arrondis en haut seulement */
        position: relative;
    }
    
    .modal-header {
        padding: 1rem 1.25rem;
        position: sticky;
        top: 0;
        z-index: 10;
        background: #7B2CBF;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .modal-back {
        order: 1;
        padding: 0.5rem;
        font-size: 0.875rem;
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: white;
        border-radius: 6px;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        transition: all 0.2s;
    }
    
    .modal-back:hover {
        background: rgba(255, 255, 255, 0.3);
    }
    
    .modal-title {
        font-size: clamp(16px, 4vw, 18px);
        order: 2;
        flex: 1;
        text-align: center;
        margin: 0;
    }
    
    .modal-close {
        order: 3;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 24px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        z-index: 10;
    }
    
    .modal-body {
        padding: 1.25rem;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100vh - calc(64px + env(safe-area-inset-bottom, 0px)) - 140px); /* Hauteur moins navbar, header et footer */
    }
    
    .modal-footer {
        padding: 1.25rem;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e9ecef;
        z-index: 10;
    }
    
    /* Formulaires - 1 colonne sur mobile */
    .modal-form .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Sections de formulaire */
    .form-section {
        margin-bottom: 1.5rem;
    }
    
    .form-section-title {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Types de véhicules - responsive */
    .vehicle-types {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .vehicle-type-card {
        min-height: auto;
    }
    
    /* Groupes de formulaire */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
    
    .form-control {
        font-size: 16px; /* Évite le zoom automatique sur iOS */
        padding: 0.75rem;
    }
    
    /* Actions du formulaire */
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1.5rem;
    }
    
    .form-actions .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
    
    /* Info du formulaire */
    .form-info {
        padding: 1rem;
        font-size: 0.875rem;
        margin-top: 1rem;
    }
}

/* ==================== ÉTATS SPÉCIAUX ==================== */
.modal-container.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

/* ==================== ACCESSIBILITÉ ==================== */
.modal-overlay:focus {
    outline: 2px solid #007bff;
    outline-offset: -2px;
}

.modal-container:focus-within {
    box-shadow: 0 10px 40px rgba(0, 123, 255, 0.4);
}

/* Désactiver le scroll du body quand modal ouverte */
body.modal-open {
    overflow: hidden; /* Cache le scroll vertical */
    overflow-x: hidden; /* S'assure que le scroll horizontal reste désactivé */
}

