:root {
  --ink: #12343b;
  --ink-soft: #2d545e;
  --accent: #e2703a;
  --paper: #f4f1ea;
  --card: #ffffff;
  --line: #e2ddd2;
  --muted: #6d7a7d;
  --ok: #2e7d5b;
  --warn: #b7791f;
  --danger: #b3402e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: #1d2a2d;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h3 { margin: 22px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
small { display: block; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }

input, select, textarea, button { font: inherit; color: inherit; }

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink-soft); outline-offset: 1px; }

label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: #1d2a2d; font-size: 16px; }

/* ----- barra e contenitori ----- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 54px;
  padding: env(safe-area-inset-top) 8px 0;
  background: var(--ink);
  color: #fff;
}

.bar h1 { flex: 1; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btn { width: 40px; height: 44px; display: grid; place-items: center; font-size: 30px; line-height: 1; }
.bar-action { padding-right: 6px; }
.bar-link { padding: 8px 10px; font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 14px 14px 40px; }
main.detail { max-width: 720px; display: flex; flex-direction: column; gap: 14px; }

.toolbar { position: sticky; top: 54px; z-index: 4; padding: 10px 14px; background: var(--paper); border-bottom: 1px solid var(--line); }
.toolbar > * { max-width: 1072px; margin-inline: auto; }

/* ----- pulsanti ----- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.btn.big { width: 100%; padding: 15px 18px; background: var(--accent); font-size: 17px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink-soft); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; }
.link { border: 0; background: none; color: var(--ink); text-decoration: underline; cursor: pointer; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  background: #e8e4da;
  color: #4a5355;
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  white-space: nowrap;
}

.badge.s-da_inviare { background: #fbe9c8; color: var(--warn); }
.badge.s-inviato { background: #d7efe3; color: var(--ok); }

/* ----- login ----- */

.login { max-width: 380px; padding-top: 12vh; text-align: center; }
.login img { border-radius: 20px; }
.login h1 { margin: 14px 0 6px; font-size: 26px; color: var(--ink); }
.login form { display: grid; gap: 14px; margin-top: 24px; text-align: left; }

/* ----- home ----- */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.tile {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  min-height: 132px;
  padding: 16px;
  border-radius: var(--radius);
  color: #fff;
}

.tile b { font-size: 22px; font-weight: 600; }
.tile span { font-size: 13px; opacity: .85; }
.t1 { background: var(--ink); }
.t2 { background: var(--ink-soft); }
.t3 { background: var(--accent); }
.t4 { background: #7a6a53; }

.resume {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: #fff;
}

.home-foot { display: flex; justify-content: space-between; margin-top: 22px; color: var(--muted); font-size: 14px; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile { min-height: 170px; }
}

/* ----- catalogo ----- */

.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chips.sub .chip.on { background: var(--ink-soft); border-color: var(--ink-soft); }

.order-bar {
  position: sticky;
  bottom: 0;
  z-index: 6;
  order: 99;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px calc(13px + env(safe-area-inset-bottom));
  background: var(--accent);
  color: #fff;
}

#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
#app > main { flex: 1; width: 100%; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }

.card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

.card.in-order { border-color: var(--accent); }
.card-img { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #f3f1ec; }
.card-img img, .product-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.noimg { width: 100%; height: 100%; display: grid; place-items: center; background: #ebe7dd; color: #b3ab99; font-size: 44px; font-weight: 700; }
.card-name { font-weight: 600; font-size: 14.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card-code { color: var(--muted); font-size: 12px; }
.card-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-top: auto; padding-top: 4px; }
.stock { color: var(--ok); font-size: 12px; white-space: nowrap; }
.stock.out { color: var(--danger); }
.more { display: flex; justify-content: center; margin-top: 18px; }
.empty { grid-column: 1 / -1; padding: 40px 10px; text-align: center; color: var(--muted); }

.stepper { display: flex; align-items: center; gap: 6px; margin-top: 6px; }

.stepper button {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.stepper input { min-width: 0; padding: 8px 4px; text-align: center; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ----- scheda articolo ----- */

.product { display: grid; gap: 18px; }
.product-img { aspect-ratio: 1; max-height: 62vh; border-radius: var(--radius); overflow: hidden; background: #fff; }
.product-body { display: flex; flex-direction: column; gap: 8px; }
.product-body h2 { font-size: 22px; }
.product-body .stepper { max-width: 220px; }
.price { font-size: 26px; font-weight: 700; color: var(--ink); }
.price small { display: inline; font-weight: 400; }
.description { white-space: pre-line; }

@media (min-width: 720px) {
  .product { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ----- elenchi e dettagli ----- */

.list { display: flex; flex-direction: column; border-radius: var(--radius); background: var(--card); overflow: hidden; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.panel { padding: 14px; border-radius: var(--radius); background: var(--card); }
.data { margin: 0; padding: 4px 14px; border-radius: var(--radius); background: var(--card); }
.data > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.data > div:last-child { border-bottom: 0; }
.data dt { color: var(--muted); font-size: 14px; }
.data dd { margin: 0; text-align: right; }
.data dd a { color: var(--ink); text-decoration: underline; }

.stat { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }

.form { display: grid; gap: 12px; }
.cols { display: grid; grid-template-columns: 1fr 2fr 80px; gap: 10px; }

/* ----- ordine ----- */

.lines { display: flex; flex-direction: column; gap: 8px; }

.line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--card);
}

.line-name { grid-column: 1 / -1; }
.line .stepper { margin: 0; max-width: 170px; }
.line .disc { display: flex; align-items: center; gap: 6px; }
.line .disc input { width: 70px; margin: 0; padding: 8px 6px; text-align: center; }
.line-total { grid-column: 1 / -1; text-align: right; }

@media (min-width: 560px) {
  .line { grid-template-columns: 1fr auto auto 100px; }
  .line-name, .line-total { grid-column: auto; }
}

.totals > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 20px; color: var(--ink); }

.sign { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: var(--radius); background: #fff; }
.sign img { height: 64px; max-width: 60%; object-fit: contain; }
.actions { display: grid; gap: 10px; }

/* ----- firma e avvisi ----- */

dialog { width: min(640px, calc(100vw - 24px)); padding: 16px; border: 0; border-radius: 16px; }
dialog::backdrop { background: rgba(10, 25, 28, .55); }
.signature { display: grid; gap: 12px; }
.signature h2 { font-size: 18px; }
#signature-canvas { width: 100%; height: 240px; border: 1px dashed #9aa5a7; border-radius: 10px; background: #fff; touch-action: none; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 10px;
  background: #1d2a2d;
  color: #fff;
  font-size: 15px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }
