/* ========================================
   FLEETZ - COMPATIBILITÀ UNIVERSALE SMARTPHONE
   ======================================== */

/* ===== RESET BASE UNIVERSALE ===== */
* {
  box-sizing: border-box !important;
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none !important;
}

/* ===== VIEWPORT UNIVERSALE ===== */
html {
  /* Supporto viewport units moderne */
  height: 100vh !important;
  height: 100dvh !important;
  height: -webkit-fill-available !important;
  
  /* Prevenzione zoom */
  -webkit-text-size-adjust: 100% !important;
  -ms-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
  
  /* Ottimizzazioni touch */
  touch-action: manipulation !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

body {
  margin: 0 !important;
  padding: 0 !important;
  height: 100vh !important;
  height: 100dvh !important;
  height: -webkit-fill-available !important;
  width: 100vw !important;
  
  /* Scroll ottimizzato */
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: none !important;
  overflow-x: hidden !important;
  
  /* Background nero universale */
  background-color: #000000 !important;
  
  /* Font system per performance */
  font-family: -apple-system, BlinkMacSystemFont, "Segui UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
}

#root {
  min-height: 100vh !important;
  min-height: 100dvh !important;
  min-height: -webkit-fill-available !important;
  width: 100vw !important;
  position: relative !important;
  background-color: #000000 !important;
}

/* ===== DIMENSIONI SMARTPHONE SPECIFICHE ===== */

/* iPhone SE, 5s (320px) */
@media screen and (max-width: 374px) {
  html, body, #root {
    font-size: 14px !important;
  }
  
  .message-input {
    font-size: 16px !important; /* Previene zoom iOS */
  }
  
  .chat-container {
    padding: 8px !important;
  }
}

/* iPhone 6/7/8, iPhone X/XS (375px) */
@media screen and (min-width: 375px) and (max-width: 413px) {
  html, body, #root {
    font-size: 15px !important;
  }
}

/* iPhone Plus, iPhone XR/11 (414px) */
@media screen and (min-width: 414px) and (max-width: 428px) {
  html, body, #root {
    font-size: 16px !important;
  }
}

/* iPhone Pro Max, Pixel XL (429px+) */
@media screen and (min-width: 429px) {
  html, body, #root {
    font-size: 17px !important;
  }
}

/* ===== SAFE AREAS AVANZATE ===== */

/* Supporto notch iPhone X+ */
@supports (padding: 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;
  }
  
  .chat-header {
    padding-top: calc(16px + env(safe-area-inset-top)) !important;
  }
  
  .message-input-container {
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }
}

/* Supporto Dynamic Island iPhone 14 Pro+ */
@supports (padding: env(safe-area-inset-top)) and (min-width: 393px) {
  .chat-header {
    padding-top: calc(20px + env(safe-area-inset-top)) !important;
  }
}

/* ===== GESTIONE TASTIERA UNIVERSALE ===== */

/* Quando la tastiera è aperta */
.keyboard-open {
  height: calc(100vh - var(--keyboard-height, 0px)) !important;
  height: calc(100dvh - var(--keyboard-height, 0px)) !important;
}

/* Input universali anti-zoom */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea {
  font-size: 16px !important; /* Previene zoom automatico */
  -webkit-appearance: none !important;
  appearance: none !important;
  border-radius: 8px !important;
  transform: translateZ(0) !important; /* Accelerazione hardware */
}

/* ===== ORIENTAMENTO PORTRAIT/LANDSCAPE ===== */

/* Portrait (la maggior parte degli use case) */
@media screen and (orientation: portrait) {
  .chat-messages {
    height: calc(100vh - 140px) !important;
    height: calc(100dvh - 140px) !important;
  }
}

/* Landscape - adatta per chat */
@media screen and (orientation: landscape) {
  .chat-messages {
    height: calc(100vh - 100px) !important;
    height: calc(100dvh - 100px) !important;
  }
  
  .message-input-container {
    padding: 8px !important;
  }
  
  .chat-header {
    height: 50px !important;
    padding: 8px 16px !important;
  }
}

/* ===== DENSITÀ PIXEL SPECIFICA ===== */

/* Retina display standard */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
  .app-icon, .user-avatar {
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
  }
}

/* High DPI (Samsung flagships, Pixel) */
@media screen and (-webkit-min-device-pixel-ratio: 3) {
  body {
    font-weight: 400 !important; /* Migliore rendering testo */
  }
}

