/*
===========================================
KINTA PERFORMANCE & RESPONSIVIDADE
===========================================
Otimizações de performance, responsividade
e carregamento para o marketplace Kinta
===========================================
*/

/* ===== OTIMIZAÇÕES DE PERFORMANCE ===== */

/* === CRITICAL CSS - ABOVE THE FOLD === */
.critical-content {
    /* Conteúdo crítico que deve carregar primeiro */
    contain: layout style paint;
    will-change: auto;
}

/* === LAZY LOADING PARA IMAGENS === */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    background: var(--kinta-gray-100);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lazy-image.loaded {
    opacity: 1;
}

.lazy-image::before {
    content: '📷';
    font-size: 2rem;
    color: var(--kinta-gray-400);
}

.lazy-image.loaded::before {
    display: none;
}

/* === OTIMIZAÇÃO DE FONTES === */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap; /* Melhora performance de carregamento */
    src: url('fonts/inter-regular.woff2') format('woff2'),
         url('fonts/inter-regular.woff') format('woff');
}

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

/* === REDUÇÃO DE REPAINTS E REFLOWS === */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* === OTIMIZAÇÃO DE ANIMAÇÕES === */
@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;
    }
}

/* ===== RESPONSIVIDADE AVANÇADA ===== */

/* === BREAKPOINTS CUSTOMIZADOS === */
:root {
    --bp-xs: 320px;
    --bp-sm: 640px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --bp-xl: 1280px;
    --bp-2xl: 1536px;
}

/* === CONTAINER RESPONSIVO === */
.container-responsive {
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--space-4);
}

@media (min-width: 640px) {
    .container-responsive {
        max-width: 640px;
        padding: 0 var(--space-6);
    }
}

@media (min-width: 768px) {
    .container-responsive {
        max-width: 768px;
        padding: 0 var(--space-8);
    }
}

@media (min-width: 1024px) {
    .container-responsive {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container-responsive {
        max-width: 1200px;
    }
}

/* === GRID RESPONSIVO AVANÇADO === */
.responsive-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .responsive-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-6);
    }
}

@media (min-width: 1024px) {
    .responsive-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-8);
    }
}

@media (min-width: 1280px) {
    .responsive-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* === TIPOGRAFIA RESPONSIVA === */
.responsive-text {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    line-height: 1.5;
}

.responsive-heading {
    font-size: clamp(1.5rem, 4vw, 3rem);
    line-height: 1.2;
}

.responsive-subheading {
    font-size: clamp(1.125rem, 3vw, 2rem);
    line-height: 1.3;
}

/* === ESPAÇAMENTOS RESPONSIVOS === */
.responsive-padding {
    padding: clamp(1rem, 4vw, 3rem);
}

.responsive-margin {
    margin: clamp(1rem, 4vw, 3rem) 0;
}

/* ===== OTIMIZAÇÕES ESPECÍFICAS MOBILE ===== */

/* === TOUCH TARGETS === */
@media (max-width: 768px) {
    .btn,
    .form-input,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Aumentar área de toque para links */
    a {
        padding: var(--space-2);
        margin: calc(var(--space-2) * -1);
    }
    
    /* Melhorar usabilidade de formulários */
    .form-input {
        font-size: 16px; /* Evita zoom no iOS */
        padding: var(--space-4);
    }
    
    /* Otimizar cards para mobile */
    .product-card,
    .testimonial-card,
    .plan-card {
        margin-bottom: var(--space-6);
    }
    
    /* Melhorar navegação mobile */
    .mobile-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid var(--kinta-gray-200);
        padding: var(--space-3);
        z-index: var(--z-fixed);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    }
    
    .mobile-nav__items {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    .mobile-nav__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-1);
        padding: var(--space-2);
        border-radius: var(--radius-md);
        transition: var(--transition-fast);
        min-width: 60px;
        text-decoration: none;
        color: var(--kinta-gray-600);
    }
    
    .mobile-nav__item:hover,
    .mobile-nav__item.active {
        background: var(--kinta-green-50);
        color: var(--kinta-green-600);
    }
    
    .mobile-nav__icon {
        font-size: 1.25rem;
    }
    
    .mobile-nav__label {
        font-size: var(--text-xs);
        font-weight: var(--font-medium);
    }
}

/* === OTIMIZAÇÕES TABLET === */
@media (min-width: 769px) and (max-width: 1024px) {
    .tablet-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .tablet-hidden {
        display: none;
    }
    
    .tablet-full-width {
        width: 100%;
    }
}

/* ===== OTIMIZAÇÕES DE IMAGEM ===== */

/* === IMAGENS RESPONSIVAS === */
.responsive-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: var(--radius-lg);
}

