/* ========================================
   RESPONSIVE DESIGN - MOBILE OPTIMIZED
   Design ottimizzato per esperienza mobile magnifica
   ======================================== */

/* Tablet (max-width: 1100px) */
@media(max-width:1100px){
  body {
    padding-left: 160px;
  }
  
  .logo-sidebar {
    width: 160px;
  }
  
  .sidebar-logo {
    width: 0px;
  }
  
  .logo-title {
    font-size: 1.1rem;
  }
  
  .new-main-flex, .card-flex {
    flex-wrap: wrap;
  }
  
  .search-section, .add-section, .ia-tile {
    flex: 1 1 calc(50% - 0.4rem);
    min-width: calc(50% - 0.4rem);
  }
}

/* Mobile (max-width: 768px) - ESPERIENZA MAGNIFICA */
@media(max-width:768px){
  /* Layout base mobile - FIXED HEADER E FOOTER */
  html {
    height: 100%;
    overflow: hidden;
  }
  
  body {
    padding-left: 0;
    font-size: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }
  
  /* Nascondi sidebar, mostra logo in topbar */
  .logo-sidebar {
    display: none;
  }
  
  /* Topbar FISSA in alto */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0.8rem 1rem;
    flex-direction: row;
    gap: 0.8rem;
    align-items: center;
    flex-wrap: wrap;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  
  /* Logo mobile nell'header */
  .topbar::before {
    content: '';
    width: 42px;
    height: 42px;
    background: url('../assets/logo.png') center/contain no-repeat;
    flex-shrink: 0;
    border-radius: 6px;
  }
  
  .gestionale-deco {
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
    margin: 0;
    flex-shrink: 0;
  }
  
  /* Navigazione mobile ottimizzata */
  nav {
    width: 100%;
    flex-basis: 100%;
  }
  
  .nav-tabs {
    width: 100%;
    justify-content: space-between;
    padding: 3px;
    gap: 4px;
  }
  
  nav button {
    font-size: 0.85rem;
    padding: 0.7rem 0.5rem;
    flex: 1;
    min-width: auto;
  }
  
  /* Layout colonne singole con scroll abilitato */
  main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    margin-top: 120px; /* Spazio per topbar fissa */
    margin-bottom: 60px; /* Spazio per footer fisso */
  }
  
  /* Footer FISSO in basso */
  footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: white;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  
  .new-main-flex, .card-flex {
    flex-direction: column;
    gap: 1rem;
  }
  
  .search-section, .add-section, .ia-tile {
    flex: 1 1 100%;
    min-width: 100%;
    width: 100%;
  }
  
  /* Card ottimizzate mobile */
  .card {
    padding: 0.8rem;
    max-height: none;
    border-radius: 12px;
    margin-bottom: 1rem;
  }
  
  .page {
    min-height: auto;
    padding-bottom: 2rem;
  }
  
  /* Form mobile friendly */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 0.8rem;
  }
  
  /* Input touch-friendly (16px previene zoom iOS) */
  input, select {
    font-size: 16px !important;
    padding: 0.75rem 0.9rem;
    margin-bottom: 0.8rem;
  }
  
  label {
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
  }
  
  /* Bottoni touch-friendly (min 48px Apple guidelines) */
  button.primary, .ia-btn {
    padding: 0.85rem 1.2rem;
    font-size: 0.95rem;
    min-height: 48px;
    font-weight: 600;
  }
  
  /* Tabella responsive con scroll orizzontale */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.8rem;
    border-radius: 8px;
  }
  
  th, td {
    padding: 0.7rem 0.6rem;
    white-space: nowrap;
  }
  
  th {
    font-size: 0.7rem;
    position: sticky;
    top: 0;
    background: var(--card-subtle);
    z-index: 10;
  }
  
  /* Bottoni tabella touch-friendly */
  .view-stats-btn {
    padding: 0.6rem 0.9rem !important;
    font-size: 0.85rem !important;
    min-height: 44px;
  }
  
  /* Filtri mobile stack verticale */
  .filters {
    grid-template-columns: 1fr !important;
    gap: 0.6rem;
    padding: 0.8rem;
  }
  
  .filters select, .filters input {
    width: 100%;
    font-size: 15px;
  }
  
  /* Paginazione mobile */
  .pagination {
    gap: 1rem;
    flex-wrap: wrap;
  }
  
  .pagination button {
    min-width: 48px;
    min-height: 48px;
    font-size: 1.2rem;
    padding: 0.6rem;
  }
  
  #pageInfo {
    font-size: 0.85rem;
    min-width: 120px;
    text-align: center;
  }
  
  /* Export buttons full width */
  .export {
    flex-direction: column;
    width: 100%;
  }
  
  .export button {
    width: 100%;
    padding: 0.85rem;
    font-size: 0.95rem;
    min-height: 48px;
  }
  
  /* Ricerca prodotti mobile */
  .search-results {
    max-height: 250px;
    font-size: 0.9rem;
  }
  
  .search-results li {
    padding: 0.85rem 1rem;
    min-height: 48px;
  }
  
  /* Statistiche mobile ottimizzate */
  .chart-wrap {
    padding: 0.5rem;
  }
  
  #statsChart {
    max-height: 250px !important;
  }
  
  #statsInfo {
    padding: 0.8rem;
  }
  
  #statsInfo > div {
    grid-template-columns: 1fr !important;
  }
  
  /* Dialog mobile */
  .product-dialog {
    max-width: 95vw;
    max-height: 90vh;
    padding: 1rem;
    margin: 1rem;
  }
  
  /* Form headers mobile */
  .form-header h2 {
    font-size: 0.95rem;
  }
  
  .form-icon {
    font-size: 1.1rem;
  }
  
  .subtitle, .info-desc {
    font-size: 0.85rem;
    line-height: 1.5;
  }
  
  /* Footer mobile */
  footer {
    padding: 1.5rem 1rem;
    font-size: 0.8rem;
  }
  
  /* Toast mobile */
  #toast {
    bottom: 20px;
    font-size: 0.9rem;
    padding: 0.9rem 1.2rem;
  }
  
  /* Main content spacing */
  main {
    padding: 0.8rem;
  }
}

/* Mobile piccoli (max-width: 480px) */
@media(max-width:480px){
  body {
    font-size: 14px;
  }
  
  .topbar {
    padding: 0.7rem 0.8rem;
  }
  
  .gestionale-deco {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
  
  nav button {
    font-size: 0.8rem;
    padding: 0.5rem 0.4rem;
  }
  
  .card {
    padding: 0.7rem;
  }
  
  h2 {
    font-size: 1rem;
  }
  
  .grid {
    gap: 0.7rem;
  }
  
  input, select {
    padding: 0.7rem 0.8rem;
  }
  
  button.primary {
    padding: 0.8rem 1rem;
    font-size: 0.9rem;
  }
  
  table {
    font-size: 0.75rem;
  }
  
  th, td {
    padding: 0.6rem 0.5rem;
  }
  
  .pagination button {
    min-width: 44px;
    min-height: 44px;
  }
  
  main {
    padding: 0.6rem;
    margin-top: 120px;
    margin-bottom: 60px;
  }
}
