/**
 * CSS di supporto per sistema scroll mobile universale
 * Compatibile con tutti gli smartphone
 */

/* Applicazione solo su dispositivi mobili */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  
  /* Reset scroll globale su mobile */
  html {
    height: 100% !important;
    overflow: hidden !important;
  }
  
  body {
    height: 100vh !important;
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* Disabilita scroll nativo su elementi principali */
  #root {
    height: 100vh !important;
    overflow: hidden !important;
    position: relative !important;
  }
  
  /* Zone di scroll personalizzate */
  .chat-messages,
  .privacy-inspector-content,
  .settings-content,
  .chat-list-container,
  .main-content,
  .scrollable-container {
    overflow: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    position: relative !important;
  }
  
  /* Previeni interferenze con gestures */
  * {
    touch-action: manipulation !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    -khtml-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
  }
  
  /* Permetti selezione testo solo dove necessario */
  input, textarea, [contenteditable="true"] {
    -webkit-user-select: auto !important;
    -khtml-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
    user-select: auto !important;
  }
  
  /* Ottimizzazioni per brand specifici */
  
  /* Samsung Galaxy - One UI */
  @supports (-webkit-appearance: none) and (not (-moz-appearance: none)) {
    body {
      -webkit-overflow-scrolling: auto !important;
      overflow-anchor: none !important;
    }
    
    .chat-messages,
    .privacy-inspector-content {
      will-change: transform !important;
      transform: translateZ(0) !important;
    }
  }
  
  /* Xiaomi MIUI */
  @media screen and (-webkit-min-device-pixel-ratio: 0) {
    body {
      -webkit-backface-visibility: hidden !important;
      backface-visibility: hidden !important;
    }
  }
  
  /* iPhone/iPad - iOS Safari */
  @supports (-webkit-appearance: none) and (not (contain: paint)) {
    body {
      -webkit-overflow-scrolling: auto !important;
      position: fixed !important;
      top: 0 !important;
      left: 0 !important;
      right: 0 !important;
      bottom: 0 !important;
    }
    
    .chat-messages,
    .privacy-inspector-content {
      -webkit-transform: translateZ(0) !important;
      transform: translateZ(0) !important;
    }
  }
  
  /* Huawei EMUI */
  @media screen and (device-aspect-ratio: 16/9) {
    body {
      overflow-y: hidden !important;
    }
  }
  
  /* OnePlus OxygenOS */
  @media screen and (min-resolution: 2dppx) {
    .scrollable-container {
      contain: layout style paint !important;
    }
  }
  
  /* Vivo/Realme - FunTouch OS */
  @media screen and (orientation: portrait) {
    body {
      touch-action: pan-x pan-y !important;
    }
  }
  
  /* Forza GPU acceleration per smooth scrolling */
  .chat-messages,
  .privacy-inspector-content,
  .settings-content,
  .chat-list-container,
  .main-content {
    will-change: transform !important;
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
  }
  
  /* Previeni rubber band effect */
  body {
    overscroll-behavior: none !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* Nascondi scrollbar su mobile */
  .chat-messages::-webkit-scrollbar,
  .privacy-inspector-content::-webkit-scrollbar,
  .settings-content::-webkit-scrollbar,
  .chat-list-container::-webkit-scrollbar,
  .main-content::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    background: transparent !important;
  }
  
  /* Supporto per Firefox mobile */
  @-moz-document url-prefix() {
    body {
      overflow: hidden !important;
      scrollbar-width: none !important;
    }
    
    .chat-messages,
    .privacy-inspector-content,
    .settings-content,
    .chat-list-container,
    .main-content {
      scrollbar-width: none !important;
    }
  }
  
  /* Ottimizzazioni per dispositivi con notch */
  @supports (padding-top: env(safe-area-inset-top)) {
    body {
      padding-top: env(safe-area-inset-top) !important;
      padding-bottom: env(safe-area-inset-bottom) !important;
      padding-left: env(safe-area-inset-left) !important;
      padding-right: env(safe-area-inset-right) !important;
    }
  }
  
  /* Supporto per Dynamic Island (iPhone 14 Pro) */
  @supports (top: env(titlebar-area-inset)) {
    body {
      padding-top: max(env(safe-area-inset-top), env(titlebar-area-inset)) !important;
    }
  }
  
  /* Gestione viewport per dispositivi foldable */
  @media screen and (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    body {
      width: 100vw !important;
      height: 100vh !important;
    }
  }
  
  /* Ottimizzazioni per performance */
  .chat-messages *,
  .privacy-inspector-content *,
  .settings-content *,
  .chat-list-container *,
  .main-content * {
    contain: layout style paint !important;
    will-change: auto !important;
  }
  
  /* Smooth scrolling per transizioni */
  .chat-messages,
  .privacy-inspector-content,
  .settings-content,
  .chat-list-container,
  .main-content {
    scroll-behavior: smooth !important;
    -webkit-scroll-behavior: smooth !important;
  }
  
  /* Fix per keyboard overlay */
  @media screen and (max-height: 600px) {
    .chat-messages,
    .privacy-inspector-content {
      height: calc(100vh - 60px) !important;
    }
  }
  
  /* Ulteriori ottimizzazioni per brand meno comuni */
  
  /* Motorola */
  @media screen and (device-width: 360px) {
    body {
      position: fixed !important;
      overflow: hidden !important;
    }
  }
  
  /* Sony Xperia */
  @media screen and (device-aspect-ratio: 21/9) {
    .scrollable-container {
      overflow-anchor: none !important;
    }
  }
  
  /* Google Pixel */
  @media screen and (-webkit-device-pixel-ratio: 2.75) {
    body {
      -webkit-overflow-scrolling: auto !important;
    }
  }
  
  /* Nokia */
  @media screen and (device-width: 320px) {
    .chat-messages,
    .privacy-inspector-content {
      transform: translate3d(0, 0, 0) !important;
    }
  }
  
  /* LG */
  @media screen and (device-aspect-ratio: 18/9) {
    body {
      overflow-y: hidden !important;
      touch-action: pan-x pan-y !important;
    }
  }
  
  /* HTC */
  @media screen and (device-width: 414px) and (device-height: 896px) {
    .scrollable-container {
      will-change: transform !important;
    }
  }
  
}

/* Stili per debug (solo in development) */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  .mobile-scroll-debug {
    position: fixed !important;
    top: 10px !important;
    left: 10px !important;
    background: rgba(255, 0, 0, 0.8) !important;
    color: white !important;
    padding: 5px !important;
    font-size: 12px !important;
    z-index: 9999 !important;
    border-radius: 3px !important;
    pointer-events: none !important;
  }
}