/* Forma — un'app da tasca: carattere di sistema (SF Pro su iPhone), carta
   calda, un solo colore d'azione (salvia) e un colore per ogni nutriente.
   Niente ombre pesanti né gradienti: linee sottili e spazi su scala di 4 px. */

:root {
  --sfondo: #f5f2ec;
  --superficie: #ffffff;
  --superficie-2: #eee9df;
  --inchiostro: #1c1b18;
  --tenue: #625d53;
  --linea: #e2dbcf;
  --accento: #2f5d50;
  --accento-tenue: #dde8e2;
  --su-accento: #ffffff;
  --kcal: var(--accento);
  --proteine: #b8502f;
  --carboidrati: #c6961a;
  --grassi: #7a62a8;
  --fibre: #5f7f2e;
  --acqua: #2a78b8;
  --pericolo: #b3261e;
  --avviso-sfondo: #fbefd2;
  --avviso-testo: #6b4a00;

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px;
  --r-1: 8px; --r-2: 14px;
  --barra: 64px;

  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sfondo: #121311;
    --superficie: #1c1d1a;
    --superficie-2: #262723;
    --inchiostro: #f0eee8;
    --tenue: #a8a397;
    --linea: #33342f;
    --accento: #7fb8a4;
    --accento-tenue: #24352f;
    --su-accento: #0f1a16;
    --proteine: #e58a6d;
    --carboidrati: #e2b94a;
    --grassi: #b49be0;
    --fibre: #9fc069;
    --acqua: #6fb3ea;
    --pericolo: #ff8a80;
    --avviso-sfondo: #3a2f12;
    --avviso-testo: #f3d68c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--sfondo); color: var(--inchiostro); }
body { min-height: 100dvh; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accento); outline-offset: 2px; }
.numeri, .anello-valore, .barra-valori, input[type="number"] { font-variant-numeric: tabular-nums; }
.nascosto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Struttura */
#app { max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) var(--s-4) calc(var(--barra) + env(safe-area-inset-bottom) + var(--s-5)); }
.testata { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) 0 var(--s-3); }
.testata h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
.sottotitolo { color: var(--tenue); font-size: 15px; margin: var(--s-1) 0 0; }
h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 17px; margin: 0; }
p { margin: 0; }
.sezione { margin-top: var(--s-5); }
.sezione > h2 { margin-bottom: var(--s-3); }
.scheda { background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--r-2); padding: var(--s-4); }
.scheda + .scheda { margin-top: var(--s-3); }
.riga { display: flex; align-items: center; gap: var(--s-3); }
.riga-spazio { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.tenue { color: var(--tenue); }
.piccolo { font-size: 14px; }

/* --- Barra in basso */
.barra-schede { position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--barra) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--superficie) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--linea); }
.barra-schede[hidden] { display: none; }
.barra-schede a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--tenue); font-size: 11px; font-weight: 500; }
.barra-schede a[aria-current="page"] { color: var(--accento); }
.barra-schede svg { width: 26px; height: 26px; }
.barra-schede .scatto { color: var(--su-accento); }
.barra-schede .scatto span:first-child { color: var(--su-accento); display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--accento); margin-top: -10px; }
.barra-schede .scatto span:last-child { color: var(--tenue); }
.barra-schede .scatto[aria-current="page"] span:last-child { color: var(--accento); }

/* --- Comandi */
.bottone { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 48px; padding: 0 var(--s-5);
  border: 0; border-radius: var(--r-1); background: var(--accento); color: var(--su-accento); font-weight: 600; cursor: pointer; text-decoration: none; }
.bottone:disabled { opacity: 0.45; cursor: default; }
.bottone.largo { width: 100%; }
.bottone.secondario { background: var(--superficie-2); color: var(--inchiostro); }
.bottone.pericolo { background: transparent; color: var(--pericolo); border: 1px solid currentColor; }
.bottone.piccolo { min-height: 36px; padding: 0 var(--s-3); font-size: 15px; }
.bottone-icona { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--superficie-2); cursor: pointer; font-size: 17px; }
.bottone-icona:disabled { opacity: 0.35; cursor: default; }
.collegamento { background: none; border: 0; padding: var(--s-2) 0; color: var(--accento); font-weight: 600; cursor: pointer; min-height: 44px; }

.campo { display: grid; gap: var(--s-1); }
.campo + .campo { margin-top: var(--s-4); }
.campo > span { font-size: 15px; font-weight: 600; }
.campo small { color: var(--tenue); font-size: 13px; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; min-height: 48px; padding: var(--s-2) var(--s-3); border: 1px solid var(--linea); border-radius: var(--r-1); background: var(--superficie); font-size: 17px; }
textarea { min-height: 88px; resize: vertical; }
.con-unita { position: relative; }
.con-unita input { padding-right: 56px; }
.con-unita::after { content: attr(data-unita); position: absolute; right: var(--s-3); top: 50%; transform: translateY(-50%); color: var(--tenue); pointer-events: none; }

