/* =========================================
   CORE FRAMEWORK - TRACCIAFOOD
   Tema Aurora Glassmorphism + Design System
   ========================================= */
:root {
  --bg-body: #0f172a;
  --bg-glass: rgba(255, 255, 255, 0.08);
  --color-primary: #10b981;
  --color-secondary: #3b82f6;
  --color-danger: #ef4444;
  --color-text: #f8fafc;
  --color-muted: #cbd5e1;
  --color-gray: #64748b;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-body);
  background-image:
    radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15), transparent 40%),
    radial-gradient(circle at 85% 30%, rgba(59, 130, 246, 0.15), transparent 40%),
    radial-gradient(circle at 50% 80%, rgba(236, 72, 153, 0.1), transparent 40%);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  min-height: 100vh;
  padding-bottom: 80px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.auth-form { display: contents; }

.glass-panel {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

button, .btn, h1, h2, h3 {
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.3;
}

/* =========================================================
   SCHERMATA LOGIN / REGISTRAZIONE (SFONDO CHIARO)
   ========================================================= */
.auth-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-box {
  background: #ffffff;
  color: #0f172a;
  padding: 36px 24px;
  border-radius: 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.logo { font-size: 56px; margin-bottom: 8px; }
.auth-box h1 { margin: 0; font-size: 26px; font-weight: 800; color: #0f172a; }
.sub { color: #475569; font-size: 14px; margin: 4px 0 22px; }

.auth-box label {
  display: block;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 6px;
  text-transform: uppercase;
}

#auth-screen input:not([type="hidden"]),
#auth-screen select {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 1.5px solid #94a3b8;
  border-radius: 12px;
  font-size: 16px;
  background: #f1f5f9;
  color: #0f172a;
  font-family: inherit;
}

#auth-screen input:not([type="hidden"])::placeholder {
  color: #475569;
  opacity: 1;
}

#auth-screen input:not([type="hidden"]):focus,
#auth-screen select:focus {
  outline: none;
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.btn-primary {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: #2563eb;
  color: #ffffff;
  margin-bottom: 10px;
  min-height: 48px;
}

.btn-outline {
  width: 100%;
  padding: 13px 16px;
  border: 2px solid #3b82f6;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: #3b82f6;
  margin-bottom: 10px;
  min-height: 46px;
}

.btn-danger {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: #ef4444;
  color: #ffffff;
  min-height: 46px;
}

.link {
  color: #2563eb;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: block;
  margin-top: 12px;
}

.link.link-admin {
  color: #b45309;
  font-weight: 700;
  margin-top: 18px;
}

.error {
  color: #dc2626;
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 6px;
  font-weight: 600;
}

.auth-info {
  color: #059669;
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 6px;
  font-weight: 600;
}

/* =========================================================
   HEADER APP
   ========================================================= */
.app-header {
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: calc(14px + env(safe-area-inset-top));
  border-radius: 0 0 22px 22px;
}

.header-left h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
}

.user-info-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: #cbd5e1;
}

