/* Spesa — stile iOS a elenchi raggruppati, tonalità blu, tema chiaro/scuro di sistema.
   Solo font di sistema e nessuna risorsa esterna. Animazioni solo su transform/opacity. */
:root {
  --bg: #F1F4F9;
  --surface: #FFFFFF;
  --ink: #0B1220;
  --muted: #6B7385;
  --line: #DFE4EE;
  --accent: #1E5BD8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2EBFC;
  --accent-2: #0E3A8C;
  --warn: #A85700;
  --warn-soft: #FBEAD5;
  --danger: #C62828;
  --scrim: rgba(5, 10, 25, .4);
  --shadow: 0 8px 28px -10px rgba(10, 20, 45, .35);
  --r: 12px;
  --r-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --app-h: 100dvh;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #05080F;
    --surface: #141A26;
    --ink: #F2F5FA;
    --muted: #8A93A6;
    --line: #252D3D;
    --accent: #5B9BFF;
    --accent-ink: #05080F;
    --accent-soft: #15264A;
    --accent-2: #A9C8FF;
    --warn: #FFB054;
    --warn-soft: #3A2812;
    --danger: #FF6B6B;
    --scrim: rgba(0, 0, 0, .55);
    --shadow: 0 8px 28px -10px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.35 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; color: var(--ink); font-size: 16px; } /* 16px: niente zoom su iOS */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- struttura ---------- */
.shell {
  position: fixed; left: 0; right: 0; top: 0; height: var(--app-h);
  display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal);
}
.ptabs { display: flex; align-items: center; gap: 4px; padding: 10px 14px 6px; flex: none; background: var(--bg); position: relative; z-index: 1; }
.ptab { font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--muted); padding: 2px 6px; transition: color .2s; }
.ptab[aria-selected="true"] { color: var(--ink); }
.dots { display: flex; gap: 5px; margin-left: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--line); transition: width .2s, background-color .2s; }
.dots i.on { width: 16px; background: var(--accent); }
.sync {
  margin-left: auto; font-size: 12px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn);
}
.sync::before { content: ""; width: 6px; height: 6px; border-radius: 3px; background: currentColor; }

