/**
 * modal-portal.css
 * Styles pour le système de modales via portal
 * Optimisé pour mobile (viewport, clavier virtuel, scroll)
 */

/* ========================================
   MODAL PORTAL - Container principal
   ======================================== */

.modal-portal {
    /* Position fixed pour isolation complète */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    /* Z-index élevé mais isolé */
    z-index: 10000;
    
    /* Caché par défaut */
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    
    /* Transition douce */
    transition: opacity 0.3s ease, visibility 0.3s ease;
    
    /* Empêcher le scroll */
    overflow: hidden;
}

.modal-portal.active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

/* ========================================
   BACKDROP - Fond semi-transparent
   ======================================== */

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* ========================================
   MODAL CONTAINER - Contenu de la modale
   ======================================== */

.modal-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    /* Centrage du contenu */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Padding pour respirer */
    padding: 20px;
    
    /* Scroll indépendant */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll iOS */
}

/* ✅ MOBILE : Supprimer le padding sur mobile */
@media (max-width: 768px) {
    .modal-container {
        padding: 0;
        align-items: flex-start; /* Aligner en haut sur mobile */
    }
}

/* ========================================
   MODAL CONTENT WRAPPER - Wrapper du contenu
   ======================================== */

.modal-content-wrapper {
    position: relative;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    
    /* Animation d'apparition */
    transform: scale(0.95) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-portal.active .modal-content-wrapper {
    transform: scale(1) translateY(0);
}

/* ✅ Assurer que le contenu cloné (.modal-content existant) s'étire correctement dans le portal */
.modal-portal .modal-content {
    width: 100% !important;
    max-width: none !important;
    height: auto;
}

/* ✅ MOBILE : Occupation totale de l'écran */
@media (max-width: 768px) {
    .modal-content-wrapper {
        border-radius: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        
        /* ✅ CORRECTIF : Utiliser 100dvh pour gérer la barre d'adresse mobile */
        height: 100dvh; /* Dynamic Viewport Height */
        max-height: 100dvh;
    }
}

/* ========================================
   BOUTON DE FERMETURE
   ======================================== */

.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10001;
    
    background: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.modal-close-btn:hover {
    background: #f5f5f5;
    transform: scale(1.1);
}

.modal-close-btn i {
    font-size: 18px;
    color: #666;
}

/* ✅ MOBILE : Bouton plus grand et accessible */
@media (max-width: 768px) {
    .modal-close-btn {
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
    }
}

/* ========================================
   TAILLES DE MODALES
   ======================================== */

/* Small */
.modal-portal[data-size="small"] .modal-content-wrapper {
    max-width: 400px;
}

/* Medium (par défaut) */
.modal-portal[data-size="medium"] .modal-content-wrapper {
    max-width: 600px;
}

/* Large */
.modal-portal[data-size="large"] .modal-content-wrapper {
    max-width: 900px;
}

/* XLarge */
.modal-portal[data-size="xlarge"] .modal-content-wrapper {
    max-width: 1280px;
    width: 98%;
    max-height: 95vh;
}

/* Fullscreen */
.modal-portal[data-size="fullscreen"] .modal-content-wrapper {
    max-width: 100%;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

/* ========================================
   STRUCTURE INTERNE DE LA MODALE
   ======================================== */

.modal-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 90vh;
}

/* ✅ MOBILE : Utiliser tout l'écran */
@media (max-width: 768px) {
    .modal-wrapper {
        max-height: 100%;
        height: 100%;
    }
}

/* Header */
.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
}

.modal-close-btn-inline {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s ease;
}

.modal-close-btn-inline:hover {
    color: #1a1a1a;
}

/* Body */
.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch; /* Smooth scroll iOS */
}

/* ✅ MOBILE : Padding réduit */
@media (max-width: 768px) {
    .modal-body {
        padding: 15px;
    }
}

/* Footer */
.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ✅ MOBILE : Boutons empilés */
@media (max-width: 768px) {
    .modal-footer {
        flex-direction: column-reverse;
        padding: 15px;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ========================================
   CLAVIER VIRTUEL MOBILE
   ======================================== */

/* ✅ Quand le clavier est ouvert */
.modal-portal.keyboard-open .modal-container {
    align-items: flex-start;
    padding-top: 0;
}

.modal-portal.keyboard-open .modal-content-wrapper {
    /* Permettre le scroll quand le clavier est ouvert */
    max-height: 100%;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes modalSlideIn {
    from {
        transform: scale(0.95) translateY(30px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes modalSlideOut {
    from {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    to {
        transform: scale(0.95) translateY(30px);
        opacity: 0;
    }
}

/* ========================================
   THÈME SOMBRE
   ======================================== */

.dark-mode .modal-content-wrapper {
    background-color: #1e1e1e;
    color: #ffffff;
}

.dark-mode .modal-header {
    border-bottom-color: #333;
}

.dark-mode .modal-footer {
    border-top-color: #333;
}

.dark-mode .modal-backdrop {
    background-color: rgba(0, 0, 0, 0.8);
}

.dark-mode .modal-close-btn {
    background: #2a2a2a;
    color: #ffffff;
}

.dark-mode .modal-close-btn:hover {
    background: #333;
}

/* ========================================
   ACCESSIBILITÉ
   ======================================== */

/* Focus visible */
.modal-close-btn:focus,
.modal-close-btn-inline:focus,
.modal-action-btn:focus {
    outline: 2px solid #0A66C2;
    outline-offset: 2px;
}

/* Réduction de mouvement */
@media (prefers-reduced-motion: reduce) {
    .modal-portal,
    .modal-content-wrapper {
        transition: none;
    }
}

