/* ─── Variables ─── */
:root {
  --color-primary:    #E63946;
  --color-primary-dk: #C0303C;
  --color-bg:         #F4F4F5;
  --color-surface:    #FFFFFF;
  --color-border:     #E4E4E7;
  --color-text:       #18181B;
  --color-text-muted: #71717A;
  --color-success:    #22C55E;
  --color-warning:    #F59E0B;
  --color-danger:     #EF4444;
  --sidebar-width:    240px;
  --header-height:    56px;
  --radius:           8px;
  --radius-sm:        6px;
  --shadow:           0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --transition:       0.15s ease;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: Inter, system-ui, sans-serif; background: var(--color-bg); color: var(--color-text); -webkit-font-smoothing: antialiased; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ─── Login Screen ─── */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-bg);
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.login-logo { font-size: 24px; font-weight: 800; color: var(--color-primary); text-align: center; }
.login-subtitle { text-align: center; font-size: 14px; color: var(--color-text-muted); margin-top: -12px; }
.login-error {
  background: #FEE2E2;
  color: #B91C1C;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.login-error.visible { display: block; }

/* ─── App Shell ─── */
#app-shell {
  display: none;
  min-height: 100dvh;
}
#app-shell.visible { display: flex; flex-direction: column; }

/* ─── Top Header ─── */
.admin-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.admin-header-logo { font-size: 16px; font-weight: 700; color: var(--color-primary); }
.admin-header-spacer { flex: 1; }

/* ─── Layout ─── */
.admin-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ─── Sidebar ─── */
.admin-sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  flex-shrink: 0;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
  width: 100%;
  text-align: left;
  transition: all var(--transition);
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--color-bg); color: var(--color-text); }
.nav-link.active { background: #FEE2E2; color: var(--color-primary); font-weight: 600; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  padding: 8px 12px 4px;
}

/* ─── Main Content ─── */
.admin-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  min-width: 0;
}

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dk); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-border); }
.btn-danger { background: #FEE2E2; color: var(--color-danger); }
.btn-danger:hover { background: #FECACA; }
.btn-ghost { background: none; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-bg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 6px; }

/* ─── Form Elements ─── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--color-text); }
.form-label.required::after { content: ' *'; color: var(--color-danger); }
.form-hint { font-size: 12px; color: var(--color-text-muted); }

.input, .textarea, .select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition);
  outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--color-primary); }
.textarea { resize: vertical; min-height: 80px; }

/* ─── Tabs (multilingua) ─── */
.lang-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--color-border); margin-bottom: 12px; }
.lang-tab {
  padding: 7px 14px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-transform: uppercase;
}
.lang-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ─── Tipo pills (sezioni speciali) ─── */
.tipo-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.tipo-pill {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
  text-transform: capitalize;
  transition: all var(--transition);
}
.tipo-pill.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ─── Toggle ─── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 12px;
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--color-primary); }
.toggle input:checked + .toggle-slider::after { transform: translateX(18px); }
.toggle-label { font-size: 14px; font-weight: 500; }

/* ─── Menu Tree ad Accordeon (Mobile First) ─── */
.tree { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; }

