/* MDRN Performance-Optimized Styles */
/* Skeleton loading, animations, and performance enhancements */

/* Skeleton Loading States */
.skeleton-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    animation: skeleton-pulse 1.5s ease-in-out infinite alternate;
    pointer-events: none;
}

.skeleton-image {
    width: 100%;
    height: 300px;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-subtle) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    border-radius: 8px;
    margin-bottom: 16px;
    animation: skeleton-shimmer 2s infinite;
}

.skeleton-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.skeleton-title {
    height: 24px;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-subtle) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    width: 80%;
    animation: skeleton-shimmer 2s infinite;
}

.skeleton-genre {
    height: 18px;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-subtle) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    width: 50%;
    animation: skeleton-shimmer 2s infinite;
}

.skeleton-description {
    height: 16px;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-subtle) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    width: 100%;
    animation: skeleton-shimmer 2s infinite;
}

.skeleton-description.short {
    width: 75%;
}

@keyframes skeleton-pulse {
    0% { opacity: 1; }
    100% { opacity: 0.7; }
}

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

/* Lazy Loading Image States */
img.lazy-load {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    opacity: 1;
}

img.lazy-load.skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-subtle) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 2s infinite;
    min-height: 300px;
}

img.lazy-load[data-src] {
    opacity: 0;
    transform: scale(0.95);
}

img.lazy-load.loaded {
    opacity: 1;
    transform: scale(1);
}

/* Smooth Animations */
.fade-in-up {
    opacity: 0;
    transform: translateY(30px);
    animation: fadeInUp 0.6s ease-out forwards;
}

.animate-in {
    animation: slideInView 0.5s ease-out;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInView {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Performance-Optimized Book Cards */
.book-card {
    position: relative;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform;
    contain: layout style paint;
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Optimized Image Container */
.book-image-container {
    position: relative;
    width: 100%;
    height: 300px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transform-origin: center;
    will-change: transform, opacity;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.book-card:hover .image-overlay {
    opacity: 1;
}

/* Optimized Action Buttons */
.book-actions {
    display: flex;
    gap: 12px;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.book-card:hover .book-actions {
    transform: translateY(0);
}

.action-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn.primary {
    background: var(--accent-primary);
    color: white;
}

.action-btn.primary:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.action-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* Optimized Text Rendering */
.book-info {
    padding: 20px;
}

.book-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px 0;
    line-height: 1.3;
    /* Optimize text rendering */
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.book-genre {
    font-size: 14px;
    color: var(--accent-primary);
    margin: 0 0 12px 0;
    font-weight: 500;
}

.book-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 16px 0;
    /* Clamp to 3 lines for consistent card heights */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.book-id {
    color: var(--text-secondary);
}

.book-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.book-status.available {
    background: rgba(16, 185, 129, 0.2);
    color: #10B981;
}

.book-status.unavailable {
    background: rgba(239, 68, 68, 0.2);
    color: #EF4444;
}

/* Loading States */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 1s linear infinite;
}

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

/* Performance Optimizations */
* {
    /* Enable hardware acceleration for transforms */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Optimize scrolling performance */
.books-grid {
    /* Enable GPU compositing */
    will-change: scroll-position;
    /* Contain paint operations */
    contain: layout style paint;
}

/* Reduce paint operations on hover */
.book-card,
.action-btn,
.chip {
    contain: layout paint;
}

/* Optimize filter operations */
.chip {
    transition: background-color 0.2s ease, transform 0.2s ease;
    will-change: background-color, transform;
}

/* Critical CSS for above-the-fold content */
.ecosystem-section,
.controls {
    contain: layout style;
}

/* Mobile Performance Optimizations */
@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    .book-card {
        transition: transform 0.15s ease;
    }
    
    .fade-in-up {
        animation-duration: 0.4s;
    }
    
    /* Simplify hover states on touch devices */
    @media (hover: none) {
        .book-card:hover {
            transform: none;
            box-shadow: none;
        }
        
        .image-overlay {
            opacity: 1;
            background: rgba(0, 0, 0, 0.4);
        }
        
        .book-actions {
            transform: none;
        }
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .skeleton-shimmer,
    .skeleton-pulse {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .skeleton-card,
    .skeleton-image,
    .skeleton-title,
    .skeleton-genre,
    .skeleton-description {
        border: 1px solid currentColor;
    }
}

/* Print optimizations */
@media print {
    .book-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .image-overlay,
    .book-actions {
        display: none;
    }
}