/* Griglia desktop: colonna 1100 = lavoro 708 + spazio 12 + scontrino 380. */
:root {
  --ground: #f0f5f4;
  --surface: #ffffff;
  --raised: #eeeeee;
  --border: #e6e6e6;
  --rule: #f0f0f0;
  --control: #d4d4d4;
  --text: #0a0a0a;
  --muted: #666666;
  --primary: #0f6e66;
  --primary-hover: #0b5a53;
  --soft: #dcf0ed;
  --soft-hover: #c8e6e1;
  --soft-ink: #0b5a53;
  --positive: #2e7d32;
  --negative: #c4242a;
  --radius-card: 8px;
  --radius-control: 6px;
  --gap: 12px;
  --margin: 16px;
  --target: 44px;
  --fs-kpi: 28px;
  --fs-section: 16px;
  --fs-body: 15px;
  --fs-small: 13px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/1.4 "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, p, ul { margin: 0; padding: 0; }
h1 { font-size: 20px; font-weight: 500; }
h2 { font-size: var(--fs-section); font-weight: 500; }

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

.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--target);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 90ms ease-out, background-color 90ms ease-out;
}
button:active:not(:disabled) { transform: scale(.97); }

:is(button, input, select, textarea):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.primary { background: var(--primary); color: #fff; font-weight: 500; }
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.primary:disabled { background: var(--raised); color: #5c5c5c; cursor: default; }

.secondary { background: var(--soft); color: var(--soft-ink); font-weight: 500; }
.secondary:hover:not(:disabled) { background: var(--soft-hover); }
.secondary:disabled { background: var(--raised); color: #5c5c5c; cursor: default; }

.text { gap: 6px; padding: 0; color: var(--soft-ink); font-size: var(--fs-small); font-weight: 500; }
.text:hover { text-decoration: underline; text-underline-offset: 3px; }
.text .icon { width: 16px; height: 16px; }
.danger { margin-right: auto; padding: 0 4px; color: var(--negative); }

/* Barra */
.top { background: var(--surface); border-bottom: 1px solid var(--border); padding: env(safe-area-inset-top, 0px) var(--margin) 0; }

.top-row {
  max-width: 1100px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  min-height: 56px;
}

.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.mark { width: 24px; height: 24px; color: var(--primary); }

.settings {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 10px;
  border-color: var(--control);
  font-size: var(--fs-small);
  font-weight: 500;
}
.settings .icon { color: var(--primary); }
.settings:hover { background: var(--raised); }
.settings.unset::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--negative);
}

/* Area di lavoro */
.layout {
  display: grid;
  gap: 24px;
  padding: 20px var(--margin) calc(168px + env(safe-area-inset-bottom, 0px));
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  min-height: var(--target);
  margin-bottom: 4px;
}

.section-head h2 { display: flex; align-items: center; gap: 8px; }
.section-head h2 .icon { color: var(--primary); }
.count { margin-left: -2px; color: var(--muted); font-size: var(--fs-small); font-weight: 400; }

.c-teal { --tile: #dcf0ed; --tile-ink: #0b5f58; }
.c-amber { --tile: #fdeecf; --tile-ink: #7f4b00; }
.c-red { --tile: #fde4e1; --tile-ink: #a32620; }
.c-blue { --tile: #e0ebfb; --tile-ink: #1d55a8; }
.c-green { --tile: #e2f3da; --tile-ink: #2f6b1f; }
.c-pink { --tile: #fbe4ef; --tile-ink: #a01f63; }

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

.product {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 6px;
  min-height: 124px;
  padding: 14px;
  background: var(--tile);
  text-align: left;
}
.product > .icon { width: 28px; height: 28px; color: var(--tile-ink); }
.product:hover { border-color: var(--tile-ink); }
.product.in-cart { border-color: var(--tile-ink); box-shadow: inset 0 0 0 1px var(--tile-ink); }
.products.editing .product { border-style: dashed; border-color: var(--tile-ink); }

.product-name { font-size: 17px; font-weight: 500; overflow-wrap: anywhere; }
.product-price { display: flex; align-items: center; min-height: 32px; margin-top: auto; color: var(--tile-ink); font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.product-cell { position: relative; display: grid; }
/* Area di tocco 44 px, sfondo visibile 32 px: i bordi visibili cadono sul margine di 15 px (14 + bordo). */
.product-minus {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: var(--target);
  padding: 0;
  color: var(--tile-ink);
}
.product-minus::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: var(--radius-control);
  background: rgb(0 0 0 / .08);
}
.product-minus:hover::before { background: rgb(0 0 0 / .14); }
.product-minus .icon { position: relative; }
.product-minus .icon { width: 22px; height: 22px; stroke-width: 2.5; }
.product-qty {
  position: absolute;
  top: 18px;
  right: 15px;
  pointer-events: none; /* il tocco sull'etichetta aggiunge, come sul resto della casella */
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--tile-ink);
  color: #fff;
  font-size: var(--fs-small);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.add-product {
  min-height: 124px;
  border: 1px dashed var(--primary);
  color: var(--primary);
}
.add-product .icon { width: 36px; height: 36px; }
.add-product:hover { background: var(--soft); }

.panel {
  padding: 8px 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

/* Spesa */
.cart { list-style: none; }

.line {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto minmax(72px, auto);
  align-items: center;
  gap: 8px;
  padding-block: 10px;
  border-top: 1px solid var(--rule);
}
.line:first-child { border-top: 0; }

.line-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-card);
  background: var(--tile);
  color: var(--tile-ink);
}
.line-icon .icon { width: 20px; height: 20px; }
.line-info { display: grid; min-width: 0; }
.line-name { font-size: 16px; font-weight: 500; line-height: 1.25; overflow-wrap: anywhere; }
.line-unit { color: var(--muted); font-size: var(--fs-small); font-variant-numeric: tabular-nums; }
.line-amount { text-align: right; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.stepper {
  display: flex;
  align-items: center;
  flex: none;
  border-radius: var(--radius-control);
  background: var(--soft);
}
.stepper button {
  width: var(--target);
  padding: 0;
  color: var(--soft-ink);
}
.stepper button:hover { background: var(--soft-hover); }
.stepper button.remove { background: #fde4e1; color: #a32620; }
.stepper button.remove:hover { background: #fbd3ce; }
.stepper .icon { width: 18px; height: 18px; }
.stepper .stepper-qty {
  width: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--soft-ink);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.empty { padding-block: 12px; color: var(--muted); }
.products .empty { grid-column: 1 / -1; }

/* Totale e stampa: sempre in vista sul telefono */
.dock {
  position: fixed;
  inset: auto 0 0;
  z-index: 1;
  padding: 10px var(--margin) calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.dock-row { display: flex; align-items: center; gap: 8px; }
.dock-row button { min-height: 52px; flex: none; }
.dock-row .primary { padding-inline: 24px; }
.preview-btn { width: 52px; padding: 0; }
.dock-row button .icon { width: 20px; height: 20px; }

.dock-row .total { display: grid; justify-content: start; justify-items: start; flex: 1; min-width: 0; padding: 0; text-align: left; }
.total:disabled { cursor: default; }
.total span { color: var(--muted); font-size: var(--fs-small); }
.total-label { display: flex; align-items: center; gap: 4px; max-width: 100%; white-space: nowrap; }
.total-label .icon { color: var(--primary); }
.dock-row .total-label .icon { width: 16px; height: 16px; }
.total strong {
  color: var(--soft-ink);
  font-size: var(--fs-kpi);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.total strong.zero { color: var(--muted); font-weight: 400; }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 8px;
}
.status-row.ok, .status-row.error { padding: 6px 12px; border-radius: var(--radius-control); font-weight: 500; }
.status-row.ok { background: #dcfae5; color: #04250e; }
.status-row.error { background: #ffedea; color: #831c1e; }
#status { min-width: 0; font-size: var(--fs-small); overflow-wrap: anywhere; }
.status-row .text { flex: none; min-height: 36px; color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.head-actions { display: flex; align-items: center; gap: 12px; }
.close-cart { width: var(--target); padding: 0; }

/* Campi */
.field { display: grid; gap: 6px; flex: 1; min-width: 0; margin-bottom: 16px; font-weight: 500; font-size: 14px; }

input:not([type="checkbox"]), select, textarea {
  width: 100%;
  min-height: var(--target);
  padding: 9px 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 16px; /* sotto i 16px iOS ingrandisce la pagina al tocco */
  font-weight: 400;
}
input::placeholder { color: var(--muted); }
textarea { display: block; resize: vertical; }

.field-row { display: flex; align-items: flex-end; gap: var(--gap); }
.field-row .test { flex: 1; margin-bottom: 16px; }

.joined { display: flex; gap: 8px; }
.joined select { flex: 1; min-width: 0; }
.joined button { flex: none; }
.serial-state { flex: 1; align-self: center; min-width: 0; font-size: 16px; font-weight: 400; }

.check { display: flex; align-items: center; gap: 10px; min-height: var(--target); }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }

.icon-picker, .color-picker { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.icon-picker button { padding: 0; border-color: var(--border); font-weight: 400; }
.icon-picker .icon { width: 24px; height: 24px; }
.icon-picker button[aria-pressed="true"] { background: var(--tile); border-color: var(--tile-ink); color: var(--tile-ink); box-shadow: inset 0 0 0 1px var(--tile-ink); }
.logo-picker { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.color-picker button { padding: 0; background: var(--tile); border-color: var(--tile-ink); }
.color-picker button[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--tile-ink); }

.error { color: var(--negative); font-size: var(--fs-small); min-height: 1.4em; margin-bottom: 8px; }

/* Fogli che salgono dal basso */
.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 88dvh;
  margin: auto 0 0;
  padding: 20px var(--margin) calc(16px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -4px 24px rgb(0 0 0 / .18);
}
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet h2 { margin-bottom: 14px; font-size: 18px; }
.sheet h2:not(:first-child) { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--rule); }

.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.sheet-actions .primary { padding-inline: 24px; }

/* Il foglio è lungo e scorre: Fatto resta sempre in vista. */
#settings-sheet, #cart-sheet { padding-bottom: 0; }
.sheet .panel { padding: 0; border: 0; }
.sheet .section-head h2 { margin-bottom: 0; }
#settings-sheet .sheet-actions, #cart-sheet .sheet-actions {
  position: sticky;
  bottom: 0;
  padding-block: 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--rule);
}

.app-section { margin-top: 24px; margin-bottom: 16px; padding-top: 20px; border-top: 1px solid var(--rule); }
.apk-row { margin-top: 16px; }
.download-link { display: inline-flex; align-items: center; min-height: var(--target); padding: 0 14px; border-radius: var(--radius-control); text-decoration: none; }
.install-hint { margin-bottom: 12px; color: var(--muted); font-size: 14px; }

#settings-status { color: var(--muted); font-size: var(--fs-small); }
#settings-status:empty { display: none; }

.paper-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--raised);
  border-radius: var(--radius-control);
}
#preview-img { display: block; width: 100%; max-width: 288px; height: auto; background: #fff; }

@media (min-width: 900px) {
  :root { --margin: 24px; }

  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
    gap: 24px;
    max-width: 1148px;
    margin-inline: auto;
    padding-bottom: 32px;
  }

  .ticket {
    position: sticky;
    top: 16px;
    display: grid;
    gap: var(--gap);
    margin-top: 48px;
  }

  .close-cart, .total-label .icon { display: none; }
  .stepper button { width: 40px; }
  .stepper .stepper-qty { width: 32px; }

  .dock {
    position: static;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
  }

  .sheet {
    max-width: 480px;
    margin: auto;
    border-radius: var(--radius-card);
    padding: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:active:not(:disabled) { transform: none; }
}
