/* ===================================================================
   MOBILE-BASE.CSS - Fundações Mobile-First para WiniVerse Chat
   ================================================================
   
   Descrição:
   - Variáveis CSS específicas para mobile
   - Reset e normalize para dispositivos móveis
   - Tipografia base mobile
   - Utilitários fundamentais
   
   Carregado apenas em: max-width: 767px (mobile)
   
   Versão: 1.0
   Data: 2025-01-23
   =================================================================== */

/* ===================================================================
   1. VARIÁVEIS CSS MOBILE
   =================================================================== */

:root {
  /* === SPACING MOBILE === */
  --mobile-spacing-xs: 4px;
  --mobile-spacing-sm: 8px;
  --mobile-spacing-md: 12px;
  --mobile-spacing-lg: 16px;
  --mobile-spacing-xl: 24px;
  --mobile-spacing-xxl: 32px;
  
  /* === TOUCH TARGETS === */
  --mobile-touch-min: 44px;      /* Mínimo Apple HIG */
  --mobile-touch-comfortable: 48px; /* Confortável */
  --mobile-touch-large: 56px;    /* Ações primárias */
  
  /* === HEADER/FOOTER === */
  --mobile-header-height: 56px;
  --mobile-input-height: auto;   /* Cresce com conteúdo */
  --mobile-input-min-height: 56px;
  /* ✅ NOVO: Altura estimada do input container para cálculos (padding + wrapper + info) */
  --mobile-input-container-min-height: 100px; /* Mínimo seguro: padding + textarea + info + safe area */
  
  /* === TIPOGRAFIA MOBILE === */
  --mobile-font-xs: 12px;
  --mobile-font-sm: 14px;
  --mobile-font-base: 16px;      /* Base legível */
  --mobile-font-lg: 18px;
  --mobile-font-xl: 20px;
  --mobile-font-xxl: 24px;
  
  --mobile-line-height-tight: 1.2;
  --mobile-line-height-normal: 1.5;
  --mobile-line-height-relaxed: 1.75;
  
  /* === Z-INDEX MOBILE === */
  --z-mobile-drawer: 1000;
  --z-mobile-drawer-overlay: 999;
  --z-mobile-header: 900;
  --z-mobile-bottom-sheet: 1100;
  --z-mobile-bottom-sheet-overlay: 1099;
  --z-mobile-input: 800;
  --z-mobile-toast: 1200;
  
  /* === ANIMAÇÕES MOBILE === */
  --mobile-transition-fast: 150ms;
  --mobile-transition-normal: 250ms;
  --mobile-transition-slow: 350ms;
  --mobile-easing: cubic-bezier(0.4, 0, 0.2, 1);
  --mobile-easing-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  
  /* === CORES ADAPTADAS MOBILE === */
  /* Usar cores do tema existente, mas com ajustes para mobile */
  --mobile-bg-primary: var(--background-primary, #0a0a0f);
  --mobile-bg-secondary: var(--background-secondary, #1a1a2e);
  --mobile-accent: var(--accent-primary, #00ffff);
  --mobile-text-primary: var(--text-primary, #ffffff);
  --mobile-text-secondary: var(--text-secondary, #b0b0b0);
  
  /* Glow reduzido para performance mobile */
  --mobile-glow-subtle: 0 0 8px var(--mobile-accent);
  --mobile-glow-normal: 0 0 12px var(--mobile-accent);
  --mobile-glow-strong: 0 0 16px var(--mobile-accent);
  
  /* === SAFE AREAS (iPhone notch, etc) === */
  --mobile-safe-top: env(safe-area-inset-top);
  --mobile-safe-bottom: env(safe-area-inset-bottom);
  --mobile-safe-left: env(safe-area-inset-left);
  --mobile-safe-right: env(safe-area-inset-right);
}

/* ===================================================================
   2. RESET E NORMALIZE MOBILE
   =================================================================== */

@media screen and (max-width: 767px) {
  
  /* === RESET BÁSICO === */
  * {
    -webkit-tap-highlight-color: rgba(0, 255, 255, 0.1);
    -webkit-touch-callout: none;
  }
  
  /* === HTML/BODY === */
  html {
    /* Prevenir zoom em inputs iOS */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    
    /* Scroll suave */
    scroll-behavior: smooth;
    
    /* Overscroll behavior */
    overscroll-behavior-y: contain;
  }
  
  body {
    /* Prevenir bounce scroll */
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    
    /* Touch optimization */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  
  /* === CONTAINER PRINCIPAL === */
  .winiverse-container {
    /* Mobile ocupa 100% da viewport */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
    overflow: hidden;
  }
  
  /* === SAFE AREA PADDING === */
  .winiverse-container {
    padding-top: var(--mobile-safe-top);
    padding-bottom: var(--mobile-safe-bottom);
    padding-left: var(--mobile-safe-left);
    padding-right: var(--mobile-safe-right);
  }
  
  /* === TOUCH TARGETS === */
  button,
  a,
  input,
  textarea,
  select,
  [role="button"],
  [tabindex]:not([tabindex="-1"]) {
    /* Garantir touch target mínimo */
    min-width: var(--mobile-touch-min);
    min-height: var(--mobile-touch-min);
    
    /* Melhorar área de toque */
    position: relative;
  }
  
  /* Pseudo-elemento para expandir área de toque */
  button::before,
  a::before,
  [role="button"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: var(--mobile-touch-min);
    min-height: var(--mobile-touch-min);
    z-index: -1;
  }
  
  /* === INPUTS === */
  input,
  textarea,
  select {
    /* Prevenir zoom iOS */
    font-size: var(--mobile-font-base);
    
    /* Melhorar usabilidade */
    border-radius: 8px;
    padding: var(--mobile-spacing-md);
    
    /* Otimizar performance */
    will-change: transform;
  }
  
  textarea {
    /* Melhorar resize */
    resize: vertical;
    min-height: 56px;
    max-height: 200px;
  }
  
  /* === SCROLL CONTAINERS === */
  .mobile-scroll-container {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    
    /* Hide scrollbar mas manter funcionalidade */
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  
  .mobile-scroll-container::-webkit-scrollbar {
    display: none;
  }
  
  /* === IMAGENS === */
  img {
    /* Otimizar renderização */
    max-width: 100%;
    height: auto;
    display: block;
  }
  
  /* === LINKS === */
  a {
    /* Melhorar área de toque */
    display: inline-block;
    padding: var(--mobile-spacing-xs);
    margin: calc(var(--mobile-spacing-xs) * -1);
  }
}

/* ===================================================================
   3. TIPOGRAFIA BASE MOBILE
   =================================================================== */

@media screen and (max-width: 767px) {
  
  /* === HEADINGS === */
  h1, .h1 {
    font-size: var(--mobile-font-xxl);
    line-height: var(--mobile-line-height-tight);
    margin-bottom: var(--mobile-spacing-md);
  }
  
  h2, .h2 {
    font-size: var(--mobile-font-xl);
    line-height: var(--mobile-line-height-tight);
    margin-bottom: var(--mobile-spacing-md);
  }
  
  h3, .h3 {
    font-size: var(--mobile-font-lg);
    line-height: var(--mobile-line-height-normal);
    margin-bottom: var(--mobile-spacing-sm);
  }
  
  h4, .h4,
  h5, .h5,
  h6, .h6 {
    font-size: var(--mobile-font-base);
    line-height: var(--mobile-line-height-normal);
    margin-bottom: var(--mobile-spacing-sm);
  }
  
  /* === BODY TEXT === */
  p, .text-body {
    font-size: var(--mobile-font-base);
    line-height: var(--mobile-line-height-relaxed);
    margin-bottom: var(--mobile-spacing-md);
  }
  
  /* === SMALL TEXT === */
  small, .text-small {
    font-size: var(--mobile-font-sm);
    line-height: var(--mobile-line-height-normal);
  }
  
  /* === TINY TEXT === */
  .text-tiny {
    font-size: var(--mobile-font-xs);
    line-height: var(--mobile-line-height-normal);
  }
  
  /* === CÓDIGO === */
  code,
  pre {
    font-size: var(--mobile-font-sm);
    line-height: var(--mobile-line-height-normal);
  }
  
  /* === TRUNCATE TEXT === */
  .mobile-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .mobile-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  
  .mobile-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* ===================================================================
   4. UTILITÁRIOS MOBILE
   =================================================================== */

@media screen and (max-width: 767px) {
  
  /* === DISPLAY === */
  .mobile-hidden {
    display: none !important;
  }
  
  .mobile-visible {
    display: block !important;
  }
  
  .mobile-flex {
    display: flex !important;
  }
  
  .mobile-grid {
    display: grid !important;
  }
  
  /* === SPACING === */
  .mobile-p-0 { padding: 0 !important; }
  .mobile-p-xs { padding: var(--mobile-spacing-xs) !important; }
  .mobile-p-sm { padding: var(--mobile-spacing-sm) !important; }
  .mobile-p-md { padding: var(--mobile-spacing-md) !important; }
  .mobile-p-lg { padding: var(--mobile-spacing-lg) !important; }
  .mobile-p-xl { padding: var(--mobile-spacing-xl) !important; }
  
  .mobile-m-0 { margin: 0 !important; }
  .mobile-m-xs { margin: var(--mobile-spacing-xs) !important; }
  .mobile-m-sm { margin: var(--mobile-spacing-sm) !important; }
  .mobile-m-md { margin: var(--mobile-spacing-md) !important; }
  .mobile-m-lg { margin: var(--mobile-spacing-lg) !important; }
  .mobile-m-xl { margin: var(--mobile-spacing-xl) !important; }
  
  /* === WIDTH === */
  .mobile-w-full { width: 100% !important; }
  .mobile-w-screen { width: 100vw !important; }
  
  /* === HEIGHT === */
  .mobile-h-full { height: 100% !important; }
  .mobile-h-screen { 
    height: 100vh !important;
    height: 100dvh !important;
  }
  
  /* === POSITION === */
  .mobile-fixed {
    position: fixed !important;
  }
  
  .mobile-absolute {
    position: absolute !important;
  }
  
  .mobile-relative {
    position: relative !important;
  }
  
  .mobile-sticky {
    position: sticky !important;
  }
  
  /* === OVERFLOW === */
  .mobile-overflow-hidden {
    overflow: hidden !important;
  }
  
  .mobile-overflow-auto {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .mobile-overflow-y-auto {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* ===================================================================
   5. PERFORMANCE OPTIMIZATIONS
   =================================================================== */

@media screen and (max-width: 767px) {
  
  /* === GPU ACCELERATION === */
  .mobile-gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    perspective: 1000px;
  }
  
  /* === REDUCE MOTION (Acessibilidade) === */
  @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;
    }
  }
  
  /* === DARK MODE ONLY (Mobile sempre dark) === */
  /* WiniVerse é dark-first, então forçar dark em mobile */
  html,
  body {
    color-scheme: dark;
  }
  
  /* === GLOW REDUZIDO PARA PERFORMANCE === */
  .mobile-glow-disabled {
    box-shadow: none !important;
    text-shadow: none !important;
    filter: none !important;
  }
  
  /* Reduzir glow em elementos animados */
  .mobile-animated {
    box-shadow: var(--mobile-glow-subtle) !important;
  }
}

/* ===================================================================
   6. ACCESSIBILITY MOBILE
   =================================================================== */

@media screen and (max-width: 767px) {
  
  /* === FOCUS VISIBLE === */
  *:focus-visible {
    outline: 2px solid var(--mobile-accent);
    outline-offset: 2px;
  }
  
  /* === SCREEN READER ONLY === */
  .mobile-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
  
  /* === SKIP TO CONTENT === */
  .mobile-skip-to-content {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: var(--mobile-spacing-md);
    background: var(--mobile-bg-primary);
    color: var(--mobile-accent);
    border-radius: 8px;
    text-decoration: none;
    transition: top var(--mobile-transition-fast) var(--mobile-easing);
  }
  
  .mobile-skip-to-content:focus {
    top: var(--mobile-spacing-md);
  }
}

/* ===================================================================
   FIM DO MOBILE-BASE.CSS
   ================================================================ */
