/* ============================================
   MODAL SYSTEM STYLES
   Styles pour le système de modales dynamiques
   ============================================ */

/* Container global */
.modal-container {
    /* Container sans z-index par défaut pour ne pas bloquer les autres éléments */
    /* Le z-index sera appliqué uniquement sur les modales elles-mêmes */
    pointer-events: none; /* Transparent aux clics quand vide */
}

.modal-container:has(.modal-visible) {
    /* Activer les pointer-events uniquement quand une modale est visible */
    pointer-events: auto;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1040;
    pointer-events: none; /* Transparent aux clics quand invisible */
}

.modal-backdrop.modal-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Réactiver les clics quand visible */
}

/* Modal principale */
.modal {
    position: fixed !important; /* Force fixed pour éviter tout conflit */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1050;
    overflow-y: auto;
    padding: 20px;
    pointer-events: none; /* Transparent aux clics quand invisible */
}

.modal.modal-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Réactiver les clics quand visible */
}

/* Dialog */
.modal-dialog {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.modal-visible .modal-dialog {
    transform: scale(1);
}

/* Content */
.modal-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
}

/* Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
}

/* .modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #6b7280;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.modal-close:hover {
    background-color: #f3f4f6;
    color: #1f2937;
}

.modal-close svg {
    width: 20px;
    height: 20px;
} */

/* Body */
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-container {
    width: 100%;
    box-shadow: none;
    border-radius: 0;
    margin:0;
    padding:0;
}

/* Footer */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
}

/* ============================================
   TAILLES
   ============================================ */

.modal-small .modal-dialog {
    max-width: 400px;
}

.modal-medium .modal-dialog {
    max-width: 600px;
}

.modal-large .modal-dialog {
    max-width: 900px;
}

.modal-fullscreen .modal-dialog {
    max-width: 100%;
    width: 100%;
    height: 100%;
    margin: 0;
}

.modal-fullscreen .modal-content {
    height: 100%;
    max-height: 100%;
    border-radius: 0;
}

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

/* Fade */
.modal-fade.modal-opening .modal-dialog {
    animation: modalFadeIn 0.3s ease;
}

.modal-fade.modal-closing .modal-dialog {
    animation: modalFadeOut 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* Slide */
.modal-slide.modal-opening .modal-dialog {
    animation: modalSlideIn 0.3s ease;
}

.modal-slide.modal-closing .modal-dialog {
    animation: modalSlideOut 0.3s ease;
}

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

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

/* Zoom */
.modal-zoom.modal-opening .modal-dialog {
    animation: modalZoomIn 0.3s ease;
}

.modal-zoom.modal-closing .modal-dialog {
    animation: modalZoomOut 0.3s ease;
}

@keyframes modalZoomIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalZoomOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.5);
    }
}

/* ============================================
   ÉTATS
   ============================================ */

/* Loading */
.modal-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.modal-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

.modal-loading-content p {
    margin: 0;
    color: #6b7280;
    font-size: 0.875rem;
}

/* Error */
.modal-error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.modal-error-content svg {
    color: #ef4444;
    margin-bottom: 16px;
}

.modal-error-content p {
    margin: 0;
    color: #ef4444;
    font-size: 0.875rem;
}

/* ============================================
   BODY LOCK (empêcher le scroll)
   ============================================ */

body.modal-open {
    overflow: hidden;
}

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

@media (max-width: 768px) {
    .modal {
        padding: 0;
    }
    
    .modal-dialog {
        margin: 0;
        max-width: 100% !important;
        height: 100%;
    }
    
    .modal-content {
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .modal-header {
        padding: 16px 20px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 12px 20px;
    }
}

/* ============================================
   ACCESSIBILITÉ
   ============================================ */

.modal:focus {
    outline: none;
}

.modal-close:focus {
    
    outline-offset: 2px;
}

/* Focus trap pour les modales */
.modal[aria-modal="true"] {
    outline: none;
}

/* ============================================
   MULTI-MODALES (stacking)
   ============================================ */

.modal-backdrop:nth-of-type(n+2) {
    opacity: 0.3;
}

.modal:nth-of-type(n+2) {
    z-index: 1060;
}

.modal:nth-of-type(n+3) {
    z-index: 1070;
}
