/* ---------- tema ---------- */
:root {
  --bg: #f4ede4;
  --ink: #2a2622;
  --muted: #8a8279;
  --line: rgba(60, 40, 20, .10);
  --card: #ffffff;
  --accent: #0e0e0e;
  --accent-hi: #3f3f3f;
  --accent-ink: #ffffff;
  --btn-shadow: 0 6px 16px rgba(0, 0, 0, .28);
  --font: "Poppins", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --danger: #b3261e;
  --radius: 18px;

  /* vetro */
  --glass-bg: rgba(255, 255, 255, .58);
  --glass-edge: rgba(255, 255, 255, .75);
  --glass-shadow: 0 8px 28px rgba(60, 35, 15, .14);
  --glass-hi: inset 0 1px 0 rgba(255, 255, 255, .9), inset 0 -1px 0 rgba(255, 255, 255, .25);
  --blob-a: rgba(226, 150, 120, .45);
  --blob-b: rgba(240, 200, 150, .40);
  --blob-c: rgba(180, 160, 220, .28);

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161314;
    --ink: #f3ece6;
    --muted: #a39a92;
    --line: rgba(255, 255, 255, .10);
    --card: #221e1f;
    --accent: #d9d2cc;
    --accent-hi: #ffffff;
    --accent-ink: #121212;
    --btn-shadow: 0 6px 18px rgba(0, 0, 0, .5);
    --glass-bg: rgba(48, 42, 44, .55);
    --glass-edge: rgba(255, 255, 255, .16);
    --glass-shadow: 0 8px 28px rgba(0, 0, 0, .45);
    --glass-hi: inset 0 1px 0 rgba(255, 255, 255, .20), inset 0 -1px 0 rgba(255, 255, 255, .04);
    --blob-a: rgba(201, 118, 90, .30);
    --blob-b: rgba(160, 110, 60, .22);
    --blob-c: rgba(110, 90, 170, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100vh; }

/* sfondo morbido (fisso, senza filtri: costa quasi zero) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vmax 60vmax at 90% -10%, var(--blob-a), transparent 60%),
    radial-gradient(55vmax 55vmax at -10% 40%, var(--blob-b), transparent 60%),
    radial-gradient(50vmax 50vmax at 80% 110%, var(--blob-c), transparent 60%);
}

h1, h2 { font-family: var(--font); margin: 0; font-weight: 600; letter-spacing: -.01em; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 6px 0; }
code { background: var(--line); padding: 1px 5px; border-radius: 6px; }

/* ---------- vetro ---------- */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-hi), var(--glass-shadow);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
}

/* riflesso di luce sui pulsanti */
.shine { position: relative; overflow: hidden; isolation: isolate;
  transition: transform .18s cubic-bezier(.3, 1.4, .5, 1), filter .18s; }
.shine::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, .55) 0%, rgba(255, 255, 255, 0) 52%);
  opacity: .55;
}
.shine:active { transform: scale(.95); filter: brightness(1.06); }

/* ---------- form ---------- */
input, textarea, button { font: inherit; color: inherit; }
input, textarea {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 255, 255, .55); font-size: 16px; margin-bottom: 10px; outline: none;
}
@media (prefers-color-scheme: dark) { input, textarea { background: rgba(255, 255, 255, .06); } }
input:focus, textarea:focus { border-color: var(--accent); }

.btn { border: 1px solid var(--glass-edge); background: var(--glass-bg); padding: 13px 16px; border-radius: 14px;
  font-weight: 600; cursor: pointer; width: 100%; box-shadow: var(--glass-hi); }
.btn.primary { background: linear-gradient(180deg, var(--accent-hi), var(--accent)); color: var(--accent-ink);
  border-color: rgba(255, 255, 255, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .10), var(--btn-shadow); }
.btn.ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.btn.danger { color: var(--danger); margin-top: 10px; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; font-size: 14px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer; padding: 0; }

/* ---------- login ---------- */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; padding: 28px 22px 22px; border-radius: 28px; }
.logo { font-size: 44px; color: var(--accent); margin-bottom: 4px; }
.login-card h1 { font-size: 28px; }
.login-card form { margin-top: 22px; text-align: left; }

