/* Performance Optimizations */

/* Critical CSS for above-the-fold content */
.critical-content {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* Lazy loading for images */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.lazy-image.loaded {
    opacity: 1;
}

/* CLS Fixes - Prevent Layout Shifts */
.layout-stable {
    contain: layout;
}

/* Document viewer specific fixes */
.word-document {
    min-height: 70vh !important;
    contain: layout !important;
}

.word-content {
    min-height: 60vh !important;
    contain: layout !important;
}

/* Info sections with fixed heights */
.info-item {
    min-height: 60px !important;
    contain: layout !important;
}

/* Prevent text wrapping shifts */
.text-no-wrap {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fixed aspect ratios for images */
.aspect-ratio-container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.aspect-ratio-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Optimize animations */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Optimize scrolling */
.smooth-scroll {
    scroll-behavior: smooth;
}

/* Optimize images */
img {
    max-width: 100%;
    height: auto;
}

/* Optimize transitions */
.optimized-transition {
    will-change: transform, opacity;
}

/* Reduce layout shifts */
.layout-stable {
    contain: layout;
}

/* Optimize fonts */
.font-display-swap {
    font-display: swap;
}

/* Optimize shadows */
.optimized-shadow {
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

/* Optimize backdrop filters */
.optimized-backdrop {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Optimize gradients */
.optimized-gradient {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

/* Optimize borders */
.optimized-border {
    border: 1px solid rgba(148, 163, 184, 0.2);
}

/* Optimize text rendering */
.optimized-text {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Optimize focus states */
.optimized-focus:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Optimize hover states */
.optimized-hover:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease-in-out;
}

/* Optimize loading states */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Optimize modal performance */
.modal-optimized {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-optimized.show {
    opacity: 1;
    visibility: visible;
}

/* Optimize button interactions */
.button-optimized {
    position: relative;
    overflow: hidden;
}

.button-optimized::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.button-optimized:active::before {
    width: 300px;
    height: 300px;
}

/* Optimize form inputs */
.input-optimized {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-optimized:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Optimize card interactions */
.card-optimized {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform, box-shadow;
}

.card-optimized:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* Optimize navigation */
.nav-optimized {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.9);
}

/* Optimize content loading */
.content-optimized {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Optimize responsive images */
.responsive-image {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* Optimize grid layouts */
.grid-optimized {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* Optimize flexbox layouts */
.flex-optimized {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Optimize text overflow */
.text-optimized {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Optimize multi-line text */
.text-multiline-optimized {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Optimize scrollbars */
.scrollbar-optimized {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.scrollbar-optimized::-webkit-scrollbar {
    width: 6px;
}

.scrollbar-optimized::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.scrollbar-optimized::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.scrollbar-optimized::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Specific fixes for docx viewer */
#preview {
    contain: layout !important;
}

#info, #book, #recommendations {
    contain: layout !important;
}

/* Prevent layout shifts in document content */
.word-content p {
    margin-bottom: 16px;
    min-height: 1.2em;
}

.word-content h1, .word-content h2, .word-content h3 {
    margin: 24px 0 16px 0;
    min-height: 1.2em;
}

/* Fixed height containers */
.fixed-height-container {
    height: 60vh;
    overflow-y: auto;
    contain: layout;
}

/* Prevent image layout shifts */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Optimize SVG icons */
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Prevent text layout shifts */
p, h1, h2, h3, h4, h5, h6 {
    margin: 0;
    padding: 0;
    line-height: 1.5;
}

/* Container queries for better layout stability */
@container (min-width: 768px) {
    .responsive-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Optimize for print */
@media print {
    .word-document {
        background: white !important;
        padding: 0 !important;
        min-height: auto !important;
    }
    
    .word-content {
        box-shadow: none !important;
        border-radius: 0 !important;
        min-height: auto !important;
    }
} 