/* EPASI request feedback: shared by admin, authentication, and public forms. */
#epasi-request-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 160ms ease, visibility 160ms ease;
    -webkit-backdrop-filter: blur(1px);
    backdrop-filter: blur(1px);
}

#epasi-request-overlay.epasi-request-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.epasi-request-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.epasi-request-spinner {
    width: 42px;
    height: 42px;
    margin: 0;
    border: 4px solid rgba(255, 255, 255, 0.6);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: epasi-request-spin 650ms linear infinite;
    filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.45));
}

body.epasi-request-busy {
    cursor: progress;
}

.epasi-button-loading {
    cursor: wait !important;
    opacity: 0.82;
    pointer-events: none !important;
}

.epasi-button-busy {
    cursor: wait !important;
    opacity: 0.82;
    pointer-events: none !important;
}

button.epasi-button-loading::before,
a.epasi-button-loading::before {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    margin-right: 0.45em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.08em;
    content: '';
    animation: epasi-request-spin 600ms linear infinite;
}

body.dark-mode #epasi-request-overlay,
html.dark-mode-pending #epasi-request-overlay {
    background: rgba(2, 6, 23, 0.58);
}

body.dark-mode .epasi-request-panel,
html.dark-mode-pending .epasi-request-panel {
    border: 0;
    background: transparent;
}

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

@media (max-width: 575.98px) {
    .epasi-request-panel {
        width: 44px;
        height: 44px;
    }
    .epasi-request-spinner { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
    #epasi-request-overlay {
        transition: none;
    }

    .epasi-request-spinner,
    button.epasi-button-loading::before,
    a.epasi-button-loading::before {
        animation-duration: 1.5s;
    }
}

/*
 * Loader AJAX legacy dipakai oleh banyak modul lama melalui
 * $('#modal-loading').modal(...). Bentuknya dinormalisasi di sini agar semua
 * modul otomatis memakai spinner kecil yang sama, bukan modal putih besar.
 */
#modal-loading.epasi-legacy-loading {
    padding: 0 !important;
    background: transparent;
}

#modal-loading.epasi-legacy-loading .modal-dialog {
    width: 48px;
    max-width: 48px;
    margin: 0 auto;
    pointer-events: none;
}

.epasi-legacy-loading__indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.epasi-legacy-loading__spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(255, 255, 255, 0.6);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: epasi-request-spin 650ms linear infinite;
    filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.45));
}

body.dark-mode .epasi-legacy-loading__indicator {
    border: 0;
    background: transparent;
}

body.dark-mode .epasi-legacy-loading__spinner {
    border-color: rgba(255, 255, 255, 0.45);
    border-top-color: #60a5fa;
}

/*
 * Prioritas indikator: modal/SweetAlert > overlay global > DataTables.
 * Saat indikator yang lebih spesifik aktif, semua spinner di belakangnya
 * disembunyikan agar pengguna tidak pernah melihat dua ring bertumpuk.
 */
body.epasi-legacy-loader-active #epasi-request-overlay,
body.epasi-custom-loader-active #epasi-request-overlay {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

body.epasi-legacy-loader-active div.dataTables_processing,
body.epasi-legacy-loader-active .dataTables_wrapper .dataTables_processing,
body.epasi-custom-loader-active div.dataTables_processing,
body.epasi-custom-loader-active .dataTables_wrapper .dataTables_processing,
body.epasi-request-busy div.dataTables_processing,
body.epasi-request-busy .dataTables_wrapper .dataTables_processing {
    display: none !important;
}

body.epasi-legacy-loader-active.epasi-dt-page-busy::after,
body.epasi-custom-loader-active.epasi-dt-page-busy::after,
body.epasi-request-busy.epasi-dt-page-busy::after {
    display: none !important;
}

/* Saat notifikasi hasil muncul sebelum animasi modal lama selesai, tampilkan
 * SweetAlert saja. Ini menutup celah spinner ganda pada pergantian state. */
body.epasi-custom-loader-active #modal-loading.epasi-legacy-loading {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* DataTables tetap memproses di tengah tabel, tetapi tanpa panel teks lebar. */
div.dataTables_processing,
.dataTables_wrapper .dataTables_processing {
    top: 50% !important;
    left: 50% !important;
    width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    margin: -21px 0 0 -21px !important;
    padding: 0 !important;
    overflow: hidden;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: transparent !important;
    font-size: 0 !important;
}

div.dataTables_processing::after,
.dataTables_wrapper .dataTables_processing::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
    border: 4px solid #cbd5e1;
    border-top-color: #2563eb;
    border-radius: 50%;
    content: '';
    animation: epasi-request-spin 650ms linear infinite;
    filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.22));
}

div.dataTables_processing .epasi-dt-processing,
.dataTables_wrapper .dataTables_processing .epasi-dt-processing {
    display: none !important;
}

body.dark-mode div.dataTables_processing,
body.dark-mode .dataTables_wrapper .dataTables_processing {
    border: 0 !important;
    background: transparent !important;
}

/* SweetAlert yang sedang loading juga dibuat ringkas: hanya spinner di tengah. */
.swal2-popup.swal2-loading {
    width: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.swal2-popup.swal2-loading > :not(.swal2-actions) {
    display: none !important;
}

.swal2-popup.swal2-loading .swal2-actions {
    display: flex !important;
    margin: 0 !important;
}

.swal2-popup.swal2-loading .swal2-loader {
    width: 42px !important;
    height: 42px !important;
    margin: 0 !important;
    border-width: 4px !important;
    border-color: rgba(255, 255, 255, 0.6) !important;
    border-right-color: #3b82f6 !important;
    filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.45));
}

body.dark-mode .swal2-popup.swal2-loading {
    border: 0 !important;
    background: transparent !important;
}

body.dark-mode .swal2-popup.swal2-loading .swal2-loader {
    border-color: rgba(255, 255, 255, 0.45) !important;
    border-right-color: #60a5fa !important;
}

@media (max-width: 575.98px) {
    #modal-loading.epasi-legacy-loading .modal-dialog,
    .epasi-legacy-loading__indicator {
        width: 44px;
        max-width: 44px;
        height: 44px;
    }
    .epasi-legacy-loading__spinner { width: 38px; height: 38px; }
    .swal2-popup.swal2-loading {
        width: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    .swal2-popup.swal2-loading .swal2-loader { width: 38px !important; height: 38px !important; }
}
