/* Capa compartida para ventanas emergentes y visores. */

.modal-overlay,
.modal-interfaces-overlay,
.pwa-modal-overlay,
.visor-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    padding: clamp(8px, 2.5vw, 24px);
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.modal-box,
.modal-content,
.modal-interfaces,
.pwa-modal {
    width: min(100%, 1100px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 32px);
    margin: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-box.modal-xl {
    width: min(100%, 1200px);
}

.modal-box.modal-lg {
    width: min(100%, 960px);
}

.modal-box.modal-sm {
    width: min(100%, 560px);
}

.modal-header,
.modal-footer,
.modal-interfaces-header,
.modal-interfaces-footer {
    flex: 0 0 auto;
}

.modal-header,
.modal-interfaces-header {
    position: sticky;
    top: 0;
    z-index: 5;
}

.modal-footer,
.modal-interfaces-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.modal-body,
.modal-interfaces-body {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.modal-close,
.modal-interfaces-close,
.pwa-modal-close {
    flex: 0 0 auto;
    min-width: 42px;
    min-height: 42px;
    touch-action: manipulation;
}

.visor-container {
    width: min(100%, 1400px);
    height: min(90dvh, 900px);
    max-height: calc(100dvh - 24px);
    margin: auto;
}

html body .swal2-container {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 0 !important;
    padding: max(8px, env(safe-area-inset-top))
             max(8px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom))
             max(8px, env(safe-area-inset-left)) !important;
    display: grid !important;
    place-items: center !important;
    overflow: hidden !important;
}

html body .swal2-container.swal-iframe-visible {
    display: grid !important;
    place-items: center !important;
    overflow: hidden !important;
}

html body .swal2-popup,
html body .swal-popup-custom {
    position: relative !important;
    width: min(32em, calc(100vw - 16px)) !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 16px) !important;
    margin: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

html body.swal2-shown,
html body.swal2-height-auto {
    height: 100% !important;
    overflow: hidden !important;
}

@media (max-width: 768px) {
    .modal-overlay,
    .modal-interfaces-overlay,
    .pwa-modal-overlay,
    .visor-overlay {
        align-items: flex-start;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-left: max(8px, env(safe-area-inset-left));
    }

    .modal-box,
    .modal-content,
    .modal-interfaces,
    .pwa-modal {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 16px);
        margin: 0 auto;
        border-radius: 18px;
    }

    .modal-header,
    .modal-footer,
    .modal-interfaces-header,
    .modal-interfaces-footer {
        padding: 12px 14px;
        gap: 8px;
    }

    .modal-header h3,
    .modal-interfaces-header h3 {
        min-width: 0;
        font-size: clamp(0.9rem, 4vw, 1.1rem);
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .modal-body,
    .modal-interfaces-body {
        padding: 14px;
    }

    .modal-footer,
    .modal-interfaces-footer,
    .modal-actions,
    .modal-footer-left,
    .modal-footer-right {
        flex-wrap: wrap;
        width: 100%;
    }

    .modal-footer button,
    .modal-actions button,
    .modal-footer-left button,
    .modal-footer-right button {
        flex: 1 1 150px;
        min-height: 44px;
    }

    .modal-table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .form-row.two-cols,
    .form-row-modal.two-cols {
        grid-template-columns: 1fr;
    }

    .visor-container {
        width: 100%;
        height: calc(100dvh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: 18px;
    }

    .visor-header {
        padding: 10px 12px;
    }

    .visor-titulo {
        min-width: 0;
        flex: 1 1 160px;
    }

    .visor-titulo h3 {
        max-width: 100%;
    }

    .visor-controles {
        width: 100%;
        justify-content: center;
    }

    .logout-modal-overlay-premium {
        align-items: flex-start;
        overflow-y: auto;
        padding: max(8px, env(safe-area-inset-top)) 8px 8px;
    }

    .logout-modal-premium {
        width: 100%;
        max-width: 520px;
        max-height: calc(100dvh - 16px);
        overflow-y: auto;
        margin: 0 auto;
    }

    html body .swal2-popup,
    html body .swal-popup-custom {
        width: min(92vw, 420px) !important;
        padding: 18px 16px !important;
        border-radius: 16px !important;
    }

    html body .swal2-icon {
        margin-top: 8px !important;
        margin-bottom: 10px !important;
        transform: scale(0.82);
    }

    html body .swal2-title {
        padding-top: 0 !important;
        font-size: 1.25rem !important;
    }

    html body .swal2-html-container {
        margin: 10px 14px 4px !important;
        font-size: 0.95rem !important;
    }

    html body .swal2-actions {
        margin-top: 14px !important;
    }
}

@media (max-width: 480px) {
    .modal-footer button,
    .modal-actions button,
    .modal-footer-left button,
    .modal-footer-right button {
        flex-basis: 100%;
        width: 100%;
    }
}
