/**
 * ═══════════════════════════════════════════════════════════════
 * MAJAARH - UNIFIED LOADING SYSTEM
 * نظام Loading موحد لكامل المنصة
 * ═══════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════
   1. PAGE PRELOADER - محمل الصفحة الرئيسي
   ═══════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════
   1. ULTIMATE SOVEREIGN LOADER - التصميم الجديد
   ═══════════════════════════════════════════════════════════════ */

.ultimate-loader-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loader-aura {
    position: absolute;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(255, 46, 46, 0.2) 0%, transparent 70%);
    animation: loader-aura-pulse 4s ease-in-out infinite;
}

.loader-fab {
    width: 130px;
    height: 130px;
    background: #000;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.8);
    animation: loader-breathe 4s ease-in-out infinite;
}

/* Dual Laser Effect from Focus Design */
.loader-fab::before {
    content: '';
    position: absolute;
    width: 250%;
    height: 250%;
    background: conic-gradient(transparent, transparent, rgba(255, 46, 46, 0.6));
    animation: loader-spin 1.2s linear infinite;
    border-radius: 50%;
}

.loader-fab::after {
    content: '';
    position: absolute;
    width: 250%;
    height: 250%;
    background: conic-gradient(transparent, transparent, rgba(0, 209, 255, 0.4));
    animation: loader-spin 3s linear infinite reverse;
    border-radius: 50%;
}

