/* 
 * Otimizações de SEO e Performance
 * Lumicenter Lighting
 */

/* Critical CSS - Above the fold */
.main-header {
    contain: layout style;
    will-change: transform;
}

/* Lazy loading de imagens */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[data-src].loaded {
    opacity: 1;
}

/* Placeholder para imagens lazy */
.img-placeholder {
    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; }
}

/* Otimização de fontes */
@font-display: swap;

/* Preload de recursos críticos */
.preload-critical {
    font-display: swap;
}

/* Otimização de layout shift — sem contain:layout no card: cortava texto (descrição/estoque)
   quando combinado com proporções fixas em telas estreitas. */
.produto-card {
    aspect-ratio: auto;
    height: auto;
}

.produto-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

/* Breadcrumb otimizado para SEO */
.breadcrumb {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.breadcrumb a {
    color: #166e8c;
    text-decoration: none;
    transition: color 0.2s;
}

.breadcrumb a:hover {
    color: #145a70;
    text-decoration: underline;
}

.breadcrumb span {
    color: #333;
    font-weight: 500;
}

/* Structured data helpers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Schema markup helpers */
.product-schema {
    display: none;
}

/* Otimização de Core Web Vitals */
.hero-section {
    contain: layout style paint;
}

/* Lazy loading de seções */
.lazy-section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.lazy-section.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Otimização de imagens responsivas */
.responsive-img {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: cover;
}

/* WebP support */
.webp .jpg-fallback {
    display: none;
}

.no-webp .webp-image {
    display: none;
}

/* Otimização de carregamento de produtos */
.produtos-grid {
    contain: layout;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

/* Skeleton loading para produtos */
.produto-skeleton {
    background: #f6f7f8;
    background-image: linear-gradient(90deg, #f6f7f8 0px, #edeef1 40px, #f6f7f8 80px);
    background-size: 300px;
    animation: skeleton-loading 2s infinite linear;
    border-radius: 8px;
    height: 300px;
}

@keyframes skeleton-loading {
    0% { background-position: -300px 0; }
    100% { background-position: 300px 0; }
}

/* Mobile: grid mais denso; não fixar aspect-ratio no card (iPhone SE etc. sumia descrição/estoque). */
@media (max-width: 768px) {
    .produtos-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
}

/* Otimização de scroll */
.smooth-scroll {
    scroll-behavior: smooth;
}

/* Preload de imagens críticas */
.critical-image {
    loading: eager;
    fetchpriority: high;
}

/* Lazy loading de imagens não críticas */
.lazy-image {
    loading: lazy;
    fetchpriority: low;
}

/* Otimização de renderização */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* ================================
   Ajuste loja: 2 produtos por linha
   em telas abaixo de 545px de largura
================================ */
@media (max-width: 545px) {
    .loja .produtos-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Contenção de layout */
.contain-layout {
    contain: layout;
}

.contain-paint {
    contain: paint;
}

.contain-style {
    contain: style;
}

/* Otimização de texto */
.text-rendering-optimized {
    text-rendering: optimizeSpeed;
    font-smooth: antialiased;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Otimização de imagens de produto */
.produto-imagem {
    aspect-ratio: 1/1;
    object-fit: cover;
    background: #f8f9fa;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.produto-imagem:hover {
    transform: scale(1.05);
}
/* Otimização de carrossel */
/*
 * Hero (home): imagem inteira visível por padrão (evita corte no mobile).
 * Desktop (>=1000px) usa object-fit: cover em modules/responsive.css.
 */
 .carrossel__slide img {
    object-fit: cover;
    object-fit: contain;
    object-position: center;
    width: 100%;
    height: 100%;
    loading: eager;
    fetchpriority: high;
}

/* Otimização de modal */
.modal {
    contain: layout style;
    will-change: transform, opacity;
}

/* Otimização de filtros */
.filtros {
    contain: layout;
    position: sticky;
    top: 100px;
}

/* Otimização de paginação */
.paginacao {
    contain: layout;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin: 40px 0;
}

/* Otimização de busca */
.search-results {
    contain: layout;
    max-height: 400px;
    overflow-y: auto;
}

/* Otimização de dropdown */
.dropdown {
    contain: layout style;
    will-change: opacity, transform;
}

/* Otimização de tooltips */
.tooltip {
    contain: layout style;
    pointer-events: none;
}

/* Otimização de loading states */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #166e8c;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Otimização de acessibilidade */
.focus-visible {
    outline: 2px solid #166e8c;
    outline-offset: 2px;
}

/* Redução de movimento para usuários sensíveis */
@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;
    }
}

/* Modo escuro */
@media (prefers-color-scheme: dark) {
    .img-placeholder {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    }
    
    .produto-skeleton {
        background: #2a2a2a;
        background-image: linear-gradient(90deg, #2a2a2a 0px, #3a3a3a 40px, #2a2a2a 80px);
    }
}

/* Print styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-only {
        display: block !important;
    }
    
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a,
    a:visited {
        text-decoration: underline;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
}
