/* ============================================================
   MODAL OVERLAY — 0.3s sin delays
   ============================================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================================
   MODAL — Con redondeo
   ============================================================ */
.modal {
    position: relative;
    max-width: 1080px;
    min-width: 500px;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: 
        0 0 0 1px rgba(0, 0, 0, 0.05),
        0 10px 30px rgba(0, 0, 0, 0.1),
        0 40px 80px rgba(0, 0, 0, 0.15);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    will-change: transform, opacity;
    transform: translateY(100%);
    opacity: 0;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal {
    transform: translateY(0);
    opacity: 1;
    transition: 
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.25s ease,
        max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.closing {
    animation: modalExitDown 0.20s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes modalExitDown {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(50%);
        opacity: 0;
    }
}

/* ============================================================
   HEADER — Icono centrado verticalmente + Título/Subtítulo
   ============================================================ */
.modal-header {
    padding: 20px 24px;
    padding-right: 60px;
    background: var(--panel-2);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius) var(--radius) 0 0;
    position: relative;
    opacity: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-overlay.active .modal-header {
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal-header i {
    color: var(--accent);
    font-size: 20px;
    flex-shrink: 0;
    align-self: center;
}

.modal-header-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.modal-header-content h4 {
    color: var(--txt);
    font-weight: 600;
    font-size: 16px;
    margin: 0;
    line-height: 1.3;
}

.modal-header-content p {
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
    margin: 0;
}

/* ============================================================
   CONTENIDO
   ============================================================ */
.modal-main {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    opacity: 0;
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal-main {
    opacity: 1;
    transition: opacity 0.25s ease,
                height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   FOOTER
   ============================================================ */
.modal-footer {
    padding: 18px 24px;
    background: var(--panel-2);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0 0 var(--radius) var(--radius);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    opacity: 0;
}

.modal-overlay.active .modal-footer {
    opacity: 1;
    transition: opacity 0.25s ease;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
.modal-main::-webkit-scrollbar {
    width: 8px;
}

.modal-main::-webkit-scrollbar-track {
    background: transparent;
}

.modal-main::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 20px;
    transition: background 0.15s ease;
}

.modal-main::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ============================================================
   BOTÓN DE CERRAR
   ============================================================ */
.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 40px;
    height: 40px;
    border: 0;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--txt);
    z-index: 10;
    opacity: 0;
    transition: color 0.25s ease;
    background: transparent;
}

.modal-overlay.active .modal-close {
    opacity: 1;
}

.modal-close:hover {
    color: var(--accent);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .modal-overlay {
        height: 100dvh;
        background: transparent;
        opacity: 1 !important;
        transition: none;
    }
    
    .modal-overlay.closing {
        transition: none;
    }
    
    .modal-close {
        width: 36px;
        height: 36px;
        font-size: 20px;
        top: 12px;
        right: 12px;
    }
    
    .modal {
        width: 100%;
        height: 100dvh;
        max-width: 100%;
        max-height: 100dvh;
        min-width: 100%;
        border-radius: 0;
        box-shadow: none;
        transform: translateX(100%);
    }

    .modal-overlay.active .modal {
        transform: translateX(0);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                    opacity 0.25s ease;
    }

    .modal.closing {
        animation: modalExitRight 0.25s cubic-bezier(0.4, 0, 1, 1) forwards;
    }

    @keyframes modalExitRight {
        0% {
            transform: translateX(0);
            opacity: 1;
        }
        100% {
            transform: translateX(100%);
            opacity: 1;
        }
    }

    .modal-header {
        padding: 18px 20px;
        padding-right: 56px;
        padding-top: max(18px, env(safe-area-inset-top));
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        border-radius: 0;
        gap: 10px;
    }

    .modal-header-content h4 {
        font-size: 15px;
    }

    .modal-header-content p {
        font-size: 12px;
    }

    .modal-main {
        padding: 20px;
        padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 16px 20px;
        padding-bottom: max(16px, calc(16px + env(safe-area-inset-bottom)));
        border-top: 1px solid rgba(0, 0, 0, 0.06);
        border-radius: 0;
    }
}