/* ============ FoodCost — design system ============ */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #221d16;
  --ink-2: #57503f;
  --muted: #94897a;
  --line: #e7e0d2;
  --line-2: #d8cfbd;
  --accent: #c14e21;
  --accent-strong: #a33f16;
  --accent-soft: #f7e4d8;
  --accent-ink: #8a3410;
  --green: #2e7d4f;
  --green-soft: #e0efe5;
  --red: #b23b3b;
  --red-soft: #f6e0e0;
  --amber: #a16207;
  --amber-soft: #f7ecd4;
  --sidebar-bg: #262019;
  --sidebar-ink: #e8e0d2;
  --sidebar-muted: #9a8d7b;
  --sidebar-active: #3a2f24;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(34,29,22,.05), 0 4px 16px rgba(34,29,22,.06);
  --shadow-lg: 0 8px 32px rgba(34,29,22,.12);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 13.5px; }
a { color: var(--accent); }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 8px 14px; z-index: 100; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; display: block; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: #fff; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .08em; }

.nav { display: flex; flex-direction: column; gap: 3px; padding: 8px 12px; flex: 1; }
.nav button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  background: transparent; border: 0; color: var(--sidebar-muted);
  padding: 10px 12px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  text-align: left; transition: background .15s, color .15s;
}
.nav button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav button:hover { background: rgba(255,255,255,.06); color: var(--sidebar-ink); }
.nav button.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-foot { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.save-state { font-size: 12px; color: var(--sidebar-muted); display: block; margin-bottom: 10px; min-height: 16px; }
.foot-actions { display: flex; gap: 8px; }

.content { flex: 1; min-width: 0; padding: 28px 32px 60px; }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .spacer, .row .spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h3, .card h4 { margin: 0 0 10px; font-size: 13px; font-family: var(--font); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; }
.card-body { padding: 16px 20px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: var(--radius-sm); padding: 8px 15px; font-size: 13px; font-weight: 600;
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--line-2); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-ghost {
  display: inline-flex; align-items: center; border: 1px solid rgba(255,255,255,.18);
  background: transparent; color: var(--sidebar-ink); border-radius: 8px;
  padding: 6px 11px; font-size: 12px; font-weight: 500; transition: background .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.1); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.nav button:focus-visible { outline-color: var(--accent); }

/* ---------- forms ---------- */
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; letter-spacing: .01em; }
input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #c9bfa8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
input::placeholder, textarea::placeholder { color: #b3a892; }
textarea { resize: vertical; min-height: 76px; line-height: 1.55; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394897a' fill='none' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 220px); border-radius: 0 0 var(--radius) var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; position: sticky; top: 0; background: var(--surface-2); z-index: 2;
  border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: #faf6ee; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .cell-input { width: 100%; min-width: 60px; }
td input.cell-input { padding: 5px 8px; font-size: 12.5px; }
tr.clickable { cursor: pointer; }
tr.clickable.archived { opacity: .5; }
tr.section td { background: #f0eadd; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }

/* ---------- badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2.5px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.ghost { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.kv { display: flex; gap: 8px; font-size: 13px; padding: 4px 0; align-items: baseline; }
.kv b { min-width: 150px; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kv span { font-variant-numeric: tabular-nums; }

.channel-tabs { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.channel-tabs button {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.channel-tabs button.active { background: var(--ink); color: #fff; }

/* component rows */
.comp-card {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
  margin-bottom: 8px; background: var(--surface-2);
}
.comp-row { display: grid; grid-template-columns: minmax(0,2.4fr) 86px 64px minmax(0,1.3fr) auto auto; gap: 8px; align-items: center; }
.comp-row .ckg { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quickadd {
  display: flex; gap: 8px; padding: 12px; border: 1.5px dashed var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface-2); margin-bottom: 12px;
}
.quickadd:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.quickadd input:first-child { flex: 1; }

/* product list cards */
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.prod-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s;
  box-shadow: var(--shadow);
}
.prod-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.prod-card .pc-code { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: .06em; }
.prod-card .pc-name { font-family: var(--font-display); font-size: 16px; font-weight: 600; margin: 2px 0 6px; }
.prod-card .pc-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.prod-card .pc-foot { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.prod-card.archived { opacity: .55; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty .e-ico { font-size: 34px; margin-bottom: 10px; opacity: .5; }
.empty p { margin: 4px 0; }

#toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 36px 32px; width: 100%; max-width: 380px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 28px; margin: 12px 0 4px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; text-align: left; }
.login-err { color: var(--red); font-size: 13px; margin: 10px 0 0; }
/* ---------- allergen chips ---------- */
.allergen-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.allergen-chips .chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border: 1px solid var(--line-2); border-radius: 999px; padding: 4px 11px;
  font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface-2);
  transition: all .12s; user-select: none;
}
.allergen-chips .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.allergen-chips .chip:hover { border-color: var(--accent); }

/* ---------- scheda tecnica stampabile ---------- */
.scheda-sheet {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 34px 40px; max-width: 800px; margin: 0 auto; box-shadow: var(--shadow);
}
.scheda-head { display: flex; align-items: center; gap: 14px; border-bottom: 3px solid var(--accent); padding-bottom: 16px; margin-bottom: 18px; }
.scheda-title { font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .02em; }
.scheda-sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.scheda-meta { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.scheda-meta th { text-align: left; width: 170px; padding: 7px 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line); font-weight: 600; vertical-align: top; }
.scheda-meta td { padding: 7px 10px; font-size: 14px; border-bottom: 1px solid var(--line); }
.scheda-sheet h4 { margin: 18px 0 8px; font-size: 13px; font-family: var(--font); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.scheda-allergens { display: flex; flex-wrap: wrap; gap: 6px; }
.scheda-allergens span { border-radius: 7px; padding: 4px 10px; font-size: 12px; font-weight: 600; }
.scheda-allergens .al-on { background: #fde8e8; color: var(--red); border: 1px solid #f0c9c9; }
.scheda-allergens .al-off { background: var(--surface-2); color: #b8ad99; border: 1px solid var(--line); }
.scheda-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; margin: 0; }
.scheda-foot { margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line-2); font-size: 12.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }

@media print {
  .sidebar, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .scheda-sheet { box-shadow: none; border: 0; border-radius: 0; max-width: none; padding: 10mm; }
  .scheda-allergens .al-off { border-color: #ccc; color: #888; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.loading::after { content: ''; display: block; width: 26px; height: 26px; margin: 14px auto 0; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.filterbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filterbar input, .filterbar select { width: auto; }

.section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; gap: 10px; }
  .brand { padding: 0; }
  .brand-sub, .sidebar-foot { display: none; }
  .nav { flex-direction: row; padding: 0; overflow-x: auto; }
  .nav button { width: auto; white-space: nowrap; padding: 8px 10px; }
  .content { padding: 18px 14px 60px; }
  .comp-row { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
