/* ============================================
   BOXMANAGER - MODERN GLASSMORPHISM UI
   ============================================ */

/* CSS Variables & Theme */
:root {
  /* Colors - Modern Blue-Green Palette */
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --secondary: #06b6d4;
  --accent: #f472b6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  
  /* Glassmorphism Backgrounds */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-bg-strong: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.3);
  --glass-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  
  /* Dark mode colors */
  --bg-dark: #0f172a;
  --bg-dark-elevated: #1e293b;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #f8fafc;
  
  /* Spacing */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  
  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* Dark mode detection */
@media (prefers-color-scheme: dark) {
  :root {
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-bg-strong: rgba(30, 41, 59, 0.9);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
  }
}

/* Base Reset & Typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Modifica la sezione body::before per renderla statica */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  /* Sfondo statico invece di animato */
  background: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.15) 0%, transparent 60%);
  z-index: -1;
  /* Animazione disabilitata per migliorare le prestazioni */
  /* animation: bgPulse 10s ease-in-out infinite; */  
}

/* @keyframes bgPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
} */

/* ============================================
   NAVIGATION - Floating Glass Bar
   ============================================ */
.glass-nav {
  position: fixed;
  top: var(--space-sm);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - var(--space-lg));
  max-width: 1200px;
  height: 60px; /* Altezza fissa invece di max-height */
  min-height: 60px; /* Previene espansione */
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  padding: 0 var(--space-md); /* Rimosso padding verticale */
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--glass-shadow);
  z-index: 1000;
  transition: var(--transition-base);
  box-sizing: border-box; /* Importante */
}

/* Rimuovi o commenta la classe .scrolled che potrebbe causare problemi */
.glass-nav.scrolled {
  top: var(--space-xs);
  background: var(--glass-bg-strong);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  height: 60px; /* Mantieni altezza fissa */
  min-height: 60px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  text-decoration: none;
}

.nav-brand i {
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  gap: var(--space-xs);
  list-style: none;
}

.nav-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition-fast);
  position: relative;
}

.nav-links a:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
  transform: translateY(-2px);
}

.nav-links a.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* Tooltip */
.nav-links a::after {
  content: attr(data-tooltip);
  position: absolute;
  top: -40px; /* Cambiato da bottom a top */
  bottom: auto; /* Rimuovi bottom */
  left: 50%;
  transform: translateX(-50%) scale(0);
  background: #1e293b;
  color: #ffffff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.nav-links a:hover::after {
  transform: translateX(-50%) scale(1);
  opacity: 1;
}

/* Mobile Nav 
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Disabilita blur su mobile - troppo pesante */
  .glass-card,
  .modal-content {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(30, 41, 59, 0.95); /* Sfondo solido quasi opaco */
  }
  
  /* Navbar mobile ottimizzata */
  .glass-nav {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    bottom: var(--space-sm);
    top: auto;
    width: calc(100% - var(--space-md));
    max-width: none;
    height: 64px;
    min-height: 64px;
    padding: 0 var(--space-sm);
    border-radius: var(--radius-full);
    /* Nessun blur, solo colore solido con leggera trasparenza */
    background: rgba(30, 41, 59, 0.98);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  }
  
  .nav-links {
    gap: var(--space-xs);
  }
  
  .nav-links a {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
  
  /* Ottimizza animazioni su mobile */
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.1s !important;
  }
  
  /* Mantieni solo animazioni essenziali */
  .flash {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(30, 41, 59, 0.95);
    animation: slideInRight 0.3s ease !important;
  }
  
  /* Disabilita hover effects su touch */
  .room-card:hover,
  .item-card:hover,
  .glass-card:hover {
    transform: none !important;
  }
  
  /* Ottimizza scrolling */
  body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
  }
  
  /* Nascondi tooltip su mobile (non servono su touch) */
  .nav-links a::after {
    display: none !important;
  }
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 100px var(--space-md) var(--space-xl);
}

@media (max-width: 768px) {
  .main-container {
    padding: var(--space-md) var(--space-sm) 100px;
    /* Forza GPU acceleration */
    transform: translateZ(0);
    will-change: transform;
  }
}

/* ============================================
   GLASS CARDS
   ============================================ */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--glass-shadow);
  transition: var(--transition-base);
}