/* scelte a pulsanti (radio nascosti) */
.scelte { display: grid; gap: var(--s-2); }
.scelte.affiancate { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; }
.scelta { position: relative; display: block; }
.scelta input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.scelta > span { display: block; padding: var(--s-3); border: 1px solid var(--linea); border-radius: var(--r-1); background: var(--superficie); min-height: 48px; }
.scelta.affiancata > span { text-align: center; font-weight: 600; }
.scelta input:checked + span { border-color: var(--accento); background: var(--accento-tenue); box-shadow: inset 0 0 0 1px var(--accento); }
.scelta input:focus-visible + span { outline: 2px solid var(--accento); outline-offset: 2px; }
.scelta input:disabled + span { opacity: 0.4; }
.scelta strong { display: block; }
.scelta small { color: var(--tenue); font-size: 14px; }

.etichette { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { min-height: 36px; padding: 0 var(--s-3); border: 1px solid var(--linea); border-radius: 999px; background: var(--superficie); font-size: 15px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accento); border-color: var(--accento); color: var(--su-accento); }
/* Chip e bottoni piccoli restano alti 36 px a vista, ma il dito ne prende 44
   (il minimo che Apple chiede): 4 px invisibili sopra e sotto. Con 8 px tra
   una riga e l'altra le aree si toccano senza sovrapporsi. */
.chip, .bottone.piccolo { position: relative; }
.chip::after, .bottone.piccolo::after { content: ""; position: absolute; inset: -4px 0; }

.contatore { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: var(--s-2); align-items: center; }
.contatore input { text-align: center; }

/* --- Avvisi */
.riquadro-avviso { padding: var(--s-3) var(--s-4); border-radius: var(--r-1); background: var(--avviso-sfondo); color: var(--avviso-testo); font-size: 15px; }
.avviso-breve { position: fixed; left: 50%; bottom: calc(var(--barra) + env(safe-area-inset-bottom) + var(--s-4)); transform: translateX(-50%);
  z-index: 30; width: max-content; max-width: calc(100% - 32px); padding: var(--s-3) var(--s-4); border-radius: var(--r-1); background: var(--inchiostro); color: var(--sfondo); font-size: 15px; transition: opacity .3s; }
.avviso-breve.via { opacity: 0; }

/* --- Foglio dal basso */
.foglio { position: fixed; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 560px; max-height: 92dvh; padding: 0; border: 0;
  border-radius: var(--r-2) var(--r-2) 0 0; background: var(--sfondo); color: var(--inchiostro); display: flex; flex-direction: column; }
.foglio:not([open]) { display: none; }
.foglio::backdrop { background: rgb(0 0 0 / 0.4); }
.foglio-testa { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-2); }
.foglio-corpo { overflow-y: auto; padding: var(--s-2) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom)); }
@media (prefers-reduced-motion: no-preference) {
  .foglio[open] { animation: sali .22s ease-out; }
  @keyframes sali { from { transform: translateY(24px); opacity: 0; } }
}

/* --- Oggi */
.giorno-nav { display: flex; align-items: center; gap: var(--s-2); }
.cruscotto { display: grid; grid-template-columns: 148px minmax(0, 1fr); gap: var(--s-4); align-items: center; }
.anello { position: relative; width: 148px; height: 148px; }
.anello svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.anello-testo { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.anello-valore { font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.anello-etichetta { font-size: 13px; color: var(--tenue); margin-top: var(--s-1); }
.barre { display: grid; gap: var(--s-3); }
.barra-nome { display: flex; justify-content: space-between; font-size: 14px; }
.barra-nome strong { font-weight: 600; }
.barra-valori { color: var(--tenue); }
.barra { height: 8px; border-radius: 4px; background: var(--superficie-2); overflow: hidden; margin-top: 4px; }
.barra > span { display: block; height: 100%; border-radius: 4px; background: var(--colore, var(--accento)); }
.oltre { color: var(--pericolo); font-weight: 600; }

.acqua-bicchieri { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--s-3) 0; }
.acqua-bicchieri span { width: 22px; height: 28px; border: 2px solid var(--acqua); border-top-width: 1px; border-radius: 2px 2px 6px 6px; }
.acqua-bicchieri span.pieno { background: var(--acqua); }

.pasto + .pasto { margin-top: var(--s-3); }
.pasto-testa { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.voci { list-style: none; margin: var(--s-2) 0 0; padding: 0; }
.voce { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); width: 100%; min-height: 48px; padding: var(--s-2) 0;
  border: 0; border-top: 1px solid var(--linea); background: none; text-align: left; cursor: pointer; }
.voce-nome { min-width: 0; }
.voce-nome span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voce-nome small { color: var(--tenue); font-size: 13px; }
.voce-kcal { flex: none; font-variant-numeric: tabular-nums; }
.segno { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 999px; background: var(--superficie-2); color: var(--tenue); vertical-align: 1px; }

/* --- Ricerca alimenti */
.risultati { list-style: none; margin: var(--s-3) 0 0; padding: 0; }
.risultati button { display: flex; justify-content: space-between; gap: var(--s-3); width: 100%; min-height: 52px; padding: var(--s-2) 0; border: 0; border-bottom: 1px solid var(--linea); background: none; text-align: left; cursor: pointer; }
.valori-griglia { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2); text-align: center; margin: var(--s-4) 0; }
.valori-griglia div { padding: var(--s-2) 0; border-radius: var(--r-1); background: var(--superficie); border: 1px solid var(--linea); }
.valori-griglia strong { display: block; font-size: 20px; }
.valori-griglia small { color: var(--tenue); font-size: 12px; }

