/* Match Bootstrap's agency-detail modal without changing popup layout or close behavior. */
:root {
    --agency-popup-fade-duration: 150ms;
    --agency-popup-enter-duration: 300ms;
    --agency-popup-enter-offset: -50px;
}

@keyframes agency-popup-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes agency-popup-enter {
    from { transform: translateY(var(--agency-popup-enter-offset)); }
    to { transform: none; }
}

/* Display/hidden based popups restart naturally when opened again. */
.account-password-modal:not([hidden]),
.parent-qr-modal:not([hidden]),
.profile-contract-modal:not([hidden]),
.ob-detail-modal:not([hidden]),
#overlay:not([hidden]),
.pop:not([hidden]),
.rp-modal:not([hidden]),
.rp-network-modal:not([hidden]),
.ts-modal:not(.is-hide),
.popup-overlay,
.sf-lightbox {
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear;
}

.account-password-modal:not([hidden]) > .account-password-sheet,
.parent-qr-modal:not([hidden]) > .parent-qr-sheet,
.profile-contract-modal:not([hidden]) > .profile-contract-sheet,
.ob-detail-modal:not([hidden]) > .ob-detail-dialog,
#overlay:not([hidden]) > #orderForm,
.pop:not([hidden]) > .pop-box,
.rp-modal:not([hidden]) > .rp-modal-box,
.rp-network-modal:not([hidden]) > .rp-network-dialog,
.ts-modal:not(.is-hide) > .ts-box,
.popup-overlay > .popup-content,
.sf-lightbox > img {
    animation: agency-popup-enter var(--agency-popup-enter-duration) ease-out;
}

/* Registration QR stays mounted and uses visibility instead of display/hidden. */
.qr-modal.is-open {
    transition: none;
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear;
}

.qr-modal.is-open > .qr-box {
    animation: agency-popup-enter var(--agency-popup-enter-duration) ease-out;
}

/* Native dialogs are both the panel and the fade surface. */
dialog.db-qr-dialog[open],
dialog.db-ranks-dialog[open] {
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear,
        agency-popup-enter var(--agency-popup-enter-duration) ease-out;
}

dialog.db-qr-dialog[open]::backdrop,
dialog.db-ranks-dialog[open]::backdrop {
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear;
}

/* Override only SweetAlert's opening animation; retain icons, focus and closing. */
.sweet-alert.showSweetAlert[data-animation] {
    -webkit-animation: agency-popup-fade var(--agency-popup-fade-duration) linear,
        agency-popup-enter var(--agency-popup-enter-duration) ease-out;
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear,
        agency-popup-enter var(--agency-popup-enter-duration) ease-out;
}

.sweet-overlay {
    animation: agency-popup-fade var(--agency-popup-fade-duration) linear;
}

@media (prefers-reduced-motion: reduce) {
    .account-password-modal,
    .account-password-sheet,
    .parent-qr-modal,
    .parent-qr-sheet,
    .profile-contract-modal,
    .profile-contract-sheet,
    .ob-detail-modal,
    .ob-detail-dialog,
    #overlay,
    #orderForm,
    .pop,
    .pop-box,
    .rp-modal,
    .rp-modal-box,
    .rp-network-modal,
    .rp-network-dialog,
    .ts-modal,
    .ts-box,
    .popup-overlay,
    .popup-content,
    .sf-lightbox,
    .sf-lightbox > img,
    .qr-modal,
    .qr-modal > .qr-box,
    dialog.db-qr-dialog,
    dialog.db-ranks-dialog,
    dialog.db-qr-dialog::backdrop,
    dialog.db-ranks-dialog::backdrop,
    .sweet-alert,
    .sweet-overlay {
        animation: none !important;
        transition: none !important;
    }

    /* SweetAlert also fades this surface with an inline JavaScript timer. */
    .sweet-overlay {
        opacity: 1 !important;
    }
}
