:root {
  /* Palette basata sul Logo FOOD */
  --bg-gradient: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  --surface-color: rgba(255, 255, 255, 0.8);
  --surface-solid: #FFFFFF;
  
  --primary-color: #2D5A27; /* Verde Bosco dal Logo */
  --primary-gradient: linear-gradient(135deg, #2D5A27, #1e3d1a);
  
  --success-color: #88B04B; /* Verde Mela dal Logo */
  --success-gradient: linear-gradient(135deg, #88B04B, #6a8a3a);
  
  --danger-color: #e53e3e;
  --danger-gradient: linear-gradient(135deg, #e53e3e, #c53030);
  
  --warning-color: #ed8936;
  --warning-gradient: linear-gradient(135deg, #ed8936, #dd6b20);
  
  --text-main: #4A4A4A; /* Grigio Antracite dal Logo */
  --text-secondary: #718096;
  --border-color: rgba(0, 0, 0, 0.08);
  
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --shadow-sm: 0 4px 12px rgba(0,0,0,0.03);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.06);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.08);
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 120px; /* Increased padding to ensure content is not hidden by nav */
  min-height: 100vh;
  overflow-x: hidden;
}

/* Typography */
h1, h2, h3 { font-weight: 700; letter-spacing: -0.5px; }
h1 { font-size: 32px; margin-bottom: 16px; }
h2 { font-size: 24px; margin-bottom: 12px; }
h3 { 
  font-size: 18px; 
  margin-bottom: 8px; 
  display: flex; 
  align-items: center; 
  gap: 8px; 
}
h3 i { color: var(--primary-color); font-size: 22px; }
p { font-size: 15px; line-height: 1.5; color: var(--text-secondary); }

/* Layout */
#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  box-shadow: 0 0 30px rgba(0,0,0,0.03);
  background: transparent;
}

header {
  padding: 30px 20px 15px;
  background: rgba(253, 251, 251, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}
header h1 { margin-bottom: 0; font-size: 28px; }
header i { font-size: 32px; color: var(--primary-color); }

.view-container {
  padding: 20px;
  display: none;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.view-container.active { display: block; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards & Surfaces */
.card {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
  /* NO transform on card:active — conflicts with button clicks inside card */
}

/* Forms & Inputs */
.form-group { margin-bottom: 20px; }
label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
input, select, textarea {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-main);
  transition: all 0.3s;
  font-family: inherit;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.01);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-solid);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.checkbox-group input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--primary-color);
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  /* Prevent double-tap zoom delay on mobile — makes taps feel instant */
  touch-action: manipulation;
  /* Minimum accessible touch target */
  min-height: 44px;
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
}
button i { font-size: 20px; }
/* No generic button:active transform — each class handles its own */

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  border-bottom: 2.5px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 3px 6px rgba(0, 122, 255, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.btn-primary:hover { 
  box-shadow: 0 5px 12px rgba(0, 122, 255, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.2); 
}
.btn-primary:active {
  box-shadow: 0 1px 2px rgba(0, 122, 255, 0.2), inset 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: translateY(1.5px) scale(0.98);
}

.btn-secondary {
  background: var(--surface-solid);
  color: var(--primary-color);
  border: 1px solid rgba(0, 122, 255, 0.25);
  border-bottom: 2.5px solid rgba(0, 122, 255, 0.35);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), inset 0 -2px 0 rgba(0, 122, 255, 0.1);
}
.btn-secondary:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08), inset 0 -2px 0 rgba(0, 122, 255, 0.1);
}
.btn-secondary:active {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02), inset 0 1px 2px rgba(0, 122, 255, 0.05);
  transform: translateY(1.5px) scale(0.98);
}