/* ---------- app ---------- */
#app { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 130px); }
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.top h1 { font-size: 32px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin-bottom: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--glass-edge); background: var(--glass-bg); padding: 7px 14px; border-radius: 999px;
  font-size: 14px; cursor: pointer; }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card { background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 2px 10px rgba(60, 35, 15, .08); display: flex; flex-direction: column; }
.thumb { position: relative; aspect-ratio: 3 / 4; background: var(--line); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; color: var(--muted); }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(42, 38, 34, .82); color: #fff;
  font-size: 12px; padding: 3px 9px; border-radius: 999px; }
.card.bought .thumb img { opacity: .55; }
.info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.info .name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.info .brand { color: var(--muted); font-size: 13px; }
.info .price { font-weight: 700; margin-top: 2px; }
.actions { display: flex; gap: 6px; margin-top: 8px; }
.actions a, .actions button { flex: 1; text-align: center; text-decoration: none; font-size: 13px; font-weight: 600;
  padding: 9px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass-bg); color: var(--ink); cursor: pointer; }
.actions .buy { background: linear-gradient(180deg, var(--accent-hi), var(--accent)); border-color: transparent; color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45); }

.empty { text-align: center; color: var(--muted); margin-top: 60px; line-height: 1.6; }

/* ---------- dock ---------- */
.dock-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 14px); z-index: 5;
  display: flex; justify-content: center; align-items: center; gap: 10px; padding: 0 16px; pointer-events: none; }
.dock-wrap > * { pointer-events: auto; }
.dock { display: flex; padding: 5px; border-radius: 999px; max-width: 420px; flex: 1;
  background: color-mix(in srgb, var(--glass-bg) 88%, var(--bg)); }
.dock button { flex: 1; border: 0; background: transparent; padding: 11px 2px; border-radius: 999px; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .2s, color .2s; }
.dock button.active { color: var(--ink); background: rgba(255, 255, 255, .55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 2px 8px rgba(60, 35, 15, .12); }
@media (prefers-color-scheme: dark) { .dock button.active { background: rgba(255, 255, 255, .14); } }

.fab { flex: none; width: 58px; height: 58px; border-radius: 50%; font-size: 32px; line-height: 1; cursor: pointer; padding: 0 0 3px;
  color: var(--accent-ink); background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border-color: rgba(255, 255, 255, .4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 8px 22px rgba(0, 0, 0, .32); }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--glass-edge); border-radius: 28px; padding: 20px; width: min(92vw, 420px); max-height: 90vh;
  overflow-y: auto; color: var(--ink); }
dialog.glass { background: color-mix(in srgb, var(--glass-bg) 75%, var(--bg)); }
dialog :focus:not(:focus-visible) { outline: none; }
dialog::backdrop { background: rgba(20, 12, 8, .35); }
dialog h2 { margin-bottom: 14px; font-size: 22px; }
.menu-list { display: grid; gap: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.photo { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 10; border: 2px dashed var(--line); border-radius: 16px;
  background: rgba(255, 255, 255, .35); color: var(--muted); cursor: pointer; overflow: hidden; margin-bottom: 8px;
  text-align: center; padding: 8px; }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }

/* niente blur se l'utente riduce la trasparenza */
@media (prefers-reduced-transparency: reduce) {
  .glass { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--card); }
}

/* ---------- icone centrate ---------- */
.fab, .icon-btn { display: grid; place-items: center; padding: 0; }
.fab svg, .icon-btn svg { display: block; }

/* ---------- animazioni ---------- */
/* feedback al tocco: tutto ciò che si preme "cede" un po' e torna con un piccolo rimbalzo */
:is(button, .chip, .thumb, .actions a):not(:disabled) {
  transition: transform .22s cubic-bezier(.3, 1.4, .5, 1), background .2s, color .2s, filter .18s;
}
:is(button, .chip, .thumb, .actions a):not(:disabled):active { transform: scale(.95); }
.thumb:active { transform: scale(.985); }

