/**
 * Lazy Loading CSS Styles
 * Advanced styling for skeleton loaders, transitions, and loading states
 */

/* ======================
   SKELETON ANIMATIONS
   ====================== */
@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ======================
   BASE SKELETON STYLES
   ====================== */
.skeleton-base {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

/* ======================
   IMAGE LAZY LOADING
   ====================== */
img[data-lazy-src] {
    transition: opacity 0.3s ease-in-out;
    background: #f8f9fa;
    border-radius: 8px;
}

img[data-lazy-src]:not([data-lazy-loaded]) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s infinite;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

img[data-lazy-src]:not([data-lazy-loaded])::before {
    content: '📷';
    font-size: 2rem;
    opacity: 0.3;
    position: absolute;
}

img.lazy-loaded {
    animation: fade-in 0.5s ease-in-out;
}

img.lazy-error {
    background: #f8d7da;
    color: #721c24;
    display: flex;
    align-items: center;
    justify-content: center;
}

img.lazy-error::before {
    content: '⚠️ Failed to load';
    font-size: 0.875rem;
}

.lazy-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    padding: 8px;
}

/* ======================
   TABLE SKELETON
   ====================== */
.table-skeleton {
    width: 100%;
    border-collapse: collapse;
}

.skeleton-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    background: rgba(248, 249, 250, 0.5);
}

.skeleton-cell {
    flex: 1;
    height: 20px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-cell:nth-child(1) { max-width: 25%; }
.skeleton-cell:nth-child(2) { max-width: 35%; }
.skeleton-cell:nth-child(3) { max-width: 20%; }
.skeleton-cell:nth-child(4) { max-width: 20%; }

/* Table loading state */
[data-lazy-table].lazy-loading {
    position: relative;
    overflow: hidden;
}

[data-lazy-table].lazy-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: table-loading-shine 2s infinite;
}

@keyframes table-loading-shine {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* ======================
   CONTENT SKELETON
   ====================== */
.content-skeleton {
    padding: 1rem;
    background: rgba(248, 249, 250, 0.3);
    border-radius: 8px;
}

.skeleton-line {
    height: 16px;
    margin-bottom: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-line:last-child { margin-bottom: 0; }

/* Content loading state */
[data-lazy-content].lazy-loading {
    position: relative;
    min-height: 100px;
    border-radius: 8px;
    overflow: hidden;
}

/* ======================
   FORM LOADING STATES
   ====================== */
form[data-lazy-submit] {
    position: relative;
}

form[data-lazy-submit].lazy-loading {
    pointer-events: none;
    opacity: 0.7;
}

form[data-lazy-submit].lazy-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* Button loading states */
button.btn-loading {
    position: relative;
    color: transparent !important;
}

button.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-right-color: transparent;
    animation: btn-spin 0.6s linear infinite;
}

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

/* ======================
   API LOADING STATES
   ====================== */
[data-lazy-api] {
    position: relative;
    min-height: 24px;
    transition: all 0.3s ease;
}

[data-lazy-api].lazy-loading {
    color: transparent;
}

[data-lazy-api].lazy-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid #dee2e6;
    border-top-color: #6c757d;
    border-radius: 50%;
    animation: api-spin 0.8s linear infinite;
}

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

/* Badge/counter loading */
.badge[data-lazy-api].lazy-loading {
    background: #e9ecef !important;
    color: transparent !important;
}

/* ======================
   PROGRESSIVE LOADING EFFECTS
   ====================== */
.lazy-loaded {
    animation: fade-in 0.5s ease-in-out;
}

.lazy-content {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease-out;
}

.lazy-content.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* ======================
   ERROR STATES
   ====================== */
.lazy-error {
    border: 1px dashed #dc3545;
    background: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border-radius: 6px;
    text-align: center;
    font-size: 0.875rem;
}

.lazy-error i {
    margin-right: 0.5rem;
    opacity: 0.7;
}

/* ======================
   RESPONSIVE DESIGN
   ====================== */
@media (max-width: 768px) {
    .skeleton-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .skeleton-cell {
        max-width: 100% !important;
    }
    
    .content-skeleton {
        padding: 0.75rem;
    }
    
    .skeleton-line {
        height: 14px;
        margin-bottom: 10px;
    }
}

@media (max-width: 576px) {
    .lazy-loading-spinner {
        padding: 6px;
    }
    
    img[data-lazy-src]:not([data-lazy-loaded]) {
        min-height: 120px;
    }
    
    .skeleton-line {
        height: 12px;
        margin-bottom: 8px;
    }
}

/* ======================
   ACCESSIBILITY
   ====================== */
@media (prefers-reduced-motion: reduce) {
    .skeleton-base,
    .skeleton-cell,
    .skeleton-line {
        animation: skeleton-pulse 2s infinite;
    }
    
    @keyframes skeleton-pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.6; }
    }
    
    img[data-lazy-src]:not([data-lazy-loaded]) {
        animation: skeleton-pulse 2s infinite;
    }
}

/* ======================
   THEME SUPPORT
   ====================== */
@media (prefers-color-scheme: dark) {
    .skeleton-base,
    .skeleton-cell,
    .skeleton-line {
        background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
    }
    
    img[data-lazy-src]:not([data-lazy-loaded]) {
        background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
        background-size: 200px 100%;
    }
    
    .content-skeleton {
        background: rgba(45, 55, 72, 0.3);
    }
    
    .skeleton-row {
        background: rgba(26, 32, 44, 0.3);
    }
}

/* ======================
   UTILITY CLASSES
   ====================== */
.lazy-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: inherit;
}

.lazy-loading-overlay .spinner-border {
    color: var(--primary-color, #007bff);
}

.lazy-shimmer {
    background: linear-gradient(-45deg, #eee 40%, #fafafa 50%, #eee 60%);
    background-size: 300% 300%;
    animation: lazy-shimmer-animation 1.5s ease-in-out infinite;
}

@keyframes lazy-shimmer-animation {
    0% { background-position: 0% 0%; }
    100% { background-position: 100% 100%; }
}

.lazy-fade-in {
    animation: fade-in 0.6s ease-out;
}

.lazy-slide-up {
    animation: slide-up 0.6s ease-out;
}

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