.btn-danger {
  background: var(--danger-gradient);
  color: white;
  border-bottom: 2.5px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 3px 6px rgba(255, 59, 48, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.btn-danger:hover {
  box-shadow: 0 5px 12px rgba(255, 59, 48, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}
.btn-danger:active {
  box-shadow: 0 1px 2px rgba(255, 59, 48, 0.2), inset 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: translateY(1.5px) scale(0.98);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  max-width: 600px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 12px 0 28px;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  gap: 6px;
  transition: all 0.3s;
}
.nav-item.active {
  color: var(--primary-color);
  transform: translateY(-2px);
}
.nav-item i {
  font-size: 26px;
  transition: all 0.3s;
}
.nav-item.active i {
  /* Using phosphor solid icon look if possible, or just scale */
  transform: scale(1.1);
}

/* Dashboard Widgets */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.widget {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.widget::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 4px;
}
.widget.ok::before { background: var(--success-gradient); }
.widget.alert::before { background: var(--danger-gradient); }

.widget-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  box-shadow: var(--shadow-sm);
}
.widget-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
}
.widget-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Status Colors */
.status-ok { background: rgba(52, 199, 89, 0.1); color: var(--success-color); padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; display:flex; align-items:center; gap:4px;}
.status-alert { background: rgba(255, 59, 48, 0.1); color: var(--danger-color); padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; display:flex; align-items:center; gap:4px;}
.bg-green { background: var(--success-gradient); }
.bg-red { background: var(--danger-gradient); }
.bg-blue { background: var(--primary-gradient); }
.bg-orange { background: var(--warning-gradient); }

/* Lists and Tables */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}
.list-item:last-child { border-bottom: none; }
.item-title { font-weight: 600; font-size: 16px; margin-bottom: 4px; display:flex; align-items:center; gap:6px;}
.item-subtitle { font-size: 13px; color: var(--text-secondary); display:flex; align-items:center; gap:4px; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: flex-end; /* iOS style bottom sheet */
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  overflow-y: auto; /* Allow overlay to scroll if needed */
  -webkit-overflow-scrolling: touch;
}
.modal-overlay.active { display: flex; animation: fadeInModal 0.3s; }
.modal-content {
  background: var(--surface-solid);
  width: 100%;
  max-width: 600px;
  max-height: 92vh; /* Ensure it doesn't cover the whole screen and allows scrolling */
  overflow-y: auto; /* Enable internal scrolling */
  border-radius: 24px 24px 0 0;
  padding: 30px 20px 100px; /* Extra bottom padding for mobile keyboard/scrolling */
  box-shadow: var(--shadow-lg);
  animation: slideUpModal 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

@keyframes fadeInModal {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUpModal {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Label Preview */
.label-preview {
  border: 2px dashed var(--border-color);
  padding: 24px;
  background: #fff;
  color: #000;
  border-radius: var(--radius-lg);
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
}
.label-title {
  text-align: center;
  font-weight: 900;
  font-size: 22px;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.label-ingredients {
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.6;
}
.label-qr {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  padding: 10px;
  background: #fff;
  border-radius: 12px;
}

/* Modifiche aggiunte */
.text-conforme { color: var(--success-color); font-weight: bold; }
.text-non-conforme { color: var(--danger-color); font-weight: bold; }
.btn-sm-plus { padding: 8px 12px; width: auto; flex: none; font-size: 16px; border-radius: var(--radius-sm); }
.input-lg { font-size: 16px; padding: 12px 16px; }

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-gradient);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.login-card {
  background: var(--surface-color);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 40px 30px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-logo-container {
  margin-bottom: 24px;
}

.login-logo {
  height: 60px;
  width: auto;
  object-fit: contain;
}

.login-card h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-main);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.login-form {
  text-align: left;
}

.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper i {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 20px;
  pointer-events: none;
}

.input-icon-wrapper input {
  padding-left: 48px;
}

.login-error {
  background: rgba(229, 62, 62, 0.1);
  color: var(--danger-color);
  border: 1px solid rgba(229, 62, 62, 0.2);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.login-error i {
  font-size: 18px;
}