.glass-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--glass-border);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.card-title i {
  color: var(--primary);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:active::before {
  width: 300px;
  height: 300px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: var(--glass-bg-strong);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
  background: var(--primary);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #dc2626);
  color: white;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-full);
}

.btn-floating {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  font-size: 1.5rem;
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5);
  z-index: 100;
}

@media (max-width: 768px) {
  .btn-floating {
    bottom: 90px;
    right: var(--space-sm);
    width: 56px;
    height: 56px;
  }
}

/* ============================================
   FORMS & INPUTS
   ============================================ */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--glass-bg-strong);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--text-primary);
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.form-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Search Bar Special */
.search-bar {
  position: relative;
  margin-bottom: var(--space-lg);
}

.search-bar i {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.search-bar .form-input {
  padding-left: 3rem;
  font-size: 1.1rem;
  height: 60px;
}

/* ============================================
   ROOMS GRID
   ============================================ */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.room-card {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.room-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.room-header {
  padding: var(--space-md);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(6, 182, 212, 0.1));
  border-bottom: 1px solid var(--glass-border);
}

.room-title {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.room-stats {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xs);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.room-preview {
  padding: var(--space-md);
  min-height: 120px;
}

.boxes-preview {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.box-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.5rem 1rem;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  transition: var(--transition-fast);
}

.box-chip:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.05);
}

.box-chip.full {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.box-chip.full:hover {
  background: var(--danger);
  color: white;
}

.box-chip.more {
  background: transparent;
  border-style: dashed;
  color: var(--text-secondary);
}

/* ============================================
   QUICK ACTIONS
   ============================================ */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.action-card {
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  cursor: pointer;
  transition: var(--transition-base);
  text-decoration: none;
  color: inherit;
}

.action-card:hover {
  transform: translateY(-4px);
  background: var(--glass-bg-strong);
}

.action-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto var(--space-sm);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
}

.action-card h3 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.action-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============================================
   ITEMS LIST
   ============================================ */
.items-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.item-card:hover {
  background: var(--glass-bg-strong);
  transform: translateX(8px);
}

.item-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
}

