/* OTTIMIZZAZIONI MOBILE SEMPIPLANCIA */

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

/* Accelerazione hardware per elementi chiave */
.dashboard-card, .sidebar-item, .mobile-menu, .loading-spinner {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Mobile-first responsive breakpoints */
@media screen and (max-width: 768px) {
  /* Sidebar compatta su mobile */
  .sidebar {
    width: 100% !important;
    height: auto !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 1000 !important;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%) !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 10px !important;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.3) !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  }

  .sidebar.mobile-open {
    transform: translateY(0) !important;
  }

  /* Navigation mobile-friendly */
  .nav-items {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-around !important;
    align-items: center !important;
    gap: 0 !important;
  }

  .nav-item {
    flex: 1 !important;
    min-width: 50px !important;
    padding: 12px 8px !important;
    text-align: center !important;
    border-radius: 15px !important;
    background: transparent !important;
    transition: all 0.2s ease !important;
  }

  .nav-item:active, .nav-item.active {
    background: rgba(241, 105, 38, 0.2) !important;
    transform: scale(0.95) !important;
  }

  .nav-item-icon {
    font-size: 18px !important;
    margin-bottom: 4px !important;
    display: block !important;
  }

  .nav-item-text {
    font-size: 10px !important;
    font-weight: 500 !important;
    color: #fff !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  /* Dashboard mobile ottimizzato */
  .dashboard-container {
    padding-bottom: 100px !important; /* Spazio per bottom navigation */
    margin: 0 !important;
  }

  .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 15px !important;
    padding: 15px !important;
  }

  /* Cards responsive */
  .dashboard-card {
    border-radius: 20px !important;
    padding: 20px !important;
    margin: 0 !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
    background: #fff !important;
    min-height: auto !important;
  }

  .dashboard-card h3 {
    font-size: 18px !important;
    margin-bottom: 12px !important;
  }

  .dashboard-card .metric-value {
    font-size: 24px !important;
    font-weight: bold !important;
    color: #F16926 !important;
  }

  /* Header mobile */
  .header-container {
    padding: 10px 15px !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 999 !important;
    background: #fff !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
  }

  .header-title {
    font-size: 20px !important;
    font-weight: bold !important;
  }

  /* Mobile menu trigger */
  .mobile-menu-toggle {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 60px !important;
    height: 60px !important;
    background: linear-gradient(135deg, #F16926, #ff8f47) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: white !important;
    font-size: 24px !important;
    box-shadow: 0 4px 20px rgba(241, 105, 38, 0.4) !important;
    z-index: 1001 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    border: none !important;
  }

  .mobile-menu-toggle:active {
    transform: scale(0.9) !important;
  }

  /* Touch-friendly tap targets */
  button, .clickable, .nav-item, .dashboard-card {
    min-height: 44px !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: rgba(241, 105, 38, 0.2) !important;
  }

  /* Form elementi mobile-friendly */
  input, select, textarea {
    font-size: 16px !important; /* Previene zoom su iOS */
    padding: 15px !important;
    border-radius: 10px !important;
    border: 2px solid #e2e8f0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  input:focus, select:focus, textarea:focus {
    border-color: #F16926 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(241, 105, 38, 0.1) !important;
  }

  /* Loading ottimizzato per mobile */
  .loading-spinner {
    width: 40px !important;
    height: 40px !important;
    border: 3px solid rgba(241, 105, 38, 0.3) !important;
    border-top: 3px solid #F16926 !important;
    border-radius: 50% !important;
    animation: spin 1s linear infinite !important;
    margin: 20px auto !important;
  }

  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
}

/* Ottimizzazioni tablet */
@media screen and (min-width: 769px) and (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 20px !important;
  }

  .sidebar {
    width: 250px !important;
  }

  .dashboard-container {
    margin-left: 250px !important;
  }
}

/* Performance: Lazy loading per immagini */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* Critical path optimization */
.above-fold {
  font-display: swap;
}

/* Riduzione layout shift */
.dashboard-card {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Gesture supporto */
@media (hover: none) and (pointer: coarse) {
  .hover-effect:hover {
    background-color: transparent !important;
  }
  
  .hover-effect:active {
    background-color: rgba(241, 105, 38, 0.1) !important;
    transform: scale(0.98) !important;
  }
}