/* ===== BROWSER MOBILI SPECIFICI ===== */

/* Chrome Mobile Android */
@supports (-webkit-appearance: none) and (not (-webkit-touch-callout: none)) {
  .chrome-mobile {
    scroll-behavior: smooth !important;
  }
  
  .message-bubble {
    will-change: transform !important;
    transform: translateZ(0) !important;
  }
}

/* Safari iOS */
@supports (-webkit-touch-callout: none) {
  html {
    height: -webkit-fill-available !important;
  }
  
  body {
    height: -webkit-fill-available !important;
  }
  
  /* Fix bounce iOS */
  .chat-container {
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: none !important;
  }
}

/* Samsung Internet */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .samsung-internet .message-input {
    background-color: rgba(255, 255, 255, 0.95) !important;
  }
}

/* Firefox Mobile */
@-moz-document url-prefix() {
  .firefox-mobile .chat-messages {
    scrollbar-width: none !important;
  }
}

/* ===== PERFORMANCE LOW-END DEVICES ===== */

/* Dispositivi con RAM < 2GB */
@media screen and (max-width: 480px) and (max-height: 854px) {
  /* Riduce animazioni */
  *, *::before, *::after {
    animation-duration: 0.1s !important;
    animation-delay: 0s !important;
    transition-duration: 0.1s !important;
  }
  
  /* Semplifica shadows */
  .message-bubble, .input-container {
    box-shadow: none !important;
  }
  
  /* Riduce blur effects */
  .backdrop-blur {
    backdrop-filter: none !important;
    background-color: rgba(0, 0, 0, 0.8) !important;
  }
}

/* ===== TOUCH GESTURES UNIVERSALI ===== */

/* Area touch più ampia per pulsanti */
.touch-target {
  min-height: 44px !important;
  min-width: 44px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Feedback touch */
.button, .clickable {
  -webkit-user-select: none !important;
  user-select: none !important;
  cursor: pointer !important;
  transition: background-color 0.1s ease !important;
}

.button:active, .clickable:active {
  background-color: rgba(255, 255, 255, 0.1) !important;
  transform: scale(0.98) !important;
}

/* ===== MODELLI SMARTPHONE SPECIFICI ===== */

/* Google Pixel series */
@media screen and (device-width: 411px) and (device-height: 731px) {
  .pixel-optimization {
    font-rendering: optimizeLegibility !important;
  }
}

/* Samsung Galaxy S series */
@media screen and (device-width: 360px) and (device-height: 640px) {
  .galaxy-optimization {
    -webkit-font-smoothing: antialiased !important;
  }
}

/* OnePlus series */
@media screen and (device-width: 412px) and (device-height: 869px) {
  .oneplus-optimization {
    scroll-behavior: smooth !important;
  }
}

/* Xiaomi series */
@media screen and (device-width: 393px) and (device-height: 786px) {
  .xiaomi-optimization {
    touch-action: manipulation !important;
  }
}

/* ===== DARK MODE UNIVERSALE ===== */
@media (prefers-color-scheme: dark) {
  body {
    color-scheme: dark !important;
  }
}

/* ===== ACCESSIBILITY UNIVERSALE ===== */

/* High contrast */
@media (prefers-contrast: high) {
  .message-bubble {
    border: 2px solid #ffffff !important;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== PWA / APK STANDALONE ===== */
@media (display-mode: standalone) {
  body {
    user-select: none !important;
    -webkit-user-select: none !important;
  }
  
  /* Nasconde elementi browser */
  .browser-only {
    display: none !important;
  }
  
  .app-only {
    display: block !important;
  }
}

/* ===== DEBUGGING MOBILE (rimuovere in produzione) ===== */
.mobile-debug::after {
  content: attr(data-device-info);
  position: fixed;
  bottom: 0;
  left: 0;
  background: rgba(255, 0, 0, 0.8);
  color: white;
  padding: 4px;
  font-size: 10px;
  z-index: 9999;
  display: var(--debug-mobile, none);
}

/* ===== FALLBACK UNIVERSALE ===== */
@supports not (height: 100dvh) {
  html, body, #root {
    height: 100vh !important;
  }
}

/* Fallback per browser molto vecchi */
@media screen and (max-width: 768px) {
  .legacy-mobile {
    position: relative !important;
    width: 100% !important;
    min-height: 100vh !important;
  }
}