/* dock: la pillola scorre da una voce all'altra */
.dock { position: relative; --i: 0; }
.dock::before {
  content: ""; position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc((100% - 10px) / 3);
  border-radius: 999px; background: rgba(255, 255, 255, .55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 2px 8px rgba(60, 35, 15, .12);
  transform: translateX(calc(var(--i) * 100%));
  transition: transform .4s cubic-bezier(.3, 1.25, .5, 1);
}
@media (prefers-color-scheme: dark) { .dock::before { background: rgba(255, 255, 255, .14); } }
.dock button { position: relative; z-index: 1; }
.dock button.active { background: transparent; box-shadow: none; }

/* card che entrano quando cambia il filtro */
.card.enter { animation: rise .45s cubic-bezier(.2, .8, .3, 1) both; animation-delay: calc(var(--n, 0) * 40ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* pannelli: si aprono e si chiudono con un rimbalzo leggero */
dialog[open] { animation: sheet-in .34s cubic-bezier(.2, .9, .3, 1.12); }
dialog[open]::backdrop { animation: fade-in .3s ease-out; }
dialog.closing { animation: sheet-out .2s ease-in both; }
dialog.closing::backdrop { animation: fade-out .2s ease-in both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(26px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(18px) scale(.96); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }

/* chi ha "riduci movimento" attivo non vede animazioni */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}

/* ---------- dock: voci a misura di testo, pillola sulla voce attiva ---------- */
.dock button { flex: 1 1 auto; padding: 11px 14px; }
.dock::before {
  left: 0; width: var(--w, 0px);
  transform: translateX(var(--x, 0px));
  transition: none;
}
.dock.placed::before {
  transition: transform .4s cubic-bezier(.3, 1.25, .5, 1), width .4s cubic-bezier(.3, 1.25, .5, 1);
}

/* ---------- schermi: barra del browser, tastiera, notch ---------- */
/* dvh = altezza realmente visibile (vh include la zona sotto la barra del browser) */
body, .screen { min-height: 100vh; min-height: 100dvh; }
dialog {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b));
  overscroll-behavior: contain;
}
#app {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.dock-wrap {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* schermi stretti (≤ 380 px): voci più compatte, la dock resta dentro i margini */
@media (max-width: 380px) {
  .dock button { padding: 11px 9px; font-size: 12.5px; }
}

/* ---------- pulsanti delle card: mai a capo, vanno su due righe se non c'è spazio ---------- */
.actions { flex-wrap: wrap; }
.actions a, .actions button {
  flex: 1 1 auto; white-space: nowrap; display: flex; align-items: center; justify-content: center;
  padding: 9px 4px; min-height: 38px;
}
@media (max-width: 380px) { .actions a, .actions button { font-size: 12.5px; } }

/* schermi bassi (telefono in orizzontale): foto del pannello più piccola */
@media (max-height: 500px) { .photo { aspect-ratio: 16 / 5; } }

/* ---------- lista stabile: nessun salto quando cambia il numero di capi ---------- */
#list { min-height: 55vh; min-height: 55dvh; }
#summary { min-height: 1.5em; }               /* la riga del totale non fa più "saltare" l'intestazione */
.empty { display: grid; place-items: center; min-height: 45vh; min-height: 45dvh; margin: 0; padding: 0 28px; }

/* ---------- conferma eliminazione ---------- */
dialog.confirm { width: min(86vw, 340px); text-align: center; }
dialog.confirm h2 { margin-bottom: 6px; }
dialog.confirm p { margin: 0 0 18px; font-size: 15px; line-height: 1.5; }
.btn.danger-fill { background: linear-gradient(180deg, #e0574d, #b3261e); color: #fff; border-color: rgba(255, 255, 255, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 6px 16px rgba(179, 38, 30, .35); }
dialog.confirm.glass { background: color-mix(in srgb, var(--glass-bg) 40%, var(--bg)); }

/* card che escono con "Preso ✓" */
.card.leaving { opacity: 0; transform: scale(.92); transition: opacity .18s ease-in, transform .18s ease-in; pointer-events: none; }
