/* 
 * Stile personalizzato per la pagina prodotti.html
 * Compatibilità completa con le principali risoluzioni
 */

/* Loading states and flicker prevention */
body.prodotti-page.loading .catalogo-container { 
  visibility: hidden; 
  opacity: 0; 
}

body.prodotti-page.ready .catalogo-container { 
  visibility: visible; 
  opacity: 1; 
  transition: opacity .18s ease; 
}

/* Fixed height card layout with proper button visibility */
.prodotti-page .offerta-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: flex-start !important;
  padding: 8px 8px 6px 8px !important;
  background: #fff !important;
  border-radius: 10px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease !important;
  height: 120px !important;
  min-height: 120px !important;
  max-height: 120px !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.prodotti-page .offerta-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

.prodotti-page .offerta-card img {
  max-height: 30px !important;
  width: auto !important;
  max-width: 100% !important;
  object-fit: contain !important;
  margin-bottom: 4px !important;
  flex-shrink: 0 !important;
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

.prodotti-page .offerta-card h3 {
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  color: #1e4ddb !important;
  text-align: center !important;
  margin: 3px 0 !important;
  line-height: 1.1 !important;
  height: 1.5rem !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
}

.prodotti-page .offerta-card .prezzo {
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: #2b7cff !important;
  margin: 4px 0 !important;
  flex-shrink: 0 !important;
}

.prodotti-page .offerta-card .seleziona-prodotto-btn {
  margin-top: 2px !important;
  width: 100% !important;
  height: 28px !important;
  border-radius: 6px !important;
  background: #1e4ddb !important;
  color: #fff !important;
  border: none !important;
  font-weight: 600 !important;
  font-size: 0.75rem !important;
  cursor: pointer !important;
  transition: background 0.3s ease !important;
  flex-shrink: 0 !important;
}

.prodotti-page .offerta-card .seleziona-prodotto-btn:hover { 
  background: #2b7cff !important; 
}

.prodotti-page .offerta-card .seleziona-prodotto-btn:disabled { 
  opacity: 0.7; 
  cursor: default; 
}

.prodotti-page .offerta-card .seleziona-prodotto-btn:focus { 
  outline: 2px solid rgba(30,77,219,0.25); 
}

/* Selected state */
.prodotti-page .offerta-card.selezionata {
  box-shadow: 0 0 0 2px #1e4ddb inset, 0 2px 8px rgba(0,0,0,0.08) !important;
}

.prodotti-page .offerta-card.selezionata .seleziona-prodotto-btn {
  background: #17a34a !important;
}

.prodotti-page .offerta-card.selezionata .seleziona-prodotto-btn:hover {
  background: #12833b !important;
}

/* Layout principale per la pagina prodotti - Sovrascrive stili inline */
/* Forza espansione completa del layout principale */

.prodotti-page .card {
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  flex: 1 !important;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: visible !important;
}

/* Forza il container interno a occupare tutto lo spazio - Sovrascrive stili inline */
.prodotti-page .card > div[style*="padding: 20px"] {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box !important;
  flex: 1 !important;
  overflow: visible !important;
  height: 100% !important;
  padding: 20px !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Grid dei prodotti - Layout responsive con scroll interno */
.prodotti-page .prodotti-grid,
#prodotti-grid,
.offerte-grid {
  width: 100% !important;
  max-width: none !important;
  overflow: visible !important;
  padding-right: 0 !important;
  height: auto !important;
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
  grid-auto-rows: auto !important;
  gap: 16px !important;
  align-content: start !important;
  padding: 16px !important;
  box-sizing: border-box !important;
}

/* Override for grid cards - use fixed height from main definition */
.prodotti-grid .offerta-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: flex-start !important;
  padding: 8px 8px 6px 8px !important;
  background: #fff !important;
  border-radius: 10px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease !important;
  height: 120px !important;
  min-height: 120px !important;
  max-height: 120px !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  border: 1px solid rgba(48, 88, 158, 0.08) !important;
}

.prodotti-grid .offerta-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

/* Immagini prodotto */
.prodotti-grid .offerta-card img {
  max-height: 30px !important;
  width: auto !important;
  max-width: 100% !important;
  object-fit: contain !important;
  margin-bottom: 4px !important;
  flex-shrink: 0 !important;
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* Titoli prodotto */
.prodotti-grid .offerta-card h3 {
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  color: #1e4ddb !important;
  text-align: center !important;
  margin: 3px 0 !important;
  line-height: 1.1 !important;
  height: 1.5rem !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
}

/* Prezzi prodotto */
.prodotti-grid .offerta-card .prezzo {
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  color: #2b7cff !important;
  margin: 4px 0 !important;
  flex-shrink: 0 !important;
}

/* Bottoni */
.prodotti-grid .offerta-card button {
  margin-top: 2px !important;
  width: 100% !important;
  height: 28px !important;
  border-radius: 6px !important;
  background: #1e4ddb !important;
  color: #fff !important;
  border: none !important;
  font-weight: 600 !important;
  font-size: 0.75rem !important;
  cursor: pointer !important;
  transition: background 0.3s ease !important;
  flex-shrink: 0 !important;
}

.prodotti-grid .offerta-card button:hover {
  background: #2b7cff !important;
}

/* Container catalogo - Layout flex ottimizzato con altezza fissa */
.prodotti-page .catalogo-container {
  display: flex !important;
  gap: 0 !important;
  width: 100% !important;
  max-width: none !important;
  height: calc(100vh - 160px) !important;
  flex: 1 !important;
  min-height: calc(97vh - 160px) !important;
  max-height: calc(97vh - 160px) !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  /* Important: allow sticky children to be visible */
  overflow: visible !important;
}

.prodotti-page .prodotti-lista {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  height: calc(100vh - 160px) !important;
  min-height: calc(97vh - 160px) !important;
  max-height: calc(97vh - 160px) !important;
  width: 100% !important;
  box-sizing: border-box !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  background: #ffffff !important;
  border-radius: 12px 0 0 12px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06) !important;
  border: 1px solid rgba(48, 88, 158, 0.08) !important;
  border-right: none !important;
  padding-right: 0 !important;
  margin-right: 0 !important;
}

/* Left sidebar: match column height and allow internal scroll */
/* Carrello laterale - Fixed height matching other columns */
.prodotti-page #carrello-box {
  width: 300px !important;
  flex: 0 0 300px !important;
  background: #f8faff !important;
  border-radius: 0 12px 12px 0 !important;
  padding: 20px !important;
  height: calc(97vh - 160px) !important;
  max-height: calc(97vh - 160px) !important;
  position: sticky !important;
  top: 20px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06) !important;
  border: 1px solid rgba(48, 88, 158, 0.08) !important;
  border-left: none !important;
  margin-left: 0 !important;
  z-index: 1; /* keep above grid content */
}