/* --- Primo avvio e Profilo */
.passi { display: flex; gap: var(--s-1); margin-top: var(--s-4); }
.passi span { flex: 1; height: 4px; border-radius: 2px; background: var(--linea); }
.passi span.fatto { background: var(--accento); }
.azioni { display: flex; gap: var(--s-3); margin-top: var(--s-5); }
.azioni > * { flex: 1; }
.numeri-grandi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.numero-grande { padding: var(--s-3); border-radius: var(--r-1); background: var(--superficie); border: 1px solid var(--linea); border-left: 4px solid var(--colore, var(--accento)); }
.numero-grande strong { display: block; font-size: 24px; letter-spacing: -0.01em; }
.numero-grande small { color: var(--tenue); font-size: 13px; }
.perche summary { cursor: pointer; color: var(--accento); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.perche ol { margin: var(--s-2) 0 0; padding-left: 1.2em; display: grid; gap: var(--s-3); }
.perche li small { display: block; color: var(--tenue); font-size: 14px; }
.vuoto { text-align: center; padding: var(--s-6) var(--s-4); color: var(--tenue); }
.vuoto h2 { color: var(--inchiostro); margin-bottom: var(--s-2); }
fieldset.campo { border: 0; padding: 0; margin-inline: 0; min-width: 0; }
fieldset.campo legend { font-size: 15px; font-weight: 600; padding: 0; margin-bottom: var(--s-1); }

/* --- Foto */
.foto-scatto { display: grid; place-items: center; gap: var(--s-2); margin-top: var(--s-4); min-height: 200px; padding: var(--s-5);
  border: 2px dashed var(--accento); border-radius: var(--r-2); background: var(--accento-tenue); text-align: center; cursor: pointer; }
.foto-scatto strong { font-size: 20px; color: var(--accento); }
.foto-scatto:focus-within { outline: 2px solid var(--accento); outline-offset: 2px; }
.anteprima { width: 100%; max-height: 50dvh; object-fit: cover; border-radius: var(--r-2); }
.anteprima.piccola { width: 96px; height: 96px; flex: none; }
.voci-foto { list-style: none; margin: var(--s-3) 0 0; padding: 0; display: grid; gap: var(--s-2); }

/* --- Ricette */
.carta-su-misura { display: grid; gap: var(--s-1); text-decoration: none; color: inherit; border-color: var(--accento); background: var(--accento-tenue); }
.carta-su-misura strong { color: var(--accento); font-size: 18px; }
.elenco-ricette { display: grid; gap: var(--s-3); margin-top: var(--s-4); }
.carta-ricetta { display: grid; gap: var(--s-2); text-decoration: none; color: inherit; }
.carta-ricetta + .carta-ricetta { margin-top: 0; }
.barra-macro { display: flex; height: 6px; border-radius: 3px; overflow: hidden; gap: 2px; }
.ingredienti { list-style: none; margin: 0; padding: var(--s-2) var(--s-4); }
.ingredienti li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--linea); }
.ingredienti li:last-child { border-bottom: 0; }
.passaggi { margin: var(--s-3) 0 0; padding: 0; list-style: none; display: grid; gap: var(--s-3); counter-reset: passo; }
.passaggi li { padding: var(--s-3) var(--s-4); background: var(--superficie); border: 1px solid var(--linea); border-radius: var(--r-1); }
.passaggi li:has(input:checked) span { color: var(--tenue); text-decoration: line-through; }

/* --- Ricerca e codice a barre */
.barra-cerca { display: flex; gap: var(--s-2); margin-bottom: var(--s-3); }
.barra-cerca-campo { flex: 1; display: flex; align-items: center; gap: var(--s-2); min-height: 48px; padding: 0 var(--s-3);
  border: 1px solid var(--linea); border-radius: var(--r-1); background: var(--superficie); color: var(--tenue); font-size: 17px; text-align: left; cursor: text; }
.barra-cerca-campo svg, .bottone-icona svg { width: 22px; height: 22px; flex: none; }
.barra-cerca .bottone-icona { width: 48px; height: 48px; border-radius: var(--r-1); border: 1px solid var(--linea); background: var(--superficie); color: var(--inchiostro); }
.titolo-gruppo { margin: var(--s-4) 0 0; font-size: 14px; font-weight: 600; color: var(--tenue); }
.lettore { position: relative; overflow: hidden; border-radius: var(--r-2); background: #000; aspect-ratio: 4 / 3; }
.lettore-video { display: block; width: 100%; height: 100%; object-fit: cover; }
.lettore-mira { position: absolute; inset: 28% 8%; border: 2px solid rgb(255 255 255 / 0.9); border-radius: var(--r-1); box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.35); }
.risposta { margin-top: var(--s-3); border-color: var(--accento); }
