/* La taglia: carta chiara, inchiostro del mestiere, legno per la matrice.
   Un solo elemento forte: il timbro con lo stato della lista. */

@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Zilla Slab';
  src: url('/fonts/zilla-slab-latin-600-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Zilla Slab';
  src: url('/fonts/zilla-slab-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #ffffff;
  --ground: #f4efe8;
  --ink: #4a3020;
  --ink-soft: #6e5440;
  --text: #24180f;
  --muted: #6b5f54;
  --rule: #e2d8cb;
  --wood: #b9793c;
  --wood-text: #8a5426;
  --open: #2e7d4f;
  --closed: #c2332b;
  --draft: #8a6d1f;
  --focus: #f2b705;
  --ink-tint: rgba(74, 48, 32, 0.08);
  --display: 'Zilla Slab', Rockwell, Georgia, serif;
  --radius: 12px;
  --tap: 2.5rem;          /* 40px: pulsanti, campi, target di tocco */
  --bar: 3.25rem;         /* 52px: intestazione fissa */
  --s1: 8px; --s2: 12px; --s3: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
img, input, select, textarea { max-width: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 0.875rem/1.45 'Atkinson Hyperlegible', system-ui, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0; color: var(--ink); }
h1 { font-family: var(--display); font-weight: 700; font-size: 1.125rem; letter-spacing: -0.01em; }
h2 { font-size: 0.9375rem; font-weight: 700; }
h3 { font-size: 0.875rem; font-weight: 700; }
p { margin: 0 0 var(--s1); }
a { color: var(--ink); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--s3) var(--s3) 96px;
}

/* Il foglio del blocchetto */
.sheet {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s2);
  margin-bottom: var(--s1);
}
.sheet > h2 { margin-bottom: var(--s1); }

.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.row { display: flex; align-items: center; gap: 12px; }
.row.spread { justify-content: space-between; }
.stack > * + * { margin-top: var(--s2); }
.hidden { display: none !important; }

/* Righe del blocchetto */
.lines { list-style: none; margin: 0; padding: 0; }
.lines > li {
  border-bottom: 1px solid var(--rule);
  padding: 7px 0;
  min-height: 3.375rem;   /* 54px: nome + riga secondaria */
}
.lines > li.row { align-items: center; }
.lines > li:last-child { border-bottom: 0; }
.line-name { font-weight: 700; }
.line-meta { color: var(--muted); font-size: 0.8125rem; }
.qty { font-variant-numeric: tabular-nums; }

/* Il timbro */
/* Brand book p. 25: bordato, inclinato di 2 gradi, grassetto. L'unica cosa che alza la voce. */
.stamp {
  display: inline-block;
  border: 2px solid currentColor;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
  transform: rotate(-2deg);
  margin: 2px 0 4px;
  max-width: 100%;
  background: var(--paper);
}
.stamp.open { color: var(--open); }
.stamp.closed { color: var(--closed); }
.stamp.draft { color: var(--draft); }
.stack > .stamp { margin-top: 4px; }
@media (prefers-reduced-motion: no-preference) {
  .stamp.fresh { animation: stamp 260ms ease-out; }
  @keyframes stamp {
    from { transform: scale(1.3) rotate(-6deg); opacity: 0; }
    to { transform: rotate(-2deg); opacity: 1; }
  }
}

/* Moduli */
label { display: block; font-weight: 700; font-size: 0.8125rem; margin-bottom: 4px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.8125rem; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  font: inherit;
  font-size: 1rem;        /* 16px: iOS non ingrandisce la pagina sui campi */
  color: var(--text);
  background: var(--paper);
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--ink-tint); }
textarea { min-height: 80px; resize: vertical; }
/* Stessa altezza per campi e menu; iOS allarga e centra i campi data/ora: li riportiamo in riga */
input:not([type='checkbox']):not([type='radio']), select { height: var(--tap); box-sizing: border-box; }
input[type='datetime-local'], input[type='date'], input[type='time'] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.field + .field { margin-top: var(--s2); }
/* Campi affiancati: niente margine extra sul secondo, allineati in basso */
.row > .field + .field { margin-top: 0; }
.row:has(> .field) { align-items: flex-end; }

