/**
 * V-CRM Enterprise - System-Wide Loading Engine CSS
 * High-performance, modern glassmorphism & micro-interaction styles
 */

/* ==========================================================================
   1. TOP PROGRESS BAR (Page & AJAX Transitions)
   ========================================================================== */
#crm-top-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #3b82f6, #06b6d4, #10b981);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.8), 0 0 6px rgba(16, 185, 129, 0.6);
    z-index: 9999999;
    pointer-events: none;
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
    opacity: 0;
}

#crm-top-loader.active {
    opacity: 1;
}

#crm-top-loader-peg {
    position: absolute;
    right: 0px;
    width: 80px;
    height: 100%;
    box-shadow: 0 0 14px #06b6d4, 0 0 8px #10b981;
    transform: rotate(3deg) translate(0px, -4px);
    opacity: 1;
}

/* ==========================================================================
   2. GLOBAL FULL-SCREEN LOADING OVERLAY
   ========================================================================== */
#crm-global-loader {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.68);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.28s ease;
}

#crm-global-loader.show {
    opacity: 1;
    visibility: visible;
}

.crm-loader-card {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-radius: 20px;
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.6);
    min-width: 320px;
    max-width: 90vw;
    transform: scale(0.92);
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#crm-global-loader.show .crm-loader-card {
    transform: scale(1);
}

/* Dark mode support if applicable */
[data-bs-theme="dark"] .crm-loader-card {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(51, 65, 85, 0.8);
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.7);
}

.crm-loader-graphic {
    position: relative;
    width: 88px;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.crm-loader-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    animation: crm-logo-breathe 2s ease-in-out infinite;
}

.crm-loader-spinner-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: #2563eb;
    border-right-color: #06b6d4;
    animation: crm-spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

.crm-loader-spinner-outer {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px dashed rgba(16, 185, 129, 0.4);
    animation: crm-spin-reverse 6s linear infinite;
}

.crm-loader-title {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

[data-bs-theme="dark"] .crm-loader-title {
    color: #f8fafc;
}

.crm-loader-desc {
    font-size: 13px;
    color: #64748b;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.crm-loader-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 2px;
}

.crm-loader-dots span {
    width: 4px;
    height: 4px;
    background-color: #3b82f6;
    border-radius: 50%;
    display: inline-block;
    animation: crm-dot-bounce 1.4s infinite ease-in-out both;
}

.crm-loader-dots span:nth-child(1) { animation-delay: -0.32s; }
.crm-loader-dots span:nth-child(2) { animation-delay: -0.16s; }

/* ==========================================================================
   3. BUTTON LOADING STATE
   ========================================================================== */
.btn-crm-loading,
.btn.is-loading {
    position: relative !important;
    pointer-events: none !important;
    opacity: 0.85 !important;
    cursor: wait !important;
}

.btn-crm-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: crm-spin 0.75s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}

/* ==========================================================================
   4. SECTION / CARD / TABLE OVERLAY LOADER
   ========================================================================== */
.crm-section-relative {
    position: relative !important;
    min-height: 120px;
}

.crm-section-loader {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    animation: crm-fade-in 0.2s ease;
}

[data-bs-theme="dark"] .crm-section-loader {
    background: rgba(15, 23, 42, 0.82);
}

.crm-section-loader .crm-mini-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(59, 130, 246, 0.18);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: crm-spin 0.8s linear infinite;
    margin-bottom: 8px;
}

.crm-section-loader .crm-section-loader-text {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}

/* ==========================================================================
   5. SKELETON SHIMMER UTILITIES
   ========================================================================== */
.crm-skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
    background-size: 400% 100%;
    animation: crm-shimmer 1.5s ease infinite;
    border-radius: 6px;
}

[data-bs-theme="dark"] .crm-skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 37%, #1e293b 63%);
    background-size: 400% 100%;
}

.crm-skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.crm-skeleton-circle {
    border-radius: 50%;
}

/* ==========================================================================
   6. PAGE FADE-IN TRANSITION
   ========================================================================== */
.crm-page-transition {
    animation: crm-page-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ==========================================================================
   7. KEYFRAME ANIMATIONS
   ========================================================================== */
@keyframes crm-spin {
    to { transform: rotate(360deg); }
}

@keyframes crm-spin-reverse {
    to { transform: rotate(-360deg); }
}

@keyframes crm-logo-breathe {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 4px 8px rgba(37,99,235,0.25)); }
    50% { transform: scale(1.06); filter: drop-shadow(0 6px 16px rgba(16,185,129,0.35)); }
}

@keyframes crm-dot-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes crm-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@keyframes crm-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes crm-page-enter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