/* Responsive design per diverse risoluzioni */

/* Desktop Large (1920px e superiori) */
@media (min-width: 1920px) {
  .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)) !important;
    gap: 24px !important;
    padding: 24px 0 !important;
  }
  
  .prodotti-grid .offerta-card {
    min-height: 360px !important;
    padding: 24px !important;
  }
  
  /* Icone prodotto più grandi su schermi molto ampi */
  .prodotti-grid .offerta-card img {
    max-height: 120px !important;
  }
  
  .prodotti-grid .offerta-card h3 {
    font-size: 1.2rem !important;
  }
  
  .prodotti-grid .offerta-card .prezzo {
    font-size: 1.4rem !important;
  }
  
  .prodotti-page .catalogo-container {
    gap: 0 !important;
  }
  
  .prodotti-page #carrello-box {
    width: 350px !important;
    flex: 0 0 350px !important;
    border-radius: 0 12px 12px 0 !important;
    border-left: none !important;
    margin-left: 0 !important;
  }
  
  .prodotti-page .prodotti-lista {
    border-radius: 12px 0 0 12px !important;
    border-right: none !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
  }
}

/* Desktop Standard (1366px - 1919px) */
@media (min-width: 1366px) and (max-width: 1919px) {
  .prodotti-page .catalogo-container {
    height: calc(100vh - 160px) !important;
    min-height: calc(97vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    gap: 0 !important;
  }
  
  .prodotti-page .prodotti-lista {
    height: calc(100vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    border-radius: 12px 0 0 12px !important;
    border-right: none !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
  }
  
  .prodotti-page #carrello-box {
    height: calc(97vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    border-radius: 0 12px 12px 0 !important;
    border-left: none !important;
    margin-left: 0 !important;
  }
  
  .prodotti-page .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important;
    gap: 20px !important;
  }
  
  .prodotti-page .offerta-card {
    height: 380px !important;
    min-height: 380px !important;
    max-height: 380px !important;
  }
}

/* Desktop Small (1024px - 1365px) */
@media (min-width: 1024px) and (max-width: 1365px) {
  .prodotti-page .catalogo-container {
    height: calc(100vh - 160px) !important;
    min-height: calc(97vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    gap: 0 !important;
  }
  
  .prodotti-page .prodotti-lista {
    height: calc(100vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    border-radius: 12px 0 0 12px !important;
    border-right: none !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
  }
  
  .prodotti-page #carrello-box {
    width: 280px !important;
    flex: 0 0 280px !important;
    height: calc(97vh - 160px) !important;
    max-height: calc(97vh - 160px) !important;
    border-radius: 0 12px 12px 0 !important;
    border-left: none !important;
    margin-left: 0 !important;
  }
  
  .prodotti-page .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
    gap: 18px !important;
  }
  
  .prodotti-page .offerta-card {
    height: 360px !important;
    min-height: 360px !important;
    max-height: 360px !important;
    padding: 16px !important;
  }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .prodotti-page .main-container {
    flex-direction: column !important;
    padding: 15px !important;
  }
  
  .prodotti-page .catalogo-container {
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    flex-direction: column !important;
    gap: 20px !important;
    margin-top: 15px !important;
  }
  
  .prodotti-page .prodotti-lista {
    height: 70vh !important;
    max-height: 70vh !important;
  }
  
  .prodotti-page #carrello-box {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    position: static !important;
  }
  
  .prodotti-page .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    gap: 16px !important;
    padding: 16px !important;
  }
  
  .prodotti-page .offerta-card {
    height: 320px !important;
    min-height: 320px !important;
    max-height: 320px !important;
    padding: 14px !important;
  }
}