.item-info h4 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.item-meta {
  display: flex;
  gap: var(--space-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.item-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.item-actions {
  display: flex;
  gap: var(--space-xs);
}

/* ============================================
   MODAL / OVERLAY
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-base);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(20px);
  transition: var(--transition-base);
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: var(--space-md);
}

.modal-footer {
  padding: var(--space-md);
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ============================================
   FLASH MESSAGES
   ============================================ */
.flash-container {
  position: fixed;
  top: 100px;
  right: var(--space-md);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: 400px;
}

.flash {
  padding: var(--space-md);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: slideInRight 0.4s ease;
}

.flash.success {
  border-left: 4px solid var(--success);
}

.flash.error {
  border-left: 4px solid var(--danger);
}

.flash.warning {
  border-left: 4px solid var(--warning);
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

.empty-state h3 {
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

/* ============================================
   UTILITIES
   ============================================ */
.text-gradient {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
}

.divider {
  height: 1px;
  background: var(--glass-border);
  margin: var(--space-md) 0;
}

/* Loading Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(99, 102, 241, 0.3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */
@media (max-width: 768px) {
  .rooms-grid {
    grid-template-columns: 1fr;
  }
  
  .item-icon {
    margin: 0 auto;
  }
  
  .item-actions {
    justify-content: center;
  }
  
  .flash-container {
    left: var(--space-sm);
    right: var(--space-sm);
    top: auto;
    bottom: 100px;
  }
}

/* Hide scrollbar but keep functionality */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.5);
}

/* ============================================
   COMPACT ITEMS LIST
   ============================================ */
.items-list-compact {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.item-row-compact {
    display: grid;
    grid-template-columns: 1fr 40px; /* Contenuto | Pulsante fisso */
    grid-template-rows: auto auto;   /* Riga nome+tag | Riga descrizione */
    gap: 0.5rem 1rem;
    align-items: start;
    padding: 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    position: relative;
}

/* Area contenuto (colonna 1) */
.item-content {
    grid-column: 1;
    grid-row: 1 / -1; /* Occupa tutte le righe */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0; /* Per text-overflow */
}

.item-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.item-row-minimal {
    grid-template-rows: auto; /* Solo una riga se minimal */
    align-items: center;
    padding: 0.75rem 1rem;
}

.item-row-compact:hover {
    background: var(--glass-bg-strong);
}

.item-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    min-width: 0; /* Importante per text-overflow */
}

.item-name {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.item-tag {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Descrizione sotto */
.item-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Pulsante elimina: sempre a destra, centrato verticalmente */
.item-delete {
    grid-column: 2;
    grid-row: 1 / -1; /* Occupa tutte le righe */
    justify-self: center;
    align-self: center;
}

.item-row-minimal .item-delete {
    position: static;
    transform: none;
}

.btn-icon-delete {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-full);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-icon-delete:hover {
    background: var(--danger);
    color: white;
}

/* Minimal: tutto su una riga */
.item-row-minimal .item-content {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.item-row-minimal .item-desc {
    display: none;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .item-row-compact {
        padding: 0.875rem;
        gap: 0.5rem 0.75rem;
    }
    
    .item-name {
        font-size: 1rem;
    }
    
    .item-tag {
        font-size: 0.7rem;
    }
    
    .item-desc {
        font-size: 0.85rem;
    }
}

/* ============================================
   VERTICAL ITEM FORM
   ============================================ */
.item-form-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(99, 102, 241, 0.05);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    border: 2px dashed transparent;
    transition: var(--transition-fast);
}

.item-form-row:focus-within {
    border-color: var(--primary-light);
    background: rgba(99, 102, 241, 0.08);
}

.form-group.required .form-label {
    color: var(--text-primary);
    font-weight: 600;
}

.form-group.optional .form-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.optional-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.form-actions .btn {
    flex: 1;
    min-width: 140px;
}

/* Desktop: form orizzontale */
@media (min-width: 769px) {
    .item-form-row {
        display: grid;
        grid-template-columns: 1.2fr 0.8fr 1fr auto;
        gap: 1rem;
        align-items: end;
    }
    
    .item-form-row .form-group {
        margin: 0;
    }
}

/* Mobile: form verticale già definito sopra */
@media (max-width: 768px) {
    .item-form-row {
        padding: 1rem;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}

/* Inventory row layout */
.inventory-row {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: 0.875rem 0.75rem;
    border-bottom: 1px solid var(--glass-border);
    transition: background 0.2s;
}

.inventory-row:hover {
    background: rgba(99, 102, 241, 0.05);
}

.inventory-row:last-child {
    border-bottom: none;
}

/* Switch toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* Responsive: mobile layout */
@media (max-width: 900px) {
    .main-container > div[style*="grid-template-columns: 1fr 350px"] {
        grid-template-columns: 1fr !important;
    }
    
    .inventory-row {
        grid-template-columns: auto 1fr auto;
    }
    
    /* Nascondi colonna categoria su mobile */
    .inventory-row > div:nth-child(3) {
        display: none;
    }
}

/* usati nei tasti alexa */
.btn-fixed {
    min-width: 100px;
    justify-content: center;
}

/* Oppure larghezza fissa */
.btn-equal {
    width: 120px;
    height: 44px;           /* Altezza fissa */
    min-height: 44px;       /* Previene espansione */
    justify-content: center;
    align-items: center;    /* Centra verticalmente */
    display: inline-flex;   /* Flex per allineamento */
    padding: 0;             /* Rimuovi padding variabile */
    box-sizing: border-box;
}

/* Recent box cards hover */
a:hover > div[style*="background: rgba(255,255,255,0.03)"] {
    background: rgba(255,255,255,0.08) !important;
    border-color: rgba(255,255,255,0.15) !important;
    transform: translateX(4px);
}

/* Recent boxes - fix contrasto e layout */
.recent-box-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.recent-box-card .icon-box {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
    /* Contrasto migliorato */
    background: {% if scatola.piena %}rgba(239,68,68,0.25){% else %}rgba(99,102,241,0.25){% endif %};
    color: {% if scatola.piena %}#fca5a5{% else %}#c7d2fe{% endif %};
    border: 1px solid {% if scatola.piena %}rgba(239,68,68,0.4){% else %}rgba(99,102,241,0.4){% endif %};
}

/* Fix scroll orizzontale su Firefox mobile */
.recent-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Assicura che le card non sforino */
.recent-grid > a {
    min-width: 0;
    max-width: 100%;
}

/* Mobile specific fix */
@media (max-width: 768px) {
    .recent-grid {
        grid-template-columns: repeat(2, calc(50% - 0.375rem));
        gap: 0.75rem;
    }
    
    .recent-box-card {
        padding: 0.75rem;
    }
    
    .recent-box-card .icon-box {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

.btn-icon-edit {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  transition: var(--transition-fast);
}

.btn-icon-edit:hover {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5);
}

/* Versione Ultra-Dark */
select.form-select[multiple] {
    background-color: #1a202c;
    color: #f7fafc;
    border: 1px solid #2d3748;
    border-radius: 0.75rem;
    padding: 0.75rem;
}

select.form-select[multiple] option {
    background-color: #1a202c;
    color: #f7fafc;
    padding: 0.6rem 1rem;
    margin: 3px 0;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

select.form-select[multiple] option:checked {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #fff !important;
}

select.form-select[multiple] option:hover {
    background-color: #2d3748 !important;
    transform: translateX(4px);
}


.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin-top: 0.5rem;
}

.tag-badge {
    background-color: #4299e1;
    color: #fff;
    font-size: 0.75rem;
    padding: 0.35em 0.75em;
    border-radius: 0.375rem;
    font-weight: 500;
}

.tag-counter {
    background-color: #4a5568;
    color: #e2e8f0;
    font-size: 0.75rem;
    padding: 0.35em 0.75em;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: help;
    transition: background-color 0.2s;
}

.tag-counter:hover {
    background-color: #63b3ed;
    color: #1a202c;
}

.no-tags {
    color: #718096;
    font-style: italic;
}

/* Container del toggle */
.tag-logic-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: help;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s;
}

.tag-logic-toggle:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Label OR/AND */
.logic-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #718096;
    transition: color 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.logic-label.active {
    color: #63b3ed;
}

/* iOS Switch */
.ios-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin: 0;
}

.ios-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #4a5568;
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: #4299e1;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Hover effect sullo slider */
.ios-switch:hover .slider {
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.3);
}
/* ============================================
   MOBILE SPECIFIC RESULT CARD LAYOUT
   ============================================ */

/* 1. Reset .item-card to be a container, moving grid layout to .desktop-layout */
.item-card {
  display: block !important; /* Override the grid display */
  padding: var(--space-md);
  /* Keep visual styles */
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  position: relative;
  overflow: hidden;
}

/* 2. Desktop Layout (Default) */
.desktop-layout {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-md);
  align-items: center;
  width: 100%;
}

/* 3. Mobile Layout (Hidden by default) */
.mobile-layout {
  display: none;
}

/* 4. Mobile Sub-cards Styling */
.mobile-subcard {
  background: rgba(255, 255, 255, 0.05); /* Slight contrast */
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* Dark mode adjustment for subcards */
@media (prefers-color-scheme: dark) {
  .mobile-subcard {
    background: rgba(0, 0, 0, 0.2);
  }
}

.mobile-subcard:last-child {
  margin-bottom: 0;
}

.item-icon.small {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
}

.subcard-row {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.9rem;
  padding: 4px 0;
}

.subcard-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 4px 0;
  opacity: 0.5;
}

.subcard-label {
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}

.subcard-content {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* 5. Media Query for Mobile View */
@media (max-width: 768px) {
  .desktop-layout {
    display: none !important;
  }
  
  .mobile-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    text-align: left; /* Ensure text is left-aligned */
  }
  
  .mobile-layout .item-icon {
    margin: 0; /* Override the margin: 0 auto from existing mobile styles */
  }

  .item-card {
    padding: var(--space-sm); /* Slightly less padding on mobile item card */
  }
}

/* ============================================
   UTILITY CLASSES (Added for Mobile Layout)
   ============================================ */
.d-flex { display: flex !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.flex-column { flex-direction: column !important; }
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.m-0 { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-secondary) !important; opacity: 0.7; }
.text-end { text-align: right !important; }
.text-start { text-align: left !important; }
.small { font-size: 0.875rem !important; }
.w-100 { width: 100% !important; }
