/* macros-lite — dark sage. Colour = meaning: red kcal, yellow carbs, green protein, grey fat. */
:root {
  --bg: oklch(0.14 0.008 150);
  --bg-2: oklch(0.17 0.009 150);
  --card: oklch(0.20 0.010 150);
  --card-2: oklch(0.24 0.012 150);
  --line: oklch(0.30 0.014 150);
  --line-soft: oklch(0.25 0.012 150);
  --ink: oklch(0.97 0.005 150);
  --ink-2: oklch(0.86 0.008 150);
  --muted: oklch(0.68 0.012 150);
  --faint: oklch(0.52 0.014 150);
  --brand: oklch(0.80 0.130 150);
  --brand-deep: oklch(0.68 0.140 150);
  --brand-soft: oklch(0.29 0.050 150);
  --on-brand: oklch(0.18 0.03 150);
  --c-kcal: oklch(0.68 0.200 25);
  --c-carbs: oklch(0.84 0.160 90);
  --c-protein: oklch(0.80 0.130 150);
  --c-fat: oklch(0.74 0.020 150);
  --warn: oklch(0.80 0.160 70);
  --danger: oklch(0.68 0.190 25);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; overflow-x: hidden; overscroll-behavior-x: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 var(--sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; -webkit-tap-highlight-color: transparent; }
svg { display: block; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* iOS zooms on inputs under 16px and never zooms back. */
@media (pointer: coarse) { input, select, textarea { font-size: 16px !important; } }

/* ── shell ───────────────────────────────────────────────── */
.app { max-width: 520px; margin: 0 auto; padding: 0 16px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + 10px) 0 10px;
  background: linear-gradient(var(--bg) 75%, transparent);
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.topbar h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0; flex: 1; }
.view { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 28px); }

.tabbar {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: max(12px, calc(var(--safe-bottom) - 18px));
  width: min(440px, calc(100% - 24px)); height: var(--tabbar-h);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in oklch, var(--card) 88%, transparent);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.4);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--faint); font-size: 11px; font-weight: 500;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--brand); }

/* ── generic bits ────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 16px; margin-bottom: 12px; }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title h2 { font-size: 15px; font-weight: 600; margin: 0; }
.section-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 18px 4px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card-2); font-weight: 600; font-size: 15px; white-space: nowrap; text-decoration: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--brand); border-color: transparent; color: var(--on-brand); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in oklch, var(--danger) 40%, transparent); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row-actions { display: flex; gap: 8px; }
.row-actions .btn { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin: 0 2px 6px; font-weight: 500; }
.input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 13px;
  background: var(--bg-2); border: 1px solid var(--line); outline: none; font-size: 15px;
}
.input:focus { border-color: var(--brand-deep); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand) 18%, transparent); }
.input.num { font-family: var(--mono); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-2 .field { margin-bottom: 0; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.field-err { color: var(--danger); font-size: 13px; margin: -4px 2px 10px; }

.seg { display: flex; padding: 3px; gap: 3px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 13px; }
.seg button { flex: 1; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 500; font-size: 14px; }
.seg button.on { background: var(--card-2); color: var(--ink); box-shadow: 0 1px 0 rgb(255 255 255 / 0.05) inset; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.chip.on { background: var(--brand-soft); border-color: var(--brand-deep); color: var(--brand); }

.tile {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: var(--card-2); color: var(--ink-2); font-weight: 600; font-size: 15px;
}
.tile.recipe { background: color-mix(in oklch, var(--c-carbs) 18%, var(--card)); color: var(--c-carbs); }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px; min-height: 58px;
  border-bottom: 1px solid var(--line-soft); background: none; border-left: 0; border-right: 0; border-top: 0;
  text-align: left; width: 100%;
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .kcal { font-family: var(--mono); font-size: 14px; color: var(--ink-2); }
.item .add {
  width: 36px; height: 36px; border-radius: 11px; border: 1px solid var(--brand-deep); background: var(--brand-soft);
  color: var(--brand); display: grid; place-items: center; flex: none;
}
.item .add svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }

/* ── today ───────────────────────────────────────────────── */
.daynav { display: flex; align-items: center; gap: 8px; flex: 1; }
.daynav .label { flex: 1; text-align: center; }
.daynav .label b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.daynav .label small { color: var(--muted); font-size: 12px; }
.daynav .label button { background: none; border: 0; padding: 0; }

