/**
 * Performance Optimizations CSS - IMÓVEL.CHAT
 * 
 * Otimizações:
 * - Critical CSS inline
 * - Lazy loading styles
 * - Animações otimizadas
 * - Responsive images
 * - Print styles
 */

/* ===== CRITICAL CSS (Above the fold) ===== */

/* Reset básico para elementos críticos */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: #1f2937;
    background-color: #ffffff;
}

/* ===== LAZY LOADING STYLES ===== */

/* Placeholder para imagens lazy */
img[data-src] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    min-height: 200px;
    display: block;
}

img.lazy {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img.loaded {
    opacity: 1;
}

img.error {
    background: #f3f4f6;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

img.error::after {
    content: "Imagem não disponível";
}

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

/* ===== RESPONSIVE IMAGES ===== */

/* Container responsivo para imagens */
.responsive-image {
    position: relative;
    overflow: hidden;
    background: #f3f4f6;
}

.responsive-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

/* Aspect ratios comuns */
.aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-1-1 {
    aspect-ratio: 1 / 1;
}

.aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* Fallback para navegadores sem suporte a aspect-ratio */
@supports not (aspect-ratio: 1 / 1) {
    .aspect-16-9::before {
        content: "";
        display: block;
        padding-top: 56.25%; /* 9/16 * 100% */
    }
    
    .aspect-4-3::before {
        content: "";
        display: block;
        padding-top: 75%; /* 3/4 * 100% */
    }
    
    .aspect-1-1::before {
        content: "";
        display: block;
        padding-top: 100%;
    }
    
    .aspect-3-2::before {
        content: "";
        display: block;
        padding-top: 66.67%; /* 2/3 * 100% */
    }
    
    .aspect-16-9 img,
    .aspect-4-3 img,
    .aspect-1-1 img,
    .aspect-3-2 img {
        position: absolute;
        top: 0;
        left: 0;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Otimização de scroll */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Otimização de animações */
.animate-optimized {
    will-change: transform, opacity;
    transform: translateZ(0); /* Force hardware acceleration */
}

/* Contenção de layout */
.contain-layout {
    contain: layout;
}

.contain-paint {
    contain: paint;
}

.contain-size {
    contain: size;
}

.contain-style {
    contain: style;
}

/* ===== ANIMAÇÕES OTIMIZADAS ===== */

/* Animações que usam apenas transform e opacity */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Classes de animação */
.animate-fade-in {
    animation: fadeIn 0.6s ease-out;
}

.animate-slide-in-left {
    animation: slideInLeft 0.6s ease-out;
}

.animate-slide-in-right {
    animation: slideInRight 0.6s ease-out;
}

.animate-scale-in {
    animation: scaleIn 0.4s ease-out;
}

/* Animações com delay */
.animate-delay-100 {
    animation-delay: 0.1s;
}

.animate-delay-200 {
    animation-delay: 0.2s;
}

.animate-delay-300 {
    animation-delay: 0.3s;
}

.animate-delay-500 {
    animation-delay: 0.5s;
}

/* ===== INTERSECTION OBSERVER ANIMATIONS ===== */

/* Estados iniciais para elementos que serão animados */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.animate-on-scroll.animate-in {
    opacity: 1;
    transform: translateY(0);
}

/* Variações de animação */
.animate-on-scroll.slide-left {
    transform: translateX(-30px);
}

.animate-on-scroll.slide-left.animate-in {
    transform: translateX(0);
}

.animate-on-scroll.slide-right {
    transform: translateX(30px);
}

.animate-on-scroll.slide-right.animate-in {
    transform: translateX(0);
}

.animate-on-scroll.scale {
    transform: scale(0.9);
}

.animate-on-scroll.scale.animate-in {
    transform: scale(1);
}

/* ===== LOADING STATES ===== */

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

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    margin-bottom: 0;
    width: 60%;
}

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

.skeleton-button {
    height: 40px;
    width: 120px;
    border-radius: 6px;
}

/* Loading spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== CRITICAL RESOURCE HINTS ===== */

/* Preload de fontes críticas */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/fonts/inter-regular.woff2') format('woff2'),
         url('/assets/fonts/inter-regular.woff') format('woff');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/assets/fonts/inter-semibold.woff2') format('woff2'),
         url('/assets/fonts/inter-semibold.woff') format('woff');
}

/* ===== PROGRESSIVE ENHANCEMENT ===== */

/* Estilos base sem JavaScript */
.no-js .js-only {
    display: none !important;
}

.no-js .no-js-fallback {
    display: block !important;
}

/* Estilos quando JavaScript está disponível */
.js .js-only {
    display: block;
}

.js .no-js-fallback {
    display: none;
}

/* ===== REDUCED MOTION ===== */

/* Respeita preferência de movimento reduzido */
@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;
    }
    
    .animate-on-scroll {
        opacity: 1;
        transform: none;
    }
}

