:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #1d4ed8;
  --border: #e5e7eb;
}

body {
  margin: 0;
  font-family: system-ui;
  background: var(--bg);
  color: var(--text);
}

/* Per nascondere i campi de-commentare la riga sotto */
.optional-section { 
    /* display: none; */ 
}

/* TOPBAR */
.topbar {
  height: 56px;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
}

/* LAYOUT */
.layout {
  display: flex;
}

/* SIDEBAR */
.sidebar {
  width: 280px; /* Aumentata leggermente per ospitare il padding */
  background: #eef2ff;
  border-right: 2px solid #e5e7eb;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem; /* 2rem sopra/sotto, 1.5rem destra/sinistra */
  box-sizing: border-box; /* FONDAMENTALE: include il padding nei 280px */
}


.sidebar-nav {
  margin-top: auto;
  padding: 20px;
  display: flex;
  gap: 10px;
}

.sidebar-nav .btn {
  width: 100%;
}

.step {
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.step:hover {
  background: #2ecc71;
  color: #000;
  font-weight: 600;
}

.step.active {
  background: white;
  font-weight: 600;
  color: var(--primary);
}

/* MAIN */
.main {
flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* Evita che le card si allunghino al 100% */
}

.main-content {
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Allinea le card a sinistra */
}

/* CARD */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  max-width: 850px; /* Larghezza ottimale per l'occhio */
  margin-left: auto; 
  margin-right: auto;
  width: 100%;
}

.step.completed {
  background: #2ecc71;
  color: #000;
  font-weight: 600;
}

.step.active.completed {
  border-left: 4px solid #15803d;
}

h2 {
  margin-top: 0;
}

/* INPUT */
input, textarea {
  width: 100%;
  padding: 10px;
  margin: 6px 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

input.error, textarea.error {
  border-color: #ef4444;
  background-color: #fee2e2;
}

/* ERROR MESSAGES */
.error-messages {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: white;
  border-bottom: 2px solid #ef4444;
  padding: 16px;
  color: #dc2626;
  font-weight: 600;
  font-size: 14px;
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

.error-messages.show {
  display: block;
}

.error-messages div {
  padding: 8px 0;
}

/* GRID */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.grid-nutrizione {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  align-items: end; /* Allinea i contenitori alla base */
}

.grid-nutrizione .field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* Spinge l'input verso il basso */
  height: 100%;
}

.grid-nutrizione label {
  margin-bottom: 8px;
  min-height: 3em; /* Forza una altezza minima per contenere 2 righe di testo */
  display: flex;
  align-items: flex-end; /* Allinea il testo della label alla base */
  line-height: 1.2;
}

.grid-nutrizione input {
  width: 100%;
  box-sizing: border-box; /* Cruciale per il padding */
}

.field {
  display: flex;
  flex-direction: column;
}

.field input {
  width: 100%;
  padding: 8px;
}

.dim-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px 0 14px;
}

h3 {
  margin-top: 20px;
  color: var(--muted);
  font-size: 14px;
}

.smartbar {
  position: fixed;
  top: 56px;
  right: 0;
  background: white;
  padding: 8px 12px;
  font-size: 12px;
  border-left: 1px solid #e5e7eb;
  z-index: 999;
}

input[readonly] {
  background: #f3f4f6;
  color: #374151;
}

