/*
    Two-Stage Loader with Light/Dark Mode Support
    Stage 1: Lightweight spinner (immediate)
    Stage 2: LeptonX themed progress loader (after CSS loads)
    
    Supports: system preference, LeptonX theme (lpx:loaded-css), and data-theme attribute
*/

/* ============================================
   CSS Custom Properties (Theme Variables)
   ============================================ */
:root {
    /* Light theme (default) */
    --loader-bg: #f8f9fa;
    --loader-bg-secondary: #ffffff;
    --loader-text: #212529;
    --loader-text-muted: #6c757d;
    --spinner-color: #5c4dff;
    --spinner-secondary: #8b7fff;
    --progress-bg: #e9ecef;
    --progress-fill: linear-gradient(90deg, #5c4dff 0%, #8b7fff 100%);
    --progress-glow: rgba(92, 77, 255, 0.3);
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --card-border: rgba(0, 0, 0, 0.05);
    --resource-item-bg: rgba(0, 0, 0, 0.03);
}

/* System preference fallback for dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --loader-bg: #1a1a2e;
        --loader-bg-secondary: #16213e;
        --loader-text: #e9ecef;
        --loader-text-muted: #adb5bd;
        --spinner-color: #7c6fff;
        --spinner-secondary: #a599ff;
        --progress-bg: #2d2d44;
        --progress-fill: linear-gradient(90deg, #7c6fff 0%, #a599ff 100%);
        --progress-glow: rgba(124, 111, 255, 0.4);
        --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
        --card-border: rgba(255, 255, 255, 0.05);
        --resource-item-bg: rgba(255, 255, 255, 0.03);
    }
}

/* LeptonX dark theme support */
html.dark,
html[data-bs-theme="dark"],
html[data-loader-theme="dark"] {
    --loader-bg: #1a1a2e;
    --loader-bg-secondary: #16213e;
    --loader-text: #e9ecef;
    --loader-text-muted: #adb5bd;
    --spinner-color: #7c6fff;
    --spinner-secondary: #a599ff;
    --progress-bg: #2d2d44;
    --progress-fill: linear-gradient(90deg, #7c6fff 0%, #a599ff 100%);
    --progress-glow: rgba(124, 111, 255, 0.4);
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --card-border: rgba(255, 255, 255, 0.05);
    --resource-item-bg: rgba(255, 255, 255, 0.03);
}

/* LeptonX light theme support (explicit) */
html.light,
html[data-bs-theme="light"],
html[data-loader-theme="light"] {
    --loader-bg: #f8f9fa;
    --loader-bg-secondary: #ffffff;
    --loader-text: #212529;
    --loader-text-muted: #6c757d;
    --spinner-color: #5c4dff;
    --spinner-secondary: #8b7fff;
    --progress-bg: #e9ecef;
    --progress-fill: linear-gradient(90deg, #5c4dff 0%, #8b7fff 100%);
    --progress-glow: rgba(92, 77, 255, 0.3);
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --card-border: rgba(0, 0, 0, 0.05);
    --resource-item-bg: rgba(0, 0, 0, 0.03);
}

/* ============================================
   Auth Callback Minimal Loading
   For login-callback, logout-callback pages
   Shows simplified UI since these redirect quickly
   ============================================ */
html[data-auth-callback="true"] .loader-stage2 {
    display: none !important;
}

html[data-auth-callback="true"] .loader-stage1 {
    display: flex !important;
}

html[data-auth-callback="true"] .spinner {
    width: 48px;
    height: 48px;
}

/* Auth callback loading message */
html[data-auth-callback="true"] .loading-text {
    font-size: 14px;
    margin-top: 16px;
}

/* Custom message for auth callbacks */
.auth-callback-message {
    display: none;
    font-size: 14px;
    color: var(--loader-text-muted);
    margin-top: 16px;
    text-align: center;
}

html[data-auth-callback="true"] .auth-callback-message {
    display: block;
}

html[data-auth-callback="true"] .loading-dots {
    display: none;
}

/* ============================================
   Main Loader Container
   ============================================ */
.loader {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    background-color: var(--loader-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease-out;
}

.loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* When loader is being hidden, hide internal content immediately */
.loader.loaded {
    opacity: 0;
    pointer-events: none;
}

.loader.loaded .progress-label,
.loader.loaded .progress-status {
    visibility: hidden;
}

/* ============================================
   Stage 1: Lightweight Spinner (Immediate)
   ============================================ */
.loader-stage1 {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    transition: opacity 0.3s ease-out;
}

.loader-stage1.fade-out {
    opacity: 0;
}

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner {
    width: 60px;
    height: 60px;
    position: relative;
}

.double-bounce1, .double-bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--spinner-color);
    opacity: 0.6;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-animation: sk-bounce 2.0s infinite ease-in-out;
    animation: sk-bounce 2.0s infinite ease-in-out;
}

.double-bounce2 {
    background-color: var(--spinner-secondary);
    -webkit-animation-delay: -1.0s;
    animation-delay: -1.0s;
}

.loading-text {
    color: var(--loader-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.5px;
    opacity: 0;
    animation: fade-in-text 0.5s ease-out 0.3s forwards;
}

.loading-dots {
    display: inline-flex;
    gap: 4px;
    margin-left: 4px;
}

.loading-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: var(--spinner-color);
    animation: dot-pulse 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

/* ============================================
   Stage 2: LeptonX Themed Progress Loader
   ============================================ */
.loader-stage2 {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 420px;
    padding: 0 24px;
    opacity: 0;
}

/* Show stage 2 when visible class is added */
.loader-stage2.visible,
.loader-stage2.fade-in {
    display: flex;
    opacity: 1;
    animation: fade-in-scale 0.4s ease-out forwards;
}

/* Hide stage 1 when hidden class is added */
.loader-stage1.hidden {
    display: none !important;
}

/* LeptonX-style Card */
.loader-card {
    background: var(--loader-bg-secondary);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--card-border);
    padding: 32px;
    width: 100%;
    text-align: center;
}

/* Logo/Brand Section */
.loader-brand {
    margin-bottom: 24px;
}

.loader-logo {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: var(--progress-fill);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-glow 2s ease-in-out infinite;
}

.loader-logo svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.loader-title {
    color: var(--loader-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

/* Progress Bar */
.progress-container {
    margin-bottom: 16px;
}

.progress-container.progress-main {
    margin-bottom: 20px;
}

.progress-container.progress-secondary {
    margin-bottom: 12px;
}

.progress-label {
    color: var(--loader-text-muted);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.progress-bar-wrapper {
    height: 8px;
    background: var(--progress-bg);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-bar-wrapper.secondary {
    height: 4px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--progress-fill);
    border-radius: 4px;
    transition: width 0.3s ease-out;
    position: relative;
}

.progress-bar.secondary {
    background: linear-gradient(90deg, #28a745 0%, #5cb85c 100%);
}

html.dark .progress-bar.secondary,
html[data-bs-theme="dark"] .progress-bar.secondary,
html[data-loader-theme="dark"] .progress-bar.secondary {
    background: linear-gradient(90deg, #28a745 0%, #6fd688 100%);
}

/* Indeterminate mode for secondary bar (post-boot phase) */
.progress-bar.secondary.indeterminate {
    width: 100% !important;
    background: linear-gradient(90deg, 
        transparent 0%, 
        #28a745 20%, 
        #5cb85c 50%, 
        #28a745 80%, 
        transparent 100%);
    background-size: 200% 100%;
    animation: indeterminate-slide 1.5s ease-in-out infinite;
}

html.dark .progress-bar.secondary.indeterminate,
html[data-bs-theme="dark"] .progress-bar.secondary.indeterminate,
html[data-loader-theme="dark"] .progress-bar.secondary.indeterminate {
    background: linear-gradient(90deg, 
        transparent 0%, 
        #28a745 20%, 
        #6fd688 50%, 
        #28a745 80%, 
        transparent 100%);
    background-size: 200% 100%;
}

@keyframes indeterminate-slide {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 100%
    );
    animation: shimmer 1.5s infinite;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.progress-status {
    color: var(--loader-text-muted);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    font-weight: 500;
}

.progress-percent {
    color: var(--spinner-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
}

/* Resource Name (Dev Mode) */
.resource-name {
    display: none;
    color: var(--loader-text-muted);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 11px;
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--resource-item-bg);
    border-radius: 4px;
    word-break: break-all;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Resource List (Dev Mode) */
.resource-list {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--card-border);
    max-height: 120px;
    overflow-y: auto;
}

.resource-list-title {
    color: var(--loader-text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.resource-item {
    color: var(--loader-text-muted);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 10px;
    padding: 4px 8px;
    background: var(--resource-item-bg);
    border-radius: 3px;
    margin-bottom: 4px;
    word-break: break-all;
    animation: slide-in 0.2s ease-out;
}

/* Dev Mode Styles */
.loader.dev-mode .resource-name,
.loader.dev-mode .resource-list {
    display: block;
}

.loader.dev-mode .loader-card {
    max-width: 480px;
}

/* Dev Mode Badge */
.dev-badge {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.loader.dev-mode .dev-badge {
    display: block;
}

/* ============================================
   Animations
   ============================================ */
@-webkit-keyframes sk-bounce {
    0%, 100% { -webkit-transform: scale(0.0); transform: scale(0.0); }
    50% { -webkit-transform: scale(1.0); transform: scale(1.0); }
}

@keyframes sk-bounce {
    0%, 100% { -webkit-transform: scale(0.0); transform: scale(0.0); }
    50% { -webkit-transform: scale(1.0); transform: scale(1.0); }
}

@keyframes fade-in-text {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes dot-pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes fade-in-scale {
    from { 
        opacity: 0; 
        transform: scale(0.95) translateY(10px); 
    }
    to { 
        opacity: 1; 
        transform: scale(1) translateY(0); 
    }
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes pulse-glow {
    0%, 100% { 
        box-shadow: 0 0 0 0 var(--progress-glow);
    }
    50% { 
        box-shadow: 0 0 20px 4px var(--progress-glow);
    }
}

@keyframes slide-in {
    from { 
        opacity: 0; 
        transform: translateX(-10px); 
    }
    to { 
        opacity: 1; 
        transform: translateX(0); 
    }
}

/* ============================================
   Application Container Rules
   ============================================ */
#ApplicationContainer > div:first-child:not(:only-child) {
    display: none !important;
}

/* ============================================
   Blazor Error UI
   ============================================ */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ============================================
   LeptonX Logo Variables
   ============================================ */
:root {
    --lpx-logo: url('/images/logo/leptonx/icon.svg');
    --lpx-logo-icon: url('/images/logo/leptonx/icon.svg');
}

