/* Prevenir menu de contexto nativo do browser - VERSÃO MELHORADA */
html, body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    /* Desabilitar menu de contexto nativo */
    -webkit-context-menu: none;
    -moz-context-menu: none;
    context-menu: none;
    
    /* Prevenir drag and drop */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* Usar altura dinâmica para evitar "espaco branco" ao abrir o teclado */
html, body {
    height: 100dvh;
    min-height: var(--app-height, 100dvh);
}

/* Aplicar a todos os elementos */
*, *::before, *::after {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    /* Prevenir drag and drop */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* Prevenir especificamente em imagens e links */
img, a {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: auto; /* Manter cliques normais */
}

/* Permitir seleção em campos de texto */
input,
textarea,
[contenteditable="true"] {
    -webkit-user-select: text !important;
    -khtml-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* Permitir seleção em textos específicos */
.selectable-text {
    -webkit-user-select: text !important;
    -khtml-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* Contraste do texto do splash (JS: AppColors.textColorForBackground).
   Fallbacks até applySplashForegroundContrast rodar. */
:root {
  --splash-on-bg: #000000;
  --splash-on-bg-muted: rgba(0, 0, 0, 0.72);
  --splash-error-fg: rgba(0, 0, 0, 0.7);
}

/* ===================================================================
   SPLASH SCREEN STYLES
   Sistema de carregamento com feedback visual e recuperação de erro
   =================================================================== */

.loading-splash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 28px;
  background-color: var(--splash-bg, #FFFFFF);
  z-index: 10000;
  transition: opacity 0.5s ease-out;
}

/* Logo do tenant — caixa final desde o 1º frame (evita salto
   pequeno→grande). Pulso só com transform/opacity (compositor;
   sem layout). Hidden por padrão; Worker/JS injeta src. */
.splash-logo {
  display: block;
  height: 80px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  transform-origin: center center;
  animation: splash-logo-pulse 3s ease-in-out infinite;
}

@keyframes splash-logo-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.7;
  }
}

/* Spinner: markup e estilo preservados. Desligado via
   .splash-spinner-off no #loading-splash — remova essa classe
   em index.html para retomar. */
.splash-spinner-off .loading-spinner {
  display: none;
}

/* Spinner genérico - cor ajustável via CSS custom property */
.loading-spinner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--splash-accent, #667eea);
  animation: spin 1s ease-in-out infinite;
}

/* Animação de rotação suave */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Suporte para dark mode no nível do OS */
@media (prefers-color-scheme: dark) {
  :root {
    --splash-on-bg: #ffffff;
    --splash-on-bg-muted: rgba(255, 255, 255, 0.72);
    --splash-error-fg: rgba(255, 255, 255, 0.75);
  }

  .loading-splash {
    background-color: var(--splash-bg-dark, #1a1a2e);
  }
  
  .loading-spinner {
    border-color: rgba(255, 255, 255, 0.1);
    border-top-color: var(--splash-accent, #667eea);
  }
  
  #splash-error {
    background: rgba(30, 30, 50, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
  }
}

/* Texto de status - discreto no canto inferior esquerdo */
#splash-status {
  position: fixed !important;
  bottom: 16px !important;
  left: 16px !important;
  top: auto !important;
  right: auto !important;
  color: var(--splash-on-bg-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 11px;
  font-weight: 400;
  margin: 0;
  z-index: 10001;
}

/* Container de erro - discreto no canto inferior esquerdo */
#splash-error {
  position: fixed !important;
  bottom: 16px !important;
  left: 16px !important;
  right: auto !important;
  top: auto !important;
  text-align: left;
  max-width: 320px;
  animation: splash-fade-in 0.3s ease;
  background: rgba(255, 255, 255, 0.98);
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 10001;
}

#splash-error p {
  margin: 0 0 6px 0;
  color: var(--splash-error-fg);
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@keyframes splash-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Botão de reload - discreto */
#splash-reload-btn {
  background: transparent;
  color: #0175C2;
  border: 1px solid rgba(1, 117, 194, 0.3);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  transition: all 0.2s ease;
}

#splash-reload-btn:hover {
  background: rgba(1, 117, 194, 0.08);
  border-color: rgba(1, 117, 194, 0.5);
}

/* Esconder elementos desnecessários no centro */
#splash-progress-container {
  display: none !important;
}

/* Responsividade do splash */
@media (max-width: 480px) {
  .loading-spinner {
    width: 48px;
    height: 48px;
    border-width: 3px;
  }
  
  #splash-status {
    font-size: 10px !important;
    bottom: 10px !important;
    left: 10px !important;
  }
  
  #splash-error {
    bottom: 10px !important;
    left: 10px !important;
    right: 10px !important;
    max-width: none;
    padding: 8px 10px;
  }
  
  #splash-error p {
    font-size: 11px;
  }
  
  #splash-reload-btn {
    font-size: 10px;
    padding: 5px 10px;
  }
}

/* 🚀 OTIMIZAÇÕES DE PERFORMANCE PARA ROLAGEM */
/* Força composição de GPU no canvas do Flutter */
flt-glass-pane {
  contain: strict;
  will-change: transform;
}

/* Otimiza scroll em todo o app */
flt-scene-host {
  contain: layout style paint;
}

/* Promove camadas de composição para melhor performance */
flt-semantics-host {
  contain: strict;
}

/* Otimiza elementos scrolláveis */
[data-flutter-view] {
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Força GPU para canvas WebGL/WebGPU */
canvas {
  will-change: contents;
  contain: strict;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Reduz repaints desnecessários */
.flt-scene {
  contain: layout style paint;
  will-change: transform;
}

/* Flutter 3.44+: respeitar prefers-reduced-motion no splash HTML */
@media (prefers-reduced-motion: reduce) {
  .splash-logo,
  .loading-spinner {
    animation: none !important;
  }

  .loading-splash {
    transition: none !important;
  }
}