.hero { display: grid; grid-template-columns: 148px 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 148px; height: 148px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .track { stroke: var(--card-2); }
.ring .bar { stroke: var(--brand); transition: stroke-dashoffset .5s ease; }
.ring .bar.over { stroke: var(--c-kcal); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .center b { font: 600 28px/1 var(--mono); letter-spacing: -0.04em; }
.ring .center small { color: var(--muted); font-size: 12px; margin-top: 4px; }
.macros { display: flex; flex-direction: column; gap: 12px; }
.macro .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.macro .top span:first-child { color: var(--ink-2); font-weight: 500; }
.macro .top span:last-child { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.bar-track { height: 7px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .4s ease; }
.hero-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--muted); }
.hero-foot b { color: var(--ink); font-family: var(--mono); font-weight: 500; }
.streak { color: var(--warn); font-weight: 600; }

.add-cta { display: flex; gap: 8px; margin-bottom: 12px; }
.add-cta .btn.primary { flex: 1; height: 50px; border-radius: 16px; font-size: 16px; }
.add-cta .icon-btn { width: 50px; height: 50px; border-radius: 16px; }

.slot { padding: 6px 14px 6px; }
.slot-head { display: flex; align-items: center; gap: 10px; padding: 8px 2px; }
.slot-head h3 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; }
.slot-head .num { color: var(--muted); font-size: 13px; }
.slot-head .icon-btn { width: 32px; height: 32px; border-radius: 10px; }
.slot .item { min-height: 50px; padding: 8px 2px; }
.slot .hint { font-size: 13px; color: var(--faint); padding: 0 2px 10px; }

/* ── sheet ───────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.55);
  animation: fade .18s ease; display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: min(520px, 100%); max-height: calc(100dvh - var(--safe-top) - 24px);
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  display: flex; flex-direction: column; animation: up .24s cubic-bezier(.2,.8,.2,1);
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line-soft); display: flex; gap: 8px; }
.sheet-foot .btn { flex: 1; height: 50px; border-radius: 16px; }
.sheet.tall { height: calc(100dvh - var(--safe-top) - 24px); }
.sheet.tall .sheet-body { flex: 1; }
.grabber { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 8px auto 0; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--r-xl); border-bottom: 1px solid var(--line); max-height: 86dvh; }
  .sheet.tall { height: 86dvh; }
  .grabber { display: none; }
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.search { position: relative; margin-bottom: 10px; }
.search svg { position: absolute; left: 13px; top: 14px; width: 18px; height: 18px; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; }
.search .input { padding-left: 40px; }

.nutri { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.nutri div { background: var(--card); border: 1px solid var(--line-soft); border-radius: 13px; padding: 10px 8px; text-align: center; }
.nutri b { display: block; font: 600 18px/1.1 var(--mono); letter-spacing: -0.03em; }
.nutri small { font-size: 11px; color: var(--muted); }
.micros { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 13px; color: var(--muted); margin: 4px 2px 12px; }
.micros div { display: flex; justify-content: space-between; }
.micros b { font-family: var(--mono); font-weight: 500; color: var(--ink-2); }

.qty-row { display: flex; gap: 8px; align-items: center; }
.qty-row .input { flex: 1; text-align: center; font-size: 20px; height: 52px; font-weight: 600; }
.qty-row .icon-btn { width: 52px; height: 52px; border-radius: 14px; }
.qty-row .icon-btn svg { width: 20px; height: 20px; }

details.more { margin: 4px 0 12px; }
details.more summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 2px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary { margin-bottom: 8px; }

.scanner { position: relative; border-radius: var(--r-lg); overflow: hidden; background: #000; aspect-ratio: 4 / 3; margin-bottom: 12px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 22% 12%; border: 2px solid var(--brand); border-radius: 14px; box-shadow: 0 0 0 999px rgb(0 0 0 / 0.35); }
.scanner .msg { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; }

/* ── week ────────────────────────────────────────────────── */
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 170px; align-items: end; position: relative; margin: 8px 0 4px; }
.week-chart .goal-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--faint); pointer-events: none; }
.week-chart button { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; background: none; border: 0; padding: 0; }
.week-chart .b { width: 100%; max-width: 34px; border-radius: 8px 8px 4px 4px; background: var(--brand); min-height: 3px; transition: height .4s ease; }
.week-chart .b.over { background: var(--c-kcal); }
.week-chart .b.none { background: var(--card-2); }
.week-chart .b.today { outline: 2px solid var(--ink); outline-offset: 2px; }
.week-chart small { font-size: 11px; line-height: 14px; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line-soft); border-radius: 14px; padding: 12px 10px; }
.stat b { display: block; font: 600 18px/1.1 var(--mono); letter-spacing: -0.03em; }
.stat small { font-size: 11px; color: var(--muted); }
.daytable .item { min-height: 48px; }

/* ── login ───────────────────────────────────────────────── */
.login { min-height: 80dvh; display: grid; place-content: center; text-align: center; gap: 18px; padding: 0 8px; }
.login img { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto; }
.login h1 { margin: 0; font-size: 26px; letter-spacing: -0.03em; }
.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; }

/* ── toast & sync pill ───────────────────────────────────── */
.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(var(--safe-top) + 12px);
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px;
  font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgb(0 0 0 / .45);
  transition: opacity .2s ease, transform .2s ease; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: color-mix(in oklch, var(--danger) 60%, transparent); color: oklch(0.85 0.08 25); }
.pill { font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.warn { color: var(--warn); }
