/* ============ NutriDiario ============ */
:root {
  --bg: #F3F4F0;
  --surface: #FFFFFF;
  --surface-2: #F7F8F5;
  --line: #E4E6E0;
  --text: #15191A;
  --muted: #6A7174;
  --faint: #9AA0A2;
  --accent: #1E9E62;
  --accent-strong: #15814F;
  --accent-soft: #E3F4EB;
  --on-accent: #FFFFFF;
  --danger: #D6453D;
  --danger-soft: #FBE9E7;
  --warn: #E08A1E;
  --prot: #E2574C;
  --carb: #E9A23B;
  --fat: #4A86E8;
  --water: #2F9BE0;
  --water-soft: #E3F1FB;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 6px 20px rgba(20, 30, 25, .06);
  --radius: 20px;
  --radius-sm: 14px;
  --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);
  --tabbar-h: 64px;
  --kb: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1412;
    --surface: #182019;
    --surface-2: #1E2720;
    --line: #2A342D;
    --text: #EEF2EE;
    --muted: #A2ABA5;
    --faint: #6E7872;
    --accent: #35C07E;
    --accent-strong: #4FD192;
    --accent-soft: #1C3528;
    --on-accent: #06140C;
    --danger: #F06A60;
    --danger-soft: #3A1E1C;
    --prot: #F0766C;
    --carb: #F2B557;
    --fat: #6FA0F0;
    --water: #55B3F0;
    --water-soft: #16303F;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
input, select, textarea { font-size: 16px; } /* niente zoom su iOS */
img { max-width: 100%; display: block; }
svg { display: block; }
[hidden] { display: none !important; }
.ico { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 18px; height: 18px; }
.ico.lg { width: 28px; height: 28px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.center { text-align: center; }

/* ---------- Layout ---------- */
#view {
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) calc(var(--tabbar-h) + var(--sab) + 28px) calc(var(--sal) + 16px);
  max-width: 640px; margin: 0 auto;
}
#view.no-tabs { padding-bottom: calc(var(--sab) + 24px); }

.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 2px 16px; min-height: 52px; }
.topbar h1 { margin: 0; font-size: 30px; line-height: 1.1; letter-spacing: -.02em; font-weight: 750; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: capitalize; margin-bottom: 2px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; }
.section-title h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 650; font-size: 16px; background: var(--surface-2); color: var(--text); transition: transform .12s ease, background .2s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:disabled { opacity: .45; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent-strong); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 11px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.icon-btn.flat { box-shadow: none; background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; }
.icon-btn:active { transform: scale(.94); }
.link { color: var(--accent-strong); font-weight: 650; font-size: 15px; }

/* ---------- Date nav ---------- */
.datenav { display: flex; align-items: center; gap: 6px; }
.datepill { position: relative; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 14px; overflow: hidden; }
.datepill input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; -webkit-appearance: none; appearance: none; }