.loader-inner {
    position: absolute;
    inset: 5px;
    background: #05070a;
    border-radius: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.loader-scan {
    position: absolute;
    width: 100%;
    height: 3px;
    background: linear-gradient(to right, transparent, #ff2e2e, transparent);
    box-shadow: 0 0 15px #ff2e2e;
    top: -100%;
    z-index: 3;
    animation: loader-scan-anim 2.5s linear infinite;
}

.loader-img {
    width: 65px;
    height: 65px;
    object-fit: contain;
    z-index: 4;
    filter: drop-shadow(0 0 10px #ff2e2e);
    transition: all 0.3s ease;
}

/* Progress Ring Styles */
.progress-ring-svg {
    position: absolute;
    z-index: 1;
    transform: rotate(-90deg);
}

.progress-ring-bg {
    fill: transparent;
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 4;
}

.progress-ring-circle {
    fill: transparent;
    stroke: #ff2e2e;
    stroke-width: 4;
    stroke-dasharray: 314;
    stroke-dashoffset: 314;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear;
    filter: drop-shadow(0 0 5px #ff2e2e);
}

.loading-percent {
    margin-top: 25px;
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: -1px;
    font-family: 'Tajawal', sans-serif;
    text-shadow: 0 0 20px rgba(255, 46, 46, 0.5);
}

.loading-text {
    margin-top: 10px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-align: center;
}

@keyframes loader-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes loader-scan-anim { 0% { top: -110%; } 100% { top: 110%; } }
@keyframes loader-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes loader-aura-pulse { 0%, 100% { transform: scale(1); opacity: 0.3; } 50% { transform: scale(1.5); opacity: 0.7; } }

/* Premium Ring Styles */
.loader-svg-ring {
    position: absolute;
    inset: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    z-index: 1;
    transform: rotate(-90deg);
    pointer-events: none;
}

.loader-ring-bg {
    fill: transparent;
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 2;
}

.loader-ring-progress {
    fill: transparent;
    stroke: var(--mj-red, #ff2e2e);
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear;
    filter: drop-shadow(0 0 10px var(--mj-red, #ff2e2e));
}

/* Loader Content Bottom */
.loading-percent-text {
    font-size: 3rem;
    font-weight: 900;
    color: var(--mj-text, #fff);
    font-family: 'Cairo', sans-serif;
    letter-spacing: -2px;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(227, 27, 35, 0.3);
}

.loading-status-bar {
    width: 240px;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin: 0 auto 20px;
    overflow: hidden;
    position: relative;
}

.loading-status-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--mj-red, #ff2e2e), var(--mj-cyan, #00d1ff));
    box-shadow: 0 0 15px var(--mj-red, #ff2e2e);
    transition: width 0.2s ease;
}

.loading-text-sub {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--mj-text-muted, rgba(255, 255, 255, 0.4));
    font-weight: 700;
}

#preloader {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: var(--mj-bg, #05070a) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 999999 !important;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    overflow: hidden !important;
}

#preloader.fade-out {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* ── Light Mode Overrides ── */
:root:not(.dark) #preloader {
    background: #ffffff !important;
}
:root:not(.dark) .loader-inner {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.05) !important;
}
:root:not(.dark) .loader-fab {
    background: #f8fafc !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05) !important;
}
:root:not(.dark) .loading-status-bar {
    background: rgba(0, 0, 0, 0.05) !important;
}
:root:not(.dark) .loading-text-sub {
    color: #64748b !important;
}
:root:not(.dark) .loading-percent-text,
:root:not(.dark) #mj-loader-percent {
    color: #0f172a !important;
    text-shadow: none !important;
}


/* ── داشبورد فقط: تأكيد ألوان العداد ── */
/* #loading-percent يستخدم inline style color:#ffffff !important في header.php */
/* هذا block يضمن عدم تجاوز unified-design-system.css عليه */
#loading-percent {
    color: #ffffff !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* ── NewThemeLayoutRenderer: تأكيد ألوان العداد الجديد ── */
#mj-loader-percent {
    color: #ffffff;
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
}

/* تأكيد لون الـ preloader container ── */
#preloader {
    color: var(--mj-text, #ffffff);
}

#preloader .loader-img {
    width: 65px !important;
    height: 65px !important;
    object-fit: contain !important;
    z-index: 4 !important;
    filter: drop-shadow(0 0 10px #ff2e2e) !important;
}

@keyframes loading {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(300%);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ═══════════════════════════════════════════════════════════════
   2. INLINE LOADING SPINNER - سبينر التحميل الداخلي
   ═══════════════════════════════════════════════════════════════ */

.spinner-border {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    vertical-align: text-bottom;
    border: 0.25em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.2em;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

/* ═══════════════════════════════════════════════════════════════
   3. BUTTON LOADING STATE - حالة التحميل للأزرار
   ═══════════════════════════════════════════════════════════════ */

.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner-border 0.75s linear infinite;
}

/* ═══════════════════════════════════════════════════════════════
   4. CONTENT LOADING SKELETON - هيكل التحميل للمحتوى
   ═══════════════════════════════════════════════════════════════ */

.skeleton {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0.05) 25%, 
        rgba(255, 255, 255, 0.1) 50%, 
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 10px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 15px;
}

.skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.skeleton-card {
    height: 200px;
    border-radius: 16px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ═══════════════════════════════════════════════════════════════
   5. OVERLAY LOADING - تحميل الطبقة العلوية
   ═══════════════════════════════════════════════════════════════ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 9, 12, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-overlay .spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #C41E3A;
    border-radius: 50%;
    animation: spinner-border 0.8s linear infinite;
}

.loading-overlay .loading-text {
    color: white;
    margin-top: 20px;
    font-size: 14px;
    text-align: center;
}

/* ═══════════════════════════════════════════════════════════════
   6. PROGRESS BAR - شريط التقدم
   ═══════════════════════════════════════════════════════════════ */

.progress-bar-loading {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.progress-bar-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 30%;
    height: 100%;
    background: linear-gradient(90deg, #C41E3A, #ff2e2e);
    border-radius: 10px;
    animation: progress-loading 1.5s ease-in-out infinite;
}

@keyframes progress-loading {
    0% {
        left: -30%;
    }
    100% {
        left: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════════
   7. DOTS LOADING - نقاط التحميل
   ═══════════════════════════════════════════════════════════════ */

.dots-loading {
    display: inline-flex;
    gap: 8px;
}

.dots-loading span {
    width: 8px;
    height: 8px;
    background: #C41E3A;
    border-radius: 50%;
    animation: dots-bounce 1.4s ease-in-out infinite;
}

.dots-loading span:nth-child(1) {
    animation-delay: 0s;
}

.dots-loading span:nth-child(2) {
    animation-delay: 0.2s;
}

.dots-loading span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════════════════════════════
   8. RESPONSIVE ADJUSTMENTS
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .loader-logo {
        width: 80px;
    }
    
    .loader-bar {
        width: 150px;
    }
    
    .loading-overlay .spinner {
        width: 40px;
        height: 40px;
    }
}