/* === PLACEHOLDER PARA IMAGENS === */
.image-placeholder {
    background: linear-gradient(45deg, var(--kinta-gray-100), var(--kinta-gray-200));
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kinta-gray-500);
    font-size: var(--text-sm);
    min-height: 200px;
    border-radius: var(--radius-lg);
}

/* === OTIMIZAÇÃO WEBP === */
.webp-image {
    background-image: url('image.webp');
    background-size: cover;
    background-position: center;
}

.no-webp .webp-image {
    background-image: url('image.jpg');
}

/* ===== OTIMIZAÇÕES DE CARREGAMENTO ===== */

/* === SKELETON LOADING === */
.skeleton-loader {
    background: linear-gradient(
        90deg,
        var(--kinta-gray-200) 25%,
        var(--kinta-gray-100) 50%,
        var(--kinta-gray-200) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

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

.skeleton-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-md);
}

.skeleton-image {
    height: 200px;
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
}

.skeleton-title {
    height: 24px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-3);
    width: 80%;
}

.skeleton-text {
    height: 16px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-2);
}

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

/* === PROGRESSIVE ENHANCEMENT === */
.js-enabled .enhanced-feature {
    display: block;
}

.no-js .enhanced-feature {
    display: none;
}

.no-js .fallback-content {
    display: block;
}

.js-enabled .fallback-content {
    display: none;
}

/* ===== OTIMIZAÇÕES DE SCROLL ===== */

/* === SCROLL SUAVE === */
.smooth-scroll-container {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* === SCROLL SNAP === */
.scroll-snap-container {
    scroll-snap-type: x mandatory;
    overflow-x: auto;
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4);
}

.scroll-snap-item {
    scroll-snap-align: start;
    flex: 0 0 auto;
    width: 300px;
}

/* === SCROLL INDICATOR === */
.scroll-indicator {
    position: fixed;
    top: 0;
    left: 0;
    height: 4px;
    background: var(--kinta-green-500);
    z-index: var(--z-fixed);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.1s ease-out;
}

/* ===== OTIMIZAÇÕES DE FORMULÁRIO ===== */

/* === VALIDAÇÃO VISUAL === */
.form-input:valid {
    border-color: var(--kinta-success);
}

.form-input:invalid:not(:placeholder-shown) {
    border-color: var(--kinta-error);
}

.form-input:focus:valid {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-input:focus:invalid {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* === AUTOCOMPLETE STYLING === */
.form-input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--kinta-green-50) inset;
    -webkit-text-fill-color: var(--kinta-gray-900);
}

/* ===== PRINT STYLES ===== */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-only {
        display: block !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
    
    .btn {
        border: 1px solid black;
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    .card {
        border: 1px solid #ccc;
        box-shadow: none !important;
        break-inside: avoid;
    }
    
    h1, h2, h3 {
        break-after: avoid;
    }
    
    img {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --kinta-gray-50: #1f2937;
        --kinta-gray-100: #374151;
        --kinta-gray-200: #4b5563;
        --kinta-gray-300: #6b7280;
        --kinta-gray-400: #9ca3af;
        --kinta-gray-500: #d1d5db;
        --kinta-gray-600: #e5e7eb;
        --kinta-gray-700: #f3f4f6;
        --kinta-gray-800: #f9fafb;
        --kinta-gray-900: #ffffff;
    }
    
    .dark-mode-image {
        filter: brightness(0.8) contrast(1.2);
    }
}

/* ===== UTILITÁRIOS DE PERFORMANCE ===== */

/* === CONTENÇÃO DE LAYOUT === */
.contain-layout {
    contain: layout;
}

.contain-style {
    contain: style;
}

.contain-paint {
    contain: paint;
}

.contain-strict {
    contain: strict;
}

/* === WILL-CHANGE OTIMIZADO === */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

.will-change-scroll {
    will-change: scroll-position;
}

/* === CONTENT-VISIBILITY === */
.content-auto {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* ===== DEBUGGING E DESENVOLVIMENTO ===== */
@media (max-width: 768px) {
    .debug-mobile::before {
        content: 'MOBILE';
        position: fixed;
        top: 0;
        right: 0;
        background: red;
        color: white;
        padding: 4px 8px;
        font-size: 12px;
        z-index: 9999;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .debug-tablet::before {
        content: 'TABLET';
        position: fixed;
        top: 0;
        right: 0;
        background: orange;
        color: white;
        padding: 4px 8px;
        font-size: 12px;
        z-index: 9999;
    }
}

@media (min-width: 1025px) {
    .debug-desktop::before {
        content: 'DESKTOP';
        position: fixed;
        top: 0;
        right: 0;
        background: green;
        color: white;
        padding: 4px 8px;
        font-size: 12px;
        z-index: 9999;
    }
}