/* Pulsanti */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 10px;
  border: 0;
  background: var(--ink-tint);
  color: var(--ink);
  font: 700 0.8125rem 'Atkinson Hyperlegible', system-ui, sans-serif;
  gap: 6px;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary { background: var(--ink); color: #fff; }
button.danger { background: rgba(194, 51, 43, 0.09); color: var(--closed); }
button.quiet { background: transparent; padding: 0 8px; }
button.wide { width: 100%; }
/* Icone a tratto nei pulsanti e nelle righe */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.meta .ic { width: 14px; height: 14px; }
.meta .ic ~ .ic { margin-left: 8px; }
p.meta .ic { align-self: flex-start; margin-top: 2px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Selettore di quantità */
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
/* − e + tondi da 32px, con area di tocco di 40px */
.stepper button { width: var(--tap); min-height: var(--tap); padding: 0; background: transparent; font-size: 1.125rem; line-height: 1; position: relative; color: var(--ink); }
.stepper button::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: var(--ink-tint); z-index: -1; }
.stepper button { z-index: 0; isolation: isolate; }
.stepper button:last-child { color: #fff; }
.stepper button:last-child::before { background: var(--ink); }
.stepper button:disabled::before { background: var(--rule); }
.stepper button:disabled { color: var(--muted); opacity: 1; }
/* Larghezza fissa: i pulsanti restano in colonna anche con unità lunghe ("1 confezione" va a capo) */
.stepper output { width: 3.4em; display: flex; flex-direction: column; align-items: center; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stepper output b { font-size: 0.9375rem; }
.stepper output small { font-size: 0.6875rem; color: var(--muted); overflow-wrap: anywhere; text-align: center; }
/* A quantità zero: un solo pulsante "+ Aggiungi"; dopo il primo tocco diventa − n + */
.stepper .plus-label { display: none; }
.stepper.empty .minus, .stepper.empty output { display: none; }
.stepper.empty .plus { width: auto; padding: 0 16px 0 12px; gap: 4px; font-size: 0.875rem; }
.stepper.empty .plus::before { inset: 4px 0; border-radius: 999px; }
.stepper.empty .plus-label { display: inline; }
.stepper.empty .plus > span:first-child { font-size: 1.125rem; }
/* Pagina cliente: comandi da 48px come chiede il brand book (p. 25), anche per chi ha le mani sporche di farina */
.cliente { --tap: 3rem; }
.cliente button, .cliente .button { font-size: 0.9375rem; }
.cliente .stepper button::before { inset: 5px; }
/* Riquadri con domanda (fasce, ritiro/consegna): titolo dentro il riquadro, non sul bordo */
fieldset.sheet { margin: 0; min-width: 0; }
fieldset.sheet > legend { float: left; width: 100%; padding: 0 !important; margin: 0 0 var(--s1); font-weight: 700; font-size: 0.9375rem; color: var(--ink); }
fieldset.sheet > legend + * { clear: both; }

/* Scelte a pulsante (fasce di ritiro) */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choices label {
  margin: 0;
  font-weight: 700;
  font-size: 0.875rem;
  border: 0;
  background: var(--ink-tint);
  color: var(--ink);
  border-radius: 10px;
  padding: 6px 14px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.choices input:checked + label { border-color: var(--ink); background: var(--ink); color: #fff; }
.choices input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Barra fissa in basso */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  min-height: 3.5rem;
  z-index: 10;
}
.bottom-bar .inner { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bottom-bar .inner > div > .small { font-size: 0.75rem; line-height: 1.2; }
.total { font-size: 1.0625rem; font-weight: 700; line-height: 1.2; color: var(--ink); font-variant-numeric: tabular-nums; }

/* Barra delle sezioni del produttore */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabs button {
  flex: 1;
  max-width: 120px;
  flex-direction: column;
  gap: 2px;
  border-radius: 0;
  background: transparent;
  min-height: 3.5rem;
  padding: 6px 0 4px;
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--muted);
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-selected='true'] { color: var(--ink); font-weight: 700; }
.tabs button[aria-selected='true'] svg { stroke-width: 2.2; }

/* Intestazione fissa dell'app: titolo e pallino del profilo */
.appbar {
  position: sticky; top: 0; z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  min-height: var(--bar);
  margin: calc(-1 * var(--s3)) calc(-1 * var(--s3)) var(--s2);
  padding: 6px var(--s3);
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--ground);
  border-bottom: 1px solid var(--rule);
}
.appbar .title { display: flex; align-items: center; gap: var(--s1); min-width: 0; margin: 0; font: 700 1.125rem/1.15 var(--display); color: var(--ink); }
.appbar .title > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .brand svg { width: 28px; height: 28px; }
.appbar .avatar { width: 36px; height: 36px; min-height: 36px; }

/* Avvisi */
.notice { border-left: 3px solid var(--ink); background: var(--ground); padding: 8px 12px; border-radius: 6px; font-size: 0.8125rem; }
.notice.error { border-left-color: var(--closed); }
.notice.ok { border-left-color: var(--open); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 6px 6px 6px 16px;
  min-height: 44px;
  border-radius: 12px;
  width: max-content;
  max-width: min(calc(100% - 32px), 528px);
  z-index: 20;
  display: flex; align-items: center; gap: 12px;
  font-size: 0.875rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.toast > span { padding: 6px 0; }
.toast:not(:has(.toast-action)) { padding-right: 16px; }
.toast-action { background: transparent; color: #ffd47a; min-height: 36px; padding: 0 10px; font-weight: 700; flex: none; }
.toast-action .ic { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 180ms ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
}

.badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--ground); color: var(--ink-soft); }
.badge.yes { background: #e3f1e8; color: var(--open); }

.copybox { display: flex; gap: 8px; }
.copybox input { font-size: 0.9rem; }

.big-number { font-size: 1.125rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

details > summary { cursor: pointer; font-weight: 700; color: var(--ink); min-height: var(--tap); display: flex; align-items: center; }

/* Identità per mestiere: cambia l'inchiostro (il ceppo) e la carta, non il significato.
   La matrice resta legno; il verde "aperta" e il rosso "chiusa" restano uguali per tutti. */
:root[data-theme='azienda-agricola'], [data-theme='azienda-agricola'] { --ink: #3f5226; --ink-soft: #5c6e44; --ground: #eff2e6; --rule: #d5dcc6; --text: #1d2812; --ink-tint: rgba(63, 82, 38, 0.10); }
:root[data-theme='forno'], [data-theme='forno']            { --ink: #7a3418; --ink-soft: #8f553a; --ground: #f6eee8; --rule: #e6d6cb; --text: #2b1409; --ink-tint: rgba(122, 52, 24, 0.10); }
:root[data-theme='pastificio'], [data-theme='pastificio']       { --ink: #6b4f05; --ink-soft: #7e6527; --ground: #f7f1e0; --rule: #e8dcb8; --text: #2a2006; --ink-tint: rgba(107, 79, 5, 0.10); }
:root[data-theme='caseificio'], [data-theme='caseificio']       { --ink: #2f4a55; --ink-soft: #4d6670; --ground: #edf2f3; --rule: #cfdcdf; --text: #142328; --ink-tint: rgba(47, 74, 85, 0.10); }

/* Marchio: la taglia. Il ceppo prende l'inchiostro, la matrice resta legno. */
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; text-decoration: none; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand span { font-family: var(--display); font-size: 1.15rem; letter-spacing: -0.01em; }
.brand .matrice { fill: var(--wood); }
.badge { background: var(--ink-tint); }

/* Logo dell'attività */
.producer-tag { display: flex; align-items: center; gap: 8px; }
.logo { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; flex: none; }
.logo-big { width: 96px; height: 96px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.search { margin: 0 -12px 4px; padding: 6px 12px; position: sticky; top: 0; z-index: 5; background: var(--paper); } .search p { margin: 8px 0 0; }
.appbar ~ * .search { top: var(--bar); }
/* Ricerca con lente, su fondo tinta */
.search input { background: var(--ground) no-repeat 12px 50% / 16px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b5f54' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E"); border-color: transparent; padding-left: 36px; }
/* Pallino del profilo in alto a destra */
.avatar { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; display: grid; place-items: center; overflow: hidden; flex: none; background: var(--ink-tint); border: 1.5px solid var(--rule); color: var(--ink); }
.avatar[aria-current='page'] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-tint); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
/* Analisi nell'area admin */
.analisi h1 { font-size: 1.3rem; } .analisi h2 { margin: 22px 0 8px; }
.analisi table { width: 100%; border-collapse: collapse; font-size: 0.85rem; display: block; overflow-x: auto; }
.analisi th, .analisi td { border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: left; vertical-align: top; min-width: 7em; }
.analisi li { margin: 4px 0; }
/* Titoli di sezione con icona */
.with-ic { display: flex; align-items: center; gap: 8px; }
.with-ic > .ic { width: 20px; height: 20px; color: var(--ink); opacity: 0.85; }
.sub-ic > .ic { width: 15px; height: 15px; margin-right: 5px; vertical-align: -2px; color: var(--ink); opacity: 0.8; }
summary.sub-ic > .ic { margin-right: 8px; width: 18px; height: 18px; }
/* Sezioni richiudibili del modulo lista: titolo + riassunto, freccia a destra */
.section > summary { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: center; min-height: var(--tap); list-style: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: ''; grid-column: 2; grid-row: 1 / span 2; width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); margin: 0 6px 4px; transition: transform 150ms; }
.section[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }
.section > summary > h2 { margin: 0; }
.section-sum { grid-column: 1; font-size: 0.8125rem; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section[open] .section-sum { display: none; }
.section-body { margin-top: var(--s2); }
/* Freccia indietro nell'intestazione */
.appbar .back { width: var(--tap); padding: 0; margin-left: -8px; background: transparent; flex: none; }
.appbar .back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.appbar .title { flex: 1; }
/* Ordini: Ritirato / Pagato come interruttori, riga sbiadita quando è tutto fatto */
.toggles label { gap: 6px; }
.toggles label svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.35; }
.toggles input:checked + label svg { opacity: 1; }
.toggles .button { margin-left: auto; }
.order-row.done > :not(.toggles) { opacity: 0.55; }
.order-row.done .line-name { text-decoration: line-through; text-decoration-thickness: 1.5px; }
/* Caricamento: riquadri grigi della forma della pagina */
.skel { display: grid; gap: 10px; padding: 16px var(--s2); }
.skel-bar { display: block; height: 12px; border-radius: 6px; background: var(--rule); }
.skel-bar:first-child { height: 16px; }
@media (prefers-reduced-motion: no-preference) {
  .skel-bar { animation: skel 1.2s ease-in-out infinite alternate; }
  @keyframes skel { to { opacity: 0.45; } }
}