/* Classe para forçar movimento reduzido */
.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ===== HIGH CONTRAST MODE ===== */

@media (prefers-contrast: high) {
    :root {
        --text-color: #000000;
        --bg-color: #ffffff;
        --border-color: #000000;
        --link-color: #0000ff;
        --button-bg: #000000;
        --button-text: #ffffff;
    }
}

/* Classe para forçar alto contraste */
.high-contrast {
    --text-color: #000000;
    --bg-color: #ffffff;
    --border-color: #000000;
    --link-color: #0000ff;
    --button-bg: #000000;
    --button-text: #ffffff;
}

.high-contrast * {
    color: var(--text-color) !important;
    background-color: var(--bg-color) !important;
    border-color: var(--border-color) !important;
}

.high-contrast a {
    color: var(--link-color) !important;
}

.high-contrast button,
.high-contrast .btn {
    background-color: var(--button-bg) !important;
    color: var(--button-text) !important;
    border: 2px solid var(--border-color) !important;
}

/* ===== PRINT STYLES ===== */

@media print {
    /* Remove elementos desnecessários na impressão */
    .no-print,
    nav,
    .navigation,
    .sidebar,
    .ads,
    .social-share,
    .comments,
    .back-to-top,
    .accessibility-panel {
        display: none !important;
    }
    
    /* Otimiza texto para impressão */
    body {
        font-size: 12pt;
        line-height: 1.4;
        color: #000;
        background: #fff;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        color: #000;
    }
    
    p, li {
        orphans: 3;
        widows: 3;
    }
    
    /* Mostra URLs dos links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Remove URLs de links internos */
    a[href^="/"]:after,
    a[href^="#"]:after {
        content: "";
    }
    
    /* Otimiza imagens para impressão */
    img {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
    }
    
    /* Força quebras de página */
    .page-break {
        page-break-before: always;
    }
    
    .page-break-avoid {
        page-break-inside: avoid;
    }
}

/* ===== UTILITY CLASSES ===== */

/* Screen reader only */
.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;
}

/* Skip to content */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
    transition: top 0.3s;
}

.skip-to-content:focus {
    top: 6px;
}

/* Performance monitoring */
.perf-mark {
    display: none;
}

/* Critical loading indicator */
.critical-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #3b82f6, #2563eb);
    background-size: 200% 100%;
    animation: loading-bar 2s infinite;
    z-index: 10000;
}

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

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Mobile first approach */
@media (min-width: 640px) {
    .sm\:animate-slide-in-left {
        animation: slideInLeft 0.6s ease-out;
    }
}

@media (min-width: 768px) {
    .md\:animate-fade-in {
        animation: fadeIn 0.6s ease-out;
    }
}

@media (min-width: 1024px) {
    .lg\:animate-scale-in {
        animation: scaleIn 0.4s ease-out;
    }
}

@media (min-width: 1280px) {
    .xl\:animate-slide-in-right {
        animation: slideInRight 0.6s ease-out;
    }
}

