/* ============================================
   Performance & Optimization Enhancements
   Turismo MT - Layout Premium
   ============================================ */

/* ============================================
   Image Loading Optimization
   ============================================ */

/* Lazy loading support for images */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Aspect ratio boxes to prevent layout shift */
.img-container {
    position: relative;
    overflow: hidden;
}

.img-container::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 aspect ratio */
}

.img-container.square::before {
    padding-top: 100%; /* 1:1 aspect ratio */
}

.img-container.portrait::before {
    padding-top: 133.33%; /* 3:4 aspect ratio */
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Blur-up placeholder effect */
.img-placeholder {
    filter: blur(10px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.img-placeholder.loaded {
    filter: blur(0);
    transform: scale(1);
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* GPU acceleration for animations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize font rendering */
body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Cross-Browser Compatibility Fixes
   ============================================ */

/* Safari flexbox fix */
.safari-flex-fix {
    flex-shrink: 0;
}

/* IE11 grid fallback */
@supports not (display: grid) {
    .grid-2,
    .grid-3,
    .grid-4,
    .biomas-grid,
    .cidades-grid,
    .atrativos-grid {
        display: flex;
        flex-wrap: wrap;
        margin: -1rem;
    }
    
    .grid-2 > *,
    .grid-3 > *,
    .grid-4 > *,
    .biomas-grid > *,
    .cidades-grid > *,
    .atrativos-grid > * {
        flex: 1 1 300px;
        margin: 1rem;
    }
}

/* Firefox scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-green) var(--bg-dark);
}

/* Edge/IE backdrop-filter fallback */
@supports not (backdrop-filter: blur(10px)) {
    .glass-card,
    .navbar.scrolled,
    .filter-btn,
    .cidade-badge,
    .atrativo-badges > * {
        background: rgba(10, 26, 20, 0.95);
    }
}

/* ============================================
   Responsive Image Optimization
   ============================================ */

/* Responsive images with srcset support */
.responsive-img {
    width: 100%;
    height: auto;
    display: block;
}

/* Object-fit fallback for older browsers */
@supports not (object-fit: cover) {
    .card-image,
    .cidade-card-image,
    .atrativo-card-image {
        background-size: cover;
        background-position: center;
    }
    
    .card-image img,
    .cidade-card-image img,
    .atrativo-card-image img {
        opacity: 0;
    }
}

/* ============================================
   Print Optimization
   ============================================ */

@media print {
    /* Hide non-essential elements */
    .navbar,
    .footer,
    .btn,
    .filter-bar,
    .filter-container,
    .pagination,
    .newsletter-section {
        display: none !important;
    }
    
    /* Optimize for print */
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }
    
    h1 { font-size: 24pt; }
    h2 { font-size: 20pt; }
    h3 { font-size: 16pt; }
    
    /* Prevent page breaks inside elements */
    .bioma-card,
    .cidade-card,
    .atrativo-card,
    .card {
        page-break-inside: avoid;
    }
    
    /* Show URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
    
    /* Remove shadows and transitions */
    * {
        box-shadow: none !important;
        text-shadow: none !important;
        transition: none !important;
    }
}

/* ============================================
   Accessibility Enhancements
   ============================================ */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 3px solid var(--primary-green);
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-green);
    color: var(--text-dark);
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    font-weight: 600;
}

.skip-to-main:focus {
    top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --text-light: #FFFFFF;
        --text-muted: #CCCCCC;
        --bg-dark: #000000;
        --border-glow: #FFFFFF;
    }
    
    .btn-primary,
    .btn-outline {
        border-width: 3px;
    }
}

/* ============================================
   Loading States
   ============================================ */

/* Skeleton loading animation */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-card) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        var(--bg-card) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Loading spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--glass-white);
    border-top-color: var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Mobile Optimizations
   ============================================ */

@media (max-width: 768px) {
    /* Reduce animations on mobile for performance */
    .fade-in,
    .slide-in-left,
    .slide-in-right,
    .scale-in {
        animation: none;
        opacity: 1;
        transform: none;
    }
    
    /* Optimize touch targets */
    .btn,
    .nav-link,
    .filter-btn,
    a {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Reduce image quality on mobile */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ============================================
   Dark Mode Support (Future Enhancement)
   ============================================ */

@media (prefers-color-scheme: light) {
    /* Light mode overrides if needed */
    /* Currently the design is dark by default */
}

/* ============================================
   Connection Speed Optimizations
   ============================================ */

/* Reduce animations on slow connections */
@media (prefers-reduced-data: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    
    /* Don't load background images */
    .hero-bg,
    .parallax {
        display: none;
    }
}

/* ============================================
   Browser-Specific Fixes
   ============================================ */

/* Chrome/Safari smooth scrolling */
@supports (scroll-behavior: smooth) {
    html {
        scroll-behavior: smooth;
    }
}

/* Firefox button fix */
@-moz-document url-prefix() {
    .btn {
        padding: 15px 35px;
    }
}

/* Safari date input fix */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

/* ============================================
   Performance Monitoring Helpers
   ============================================ */

/* Mark elements for performance monitoring */
[data-performance-mark] {
    /* Used by JavaScript performance API */
}

/* ============================================
   Utility Classes for Optimization
   ============================================ */

.no-transition {
    transition: none !important;
}

.force-gpu {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.contain-paint {
    contain: paint;
}

.contain-layout {
    contain: layout;
}

.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Remove will-change after animation */
.animation-complete {
    will-change: auto;
}
