/* Kcal — mobile-first, iOS-like. Light/dark via prefers-color-scheme. */

:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #efede8;
  --surface-3: #e6e3dc;
  --text: #17171a;
  --text-2: #64636a;
  --text-3: #9b99a1;
  --line: rgba(20, 18, 10, 0.08);
  --line-strong: rgba(20, 18, 10, 0.14);
  --accent: #ff5a2c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 90, 44, 0.12);
  --kcal: #ff5a2c;
  --p: #3e7bfa;
  --f: #f0a81c;
  --c: #22b07d;
  --danger: #e5383b;
  --over: #e5383b;
  --track: rgba(20, 18, 10, 0.07);
  --shadow: 0 1px 2px rgba(20, 18, 10, 0.04), 0 6px 20px rgba(20, 18, 10, 0.05);
  --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  --blur-bg: rgba(244, 243, 239, 0.78);
  --radius: 20px;
  --radius-s: 13px;
  --tabbar-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e;
    --surface: #18181b;
    --surface-2: #222226;
    --surface-3: #2c2c31;
    --text: #f4f4f5;
    --text-2: #a5a5ae;
    --text-3: #6f6f78;
    --line: rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.13);
    --accent: #ff6a3d;
    --accent-soft: rgba(255, 106, 61, 0.16);
    --kcal: #ff6a3d;
    --p: #5b8fff;
    --f: #f5b638;
    --c: #2fc58d;
    --danger: #ff5a5f;
    --over: #ff5a5f;
    --track: rgba(255, 255, 255, 0.08);
    --shadow: none;
    --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    --blur-bg: rgba(12, 12, 14, 0.78);
  }
}

* { 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 var(--font);
  letter-spacing: -0.01em;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; }
button:disabled { cursor: default; opacity: 0.45; }
input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.ic { display: inline-flex; flex: none; }
.ic svg { display: block; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
b { font-weight: 650; }

#view { max-width: 600px; margin: 0 auto; padding-left: var(--safe-l); padding-right: var(--safe-r); }
.view { min-height: 100dvh; }
.scroll { padding: 4px 16px 0; }
.bottom-space { height: calc(var(--tabbar-h) + var(--safe-b) + 28px); }
body[data-tab=""] .bottom-space { height: calc(var(--safe-b) + 32px); }

/* ---------- top bars ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) 8px 8px;
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.top-title { text-align: center; font-weight: 650; font-size: 17px; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.top-sub { font-size: 12px; color: var(--text-2); font-weight: 500; }
.top-actions { display: flex; }
.top-save { font-weight: 650; color: var(--accent); padding: 8px 12px; font-size: 17px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 22px; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 36px; height: 36px; color: var(--text-2); }
.icon-btn.danger { color: var(--danger); }

.diary-top { grid-template-columns: 44px 1fr auto; }
.day-title { position: relative; display: flex; flex-direction: column; align-items: center; cursor: pointer; padding: 2px 0; }
.day-main { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; }
.day-sub { font-size: 12.5px; color: var(--text-2); }
.date-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; -webkit-appearance: none; appearance: none; }

.large-title {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(var(--safe-t) + 18px) 16px 12px;
}
.large-title h1 { margin: 0; font-size: 34px; letter-spacing: -0.03em; font-weight: 780; }
.round-btn {
  width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px rgba(255, 90, 44, 0.35);
}

/* ---------- cards ---------- */

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }

.summary { padding: 18px 18px 16px; }
.sum-top { display: flex; align-items: center; gap: 20px; }
.ring { position: relative; width: 128px; height: 128px; flex: none; }
.ring-svg { width: 100%; height: 100%; display: block; }
.ring-svg circle { fill: none; stroke-width: 11; stroke-linecap: round; }
.ring-track { stroke: var(--track); }
.ring-val { stroke: var(--kcal); transition: stroke-dasharray 0.5s cubic-bezier(.2, .8, .2, 1); }
.ring-over { stroke: var(--over); opacity: 0.85; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center b { font: 750 27px/1 var(--font-num); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ring-center span { font-size: 11.5px; color: var(--text-2); margin-top: 4px; }
.kcal-stats { margin: 0; flex: 1; display: grid; gap: 9px; }
.kcal-stats > div { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.kcal-stats > div:last-child { border-bottom: 0; padding-bottom: 0; }
.kcal-stats dt { color: var(--text-2); font-size: 14px; }
.kcal-stats dd { margin: 0; font: 650 18px var(--font-num); font-variant-numeric: tabular-nums; }
.kcal-stats dd.neg { color: var(--over); }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.macro-name { font-size: 12.5px; color: var(--text-2); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.macro-name i, .mc i, .gm-name i { width: 8px; height: 8px; border-radius: 4px; display: inline-block; flex: none; }
.p .macro-name i, .mc.p i, .gm.p i { background: var(--p); }
.f .macro-name i, .mc.f i, .gm.f i { background: var(--f); }
.c .macro-name i, .mc.c i, .gm.c i { background: var(--c); }
.macro-val { margin: 4px 0 7px; white-space: nowrap; }
.macro-val b { font: 700 22px var(--font-num); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.macro-val span { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.bar { height: 7px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > div { height: 100%; border-radius: 4px; transition: width 0.5s cubic-bezier(.2, .8, .2, 1); }
.p .bar > div { background: var(--p); }
.f .bar > div { background: var(--f); }
.c .bar > div { background: var(--c); }
.bar.over > div { background: var(--over) !important; }
.macro-rem { font-size: 11.5px; color: var(--text-2); margin-top: 6px; font-variant-numeric: tabular-nums; }
.macro-rem.neg { color: var(--over); font-weight: 600; }

/* meals */
.meal { padding: 4px 0 6px; overflow: hidden; }
.meal-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 8px 18px; }
.meal-title { flex: 1; min-width: 0; }
.meal-title h2 { margin: 0; font-size: 18px; font-weight: 720; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.meal-macros { font-size: 12px; color: var(--text-3); margin-top: 1px; font-variant-numeric: tabular-nums; }
.meal-kcal { font-variant-numeric: tabular-nums; margin-right: 2px; white-space: nowrap; }
.meal-kcal b { font: 700 17px var(--font-num); }
.meal-kcal span { color: var(--text-2); font-size: 12.5px; }
.tag { font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--surface-2); padding: 2px 7px; border-radius: 6px; letter-spacing: 0; }
.add-btn { width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.add-btn:active { transform: scale(0.94); }
.entries { list-style: none; margin: 0; padding: 0; }
.entries li + li .entry { border-top: 1px solid var(--line); }
.entries li { padding: 0 0 0 18px; }
.entry { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 18px 11px 0; text-align: left; }
.entry:active { opacity: 0.6; }
.entry-main { flex: 1; min-width: 0; }
.entry-name { font-weight: 560; font-size: 15.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.entry-sub { display: flex; align-items: center; gap: 7px; margin-top: 4px; min-width: 0; }
.qty-pill.quick { display: inline-flex; align-items: center; gap: 3px; background: var(--accent-soft); color: var(--accent); }
.qty-pill { font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--text); border-radius: 7px; padding: 2px 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry-brand { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-kcal { text-align: right; display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.entry-kcal b { font: 650 16px var(--font-num); font-variant-numeric: tabular-nums; }
.entry-kcal span { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty-meal { display: flex; align-items: center; gap: 8px; margin: 2px 14px 10px; padding: 12px 14px; width: calc(100% - 28px); border-radius: var(--radius-s); border: 1.5px dashed var(--line-strong); color: var(--text-2); font-size: 14.5px; font-weight: 500; }

.banner { display: flex; align-items: flex-start; gap: 10px; background: var(--surface-2); color: var(--text); border-radius: var(--radius-s); padding: 11px 13px; margin-bottom: 12px; font-size: 14px; }
.banner .ic { margin-top: 1px; color: var(--text-2); }
.banner.error { background: rgba(229, 56, 59, 0.1); color: var(--danger); }
.banner.info { background: var(--accent-soft); }
.banner.info .ic { color: var(--accent); }
.link-inline { color: var(--accent); font-weight: 600; margin-left: auto; }

.skeleton-list { display: grid; gap: 14px; }
.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 6px max(8px, var(--safe-l)) calc(var(--safe-b) + 4px);
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line-strong);
  transition: transform 0.25s ease;
}
body[data-tab=""] .tabbar { transform: translateY(110%); }
.tabbar a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--text-3); font-size: 10.5px; font-weight: 600; padding: 4px 0;
}
.tabbar a.on { color: var(--accent); }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 15px; font-weight: 650; font-size: 16.5px;
  transition: transform 0.1s ease, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { background: var(--surface-3); color: var(--text-3); opacity: 1; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--danger); margin-top: 20px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.link-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 14px 0 2px; color: var(--text-2); font-size: 14px; font-weight: 500; }

.seg { display: flex; background: var(--surface-3); border-radius: 11px; padding: 2px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background 0.2s, color 0.2s; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg.small { margin: 0; flex: none; border-radius: 9px; }
.seg.small button { flex: none; min-width: 40px; padding: 6px 11px; font-size: 13.5px; border-radius: 7px; overflow: visible; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #3a3a40; } }

input.text, .select, .date-field {
  width: 100%; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 0;
  background: var(--surface-2); outline: none; -webkit-appearance: none; appearance: none;
}
input.text:focus, .select:focus, .date-field:focus { box-shadow: 0 0 0 2px var(--accent); }
.date-field { min-height: 46px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field > span { font-size: 13px; color: var(--text-2); font-weight: 600; }
.field-row { display: flex; gap: 10px; }
.hint { font-size: 13px; color: var(--text-2); margin: 8px 4px 14px; line-height: 1.45; }
.form-error { display: flex; gap: 10px; align-items: flex-start; background: rgba(229, 56, 59, 0.1); color: var(--danger); padding: 11px 13px; border-radius: 12px; font-size: 14px; margin: 10px 0; font-weight: 500; }
.warnings { display: grid; gap: 6px; }
.warn { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: #b26b00; background: rgba(240, 168, 28, 0.13); padding: 9px 12px; border-radius: 11px; margin: 6px 0; }
@media (prefers-color-scheme: dark) { .warn { color: #f5c25b; } }

/* grouped lists (settings style) */
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); font-weight: 600; margin: 22px 6px 8px; }
.group { background: var(--surface); border-radius: var(--radius-s); overflow: hidden; box-shadow: var(--shadow); list-style: none; margin: 0; padding: 0; }
.group > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; text-align: left; font-size: 16px; justify-content: space-between; }
.row.action { justify-content: flex-start; font-weight: 500; }
.row.action .ic { color: var(--accent); }
.row.action:active { background: var(--surface-2); }
.row.action.danger, .row.action.danger .ic { color: var(--danger); }
.frow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px 6px 16px; min-height: 52px; }
.frow > span { font-size: 16px; flex: none; display: flex; flex-direction: column; }
.frow > span small { font-size: 12px; color: var(--text-3); }
.frow input.text, .frow .ac input.text { background: transparent; text-align: right; padding: 10px 8px; box-shadow: none !important; }
.frow > input.text { flex: 1; min-width: 0; }
.frow .inline { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; justify-content: flex-end; }
.frow .inline input { flex: 1; min-width: 0; }
.frow.readonly .computed { font: 650 18px var(--font-num); padding: 10px 2px; }
input.num {
  width: 100%; min-width: 0; text-align: right; font: 600 18px var(--font-num); font-variant-numeric: tabular-nums;
  border: 0; outline: none; background: transparent; padding: 10px 6px; -webkit-appearance: none; appearance: none;
}
.frow input.num { max-width: 120px; }
.unit { color: var(--text-2); font-size: 14px; flex: none; min-width: 22px; }
.ac { position: relative; flex: 1; min-width: 0; }
.suggest {
  position: absolute; right: 0; left: 0; top: calc(100% + 4px); z-index: 10; background: var(--surface); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); overflow: hidden; border: 1px solid var(--line);
}
.suggest button { display: block; width: 100%; text-align: left; padding: 12px 14px; font-size: 16px; }
.suggest button + button { border-top: 1px solid var(--line); }
.suggest button:active { background: var(--surface-2); }

.nutrition .nut-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 6px 16px; min-height: 58px; gap: 10px; }
.nut-label { display: flex; flex-direction: column; }
.nut-label .jp { font-size: 16.5px; font-weight: 600; }
.nut-label .it { font-size: 12px; color: var(--text-2); }
.nut-input { display: flex; align-items: center; gap: 6px; width: 46%; }
.nut-input .unit { width: 34px; }
.nut-row.missing { background: rgba(240, 168, 28, 0.12); }
.nut-row.missing .it::after { content: " · dato mancante"; color: #c07a00; font-weight: 600; }
.per100-preview { font-size: 13.5px; color: var(--text-2); margin: 10px 6px; font-variant-numeric: tabular-nums; }
.per100-preview:empty { display: none; }
.per100-preview b { color: var(--text); }

/* ---------- sheets ---------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.38); opacity: 0; transition: opacity 0.28s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 600px;
  max-height: calc(100dvh - var(--safe-t) - 24px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--sheet-shadow);
  padding: 8px 20px calc(var(--safe-b) + 18px);
  transform: translateY(105%); transition: transform 0.32s cubic-bezier(.2, .9, .25, 1);
}
.sheet.tall { min-height: 70dvh; }
.sheet-wrap.open { pointer-events: auto; }
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: translateY(0); }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 12px; }
.sheet-title { font-size: 20px; font-weight: 720; letter-spacing: -0.02em; margin: 4px 0 12px; }
.sheet-title.small { font-size: 14px; font-weight: 600; color: var(--text-2); text-align: center; margin-bottom: 10px; }
.actions .group { margin-bottom: 10px; background: var(--surface-2); box-shadow: none; }
.actions .btn { margin-top: 2px; }
.form-sheet .btn { margin-top: 8px; }
.form-sheet > input.text { margin-bottom: 8px; }
@media (prefers-color-scheme: dark) { .sheet { background: #1c1c1f; } .actions .group { background: var(--surface-2); } }

/* quantity sheet */
.qty-head { margin-bottom: 14px; }
.qty-title { font-size: 21px; font-weight: 720; letter-spacing: -0.02em; line-height: 1.25; }
.qty-sub { font-size: 13.5px; color: var(--text-2); margin-top: 3px; }
.qty-per { font-size: 12.5px; color: var(--text-3); margin-top: 6px; font-variant-numeric: tabular-nums; }
.qty-input { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 16px; padding: 6px 8px 6px 14px; }
.qty-input input.big { font-size: 34px; font-weight: 700; text-align: left; padding: 6px 0; }
.qty-input .unit { font-size: 17px; font-weight: 600; padding-right: 8px; }
.qty-input .seg.small { background: var(--surface-3); }
.qty-note { font-size: 13px; color: var(--text-2); margin: 7px 4px 0; min-height: 18px; font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: 8px; margin: 10px 0 14px; }
.chip { flex: 1; padding: 9px 0; border-radius: 11px; background: var(--surface-2); font-weight: 600; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.chip:active { background: var(--surface-3); }
.qty-result { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px 14px; border-top: 1px solid var(--line); }
.qty-kcal b { font: 750 30px var(--font-num); letter-spacing: -0.02em; color: var(--kcal); font-variant-numeric: tabular-nums; }
.qty-kcal span { color: var(--text-2); font-weight: 600; }
.macro-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.mc { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 5px 9px; border-radius: 9px; font-variant-numeric: tabular-nums; }
.mc b { color: var(--text); }
.meal-pills { display: flex; gap: 8px; overflow-x: auto; margin: 0 -20px 14px; padding: 0 20px 2px; scrollbar-width: none; }
.meal-pills::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: 8px 14px; border-radius: 20px; background: var(--surface-2); font-size: 14.5px; font-weight: 600; color: var(--text-2); }
.pill.on { background: var(--text); color: var(--bg); }
.entry-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.ghost-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0; border-radius: 14px; background: var(--surface-2); font-size: 13px; font-weight: 600; }
.ghost-btn.danger { color: var(--danger); }

.quick-intro { margin: -4px 0 14px; line-height: 1.45; }
.quick-sheet > input.text { margin-bottom: 12px; }
.quick-sheet .group.nutrition { background: var(--surface-2); box-shadow: none; }
.quick-hint { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-2); margin: 10px 4px 12px; min-height: 18px; font-variant-numeric: tabular-nums; }
.quick-hint b { color: var(--text); }
.quick-hint .link-inline { margin-left: auto; }
.copy-preview { margin: 4px 0 8px; min-height: 30px; }
.copy-total { font-weight: 650; margin-bottom: 6px; }
.copy-list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.copy-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.copy-list li span { color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- add / search ---------- */

.meal-picker { position: relative; display: inline-flex; align-items: center; gap: 4px; font-size: 17px; font-weight: 700; }
.meal-picker select { position: absolute; inset: 0; opacity: 0; width: 100%; -webkit-appearance: none; appearance: none; }
.search-bar { position: sticky; top: calc(var(--safe-t) + 58px); z-index: 15; padding: 0 16px 10px; background: var(--blur-bg); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.search-field { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 13px; padding: 0 6px 0 12px; box-shadow: var(--shadow); color: var(--text-3); }
@media (prefers-color-scheme: dark) { .search-field { background: var(--surface-2); } }
.search-input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 17px; padding: 12px 0; color: var(--text); -webkit-appearance: none; appearance: none; }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear { width: 28px; height: 28px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.inline-search { margin-bottom: 14px; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.big-action { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; background: var(--surface); border-radius: 16px; padding: 12px 12px 13px; box-shadow: var(--shadow); min-width: 0; }
.big-action .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 8px; }
.big-action span { font-weight: 650; }
.big-action small { font-size: 12.5px; color: var(--text-2); }
.big-action:active { transform: scale(0.98); }
.list-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); font-weight: 600; margin: 20px 6px 8px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius-s); box-shadow: var(--shadow); overflow: hidden; }
.list li + li .result { border-top: 1px solid var(--line); }
.list li { padding-left: 14px; }
.result { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 14px 11px 0; text-align: left; min-height: 58px; }
.result:active { opacity: 0.6; }
.badge { flex: none; font-size: 10px; font-weight: 750; letter-spacing: 0.03em; padding: 4px 0; width: 38px; text-align: center; border-radius: 7px; }
.badge.food { background: var(--accent-soft); color: var(--accent); }
.badge.mext { background: rgba(62, 123, 250, 0.12); color: var(--p); }
.result-main { flex: 1; min-width: 0; }
.result-name { font-size: 15.5px; font-weight: 560; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.result-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-kcal { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.result-kcal b { font: 650 16px var(--font-num); font-variant-numeric: tabular-nums; }
.result-kcal span { font-size: 11px; color: var(--text-3); }
.empty { text-align: center; padding: 36px 20px; color: var(--text); }
.empty p { margin: 0 0 10px; }
.empty.full { min-height: 80dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.empty.full h2 { margin: 6px 0 0; }

/* ---------- goals ---------- */

.goals .seg { margin-bottom: 16px; }
.goal-result { padding: 18px; }
.goal-kcal { display: flex; align-items: baseline; gap: 8px; }
.goal-kcal b { font: 760 36px var(--font-num); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.goal-kcal span { color: var(--text-2); font-weight: 500; }
.split-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; margin: 14px 0 14px; background: var(--track); }
.split-bar > div { min-width: 0; transition: flex-grow 0.4s ease; }
.split-bar .p { background: var(--p); }
.split-bar .f { background: var(--f); }
.split-bar .c { background: var(--c); }
.goal-macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.gm { display: flex; flex-direction: column; gap: 2px; }
.gm-name { font-size: 12.5px; color: var(--text-2); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.gm b { font: 700 20px var(--font-num); font-variant-numeric: tabular-nums; }
.gm-pct { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.goal-check { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.goals .btn.primary { margin-top: 6px; }

/* ---------- more ---------- */

.meals-edit .meal-row { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 6px; background: var(--surface); }
.meal-row.dragging { position: relative; z-index: 2; box-shadow: 0 8px 26px rgba(0, 0, 0, 0.18); border-radius: 12px; transform: scale(1.02); }
.drag-handle { width: 40px; height: 44px; display: grid; place-items: center; color: var(--text-3); touch-action: none; cursor: grab; }
.meal-name { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 17px; padding: 12px 4px; }
.meal-name:focus { color: var(--accent); }
.add-meal { margin-top: 10px; }
.info .row { padding: 13px 16px; }
.info .row .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.credits { line-height: 1.6; }

/* ---------- toast ---------- */

#toast {
  position: fixed; left: 0; right: 0; z-index: 60; display: flex; justify-content: center; pointer-events: none;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); opacity: 0; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s;
}
body[data-tab=""] #toast { bottom: calc(var(--safe-b) + 20px); }
#toast.show { opacity: 1; transform: none; }
#toast.top { bottom: auto; top: calc(var(--safe-t) + 12px); transform: translateY(-10px); }
#toast.top.show { transform: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  background: #232326; color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 14.5px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
@media (prefers-color-scheme: dark) { .toast { background: #f4f4f5; color: #111; } }
.toast.error { background: var(--danger); color: #fff; }
.toast button { color: var(--accent); font-weight: 700; }
.toast.error button { color: #fff; text-decoration: underline; }

/* ---------- offline / auth / splash ---------- */

.offline-pill { position: fixed; top: calc(var(--safe-t) + 2px); left: 0; right: 0; z-index: 40; display: flex; justify-content: center; pointer-events: none; opacity: 0; transform: translateY(-8px); transition: 0.25s; }
.offline-pill span { background: #2a2a2e; color: #fff; font-size: 11.5px; font-weight: 650; padding: 3px 10px; border-radius: 10px; }
body.is-offline .offline-pill { opacity: 1; transform: none; }
body.is-offline .topbar, body.is-offline .large-title { padding-top: calc(var(--safe-t) + 24px); }

.login {
  position: fixed; inset: 0; z-index: 85; background: var(--bg); display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px); transition: opacity 0.25s;
}
.login.leaving { opacity: 0; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 10px 30px rgba(255, 90, 44, 0.3); }
.login h1 { margin: 18px 0 2px; font-size: 30px; letter-spacing: -0.03em; }
.login-card > p { margin: 0 0 28px; }
.login-form { display: grid; gap: 12px; text-align: left; }
.login-form input.text { font-size: 18px; padding: 15px 16px; background: var(--surface); box-shadow: var(--shadow); }
.login-form .form-error { margin: 0; }
.auth-icon { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto; background: var(--accent-soft); color: var(--accent); }

.splash { min-height: 100dvh; display: grid; place-items: center; }
.splash-ring { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--track); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- scanner ---------- */

.scanner { position: fixed; inset: 0; z-index: 90; background: #000; color: #fff; opacity: 0; transition: opacity 0.22s; }
.scanner.open { opacity: 1; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-mask { position: absolute; inset: 0; display: grid; place-items: center; }
.scan-box { position: relative; width: min(78vw, 340px); height: min(42vw, 180px); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); }
.scan-box i { position: absolute; width: 28px; height: 28px; border: 4px solid #fff; }
.scan-box .c1 { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scan-box .c2 { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.scan-box .c3 { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.scan-box .c4 { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scan-line { position: absolute; left: 14px; right: 14px; top: 50%; height: 2px; background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: scanline 1.8s ease-in-out infinite; }
@keyframes scanline { 0%, 100% { transform: translateY(-60px); opacity: 0.4; } 50% { transform: translateY(60px); opacity: 1; } }
.scanner.failed .scan-line { display: none; }
.scan-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 10px) 14px 10px; }
.scan-title { font-weight: 650; font-size: 16px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); }
.scan-btn { width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.16); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); color: #fff; }
.scan-btn.on { background: #fff; color: #000; }
.scan-btn[hidden] { display: grid !important; visibility: hidden; }
.scan-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 20px calc(var(--safe-b) + 24px); text-align: center; display: grid; gap: 14px; justify-items: center; }
.scan-status { font-size: 15px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); max-width: 340px; line-height: 1.45; }
.scan-manual { padding: 12px 20px; border-radius: 14px; background: rgba(255, 255, 255, 0.16); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); font-weight: 600; }

@media (min-width: 640px) {
  .scroll { padding-left: 0; padding-right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