#user-name { font-weight: 700; color: #60a5fa; }
.clock-small { font-size: 11px; color: #94a3b8; }

.status-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status-pill.is-online {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.status-pill.is-offline {
  background: rgba(245, 158, 11, 0.25);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.btn-sync {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(96, 165, 250, 0.5);
  background: rgba(59, 130, 246, 0.25);
  color: #dbeafe;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.header-right {
  text-align: right;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.btn-header-action {
  padding: 6px 11px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  min-height: 32px;
}

.btn-header-action.is-active {
  background: rgba(59, 130, 246, 0.35);
  border-color: rgba(96, 165, 250, 0.65);
}

.btn-logout {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 12px;
  cursor: pointer;
  font-weight: 700;
  padding: 5px 10px;
}

/* =========================================================
   CONTENITORE, TILE GRID, RICERCA & MULTITASKING
   ========================================================= */
.container {
  padding: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 100px;
}

.tile-grid {
  display: grid;
  gap: 14px;
  margin: 18px 0;
  padding: 6px;
}

.tile-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tile-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tile-grid.cols-3.is-trash-view {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 768px) {
  .tile-grid.cols-2 { grid-template-columns: repeat(2, 130px); justify-content: center; }
  .tile-grid.cols-3 { grid-template-columns: repeat(3, 120px); justify-content: center; }
  .tile-grid.cols-3.is-trash-view { grid-template-columns: repeat(2, 120px); }
}

.tile {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.tile-btn {
  width: 96px;
  height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 14px rgba(0, 0, 0, 0.25);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.tile-btn:active { transform: scale(0.95); }

.tile-btn.green,
.bg-green {
  background-color: rgba(16, 185, 129, 0.24);
  border-color: rgba(16, 185, 129, 0.45);
}

.tile-btn.blue,
.bg-blue {
  background-color: rgba(59, 130, 246, 0.24);
  border-color: rgba(59, 130, 246, 0.45);
}

.tile-btn.red,
.bg-red {
  background-color: rgba(244, 63, 94, 0.24);
  border-color: rgba(244, 63, 94, 0.45);
}

.tile-label {
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.tile-symbol {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: #ffffff;
}

.trash-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.trash-back-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.trash-back-arrow {
  color: #ffffff;
  font-size: 20px;
  line-height: 1;
}

.btn-empty-trash {
  padding: 10px 14px;
  border: 1px solid rgba(244, 63, 94, 0.5);
  border-radius: 12px;
  background: rgba(244, 63, 94, 0.22);
  color: #fecdd3;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Multitasking Drafts */
.drafts-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 2px 12px;
  margin-bottom: 8px;
}

.draft-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  background: rgba(59, 130, 246, 0.2);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.draft-chip.is-active {
  background: rgba(16, 185, 129, 0.28);
  border-color: rgba(16, 185, 129, 0.6);
}

.draft-chip-close {
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.search {
  width: 100%;
  padding: 14px 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  margin-bottom: 12px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.search::placeholder { color: rgba(255, 255, 255, 0.6); }
.search:focus { outline: none; border-color: #60a5fa; }

.qr-counter {
  font-size: 13px;
  color: #cbd5e1;
  margin: 0 0 12px;
}

/* =========================================================
   CARD PRODOTTO
   ========================================================= */
.card {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: 6px solid #10b981;
  border-radius: 20px;
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  color: #ffffff;
}

.card.is-pending-sync {
  border-left-color: #f59e0b;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: #ffffff;
}

.card p {
  margin: 3px 0;
  font-size: 13px;
  color: #cbd5e1;
}

.badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: #f8fafc;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.3);
  color: #fde68a;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.actions button {
  flex: 1;
  min-width: 84px;
  min-height: 44px;
  padding: 10px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
}

/* =========================================================
   MODALI & FORM SCURI GLASSMORPHISM
   ========================================================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.show { display: flex; }

.modal-box {
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 20px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease;
}

.modal-box-compact {
  max-width: 420px;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 40px;
  height: 5px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  margin: 0 auto 16px;
}

.modal-box h2 {
  margin: 0 0 16px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
}

.modal-box label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.modal-box input:not([type="checkbox"]):not([type="file"]),
.modal-box textarea,
.modal-box select {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-family: inherit;
}

.modal-box select option {
  background: #0f172a;
  color: #f8fafc;
}

.modal-box input::placeholder,
.modal-box textarea::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.modal-box input:focus,
.modal-box textarea:focus,
.modal-box select:focus {
  outline: none;
  border-color: #60a5fa;
  background: rgba(255, 255, 255, 0.14);
}

.modal-box input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

#note-text-main {
  min-height: 84px;
  resize: vertical;
}

.form-group { margin-bottom: 10px; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 8px;
  color: #f8fafc;
  font-size: 14px;
  text-transform: none;
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: #10b981;
}

.form-hint {
  color: #cbd5e1;
  font-size: 13px;
  margin: 0 0 12px;
}

.ingredient-row {
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
}

.ingredient-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: 10px;
}

.ingredient-field input {
  margin-bottom: 0;
}

.photo-box {
  display: none;
  margin: 12px 0;
  text-align: center;
}

.photo-box.is-visible { display: block; }

#photo-prev {
  max-width: 100%;
  max-height: 200px;
  border-radius: 12px;
}

.photo-actions {
  margin-top: 8px;
}

.photo-remove {
  width: auto;
  padding: 8px 14px;
}

/* Fotocamera Zero-Trace */
.camera-stage {
  position: relative;
  width: 100%;
  background: #020617;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 12px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#camera-video,
#camera-snapshot {
  width: 100%;
  max-height: 55vh;
  object-fit: cover;
  display: block;
}

#reader {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
}

#qr-box {
  text-align: center;
  background: #ffffff;
  padding: 16px;
  border-radius: 16px;
  margin: 0 auto 12px;
  width: fit-content;
}

#qr-box canvas,
#qr-box img {
  display: block;
  margin: 0 auto;
}

.qr-print-code {
  font-family: monospace;
  font-size: 13px;
  text-align: center;
  color: #cbd5e1;
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

.modal-btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.modal-btn-row button {
  flex: 1;
  min-width: 110px;
  margin-bottom: 0;
}

.modal-action { margin-top: 14px; }

.detail-section { margin: 14px 0; }
.detail-section p { color: #cbd5e1; font-size: 14px; }
.detail-section img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 12px;
}

#prod-list [id^="m-preparation-"] .modal-box {
  position: relative;
}

#prod-list [id^="m-preparation-"] .modal-box > .btn-outline {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}

/* Modale Ispezione & Audit */
.inspection-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.inspection-content {
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 12px;
}

.inspection-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 10px;
}

.inspection-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
  color: #ffffff;
}

.inspection-card p {
  margin: 2px 0;
  font-size: 13px;
  color: #cbd5e1;
}

.audit-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.audit-entry {
  padding: 10px 12px;
  border-left: 3px solid #3b82f6;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0 12px 12px 0;
  margin-bottom: 8px;
  font-size: 13px;
  color: #f8fafc;
}

.audit-meta {
  margin-top: 4px;
  color: #94a3b8;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.confirm-message {
  color: #e2e8f0;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  margin: 0 0 16px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.toast.is-success { border-color: #10b981; background: rgba(6, 78, 59, 0.95); }
.toast.is-error { border-color: #ef4444; background: rgba(127, 29, 29, 0.95); }
.toast.is-warn { border-color: #f59e0b; background: rgba(120, 53, 15, 0.95); }

@media (min-width: 768px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 24px; padding: 26px; }
  .actions { justify-content: flex-end; }
  .actions button { flex: 0 0 auto; min-width: 112px; padding: 10px 14px; }
}

@media print {
  body { background: #ffffff !important; color: #000000 !important; }
  #auth-screen, #app-screen, .toast-container, .no-print, button { display: none !important; }
  .modal { position: static; display: none !important; background: #ffffff; }
  body:not(.printing-inspection) #m-qr.show { display: block !important; }
  body.printing-inspection #m-inspection.show { display: block !important; }
  .modal-box {
    max-width: none;
    max-height: none;
    overflow: visible;
    background: #ffffff !important;
    color: #000000 !important;
    border: none;
    box-shadow: none;
  }
  .inspection-content { max-height: none; overflow: visible; }
  .inspection-card, .inspection-card h3, .inspection-card p, .audit-entry {
    color: #000000 !important;
    border-color: #cbd5e1 !important;
  }
}