.footer-actions {
  position: fixed;
  bottom: 0;
  left: 240px; /* Deve corrispondere esattamente alla larghezza della sidebar */
  right: 0;
  
  /* Glassmorphism: sfondo leggermente trasparente che sfoca quello che c'è sotto */
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  
  border-top: 1px solid rgba(229, 231, 235, 0.5);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 15px;
  padding: 15px 30px; /* Più respiro ai lati */
  z-index: 1000;
  
  /* Ombra discreta per dare profondità */
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Stile per il bottone Esporta per renderlo più elegante */
.footer-actions button.primary {
  background-color: #2563eb;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9em;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-actions button.primary:hover {
  background-color: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.footer-actions button.secondary {
  background-color: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9em;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-actions button.secondary:hover {
  background-color: #e5e7eb;
}

/*Pulisci modulo*/
.footer-actions button.btn-danger {
  background-color: #fff1f2;
  color: #e11d48;
  border: 1px solid #fda4af;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9em;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-actions button.btn-danger:hover {
  background-color: #ffe4e6;
  border-color: #f43f5e;
}

/* IMPORTANTE: aggiungi un margine al fondo della pagina per non coprire i campi */
main, .container {
  padding-bottom: 80px; 
}

button.primary {
  background: #1d4ed8;
  color: white;
  border: none;
}

.nav-footer {
  background: white;
  padding: 30px 20px;
  border-top: 2px solid #eee;

  display: flex;
  flex-direction: column;
  align-items: center;

  justify-content: center;
  gap: 20px;
}

/* BOTTONI NAV */
.nav-buttons {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  max-width: 600px;
  margin: 0 auto;
}

.btn {
  padding: 16px 10px;
  font-size: 16px;
  font-weight: 800;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* secondari (avanti/indietro) */
.btn.secondary {
  background: #222;
  color: white;
}

.btn.secondary:hover {
  background: #2ecc71;
  color: black;
}

/* submit */
.btn.primary {
  background: white;
  color: black;
  border: 2px solid #ccc;
  font-size: 20px;
  padding: 18px 40px;
  width: 320px;
}

.btn.primary.ready {
  background: #22c55e;
  color: white;
}

.btn.primary:hover {
  background: #2ecc71;
  color: black;
}

.btn.primary.error {
  background: #ef4444;
  cursor: not-allowed;
}

.btn.primary.error:hover {
  background: #dc2626;
  color: white;
}

/* nascondi */
.hidden {
  display: none;
}

.form-navigation {
  display: flex;
  justify-content: space-between; /* uno a sinistra, uno a destra */
  gap: 10px;
  padding-top: 10px;
  margin-top: 20px;
}

.form-navigation button {
  flex: 1;
  min-width: 120px;
}

.upload-progress {
  transition: width 0.1s linear;
}

/* PROGRESS BAR */
.progress-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  z-index: 2000;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: #2ecc71;
  transition: width 0.3s ease;
}

/* OVERLAY INVIO */
.submit-overlay {
  position: fixed;
  top:0; left:0; width:100%; height:100%;
  background: rgba(0,0,0,0.5);
  display:flex; align-items:center; justify-content:center;
  z-index: 9999;
}

.submit-overlay.hidden { display: none; }

.submit-box {
  background:#fff;
  padding:20px 30px;
  border-radius:10px;
  text-align:center;
  width:300px;
}

.submit-bar {
  width:100%;
  height:10px;
  background:#eee;
  border-radius:5px;
  margin-top:15px;
  overflow:hidden;
}

.submit-progress {
  width:0;
  height:100%;
  background:#16a34a;
  transition: width 0.3s linear;
}

/* PREVIEW TABLE */
.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  font-size: 14px;
}

.preview-table th, .preview-table td {
  border: 1px solid var(--border);
  padding: 12px;
  text-align: left;
}

.preview-table th {
  background: #f3f4f6;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
}

.preview-table tr:nth-child(even) {
  background: #fafafa;
}

/* ERROR TEXT */
/* Messaggio di errore sotto l'input */
.error-text {
  color: #dc2626;
  font-size: 0.75rem;
  margin-top: 4px;
  display: none; /* Nascosto di default */
}

/* Campo evidenziato in rosso */
input.invalid {
  border-color: #dc2626 !important;
  background-color: #fef2f2;
}

/* Classe per mostrare il messaggio */
.error-text.visible {
  display: block;
}

/* Stile per i campi obbligatori mancanti */
.error-highlight, .invalid {
    border: 2px solid #ff4d4d !important;
    background-color: #fff2f2 !important;
    transition: all 0.3s ease;
}

/* Opzionale: aggiungi un'animazione di "scuotimento" per attirare l'attenzione */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.invalid {
    animation: shake 0.2s ease-in-out 0s 2;
}


/*Assistente AI*/
/* Sidebar per l'assistente */
.ai-assistant-sidebar {
  position: fixed;
  right: -350px; /* Nascosta di default */
  top: 0;
  width: 350px;
  height: 100%;
  background: white;
  box-shadow: -2px 0 10px rgba(0,0,0,0.1);
  transition: right 0.3s ease;
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.ai-assistant-sidebar.open {
  right: 0;
}

.toggle-assistant {
  position: fixed;
  right: 20px;
  top: 20px;
  z-index: 2001;
  background: #10a37f; /* Colore ChatGPT */
  color: white;
  border: none;
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
}

<!-- INVIO DATI EXCEL -->
.btn-smart-import {
    background: #007bff;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: bold;
    cursor: pointer;
    margin-right: 15px; /* Distanza dall'autosave */
    transition: background 0.2s;
}

.btn-smart-import:hover {
    background: #0056b3;
}

/* Overlay scuro */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

/* Contenitore modale */
.modal-content {
  background: white;
  padding: 25px;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-content textarea {
  width: 100%;
  height: 100px;
  margin: 15px 0;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.9em;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
