/**
 * Global Loading Animation System
 * Uses custom SmartShop SVG logo animation
 *
 * Usage:
 *   HTML: <div class="smartshop-loader"></div>
 *   JS: SmartShopLoader.show() / SmartShopLoader.hide()
 */

/* Loading Overlay - Full screen */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
}

.loading-overlay.active {
    display: flex;
}

/* Loading Container - Inline */
.loading,
.smartshop-loader {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    min-height: 200px;
}

/* SmartShop Logo Animation */
.smartshop-loader-logo {
    width: 120px;
    height: 120px;
    margin-bottom: 1rem;
    animation: smartshop-pulse 1.5s ease-in-out infinite;
}

.smartshop-loader-logo img {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 12px rgba(0, 123, 255, 0.2));
}

/* Pulse Animation */
@keyframes smartshop-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Rotating Animation (alternative) */
@keyframes smartshop-rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.smartshop-loader-logo.rotating img {
    animation: smartshop-rotate 2s linear infinite;
}

/* Loading Text */
.smartshop-loader-text {
    font-size: 0.95rem;
    color: #666;
    font-weight: 500;
    margin-top: 0.5rem;
    text-align: center;
}

/* Loading Dots Animation */
.smartshop-loader-dots {
    display: inline-block;
    width: 4ch;
    text-align: left;
}

.smartshop-loader-dots::after {
    content: '';
    animation: smartshop-dots 1.5s steps(4, end) infinite;
}

@keyframes smartshop-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Overlay Content */
.loading-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    text-align: center;
}

/* Spinner Fallback (for old code compatibility) */
.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Small Loader (for inline use) */
.smartshop-loader-small {
    width: 40px;
    height: 40px;
}

.smartshop-loader-small .smartshop-loader-logo {
    width: 40px;
    height: 40px;
    margin-bottom: 0;
}

.smartshop-loader-small .smartshop-loader-text {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Dark Theme Support */
.loading-overlay.dark {
    background: rgba(0, 0, 0, 0.85);
}

.loading-overlay.dark .loading-content {
    background: #1a1a1a;
    color: #fff;
}

.loading-overlay.dark .smartshop-loader-text {
    color: #ccc;
}

/* Button Loading State */
button.loading,
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

button.loading::after,
.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: spin 0.6s linear infinite;
}

/* Card Loading State */
.card.loading {
    position: relative;
    min-height: 200px;
    overflow: hidden;
}

.card.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,0.5) 50%,
        rgba(255,255,255,0) 100%
    );
    animation: shimmer 1.5s infinite;
    z-index: 1;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Table Loading State */
table.loading tbody {
    position: relative;
    opacity: 0.3;
}

table.loading tbody::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background-image: url('/static/images/loader.svg?v=5');
    background-size: contain;
    background-repeat: no-repeat;
    animation: smartshop-pulse 1.5s ease-in-out infinite;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .smartshop-loader-logo {
        width: 80px;
        height: 80px;
    }

    .loading-content {
        padding: 1.5rem;
    }
}