.pager {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.pane { flex: 0 0 100%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; display: flex; flex-direction: column; min-height: 0; position: relative; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 2px 16px 10px; flex: none; min-height: 44px; }
.scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain;
  padding: 0 16px 24px; display: flex; flex-direction: column; gap: 18px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.scroll::-webkit-scrollbar { display: none; }
/* i figli di un'area scorrevole non devono restringersi (con overflow:hidden il
   loro min-height diventa 0 e il contenuto verrebbe tagliato invece di scorrere) */
.scroll > *, .grp > * { flex-shrink: 0; }

.listpick { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: var(--accent); min-width: 0; padding: 6px 0; }
.listpick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listpick::after { content: ""; flex: none; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.avatars { display: flex; margin-left: auto; padding-left: 6px; }
.av { width: 28px; height: 28px; border-radius: 14px; display: grid; place-items: center; font-size: 11px; font-weight: 700; border: 2px solid var(--bg); margin-left: -7px; background: var(--accent-soft); color: var(--accent); }
.av.me { background: var(--accent); color: var(--accent-ink); }
.icon-btn { width: 34px; height: 34px; border-radius: 17px; display: grid; place-items: center; color: var(--accent); background: var(--surface); font-size: 18px; line-height: 1; flex: none; }
.btn { font-weight: 600; font-size: 15px; padding: 8px 14px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; margin-left: auto; flex: none; }

/* ---------- elenchi raggruppati ---------- */
.grp { display: flex; flex-direction: column; gap: 6px; }
.grp-h { display: flex; align-items: baseline; gap: 8px; padding: 0 14px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .02em; }
.grp-h small { font-size: 12px; text-transform: none; letter-spacing: 0; }
.grp-h .tag { align-self: center; font-size: 11px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--accent-ink); background: var(--accent); padding: 1px 7px; border-radius: 999px; }
.grp-h .link { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; color: var(--accent); }
.grp-items { background: var(--surface); border-radius: var(--r); overflow: hidden; }
.grp.past { opacity: .45; }

.item { display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 48px; position: relative; background: var(--surface); }
.item + .item::before { content: ""; position: absolute; top: 0; left: 48px; right: 0; border-top: .5px solid var(--line); }
.item.flash { animation: flash .9s ease; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.chk { flex: none; width: 24px; height: 24px; border-radius: 12px; border: 1.5px solid var(--muted); display: grid; place-items: center; position: relative; }
.chk::before { content: ""; position: absolute; inset: -12px; } /* area di tocco più ampia */
.item.done .chk, .item.ticked .chk { background: var(--accent); border-color: var(--accent); }
.item.done .chk::after, .item.ticked .chk::after { content: ""; width: 10px; height: 5px; border-left: 2px solid var(--accent-ink); border-bottom: 2px solid var(--accent-ink); transform: translate(0, -1px) rotate(-45deg); }
.iname { flex: 1; min-width: 0; text-align: left; padding: 13px 0; line-height: 1.3; overflow-wrap: anywhere; }
.qty { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; max-width: 40%; text-align: right; overflow-wrap: anywhere; }
.item.done .iname { text-decoration: line-through; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty b { color: var(--ink); font-size: 18px; }
.empty .btn { margin: 4px 0 0; }

/* ---------- inserimento ---------- */
.composer {
  flex: none; padding: 6px 12px max(6px, calc(var(--sab) - 16px)); display: flex; flex-direction: column; gap: 8px;
  background: var(--bg);
}
.composer:focus-within { padding-bottom: 6px; } /* tastiera aperta: niente margine per la barra Home */
.compose-row { display: flex; }
.compose-row input { flex: 1; min-width: 0; border: 1px solid transparent; background: var(--surface); border-radius: var(--r); padding: 12px 14px; outline: none; }
.compose-row input:focus { border-color: var(--accent); }
.compose-row input::placeholder { color: var(--muted); }
.compose-row input:disabled { opacity: .5; }
.sugg { display: flex; flex-direction: column-reverse; background: var(--surface); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.sugg button { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 14px; min-height: 48px; text-align: left; }
.sugg button + button { border-bottom: .5px solid var(--line); }
.sugg button.hl, .sugg button:active { background: var(--accent-soft); }
.sugg button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugg b { font-weight: 600; color: var(--accent); }
.sugg em { flex: none; font-style: normal; font-size: 13px; color: var(--muted); }
.sugg em.in { color: var(--warn); font-weight: 600; }
.sugg .new span { color: var(--accent); }
.sugg .new span::before { content: "+ "; font-weight: 700; }

/* ---------- menu ---------- */
.mhead { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.mhead b { font-size: 16px; font-weight: 600; }
.mhead span { font-size: 13px; color: var(--muted); }
.meal { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 14px; min-height: 48px; position: relative; background: var(--surface); }
.meal + .meal::before, .dish-sugg + .meal::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: .5px solid var(--line); }
.mk { flex: none; width: 54px; font-size: 14px; color: var(--muted); }
.mt { flex: 1; min-width: 0; text-align: left; padding: 13px 0; line-height: 1.3; overflow-wrap: anywhere; }
.meal.empty-slot .mt { color: var(--accent); }
.meal input { flex: 1; min-width: 0; border: 0; background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; margin: 6px 0; outline: none; }
.dish-sugg { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px 78px; background: var(--surface); }
.dish-sugg button { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; padding: 7px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.dish-sugg button:active { background: var(--accent); color: var(--accent-ink); }
.grip { flex: none; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 8px; touch-action: none; font-size: 15px; letter-spacing: -2px; }
.moving .meal { cursor: pointer; }
.moving .meal:not(.src):active { background: var(--accent-soft); }
.meal.src { background: var(--accent); color: var(--accent-ink); }
.meal.src .mk, .meal.src .mt, .meal.src .grip { color: var(--accent-ink); }
.meal.drop { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.ghost { position: fixed; z-index: 30; pointer-events: none; border-radius: var(--r); box-shadow: var(--shadow); opacity: .95; will-change: transform; }
.movebar { flex: none; margin: 0 12px max(12px, var(--sab)); display: flex; align-items: center; gap: 10px; background: var(--ink); color: var(--bg); border-radius: var(--r); padding: 12px 14px; font-size: 14px; }
.movebar span { flex: 1; }
.movebar button { color: var(--bg); font-weight: 600; text-decoration: underline; }

/* ---------- pagine sovrapposte ---------- */
/* La pagina intera è l'unico contenitore che scorre (niente aree scorrevoli annidate:
   su iOS non ricevevano lo scorrimento). Barra "Indietro" fissa in alto.
   Nessuna transform a riposo: entrata/uscita animate da ui.js (Web Animations). */
.page {
  position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); z-index: 10;
  background: var(--bg); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--sar) 0 var(--sal);
}
.page .scroll { overflow: visible; flex: none; min-height: 0; }
.page .navbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-top: calc(var(--sat) + 8px); }
.navbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px 0; min-height: 44px; flex: none; }
.navbar .back { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); padding: 8px 6px; }
.navbar .back::before { content: ""; width: 10px; height: 10px; border-left: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(45deg); margin-left: 4px; }
.navbar .right { margin-left: auto; color: var(--accent); font-weight: 600; padding: 8px 6px; }
.page h1 { font-size: 32px; font-weight: 700; letter-spacing: -.01em; margin: 4px 0 2px; padding: 0 20px; }
.page .sub { padding: 0 20px 12px; margin: 0; color: var(--muted); font-size: 14px; }
.page .scroll { padding-bottom: max(24px, var(--sab)); }

.rows { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 52px; position: relative; background: var(--surface); text-align: left; width: 100%; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: .5px solid var(--line); }
.row .t { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 10px 0; text-align: left; }
.row .t b { font-weight: 400; overflow-wrap: anywhere; }
.row .t span { font-size: 13px; color: var(--muted); }
.row .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.row .chev { flex: none; width: 8px; height: 8px; border-right: 2px solid var(--line); border-top: 2px solid var(--line); transform: rotate(45deg); }
.row.current .t b { font-weight: 600; color: var(--accent); }
.row .more { flex: none; width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center; color: var(--accent); font-size: 18px; }
.handle { flex: none; width: 36px; height: 44px; display: grid; place-items: center; touch-action: none; color: var(--muted); margin-left: -8px; }
.handle::before { content: ""; width: 16px; height: 10px; background: linear-gradient(currentColor, currentColor) top / 100% 2px no-repeat, linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat, linear-gradient(currentColor, currentColor) bottom / 100% 2px no-repeat; }
.sorting .row:not(.lift) { transition: transform .18s ease; }
.row.lift { z-index: 2; box-shadow: var(--shadow); background: var(--surface); }
/* elenco compatto: una riga sola per voce, così tutte le categorie stanno nello schermo */
.rows.compact .row { min-height: 44px; gap: 10px; }
.rows.compact .row .t { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; padding: 0; min-height: 44px; }
.rows.compact .row .t span { flex: none; font-size: 14px; font-variant-numeric: tabular-nums; }
.rows.compact .handle { height: 40px; }
.ghost-btn { display: flex; align-items: center; justify-content: center; min-height: 50px; border-radius: var(--r); background: var(--surface); color: var(--accent); font-weight: 600; }
.search { border: 0; background: var(--surface); border-radius: var(--r-sm); padding: 10px 14px; width: 100%; outline: none; }
.account { text-align: center; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 8px 0 16px; }
.account button { color: var(--danger); font-weight: 600; padding: 8px; }
.version { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); padding-bottom: 8px; }
.version span { font-variant-numeric: tabular-nums; }
.version button { color: var(--accent); font-weight: 600; padding: 8px; }
.version button:disabled { color: var(--muted); }

