/* Performance-Focused Layout Optimizations */

/* Skeleton Screens for Loading States */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

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

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.title {
    height: 24px;
    width: 70%;
}

.skeleton-text.subtitle {
    height: 18px;
    width: 90%;
}

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

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

.skeleton-card {
    padding: 20px;
    border-radius: 12px;
    background: var(--card-background, #ffffff);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.skeleton-qr {
    width: 200px;
    height: 200px;
    border-radius: 8px;
    margin: 0 auto 20px;
}

.skeleton-button {
    height: 40px;
    width: 120px;
    border-radius: 6px;
    display: inline-block;
    margin-right: 10px;
}

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

/* Progressive Image Loading */
.progressive-image {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
    border-radius: 8px;
}

.progressive-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease;
    opacity: 0;
}

.progressive-image img.loaded {
    opacity: 1;
}

.progressive-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.progressive-image.loaded::before {
    display: none;
}

/* Lazy Loading Optimization */
.lazy-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.lazy-placeholder {
    text-align: center;
    color: #666;
    font-size: 14px;
}

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

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

/* Intersection Observer Optimizations */
.observe-element {
    transition: all 0.3s ease;
}

.observe-element.in-view {
    animation: slideInUp 0.5s ease-out;
}

/* Chunked Data Loading */
.chunk-container {
    min-height: 100px;
}

.chunk-loader {
    text-align: center;
    padding: 40px 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chunk-loader.visible {
    opacity: 1;
}

.chunk-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

/* Optimized Asset Delivery */
.critical-resource {
    font-display: swap; /* For fonts */
}

.preload-hint::after {
    content: '';
    position: absolute;
    width: 1px;
    height: 1px;
    background: url('../images/next-likely-image.jpg') no-repeat;
    background-size: 1px 1px;
    opacity: 0;
    pointer-events: none;
}

/* Cached Interface States */
.cached-state {
    transition: all 0.2s ease;
}

.cached-state.restoring {
    opacity: 0.7;
    pointer-events: none;
}

.cached-state.restored {
    opacity: 1;
    pointer-events: auto;
}

/* Background Processing Indicators */
.background-process {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--primary-color, #007bff);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    z-index: 1000;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
}

.background-process.active {
    transform: translateX(0);
    opacity: 1;
}

.background-process .process-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 8px;
    vertical-align: middle;
}

/* Quick Action Shortcuts */
.quick-actions {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 100;
}

.quick-action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color, #007bff);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 123, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    transform: scale(0);
}

.quick-action-btn.visible {
    transform: scale(1);
}

.quick-action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}

.quick-actions-menu {
    position: absolute;
    right: 0;
    bottom: 70px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.quick-actions-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.quick-action-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.quick-action-item:hover {
    background: #f8f9fa;
}

/* Minimal Render Blocking */
.render-optimized {
    contain: layout style;
    will-change: transform;
}

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

/* Critical CSS Above Fold */
.above-fold {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Predictive Loading States */
.predictive-container {
    position: relative;
}

.predictive-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10;
}

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

.predictive-message {
    background: white;
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 14px;
    color: #666;
}

/* Performance Metrics Display */
.perf-metrics {
    position: fixed;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.perf-metrics.visible {
    opacity: 1;
}

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

.perf-good { color: #4caf50; }
.perf-warning { color: #ff9800; }
.perf-poor { color: #f44336; }

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

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

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

/* Resource Hints */
.preload-critical {
    /* Critical resources should be preloaded */
}

.prefetch-likely {
    /* Likely next resources should be prefetched */
}

/* Responsive Performance Optimizations */
@media (max-width: 768px) {
    .skeleton-card {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .quick-actions {
        bottom: 20px;
        right: 20px;
    }
    
    .quick-action-btn {
        width: 48px;
        height: 48px;
    }
    
    .background-process {
        top: 10px;
        right: 10px;
        padding: 8px 16px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .skeleton-qr {
        width: 150px;
        height: 150px;
    }
    
    .quick-actions-menu {
        right: -10px;
        min-width: 180px;
    }
}

/* Dark Theme Optimizations */
@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
        background-size: 200% 100%;
    }
    
    .lazy-container {
        background: #2d3748;
    }
    
    .background-process {
        background: #2d3748;
        box-shadow: 0 4px 12px rgba(45, 55, 72, 0.3);
    }
    
    .quick-actions-menu {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .quick-action-item:hover {
        background: #4a5568;
    }
    
    .predictive-message {
        background: #2d3748;
        color: #e2e8f0;
    }
}

/* Print Optimizations */
@media print {
    .skeleton,
    .background-process,
    .quick-actions,
    .perf-metrics {
        display: none !important;
    }
}