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

/* ===== OTIMIZAÇÕES DE RENDERIZAÇÃO ===== */

/* Aceleração por GPU para elementos que serão animados */
.gpu-layer {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Otimização de will-change para elementos específicos */
.btn,
.card,
.modal,
.tooltip::before,
.tooltip::after {
  will-change: transform;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  will-change: transform, box-shadow;
}

/* Remover will-change após animações */
.animation-complete {
  will-change: auto;
}

/* ===== FALLBACKS PARA NAVEGADORES ANTIGOS ===== */

/* Fallback para CSS Grid (IE 11) */
@supports not (display: grid) {
  .grid {
    display: flex;
    flex-wrap: wrap;
  }
  
  .grid > * {
    flex: 1 1 280px;
    margin: 0.5rem;
  }
  
  .grid-cols-1 > * { flex-basis: 100%; }
  .grid-cols-2 > * { flex-basis: calc(50% - 1rem); }
  .grid-cols-3 > * { flex-basis: calc(33.333% - 1rem); }
  .grid-cols-4 > * { flex-basis: calc(25% - 1rem); }
  .grid-cols-6 > * { flex-basis: calc(16.666% - 1rem); }
}

/* Fallback para CSS Custom Properties (IE 11) */
@supports not (color: var(--brand-primary)) {
  :root {
    /* Valores fixos para IE 11 */
  }
  
  .btn-primary {
    background: #062e6f;
    color: #ffffff;
  }
  
  .btn-ghost {
    background: rgba(255, 255, 255, 0.8);
    color: #062e6f;
    border: 1px solid #e2e8f0;
  }
  
  .form-input,
  .form-select,
  .form-textarea {
    border: 2px solid #e2e8f0;
    background: #ffffff;
    color: #0f172a;
  }
  
  .form-input:focus,
  .form-select:focus,
  .form-textarea:focus {
    border-color: #0ea5e9;
  }
  
  .card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
  }
  
  .app-header {
    background: rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid #e2e8f0;
    max-width: 1200px;
    margin: 0 auto;
    border-radius: 1rem;
  }
}

/* Fallback para backdrop-filter */
@supports not (backdrop-filter: blur(10px)) {
  .app-header {
    background: rgba(255, 255, 255, 0.95);
  }
  
  .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
  }
  
  .card-glass {
    background: rgba(255, 255, 255, 0.9);
  }
}

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

/* Preload de fontes críticas */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfAZ9hiA.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuGKYAZ9hiA.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Fallback de fontes do sistema */
.font-system {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

/* Lazy loading nativo */
img {
  loading: lazy;
  decoding: async;
}

/* Imagens críticas (logos, etc.) */
.critical-image {
  loading: eager;
}

/* Otimização de aspect ratio */
.aspect-ratio {
  position: relative;
  width: 100%;
  height: 0;
}

.aspect-ratio::before {
  content: '';
  display: block;
  padding-bottom: var(--aspect-ratio, 100%);
}

.aspect-ratio > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

/* Smooth scrolling otimizado */
@supports (scroll-behavior: smooth) {
  html {
    scroll-behavior: smooth;
  }
}

/* Scroll snap para carrosséis */
.scroll-snap-x {
  scroll-snap-type: x mandatory;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.scroll-snap-x > * {
  scroll-snap-align: start;
}

/* Otimização de scrollbar */
.custom-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: var(--neutral-300, #cbd5e1) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: var(--neutral-300, #cbd5e1);
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-400, #94a3b8);
}

/* ===== OTIMIZAÇÕES DE ANIMAÇÃO ===== */

/* Reduzir animações em dispositivos com pouca bateria */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Pausar animações quando a aba não está ativa */
@media (prefers-reduced-motion: no-preference) {
  .pause-when-hidden {
    animation-play-state: running;
  }
}

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

/* Contain para otimizar repaint */
.contain-layout {
  contain: layout;
}

.contain-paint {
  contain: paint;
}

.contain-size {
  contain: size;
}

.contain-style {
  contain: style;
}

/* Otimização de flexbox */
.flex-optimized {
  display: flex;
  min-width: 0; /* Previne overflow em flex items */
}

.flex-optimized > * {
  min-width: 0;
}

/* ===== COMPATIBILIDADE COM NAVEGADORES ===== */

/* Prefixos para propriedades CSS */
.backdrop-blur {
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.user-select-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.appearance-none {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Suporte para sticky positioning */
@supports not (position: sticky) {
  .sticky-fallback {
    position: fixed;
    top: 0;
    z-index: 1000;
  }
}

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

/* Preconnect para recursos externos */
.preconnect-fonts {
  /* Adicionar no HTML: <link rel="preconnect" href="https://fonts.googleapis.com"> */
}

/* Resource hints para melhor performance */
.dns-prefetch {
  /* Adicionar no HTML: <link rel="dns-prefetch" href="//fonts.googleapis.com"> */
}

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

/* Intersection Observer para lazy loading */
.lazy-load {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.lazy-load.loaded {
  opacity: 1;
  transform: translateY(0);
}

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

/* Minificação manual de seletores críticos */
.btn,.card,.form-input{transform:translateZ(0)}

/* Otimização de especificidade */
.high-specificity {
  /* Use apenas quando necessário para sobrescrever estilos */
}

/* ===== DEBUGGING E DESENVOLVIMENTO ===== */

/* Outline para debugging de layout */
.debug-layout * {
  outline: 1px solid red;
}

.debug-layout *:nth-child(odd) {
  outline-color: blue;
}

/* Performance monitoring */
.perf-monitor {
  /* Adicionar data attributes para monitoramento */
}

/* ===== PRINT OPTIMIZATIONS ===== */

@media print {
  /* Otimizações específicas para impressão */
  .no-print {
    display: none !important;
  }
  
  .print-only {
    display: block !important;
  }
  
  /* Evitar quebras de página em elementos importantes */
  .avoid-break {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  
  /* Forçar quebra de página */
  .force-break {
    page-break-before: always;
    break-before: page;
  }
  
  /* Otimizar cores para impressão */
  .print-friendly {
    color: #000 !important;
    background: #fff !important;
    box-shadow: none !important;
  }
}

/* ===== ACESSIBILIDADE E PERFORMANCE ===== */

/* Otimização para leitores de tela */
.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;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Otimização de contraste */
@media (prefers-contrast: high) {
  .high-contrast {
    border-width: 2px;
    font-weight: 600;
  }
}

/* ===== FEATURE QUERIES PARA PROGRESSIVE ENHANCEMENT ===== */

/* CSS Grid com fallback */
@supports (display: grid) {
  .progressive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
  }
}

@supports not (display: grid) {
  .progressive-grid {
    display: flex;
    flex-wrap: wrap;
    margin: -0.5rem;
  }
  
  .progressive-grid > * {
    flex: 1 1 280px;
    margin: 0.5rem;
  }
}

/* CSS Custom Properties com fallback */
@supports (color: var(--primary)) {
  .modern-colors {
    color: var(--brand-primary);
    background: var(--surface);
  }
}

@supports not (color: var(--primary)) {
  .modern-colors {
    color: #062e6f;
    background: #ffffff;
  }
}