/* Mobile (fino a 767px) */
@media (max-width: 767px) {
  .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 16px !important;
    padding: 16px 0 !important;
  }
  
  .prodotti-grid .offerta-card {
    min-height: 280px !important;
    padding: 14px !important;
  }
  
  .prodotti-grid .offerta-card img {
    max-height: 60px !important;
    margin-bottom: 12px !important;
  }
  
  .prodotti-grid .offerta-card h3 {
    font-size: 0.95rem !important;
    min-height: 2rem !important;
  }
  
  .prodotti-grid .offerta-card .prezzo {
    font-size: 1.1rem !important;
  }
  
  .prodotti-grid .offerta-card button {
    padding: 10px 16px !important;
    font-size: 0.9rem !important;
  }
  
  .catalogo-container {
    flex-direction: column !important;
    gap: 16px !important;
    padding: 0 12px !important;
  }
  
  #carrello-box {
    width: 100% !important;
    position: static !important;
    padding: 16px !important;
  }
}

/* Mobile Small (fino a 480px) */
@media (max-width: 480px) {
  .prodotti-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  
  .prodotti-grid .offerta-card {
    min-height: 260px !important;
    padding: 12px !important;
  }
  
  .prodotti-grid .offerta-card h3 {
    font-size: 0.9rem !important;
  }
  
  .prodotti-grid .offerta-card .prezzo {
    font-size: 1rem !important;
  }
}

/* Fix per assicurare che il layout si espanda correttamente */
.prodotti-page .dashboard-wrapper {
  width: 100% !important;
  max-width: none !important;
  align-items: stretch !important;
  /* ensure full viewport height so columns align */
  min-height: calc(100vh - 20px) !important;
}

/* Forza l'espansione completa del container principale */
.prodotti-page .container {
  width: 100% !important;
  max-width: none !important;
  padding: 0 !important;
}

/* Rimuove limitazioni di larghezza dalla card header */
.prodotti-page .card-header {
  width: 100% !important;
  max-width: none !important;
}

/* Ottimizzazioni per il carrello */
#carrello-contenuto {
  background: white !important;
  border-radius: 8px !important;
  padding: 16px !important;
  box-shadow: 0 2px 8px rgba(48, 88, 158, 0.08) !important;
  display: block !important;
  overflow: visible !important;
  /* Firefox thin scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 77, 219, 0.3) rgba(0, 0, 0, 0.05);
}

/* Nasconde elementi non necessari su mobile */
@media (max-width: 767px) {
  .filtri {
    display: none !important;
  }
  /* On mobile, avoid internal scroll; let page scroll naturally */
  #carrello-contenuto {
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
  }
}

/* Scrollbar personalizzata per carrello (WebKit) */
#carrello-contenuto::-webkit-scrollbar {
  width: 3px;
}

#carrello-contenuto::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

#carrello-contenuto::-webkit-scrollbar-thumb {
  background: rgba(30, 77, 219, 0.3);
  border-radius: 4px;
}

#carrello-contenuto::-webkit-scrollbar-thumb:hover {
  background: rgba(30, 77, 219, 0.5);
}

/* Scrollbar personalizzata per prodotti-grid */
.prodotti-page .prodotti-grid::-webkit-scrollbar {
  width: 6px;
}

.prodotti-page .prodotti-grid::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.prodotti-page .prodotti-grid::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.prodotti-page .prodotti-grid::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
  .prodotti-page .main-container {
    flex-direction: column !important;
    padding: 10px !important;
  }
  
  .prodotti-page .catalogo-container {
    flex-direction: column !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    gap: 15px !important;
    margin-top: 10px !important;
  }
  
  .prodotti-page .prodotti-lista {
    height: 60vh !important;
    max-height: 60vh !important;
  }
  
  .prodotti-page #carrello-box {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    position: static !important;
    margin-top: 15px !important;
  }
  
  .prodotti-page .prodotti-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 12px !important;
    padding: 12px !important;
  }
  
  .prodotti-page .offerta-card,
  .prodotti-grid .offerta-card {
    height: 120px !important;
    min-height: 120px !important;
    max-height: 120px !important;
    padding: 8px 8px 6px 8px !important;
  }
  
  .prodotti-page .offerta-card img,
  .prodotti-grid .offerta-card img {
    max-height: 30px !important;
  }
  
  .prodotti-page .offerta-card h3,
  .prodotti-grid .offerta-card h3 {
    font-size: 0.75rem !important;
    height: 1.5rem !important;
    margin: 3px 0 !important;
  }
  
  .prodotti-page .offerta-card .prezzo,
  .prodotti-grid .offerta-card .prezzo {
    font-size: 0.9rem !important;
    margin: 4px 0 !important;
  }
  
  .prodotti-page .offerta-card button,
  .prodotti-grid .offerta-card button {
    height: 28px !important;
    font-size: 0.75rem !important;
    margin-top: 2px !important;
  }
  
}