/* ---------- Summary hero ---------- */
.hero { display: grid; grid-template-columns: 148px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 148px; height: 148px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); transition: stroke-dashoffset .6s cubic-bezier(.2,.8,.2,1); }
.ring.over .bar { stroke: var(--danger); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label b { font-size: 32px; line-height: 1; letter-spacing: -.02em; }
.ring-label span { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.ring.over .ring-label b { color: var(--danger); }
.kpis { display: grid; gap: 10px; }
.kpi { display: flex; align-items: center; gap: 10px; }
.kpi .dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.kpi small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi strong { font-size: 17px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.macro small { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 650; }
.macro .val { font-size: 15px; font-weight: 700; margin: 2px 0 6px; }
.macro .val span { color: var(--muted); font-weight: 500; font-size: 13px; }
.meter { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; width: 0; transition: width .5s ease; }
.macro.p .meter i { background: var(--prot); }
.macro.c .meter i { background: var(--carb); }
.macro.f .meter i { background: var(--fat); }
.macro.over .val { color: var(--danger); }
@media (max-width: 370px) {
  .hero { grid-template-columns: 124px 1fr; gap: 12px; }
  .ring { width: 124px; height: 124px; }
  .ring-label b { font-size: 26px; }
}

/* ---------- Water ---------- */
.water-glasses { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 8px; margin: 4px 0 14px; }
.glass { height: 44px; border-radius: 10px; background: var(--water-soft); color: var(--water); display: grid; place-items: center; opacity: .55; transition: all .2s; }
.glass.full { background: var(--water); color: #fff; opacity: 1; }
.glass:active { transform: scale(.92); }
.water-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.btn.water { background: var(--water); color: #fff; }
.btn.water-soft { background: var(--water-soft); color: var(--water); }

/* ---------- Meals ---------- */
.meal { padding: 0; overflow: hidden; }
.meal-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.meal-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); flex: none; }
.meal-head h3 { margin: 0; font-size: 17px; }
.meal-head .sub { font-size: 12px; color: var(--muted); font-weight: 550; }
.meal-kcal { font-weight: 750; font-size: 17px; text-align: right; }
.meal-kcal small { display: block; font-weight: 550; font-size: 11px; color: var(--muted); }
.entries { border-top: 1px solid var(--line); }
.entry { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 16px; text-align: left; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry:active, .list-item:active { background: var(--surface-2); }
.entry .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .kcal { font-weight: 650; font-size: 15px; }
.meal-add { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 13px; color: var(--accent-strong); font-weight: 650; border-top: 1px solid var(--line); font-size: 15px; }
.meal-add:active { background: var(--accent-soft); }

.thumb { width: 42px; height: 42px; border-radius: 10px; background: var(--surface-2); flex: none; overflow: hidden; display: grid; place-items: center; color: var(--faint); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 6px calc(var(--sar) + 8px) calc(var(--sab) + 6px) calc(var(--sal) + 8px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabs { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; height: var(--tabbar-h); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%; color: var(--faint); font-size: 11px; font-weight: 650; }
.tab.active { color: var(--accent-strong); }
.tab-plus { display: grid; place-items: center; }
.tab-plus span { width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 40%, transparent); transition: transform .12s; }
.tab-plus:active span { transform: scale(.92); }

/* ---------- Layers (sheets, dialogs) ---------- */
.layer { position: fixed; left: 0; right: 0; top: 0; bottom: var(--kb); z-index: 60; display: flex; flex-direction: column; justify-content: flex-end; }
.backdrop { position: absolute; inset: 0 0 calc(-1 * var(--kb)) 0; background: rgba(8, 14, 10, .42); opacity: 0; transition: opacity .25s ease; }
.layer.open .backdrop { opacity: 1; }
.sheet {
  position: relative; background: var(--bg); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 24px 24px 0 0;
  max-height: calc(100% - var(--sat) - 10px);
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2,.85,.25,1);
  box-shadow: 0 -10px 40px rgba(0,0,0,.15);
}
.layer.open .sheet { transform: translateY(0); }
.sheet.full { height: calc(100% - var(--sat) - 10px); }
.sheet-grab { width: 38px; height: 5px; border-radius: 99px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 8px calc(var(--sar) + 16px) 10px calc(var(--sal) + 16px); flex: none; }
.sheet-head h2 { margin: 0; font-size: 19px; flex: 1; min-width: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 4px calc(var(--sar) + 16px) 16px calc(var(--sal) + 16px); flex: 1; min-height: 0; }
.sheet-foot { flex: none; padding: 10px calc(var(--sar) + 16px) calc(var(--sab) + 12px) calc(var(--sal) + 16px); border-top: 1px solid var(--line); background: var(--bg); display: flex; gap: 10px; }
.layer.kb .sheet-foot { padding-bottom: 12px; }
.sheet-body.pad-bottom { padding-bottom: calc(var(--sab) + 20px); }

.dialog-layer { justify-content: center; align-items: center; padding: 24px; }
.dialog { position: relative; background: var(--surface); border-radius: 22px; padding: 22px 20px 16px; width: 100%; max-width: 360px; transform: scale(.94); opacity: 0; transition: all .2s ease; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.layer.open .dialog { transform: scale(1); opacity: 1; }
.dialog h3 { margin: 0 0 6px; font-size: 18px; }
.dialog p { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
.dialog .actions { display: grid; gap: 8px; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 4px 6px; }
.input { width: 100%; height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 14px; outline: none; transition: border-color .15s; -webkit-appearance: none; appearance: none; }
.input:focus { border-color: var(--accent); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .suffix { position: absolute; right: 14px; color: var(--muted); font-weight: 600; pointer-events: none; font-size: 15px; }
.input-wrap .input { padding-right: 52px; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 22px, calc(100% - 15px) 22px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.seg { display: flex; background: var(--surface-2); border-radius: 13px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; font-weight: 650; font-size: 14px; color: var(--muted); white-space: nowrap; padding: 0 8px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 4px; margin: 0 -2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 36px; padding: 0 14px; border-radius: 99px; background: var(--surface); border: 1.5px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.choice { width: 100%; text-align: left; display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 2px solid transparent; box-shadow: var(--shadow); margin-bottom: 10px; }
.choice.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); }
.choice b { display: block; font-size: 16px; }
.choice small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.choice .radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.choice.on .radio { border-color: var(--accent); background: var(--accent); }
.choice.on .radio::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--on-accent); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 4px 14px; }
.note { background: var(--accent-soft); color: var(--accent-strong); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.note.warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--text); }
.toggle { position: relative; width: 50px; height: 30px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(20px); }

/* ---------- Search / lists ---------- */
.searchbar { display: flex; gap: 8px; }
.searchbar .input-wrap { flex: 1; }
.searchbar .input { padding-left: 42px; padding-right: 40px; }
.searchbar .lead { position: absolute; left: 13px; color: var(--faint); pointer-events: none; }
.searchbar .clear { position: absolute; right: 6px; width: 34px; height: 34px; display: grid; place-items: center; color: var(--faint); }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 6px; }
.qa { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 76px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); font-size: 13px; font-weight: 650; padding: 8px 4px; text-align: center; }
.qa .ico { color: var(--accent-strong); }
.qa.hl { background: var(--accent); color: var(--on-accent); }
.qa.hl .ico { color: var(--on-accent); }
.qa:active { transform: scale(.96); }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.list-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 14px; text-align: left; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-item .t { font-weight: 620; font-size: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list-item .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .r { text-align: right; font-size: 14px; font-weight: 700; white-space: nowrap; }
.list-item .r small { display: block; font-size: 11px; color: var(--muted); font-weight: 550; }
.badge { display: inline-block; font-size: 10px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); vertical-align: 1px; margin-right: 4px; }
.list-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 6px 8px; }
.empty { text-align: center; padding: 28px 18px; color: var(--muted); }
.empty .ico { margin: 0 auto 10px; width: 36px; height: 36px; color: var(--faint); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }
.skeleton { height: 64px; border-radius: 0; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
.skeleton + .skeleton { border-top: 1px solid var(--line); }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Food detail ---------- */
.food-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.food-hero .thumb { width: 72px; height: 72px; border-radius: 16px; }
.food-hero h3 { margin: 0; font-size: 18px; line-height: 1.25; }
.food-hero .brand { color: var(--muted); font-size: 14px; margin-top: 2px; }
.qty-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qty-input { height: 58px; font-size: 24px; font-weight: 700; text-align: center; }
.nut-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.nut { background: var(--surface); border-radius: 14px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.nut b { display: block; font-size: 18px; letter-spacing: -.01em; }
.nut small { font-size: 11px; font-weight: 650; color: var(--muted); }
.nut.k b { color: var(--accent-strong); }
.nut.p small { color: var(--prot); }
.nut.c small { color: var(--carb); }
.nut.f small { color: var(--fat); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table td { padding: 9px 2px; border-top: 1px solid var(--line); }
.table td:last-child { text-align: right; font-weight: 600; }
.table tr.sub td:first-child { padding-left: 14px; color: var(--muted); }

/* ---------- Scanner ---------- */
.scanner { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .shade { position: absolute; inset: 0; pointer-events: none; }
.scanner .frame { position: absolute; left: 50%; top: 42%; width: min(78vw, 340px); height: min(46vw, 200px); transform: translate(-50%, -50%); border-radius: 22px; box-shadow: 0 0 0 200vmax rgba(0,0,0,.52); }
.scanner .frame::before { content: ""; position: absolute; inset: 0; border-radius: inherit; border: 3px solid rgba(255,255,255,.9); -webkit-mask: linear-gradient(#000 0 0) top/100% 34px no-repeat, linear-gradient(#000 0 0) bottom/100% 34px no-repeat; mask: linear-gradient(#000 0 0) top/100% 34px no-repeat, linear-gradient(#000 0 0) bottom/100% 34px no-repeat; }
.scanner .laser { position: absolute; left: 10%; right: 10%; height: 2px; background: #3BE08F; box-shadow: 0 0 12px #3BE08F; top: 50%; animation: laser 1.8s ease-in-out infinite; border-radius: 2px; }
@keyframes laser { 0%,100% { top: 18%; } 50% { top: 82%; } }
.scanner.found .frame::before { border-color: #3BE08F; }
.scanner-top { position: relative; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: calc(var(--sat) + 10px) calc(var(--sar) + 16px) 10px calc(var(--sal) + 16px); }
.scanner-top .icon-btn { background: rgba(0,0,0,.45); color: #fff; box-shadow: none; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.scanner-top .icon-btn.on { background: #fff; color: #000; }
.scanner-title { font-weight: 700; font-size: 16px; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.scanner-msg { position: absolute; left: 0; right: 0; top: calc(42% + min(23vw, 100px) + 22px); text-align: center; padding: 0 24px; font-size: 15px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); z-index: 2; }
.scanner-bottom { position: relative; z-index: 2; margin-top: auto; padding: 12px calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px); display: grid; gap: 10px; }
.scanner-bottom .manual { display: flex; gap: 8px; }
.scanner-bottom .input { background: rgba(255,255,255,.14); border-color: transparent; color: #fff; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.scanner-bottom .input::placeholder { color: rgba(255,255,255,.65); }
.scanner-bottom .btn { background: rgba(255,255,255,.16); color: #fff; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.scanner-bottom .btn.primary { background: var(--accent); color: var(--on-accent); }
.scanner-error { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 32px; gap: 10px; z-index: 1; }
.scanner-error .ico { margin: 0 auto; width: 44px; height: 44px; opacity: .8; }

/* ---------- Onboarding ---------- */
.ob { min-height: calc(100dvh - var(--sat) - var(--sab) - 40px); display: flex; flex-direction: column; }
.ob-progress { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 6px 4px 22px; }
.ob-progress i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .35s ease; }
.ob h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 8px; }
.ob .lead { color: var(--muted); margin: 0 0 22px; font-size: 16px; }
.ob-body { flex: 1; }
.ob-foot { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 14px 0 calc(var(--sab) + 8px); background: linear-gradient(to top, var(--bg) 70%, transparent); margin-top: 10px; }
.ob-foot .btn.primary { flex: 1; }
.welcome { text-align: center; padding-top: 8vh; }
.welcome .logo { width: 96px; height: 96px; border-radius: 26px; margin: 0 auto 22px; box-shadow: 0 16px 40px color-mix(in srgb, var(--accent) 35%, transparent); }
.welcome ul { list-style: none; padding: 0; margin: 26px auto 0; max-width: 340px; text-align: left; }
.welcome li { display: flex; gap: 12px; align-items: center; padding: 10px 0; font-weight: 550; }
.welcome li .ico { color: var(--accent-strong); }
.big-target { text-align: center; padding: 22px 16px; }
.big-target .v { font-size: 52px; font-weight: 800; letter-spacing: -.03em; line-height: 1; color: var(--accent-strong); }
.big-target .u { font-size: 14px; color: var(--muted); font-weight: 650; margin-top: 6px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); gap: 12px; }
.stat-row:first-child { border-top: 0; }
.stat-row span { color: var(--muted); font-size: 15px; }
.stat-row b { font-size: 16px; text-align: right; }
.macro-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.macro-tile { background: var(--surface); border-radius: 14px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow); border-top: 4px solid; }
.macro-tile.p { border-color: var(--prot); } .macro-tile.c { border-color: var(--carb); } .macro-tile.f { border-color: var(--fat); }
.macro-tile b { display: block; font-size: 20px; }
.macro-tile small { color: var(--muted); font-weight: 600; font-size: 12px; }

/* ---------- Progress ---------- */
.weight-big { font-size: 38px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.weight-big span { font-size: 17px; color: var(--muted); font-weight: 650; margin-left: 3px; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; padding: 4px 9px; border-radius: 99px; background: var(--surface-2); }
.delta.down { color: var(--accent-strong); background: var(--accent-soft); }
.delta.up { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.chart { width: 100%; margin-top: 10px; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .grid text, .chart .xl text { fill: var(--faint); font-size: 11px; font-weight: 600; }
.chart .raw { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .avg { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .7; }
.chart .area { fill: url(#wgrad); }
.chart .pt { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .goal { stroke: var(--warn); stroke-dasharray: 6 5; stroke-width: 1.5; }
.chart .goal-t { fill: var(--warn); font-size: 11px; font-weight: 700; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; position: relative; margin-top: 8px; }
.bars .b { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bars .b i { width: 100%; max-width: 30px; border-radius: 8px 8px 4px 4px; background: var(--accent); min-height: 3px; transition: height .5s; }
.bars .b.over i { background: var(--danger); }
.bars .b.empty i { background: var(--line); }
.bars .b small { height: 16px; line-height: 16px; font-size: 11px; color: var(--muted); font-weight: 650; text-transform: capitalize; }
.bars .b.today small { color: var(--text); }
.bars .target { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--warn); opacity: .8; pointer-events: none; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; background: var(--accent); }
.legend i.avg { background: var(--muted); }
.legend i.goal { background: var(--warn); }

/* ---------- Toast & banners ---------- */
#toast {
  position: fixed; left: 50%; z-index: 100;
  bottom: calc(var(--tabbar-h) + var(--sab) + 24px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 15px;
  max-width: calc(100vw - 32px - var(--sal) - var(--sar)); box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transition: all .25s ease; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.sheet-open #toast { bottom: calc(var(--sab) + 96px + var(--kb)); }
.banner { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 12px; }
.banner .ico { color: var(--accent-strong); }
.banner p { margin: 0; font-size: 14px; flex: 1; }
.banner p b { display: block; font-size: 15px; }
.ios-steps { margin: 0; padding-left: 20px; }
.ios-steps li { margin: 8px 0; }
.kbd { display: inline-flex; vertical-align: -5px; background: var(--surface-2); border-radius: 7px; padding: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 700px) {
  .sheet { border-radius: 24px; margin-bottom: 20px; max-height: calc(100% - 60px); }
  .sheet.full { height: min(820px, calc(100% - 60px)); }
}
input[type=search]::-webkit-search-cancel-button, input[type=search]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
#toast { width: max-content; }