/* Nodo Macro */
.macro-node {
  background: var(--color-surface);
  border-radius: 12px;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.macro-node:hover { box-shadow: 0 8px 16px rgba(0,0,0,0.06); }
.macro-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--color-surface);
  cursor: grab;
}
.macro-header:active { cursor: grabbing; }
.macro-header.dragging { opacity: 0.4; background: #fafafa; }
.macro-toggle { background: none; border: none; color: var(--color-text-muted); padding: 8px; margin: -8px; }
.macro-toggle svg { width: 20px; height: 20px; transition: transform var(--transition); }
.macro-toggle.open svg { transform: rotate(90deg); }
.macro-name { flex: 1; font-size: 16px; font-weight: 700; }
.macro-actions { display: flex; gap: 6px; }

/* Nodo Categoria */
.cat-list { padding: 4px 16px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.cat-node {
  background: var(--color-bg);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
  cursor: grab;
}
.cat-node:active { cursor: grabbing; }
.cat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.cat-toggle { background: none; border: none; color: var(--color-text-muted); padding: 8px; margin: -8px; }
.cat-toggle svg { width: 18px; height: 18px; transition: transform var(--transition); }
.cat-toggle.open svg { transform: rotate(90deg); }
.cat-name { flex: 1; font-size: 15px; font-weight: 600; color: var(--color-text); }
.cat-actions { display: flex; gap: 6px; }

/* Nodo Voce Singola */
.voce-list { padding: 4px 12px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.voce-node {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  cursor: grab;
  transition: all var(--transition);
}
.voce-node:active { cursor: grabbing; background: #fafafa; }
.voce-node.drag-over { border-color: var(--color-primary); background: #FEF2F2; transform: scale(1.02); }
.voce-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-bg);
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.05);
}
.voce-name { flex: 1; font-size: 14px; font-weight: 600; min-width: 0; }
.voce-name-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voce-price { font-size: 15px; font-weight: 700; color: var(--color-primary); white-space: nowrap; margin-right: 6px; }
.voce-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Touch-friendly buttons for UI icons */
.btn-icon { padding: 10px; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon svg { width: 22px; height: 22px; }

.inactive-label { opacity: 0.45; text-decoration: line-through; }

/* ─── Image Upload Zone ─── */
.upload-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--color-text-muted);
  font-size: 14px;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--color-primary); background: #FEF2F2; }
.upload-zone svg { width: 32px; height: 32px; opacity: 0.5; }

.image-previews {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.image-preview {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-bg);
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ─── Allergen / Caratteristica Checkboxes ─── */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  user-select: none;
}
.check-item input { display: none; }
.check-item.checked { background: #FEE2E2; border-color: var(--color-primary); color: var(--color-primary); }
.check-dot {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1.5px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.check-item.checked .check-dot { background: var(--color-primary); border-color: var(--color-primary); }
.check-dot::after { content: ''; display: none; }
.check-item.checked .check-dot::after {
  display: block;
  width: 4px;
  height: 8px;
  border: 2px solid #fff;
  border-left: none;
  border-top: none;
  transform: rotate(45deg) translateY(-1px);
}

/* ─── Modal ─── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
#modal-overlay.open { display: flex; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ─── Card ─── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

/* ─── Table ─── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--color-text-muted); border-bottom: 1px solid var(--color-border); }
td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--color-bg); }

/* ─── Toast ─── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #18181B;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  transition: transform 0.3s ease;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  text-overflow: ellipsis;
  overflow: hidden;
}
#toast.visible { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--color-danger); }
#toast.success { background: var(--color-success); }

/* ─── Varianti Prezzo ─── */
.varianti-list { display: flex; flex-direction: column; gap: 8px; }
.variante-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.variante-row .input { flex: 1; }
.variante-row .input-price { width: 90px; flex: none; }

/* ─── Sezione config logo ─── */
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.logo-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.logo-preview {
  width: 100%;
  height: 80px;
  object-fit: contain;
  background: #F4F4F5;
  border-radius: var(--radius-sm);
}
.logo-label { font-size: 13px; font-weight: 600; }

/* ─── Responsive & Mobile App Shell ─── */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
  .mobile-only { display: inline-flex !important; }

  /* Overlay offcanvas */
  .mobile-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 90;
    opacity: 0; visibility: hidden; transition: all 0.2s;
  }
  .mobile-overlay.open { opacity: 1; visibility: visible; }

  /* Sidebar sidebar offcanvas */
  .admin-sidebar {
    position: fixed;
    top: var(--header-height); left: 0; bottom: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.33, 1, 0.68, 1);
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
  }
  .admin-sidebar.mobile-open { transform: translateX(0); }

  .admin-main { padding: 12px; }

  /* Voce mobile wrap: prezzo in basso */
  .voce-node { flex-wrap: wrap; }
  .voce-name { min-width: 100%; flex-basis: 100%; order: -1; }
  .voce-thumb { order: -2; }
  .voce-actions { margin-left: auto; }
}
