/* Lazy Loading and Performance Optimization CSS */

/* Lazy Loading Images */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.lazy-image.loaded {
    opacity: 1;
    background: none;
    animation: none;
}

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

/* Skeleton Loading for Cards */
.skeleton-card {
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.skeleton-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: skeleton-loading 1.5s infinite;
}

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

.skeleton-text {
    background: #e2e8f0;
    border-radius: 4px;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}

.skeleton-text::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-text.title {
    height: 20px;
    width: 80%;
}

.skeleton-text.subtitle {
    height: 16px;
    width: 60%;
}

.skeleton-text.line {
    height: 14px;
    width: 100%;
}

.skeleton-text.short {
    width: 40%;
}

/* Virtual Scrolling for Large Lists */
.virtual-scroll-container {
    height: 400px;
    overflow-y: auto;
    position: relative;
}

.virtual-scroll-content {
    position: relative;
}

.virtual-scroll-item {
    position: absolute;
    left: 0;
    right: 0;
    transition: transform 0.1s ease-out;
}

/* Infinite Scroll Loading */
.infinite-scroll-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.infinite-scroll-loading.active {
    opacity: 1;
}

.infinite-scroll-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e3e3e3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Performance Optimization Indicators */
.performance-badge {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-family: monospace;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.performance-badge.show {
    opacity: 1;
}

.performance-badge.good {
    background: rgba(40, 167, 69, 0.9);
}

.performance-badge.warning {
    background: rgba(255, 193, 7, 0.9);
    color: black;
}

.performance-badge.error {
    background: rgba(220, 53, 69, 0.9);
}

/* Optimized Table Loading */
.table-loading {
    position: relative;
    min-height: 200px;
}

.table-loading tbody tr {
    opacity: 0;
    animation: fadeInRow 0.3s ease-in-out forwards;
}

.table-loading tbody tr:nth-child(1) { animation-delay: 0.1s; }
.table-loading tbody tr:nth-child(2) { animation-delay: 0.2s; }
.table-loading tbody tr:nth-child(3) { animation-delay: 0.3s; }
.table-loading tbody tr:nth-child(4) { animation-delay: 0.4s; }
.table-loading tbody tr:nth-child(5) { animation-delay: 0.5s; }

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

/* Image Optimization */
.optimized-image {
    background-color: #f8f9fa;
    background-image: url("data:image/svg+xml,%3csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100' height='100' fill='%23f8f9fa'/%3e%3ctext x='50' y='50' font-size='12' text-anchor='middle' dy='.3em' fill='%236c757d'%3eLoading...%3c/text%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.optimized-image.loaded {
    background-image: none;
}

/* Progressive Enhancement */
.no-js .lazy-image {
    opacity: 1;
    animation: none;
}

.no-js .skeleton-card {
    display: none;
}

/* Memory Efficient Animations */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .skeleton-card::before,
    .skeleton-text::before,
    .infinite-scroll-spinner,
    .performance-badge,
    .table-loading tbody tr {
        animation: none !important;
        transition: none !important;
    }
}

/* Critical Resource Hints */
.critical-resource {
    /* Styles for critical above-the-fold content */
    contain: layout style paint;
    will-change: auto;
}

/* Non-critical content */
.non-critical {
    /* Content that can be loaded later */
    content-visibility: auto;
    contain-intrinsic-size: 0 200px;
}

/* Efficient Repaints */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Intersection Observer Loading States */
.intersection-loading {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border: 1px dashed #dee2e6;
    border-radius: 4px;
    color: #6c757d;
    font-size: 0.875rem;
}

.intersection-loaded {
    background: none;
    border: none;
}

/* Performance Monitoring Widget */
.perf-monitor {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.75rem;
    z-index: 9998;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.perf-monitor.visible {
    opacity: 1;
    transform: translateY(0);
}

.perf-monitor .metric {
    display: block;
    margin: 2px 0;
}

.perf-monitor .metric-value {
    color: #28a745;
    font-weight: bold;
}

.perf-monitor .metric-value.warning {
    color: #ffc107;
}

.perf-monitor .metric-value.error {
    color: #dc3545;
}

/* Responsive Image Containers */
.responsive-image-container {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
}

.responsive-image-container::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 aspect ratio */
}

.responsive-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease;
}

.responsive-image-container img.loading {
    opacity: 0;
}

.responsive-image-container img.loaded {
    opacity: 1;
}

/* Code Splitting Loading States */
.chunk-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
}

/* Efficient List Rendering */
.efficient-list {
    contain: layout;
    overflow-anchor: none; /* Prevent layout shifts */
}

.efficient-list-item {
    contain: layout style paint;
    transform: translateZ(0); /* GPU acceleration */
}

/* Memory Optimization */
.memory-efficient {
    contain: strict;
    content-visibility: auto;
    contain-intrinsic-size: auto 200px;
}

/* Network Optimization Indicators */
.network-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #007bff, #28a745);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
    z-index: 9999;
}

.network-status.loading {
    animation: networkProgress 1s linear infinite;
}

@keyframes networkProgress {
    0% { transform: scaleX(0); }
    50% { transform: scaleX(0.7); }
    100% { transform: scaleX(1); }
}