/* Piatto — carta di banco, inchiostro verde, radicchio per le calorie */

@font-face {
  font-family: "Bricolage";
  src: url("assets/fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --paper: #EEF0EA;
  --surface: #F9FAF6;
  --ink: #1D2A24;
  --muted: #66726B;
  --line: #D5DACF;
  --radicchio: #A8203F;
  --on-radicchio: #FFF6F7;
  --protein: #2F5F8F;
  --carbs: #C98E12;
  --fat: #6F8A2E;
  --danger: #B3261E;
  --ok: #2E7D4F;
  --shadow: 0 1px 0 rgba(29, 42, 36, .06), 0 8px 24px -12px rgba(29, 42, 36, .25);
  --display: "Bricolage", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121B17;
    --surface: #1B2822;
    --ink: #E9EEE4;
    --muted: #93A097;
    --line: #2C3B34;
    --radicchio: #E0516F;
    --on-radicchio: #1A0A0E;
    --protein: #6FA2D6;
    --carbs: #E3B23C;
    --fat: #A3BF58;
    --danger: #FF8A80;
    --ok: #7BD6A0;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; line-height: 1.15; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

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

/* ---------- struttura ---------- */
.view {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(var(--nav-h) + env(safe-area-inset-bottom) + 40px);
}
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

/* ---------- tab bar ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-in { max-width: 520px; margin: 0 auto; height: var(--nav-h); display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; }
.tab {
  background: none; border: 0; display: grid; justify-items: center; gap: 2px; padding: 8px 0;
  color: var(--muted); font-family: var(--display); font-size: .78rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { color: var(--radicchio); }

/* ---------- pulsanti e campi ---------- */
.btn {
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  border-radius: 999px; padding: 11px 20px; font-family: var(--display); font-weight: 650; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px;
}
.btn.primary { background: var(--radicchio); border-color: var(--radicchio); color: var(--on-radicchio); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.quiet { border-color: transparent; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--ink) 8%, transparent);
  display: grid; place-items: center; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 5px; }
.field > span, .lbl { font-size: .85rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], select, textarea {
  width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 12px; min-height: 46px; appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
.field-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-family: var(--display); font-weight: 600; font-size: .92rem;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.err { color: var(--danger); font-size: .92rem; min-height: 1.3em; }

/* ---------- accesso ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 56px) 22px 40px; display: grid; gap: 22px; }
.auth h1 { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; }

/* ---------- oggi: il piatto ---------- */
.datenav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.datelabel { position: relative; font-family: var(--display); font-weight: 700; font-size: 1.15rem; padding: 8px 12px; border-radius: 10px; }
.datelabel input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.plate { position: relative; width: min(78vw, 300px); aspect-ratio: 1; margin: 6px auto 0; }
.plate svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.plate .track { stroke: var(--line); }
.plate .rim { stroke: var(--line); }
.plate .bar { stroke: var(--radicchio); stroke-linecap: round; transition: stroke-dashoffset .9s cubic-bezier(.2, .7, .2, 1); }
.plate .centre { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px; }
.plate .big { font-family: var(--display); font-weight: 800; font-size: clamp(3.2rem, 17vw, 4.4rem); line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.plate .big.over { color: var(--radicchio); }
.plate .sub { color: var(--muted); font-size: .92rem; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 12px 0 18px; }
.macro .name { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.macro .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.macro .val { font-family: var(--display); font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.macro .val small { font-weight: 500; color: var(--muted); font-size: .8rem; }
.macro .meter { height: 5px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.macro .meter i { display: block; height: 100%; background: var(--c); border-radius: 3px; transition: width .7s cubic-bezier(.2, .7, .2, 1); }

.sync-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 14px; background: color-mix(in srgb, var(--ok) 14%, var(--surface)); margin-bottom: 14px; font-size: .92rem; }

/* ---------- lo scontrino ---------- */
.receipt {
  position: relative; background: var(--surface); box-shadow: var(--shadow);
  padding: 18px 16px 20px; border-radius: 4px 4px 0 0; margin-bottom: 16px;
}
.receipt::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px;
  background: radial-gradient(circle at 6px 0, transparent 5.5px, var(--surface) 6px) 0 0 / 12px 8px repeat-x;
  filter: drop-shadow(0 4px 3px rgba(29, 42, 36, .06));
}
.receipt-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; padding-bottom: 10px; border-bottom: 1.5px dashed var(--line); margin-bottom: 4px; }
.rgroup { margin-top: 12px; }
.rgroup > .gname { font-size: .82rem; color: var(--muted); margin-bottom: 2px; }
.rline {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; padding: 7px 0;
  border-radius: 6px;
}
.rline .thumb { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: none; background: var(--line); }
.rline .time { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; flex: none; width: 2.6em; }
.rline .title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.rline .lead { flex: 1 1 14px; min-width: 14px; border-bottom: 2px dotted var(--line); align-self: flex-end; margin-bottom: 7px; }
.rline .kc { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.rline .kc small { font-weight: 500; color: var(--muted); font-size: .72rem; }
.rtotal { display: flex; justify-content: space-between; align-items: baseline; border-top: 1.5px dashed var(--line); margin-top: 14px; padding-top: 12px; font-family: var(--display); font-weight: 800; font-size: 1.2rem; }
.empty { text-align: center; padding: 26px 8px 10px; display: grid; gap: 14px; justify-items: center; }
.empty p { max-width: 26ch; color: var(--muted); }

/* ---------- foglio aggiunta / modifica ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: var(--paper); overflow-y: auto; overscroll-behavior: contain; animation: rise .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-in { max-width: 520px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 18px calc(env(safe-area-inset-bottom) + 40px); display: grid; gap: 16px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }

.pick { display: grid; gap: 12px; }
.pick-btn {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 18px; border-radius: 18px;
  background: var(--surface); border: 1.5px solid var(--line); width: 100%;
}
.pick-btn.main { background: var(--radicchio); border-color: var(--radicchio); color: var(--on-radicchio); }
.pick-btn svg { width: 30px; height: 30px; flex: none; }
.pick-btn b { font-family: var(--display); font-size: 1.15rem; display: block; }
.pick-btn span { font-size: .9rem; opacity: .8; }

.photo { position: relative; border-radius: 18px; overflow: hidden; background: var(--line); aspect-ratio: 4 / 3; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .scan { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; background: rgba(18, 27, 23, .55); color: #fff; font-family: var(--display); font-weight: 600; }
.scan i { position: absolute; left: 0; right: 0; height: 3px; background: var(--radicchio); box-shadow: 0 0 18px 4px var(--radicchio); animation: sweep 1.8s ease-in-out infinite alternate; }
@keyframes sweep { from { top: 8%; } to { top: 92%; } }

.ai-note { display: grid; gap: 6px; padding: 12px 14px; border-radius: 14px; background: color-mix(in srgb, var(--carbs) 14%, var(--surface)); font-size: .92rem; }
.pill { display: inline-block; font-family: var(--display); font-weight: 650; font-size: .82rem; padding: 3px 10px; border-radius: 999px; background: var(--ink); color: var(--paper); justify-self: start; }
.pill.alta { background: var(--ok); color: var(--paper); }
.pill.media { background: var(--carbs); color: #1D2A24; }
.pill.bassa { background: var(--danger); color: var(--paper); }

.item { display: grid; gap: 8px; padding: 12px; border: 1.5px solid var(--line); border-radius: 16px; background: var(--surface); }
.item .top { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.item .top input { font-weight: 600; }
.nums { display: grid; grid-template-columns: 1.15fr 1.15fr 1fr 1fr 1fr; gap: 6px; }
.nums label { display: grid; gap: 3px; font-size: .72rem; color: var(--muted); }
.nums input { padding: 8px 6px; min-height: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.nums .c-p { color: var(--protein); } .nums .c-c { color: var(--carbs); } .nums .c-f { color: var(--fat); }

.totals { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; padding: 14px; border-radius: 16px; background: var(--ink); color: var(--paper); }
.totals div { display: grid; gap: 1px; }
.totals small { opacity: .7; font-size: .75rem; }
.totals b { font-family: var(--display); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.totals div:first-child b { font-size: 1.6rem; }

/* ---------- andamento ---------- */
.stat-big { display: flex; align-items: baseline; gap: 8px; }
.stat-big b { font-family: var(--display); font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--body); font-size: 10px; fill: var(--muted); }
.split { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 10px 0 8px; }
.split i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.legend b { color: var(--ink); font-family: var(--display); }

/* ---------- impostazioni ---------- */
.section { display: grid; gap: 12px; padding-top: 22px; border-top: 1.5px solid var(--line); }
.section:first-of-type { border-top: 0; padding-top: 0; }
.steps { margin: 0; padding-left: 1.25em; display: grid; gap: 8px; font-size: .94rem; }
.code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; background: var(--surface); border: 1.5px dashed var(--line); border-radius: 12px; padding: 10px 12px; user-select: all; -webkit-user-select: all; }
details > summary { cursor: pointer; font-family: var(--display); font-weight: 650; padding: 6px 0; }

/* ---------- avviso ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 999px; font-size: .94rem; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: var(--paper); }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .scan i { animation: none; top: 50%; }
}

/* ---------- rifiniture ---------- */
.btn { white-space: nowrap; }
.btn svg { width: 20px; height: 20px; flex: none; }
.chips.four { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chips.four .chip { padding: 8px 2px; text-align: center; font-size: .88rem; }
.rline .thumb.ph { display: block; background: radial-gradient(circle, transparent 7px, var(--paper) 7.5px, var(--paper) 10px, transparent 10.5px), var(--line); }
.legend { gap: 4px 14px; }
