/* ================================================================
   Gestionale Zen — stylesheet mobile-first (nessuna dipendenza esterna)
   Breakpoint: mobile (default) · tablet ≥768px · desktop ≥1024px
   ================================================================ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6ea;
  --text: #1f2733;
  --text-muted: #6b7684;
  --primary: #2f6fed;
  --primary-dark: #2258c7;
  --primary-soft: #e8f0fe;
  --green: #1f9d55;
  --green-soft: #e3f5ec;
  --amber: #c77700;
  --amber-soft: #fcf1dd;
  --red: #d64545;
  --red-soft: #fbe6e6;
  --purple: #7c4dff;
  --purple-soft: #efe9ff;
  --gray-soft: #eceef1;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
  --nav-h: 60px;
  --sidebar-w: 232px;
  --tap: 44px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
img { max-width: 100%; }

/* ---------- Layout guscio ---------- */
.app { min-height: 100vh; }
.sidebar { display: none; }
.main {
  padding: 1rem;
  padding-bottom: calc(var(--nav-h) + 1.5rem); /* spazio per bottom nav mobile */
  max-width: 1200px;
  margin: 0 auto;
}
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .6rem 1rem;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.topbar .brand span { color: var(--primary); }
.topbar .spacer { flex: 1; }
.topbar .scan-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  background: var(--primary-soft); color: var(--primary);
  border-radius: 50%; font-size: 1.3rem;
}

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-muted); font-size: .68rem; text-decoration: none;
  min-height: var(--tap);
}
.bottom-nav a .ic { font-size: 1.25rem; line-height: 1; }
.bottom-nav a.active { color: var(--primary); font-weight: 600; }

/* ---------- Sidebar / topbar visibility ---------- */
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    background: var(--surface); border-right: 1px solid var(--border);
    padding: 1rem .75rem;
  }
  .sidebar .brand { font-weight: 800; font-size: 1.2rem; padding: .5rem .5rem 1rem; }
  .sidebar .brand span { color: var(--primary); }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .6rem .7rem; border-radius: var(--radius-sm);
    color: var(--text); font-weight: 500; text-decoration: none;
  }
  .sidebar nav a .ic { font-size: 1.2rem; width: 1.4rem; text-align: center; }
  .sidebar nav a:hover { background: var(--surface-2); }
  .sidebar nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
  .sidebar .side-foot { margin-top: auto; font-size: .8rem; color: var(--text-muted); padding: .5rem; }
  .bottom-nav { display: none; }
  .topbar { display: none; }
  .main { padding: 1.5rem 2rem; padding-bottom: 3rem; }
}

/* ---------- Page header ---------- */
.page-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: .75rem;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }

/* ---------- Cards & panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: 1rem;
}
.card h2 { margin-top: 0; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .55rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: .95rem; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 34px; padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-block; padding: .2rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-gray { background: var(--gray-soft); color: var(--text-muted); }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .15rem .5rem; border-radius: 999px; font-size: .78rem; color: var(--text-muted);
}

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
label { font-weight: 600; font-size: .88rem; }
label .req { color: var(--red); }
input[type=text], input[type=number], input[type=password], input[type=date],
input[type=search], input[type=url], input[type=file], select, textarea {
  width: 100%; padding: .6rem .7rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 90px; resize: vertical; }
.help { font-size: .78rem; color: var(--text-muted); }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; min-height: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* ---------- Tables → cards on mobile ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
table.data tbody tr:hover { background: var(--surface-2); }

/* ---------- Product / list grid ---------- */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
@media (min-width: 768px) { .grid-cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
.p-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.p-card .sel-box { z-index: 2; background: rgba(255,255,255,.85); border-radius: var(--radius-sm); }
.p-card.selected { outline: 3px solid var(--primary); }
.p-card:hover { box-shadow: var(--shadow-lg); text-decoration: none; }
.p-card .thumb {
  aspect-ratio: 1 / 1; background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  overflow: hidden; color: var(--text-muted); font-size: 2rem;
}
.p-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.p-card .body { padding: .6rem .7rem; display: flex; flex-direction: column; gap: .25rem; }
.p-card .code { font-size: .72rem; color: var(--text-muted); font-family: ui-monospace, monospace; }
.p-card .name { font-weight: 600; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.p-card .price { font-weight: 700; }

/* list rows (alternate compact list) */
.list-rows { display: flex; flex-direction: column; gap: .5rem; }
.list-row {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .6rem .75rem; box-shadow: var(--shadow);
}
.list-row .thumb { width: 48px; height: 48px; border-radius: var(--radius-sm); background: var(--surface-2); flex: none; overflow: hidden; display:flex; align-items:center; justify-content:center; }
.list-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .grow .meta { font-size: .8rem; color: var(--text-muted); }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem; box-shadow: var(--shadow);
}
.stat .label { font-size: .78rem; color: var(--text-muted); }
.stat .value { font-size: 1.4rem; font-weight: 800; margin-top: .2rem; }
.stat .value.pos { color: var(--green); }
.stat .value.neg { color: var(--red); }

/* ---------- Filters bar ---------- */
.filters { display: grid; grid-template-columns: 1fr; gap: .6rem; }
@media (min-width: 768px) { .filters { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .filters { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Flash / toast ---------- */
.flash-wrap { position: fixed; top: .75rem; left: 50%; transform: translateX(-50%); z-index: 90; width: min(92%, 480px); display: flex; flex-direction: column; gap: .5rem; }
.flash {
  padding: .7rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-size: .9rem; display: flex; gap: .5rem; align-items: center;
}
.flash.success { background: var(--green-soft); color: var(--green); border: 1px solid #bfe6cf; }
.flash.error { background: var(--red-soft); color: var(--red); border: 1px solid #f2c2c2; }
.flash.info { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Misc ---------- */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.stack > * + * { margin-top: .75rem; }
.inline { display: inline; }
.hidden { display: none !important; }
.dl { display: grid; grid-template-columns: minmax(90px, 30%) 1fr; gap: .4rem .8rem; }
.dl dt { color: var(--text-muted); font-size: .85rem; }
.dl dd { margin: 0; font-weight: 500; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: .5rem; }
.gallery .ph { position: relative; aspect-ratio: 1/1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.gallery .ph img { width: 100%; height: 100%; object-fit: cover; }
.gallery .ph.primary { outline: 2px solid var(--primary); }
.gallery .ph .actions { position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; background: rgba(0,0,0,.45); padding: 2px 4px; }
.gallery .ph .actions button { background: none; border: none; color: #fff; font-size: .7rem; cursor: pointer; }
.pagination { display: flex; gap: .4rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span { padding: .4rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
.copybox { display: flex; flex-direction: column; gap: .5rem; }
.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 1.2rem; border-left: 1px dashed var(--border); margin: .3rem 0; }
.tree li { padding: .2rem 0; }
.tag-input-hint { font-size: .78rem; color: var(--text-muted); }
.bar-chart { display: flex; flex-direction: column; gap: .4rem; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: .5rem; font-size: .85rem; }
.bar-row .bar { height: 14px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; }
.bar-row .bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
canvas { max-width: 100%; }
.scanner-video { width: 100%; max-width: 480px; border-radius: var(--radius); background: #000; aspect-ratio: 4/3; object-fit: cover; margin: 0 auto; display: block; }