/* ---------- pannello dal basso ---------- */
.sheet-bg {
  position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); z-index: 20;
  background: var(--scrim); display: flex; align-items: flex-end;
  opacity: 0; transition: opacity .2s;
}
.sheet-bg.open { opacity: 1; }
.sheet {
  width: 100%; max-height: calc(var(--app-h) - var(--sat) - 24px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 10px max(16px, var(--sar)) max(18px, var(--sab)) max(16px, var(--sal));
  display: flex; flex-direction: column; gap: 14px;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet-bg.open .sheet { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); align-self: center; flex: none; }
.sheet-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.link { color: var(--accent); padding: 6px 2px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .lab { font-size: 13px; text-transform: uppercase; color: var(--muted); padding-left: 4px; }
.field input { border: 0; background: var(--surface); border-radius: var(--r-sm); padding: 12px; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font-size: 15px; padding: 8px 12px; border-radius: 999px; background: var(--surface); }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.units { gap: 6px; }
.units button { min-width: 44px; min-height: 36px; padding: 6px 10px; font-variant-numeric: tabular-nums; }
.units [data-kb] { margin-left: auto; }
.note { font-size: 13px; color: var(--muted); margin: 0; padding-left: 4px; }
.primary { background: var(--accent); color: var(--accent-ink); border-radius: var(--r); min-height: 50px; padding: 0 16px; font-weight: 600; text-align: center; width: 100%; }
.primary:disabled { opacity: .5; }
.danger { color: var(--danger); font-weight: 600; min-height: 46px; border-radius: var(--r); background: var(--surface); width: 100%; }
.danger.confirm { background: var(--danger); color: #fff; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: var(--r-sm); padding: 10px 12px; font-size: 14px; font-weight: 600; }
.summary { background: var(--surface); border-radius: var(--r); padding: 11px 14px; display: flex; flex-direction: column; gap: 2px; }
.summary b { font-size: 17px; font-weight: 600; }
.summary span { font-size: 13px; color: var(--muted); }
.actions { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r); overflow: hidden; }
.actions button { min-height: 52px; padding: 0 16px; text-align: left; color: var(--accent); position: relative; }
.actions button + button::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 0 14px; position: relative; background: var(--surface); width: 100%; text-align: left; }
.toggle-row + .toggle-row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: .5px solid var(--line); }
.switch { flex: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; transition: background-color .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 13px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
[aria-checked="true"] .switch { background: var(--accent); }
[aria-checked="true"] .switch::after { transform: translateX(20px); }

/* ---------- avvisi ---------- */
.toast {
  position: fixed; z-index: 40; left: max(12px, var(--sal)); right: max(12px, var(--sar));
  bottom: calc(var(--toast-bottom, 84px) + var(--sab));
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); color: var(--bg); border-radius: var(--r); padding: 12px 14px;
  font-size: 14px; line-height: 1.35; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast span { flex: 1; }
.toast button { color: var(--bg); font-weight: 700; text-decoration: underline; flex: none; padding: 4px; }

/* ---------- accesso ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: max(24px, var(--sat)) 20px max(24px, var(--sab)); overflow-y: auto; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 8px; }
.login-card img { align-self: center; border-radius: 16px; }
.login-card h1 { text-align: center; margin: 4px 0 0; font-size: 30px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.login-card label { font-size: 13px; text-transform: uppercase; color: var(--muted); padding-left: 4px; margin-top: 6px; }
.login-card input { border: 1px solid transparent; background: var(--surface); border-radius: var(--r-sm); padding: 12px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .primary { margin-top: 14px; }
.login-err { color: var(--danger) !important; font-weight: 600; margin: 6px 0 0 !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
