/* Food log: one stylesheet, no framework. Colour is reserved for the three macros. */
@font-face {
  font-family: "Atkinson Next";
  src: url("fonts/atkinson-next-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #e9eee8;
  --ink: #18201b;
  --ink-2: #4a554d;
  --ink-3: #69756d;
  --line: #d8dfd7;
  --primary: #1f3a2c;
  --on-primary: #ffffff;
  --protein: #2a78d6;
  --fat: #eb6834;
  --carbs: #1baf7a;
  --kcal: #5d6a62;
  --fiber: #8a6a1f;
  --over: #c4352f;
  --over-bg: #fbe9e7;
  --good: #1b7f3b;
  --focus: #2a78d6;
  --radius: 14px;
  --radius-s: 9px;
  --shadow-sheet: 0 -12px 40px rgb(16 24 19 / .18);
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131815;
    --surface: #1b221e;
    --surface-2: #252e29;
    --ink: #eef2ee;
    --ink-2: #b8c2ba;
    --ink-3: #8f9a92;
    --line: #313b35;
    --primary: #cfe6d5;
    --on-primary: #10221a;
    --protein: #3987e5;
    --fat: #d95926;
    --carbs: #199e70;
    --kcal: #9aa69e;
    --fiber: #c9a24a;
    --over: #ef6b62;
    --over-bg: #3a1f1d;
    --good: #5cc27f;
    --focus: #6aa8f0;
    --shadow-sheet: 0 -12px 40px rgb(0 0 0 / .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131815; --surface: #1b221e; --surface-2: #252e29; --ink: #eef2ee; --ink-2: #b8c2ba; --ink-3: #8f9a92;
  --line: #313b35; --primary: #cfe6d5; --on-primary: #10221a; --protein: #3987e5; --fat: #d95926; --carbs: #199e70;
  --kcal: #9aa69e; --fiber: #c9a24a; --over: #ef6b62; --over-bg: #3a1f1d; --good: #5cc27f; --focus: #6aa8f0;
  --shadow-sheet: 0 -12px 40px rgb(0 0 0 / .5);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.45 "Atkinson Next", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.h-small { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.num, .entry-amt, .meter-val, .preview b, table { font-variant-numeric: tabular-nums; }

/* ---------- top bar & day picker ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 4px;
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar .daynav:last-child { justify-self: end; }
.topbar > .btn { justify-self: end; margin-right: 4px; }
.daynav { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--ink-2); text-decoration: none; }
.daynav svg { width: 24px; height: 24px; }
.daynav:active { background: var(--surface-2); }
.daypick, .topbar-title { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 2px 0; }
.daypick { cursor: pointer; }
.daypick-label { font-weight: 700; font-size: 19px; }
.daypick-sub { font-size: 14px; color: var(--ink-3); }
.daypick input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.pagetitle { font-size: 26px; font-weight: 700; padding: 20px 0 8px; }

/* ---------- hero: net carbs on a ruler ---------- */
.hero { padding: 14px 0 18px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.hero-num { font-size: 64px; font-weight: 800; line-height: .95; letter-spacing: -.02em; }
.hero-num span { font-size: 28px; font-weight: 700; margin-left: 2px; color: var(--ink-2); letter-spacing: 0; }
.hero-label { font-size: 16px; color: var(--ink-2); margin-top: 4px; }
.hero-left { text-align: right; color: var(--ink-2); font-size: 15px; padding-bottom: 4px; }
.hero-left b { display: block; font-size: 22px; color: var(--ink); }
.hero-track {
  position: relative; height: 18px; margin-top: 14px; border-radius: 5px; overflow: hidden;
  background: color-mix(in srgb, var(--carbs) 16%, var(--surface-2));
}
/* ruler ticks every 5 g of a 30 g limit */
.hero-track::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(100% / 6 - 2px), var(--bg) calc(100% / 6 - 2px) calc(100% / 6));
}
.hero-fill { height: 100%; background: var(--carbs); border-radius: 0 4px 4px 0; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.hero.is-over .hero-fill { background: var(--over); }
.hero.is-over .hero-left b { color: var(--over); }
.hero-sub { margin: 8px 0 0; font-size: 14px; color: var(--ink-3); }

/* ---------- meters ---------- */
.meters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 14px 0 18px; border-top: 1px solid var(--line); }
.meter-head { display: flex; flex-direction: column; gap: 2px; }
.meter-label { font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.meter-val { font-size: 14px; color: var(--ink-3); }
.meter-val b { font-size: 21px; color: var(--ink); font-weight: 700; }
.meter-track { height: 6px; border-radius: 3px; background: var(--surface-2); margin: 8px 0 6px; overflow: hidden; }
.meter-track[data-empty] { background: repeating-linear-gradient(90deg, var(--surface-2) 0 6px, transparent 6px 9px); }
.meter-fill { height: 100%; border-radius: 0 3px 3px 0; }
.meter-protein .meter-fill { background: var(--protein); }
.meter-fat .meter-fill { background: var(--fat); }
.meter-kcal .meter-fill { background: var(--kcal); }
.meter-fiber .meter-fill { background: var(--fiber); }
.meter-note { font-size: 13px; color: var(--ink-3); }
.meter.is-over .meter-note { color: var(--over); font-weight: 600; }
.meter.is-done .meter-note { color: var(--good); font-weight: 600; }

.key { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--kcal); }
.key-protein { background: var(--protein); }
.key-fat { background: var(--fat); }
.key-carbs, .key-net { background: var(--carbs); }
.key-fiber { background: var(--fiber); }

/* ---------- calorie split ---------- */
.split { padding: 4px 0 18px; }
.split-bar { display: flex; gap: 2px; height: 12px; }
.split-seg { flex-basis: 0; min-width: 4px; }
.split-seg:first-child { border-radius: 4px 0 0 4px; }
.split-seg:last-child { border-radius: 0 4px 4px 0; }
.split-seg:only-child { border-radius: 4px; }
.seg-fat { background: var(--fat); }
.seg-protein { background: var(--protein); }
.seg-carbs { background: var(--carbs); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 8px 0 0; font-size: 14px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); }

/* ---------- meals ---------- */
.meal { background: var(--surface); border-radius: var(--radius); margin: 0 -4px 12px; padding: 4px 0; }
.meal-head { display: grid; grid-template-columns: 1fr 48px; grid-template-areas: "title add" "sum add"; align-items: center; padding: 10px 6px 10px 16px; }
.meal-head h2 { grid-area: title; font-size: 19px; }
.meal-sum { grid-area: sum; font-size: 14px; color: var(--ink-3); }
.meal-add { grid-area: add; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); color: var(--ink); }
.meal-add svg { width: 22px; height: 22px; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%;
  text-align: left; background: none; border: 0; border-top: 1px solid var(--line);
  padding: 11px 16px; cursor: pointer;
}
.entry:active { background: var(--surface-2); }
.entry-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.entry-amt { color: var(--ink-2); font-size: 15px; white-space: nowrap; }
.entry .mline { grid-column: 1 / -1; }
.mline { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 14px; color: var(--ink-2); }
.mline > span { display: inline-flex; align-items: center; gap: 5px; }
.mline .kcal { color: var(--ink-3); }

.dayactions { display: grid; gap: 10px; margin-top: 8px; }
.copy-meal { margin: 2px 0 6px; }
.copy-meal .btn { display: inline-flex; align-items: center; gap: 8px; }
.copy-meal svg { width: 18px; height: 18px; }
.lytes { padding: 0 0 16px; }
.h-small small { font-weight: 400; color: var(--ink-3); font-size: 13px; }
.lytes-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.lyte { display: grid; align-content: start; gap: 2px; font-size: 14px; color: var(--ink-2); }
.lyte b { font-size: 19px; color: var(--ink); }
.lyte b small, .lyte > small { font-size: 13px; color: var(--ink-3); font-weight: 400; }
.lyte-bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.lyte-bar i { display: block; height: 100%; background: var(--ink-3); }
.dayactions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.saved summary { list-style: none; cursor: pointer; }
.saved summary::-webkit-details-marker { display: none; }
.saved-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.saved-item { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border: 0; border-radius: var(--radius-s); background: var(--surface); cursor: pointer; text-align: left; font-weight: 600; }
.saved-item small { color: var(--ink-3); font-weight: 400; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-danger { background: transparent; color: var(--over); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--over) 45%, transparent); }
.btn-wide { width: 100%; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 15px; color: var(--ink-2); font-weight: 600; }
.field small { color: var(--ink-3); font-size: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 50px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 18px;
}
select { appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.stack { display: grid; gap: 16px; }
.alert { background: var(--over-bg); color: var(--ink); border-left: 4px solid var(--over); padding: 12px 14px; border-radius: 8px; }
.notice { background: var(--surface); border-left: 4px solid var(--good); padding: 12px 14px; border-radius: 8px; }

/* segmented control */
.seg { border: 0; padding: 0; margin: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.seg { min-inline-size: 0; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: grid; place-items: center; text-align: center; padding: 4px 2px; line-height: 1.2; overflow-wrap: break-word; min-height: 40px; border-radius: 9px; font-size: clamp(13px, 3.6vw, 15px); font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); }

/* ---------- add page ---------- */
.addpage { display: grid; gap: 12px; padding-top: 6px; }
.searchbar { position: relative; display: flex; gap: 8px; }
.searchbar input { padding-left: 44px; min-height: 54px; border-radius: 14px; }
.searchbar-icon { position: absolute; left: 14px; top: 15px; width: 24px; height: 24px; color: var(--ink-3); pointer-events: none; }
.scanbtn { flex: none; width: 54px; height: 54px; border-radius: 14px; border: 0; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; cursor: pointer; }
.scanbtn svg { width: 26px; height: 26px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 8px; }
.tabs button { flex: none; border: 0; background: transparent; padding: 8px 14px; border-radius: 99px; font-weight: 600; color: var(--ink-2); cursor: pointer; box-shadow: inset 0 0 0 1.5px var(--line); }
.tabs button[aria-selected=true] { background: var(--ink); color: var(--bg); box-shadow: none; }
.flist { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.fitem { display: flex; border-top: 1px solid var(--line); }
.fitem:first-child { border-top: 0; }
.fitem-form { display: contents; }
.fitem-main { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; background: none; border: 0; padding: 12px 14px 12px 16px; cursor: pointer; }
.fitem-main:active, .fitem-quick:active { background: var(--surface-2); }
.fitem-name { font-weight: 600; overflow-wrap: anywhere; }
.fitem-name .star { width: 16px; height: 16px; fill: var(--fat); stroke: none; vertical-align: -2px; margin-right: 5px; }
.fitem-meta { font-size: 14px; color: var(--ink-3); }
.fitem-quick { flex: none; width: 60px; border: 0; border-left: 1px solid var(--line); background: none; color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.fitem-quick svg { width: 24px; height: 24px; }
.fitem-quick.is-done { color: var(--good); }
.empty { color: var(--ink-2); background: var(--surface); padding: 18px 16px; border-radius: var(--radius); margin: 0; }
.results .empty a { font-weight: 600; }
.results-loading { opacity: .55; transition: opacity .15s; }

/* barcode scanner */
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: grid; place-items: center; }
.scanner[hidden] { display: none; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner-frame { position: relative; width: min(78vw, 340px); aspect-ratio: 16 / 10; border-radius: 16px; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .45); outline: 3px solid #fff; }
.scanner-msg { position: absolute; top: calc(env(safe-area-inset-top) + 24px); left: 16px; right: 16px; text-align: center; color: #fff; font-weight: 600; font-size: 18px; margin: 0; }
.scanner-manual { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 92px); left: 16px; right: 16px; display: flex; gap: 8px; }
.scanner-manual input { background: rgb(255 255 255 / .95); color: #111; border: 0; }
.scanner-close { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 24px); left: 16px; right: 16px; background: #fff; color: #111; }

/* ---------- bottom sheet ---------- */
.sheet {
  margin: auto auto 0; width: 100%; max-width: min(560px, 100vw); overflow-x: hidden; max-height: 92dvh;
  border: 0; border-radius: 22px 22px 0 0; padding: 0;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sheet);
  overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-up .28s cubic-bezier(.2,.8,.2,1); }
.sheet::backdrop { background: rgb(10 16 12 / .45); }
@keyframes sheet-up { from { transform: translateY(40%); opacity: .4; } }
.sheet-form { display: grid; gap: 14px; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 4px; }
.sheet-head { display: flex; gap: 12px; align-items: flex-start; }
.sheet-title { flex: 1; font-size: 20px; overflow-wrap: anywhere; }
.sheet-src { margin: -10px 0 0; font-size: 14px; color: var(--ink-3); }
.fav { flex: none; width: 44px; height: 44px; margin: -6px -8px 0 0; border: 0; background: none; color: var(--ink-3); display: grid; place-items: center; cursor: pointer; border-radius: 50%; }
.fav svg { width: 26px; height: 26px; }
.fav[aria-pressed=true] { color: var(--fat); }
.fav[aria-pressed=true] svg { fill: currentColor; }
.amount-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; }
.amount-row select { min-width: 0; text-overflow: ellipsis; }
.amount input { font-size: 24px; font-weight: 700; text-align: center; }
/* Roller: scroll-snap number wheels like Google Fit's picker - 3 rows, the middle one picked between two lines */
.roller { display: flex; justify-content: center; align-items: center; gap: 6px; }
.wheel-box { position: relative; flex: 0 1 120px; min-width: 0; }
.wheel-box.narrow { flex-basis: 76px; }
.wheel-box::before, .wheel-box::after { content: ""; position: absolute; left: 6px; right: 6px; height: 2px; border-radius: 1px; background: var(--ink-3); opacity: .55; pointer-events: none; }
.wheel-box::before { top: 47px; }
.wheel-box::after { top: 95px; }
.wheel {
  height: 144px; padding-block: 48px; box-sizing: border-box;
  overflow-y: auto; scroll-snap-type: y mandatory; overscroll-behavior: contain; scrollbar-width: none;
  touch-action: pan-y; -webkit-tap-highlight-color: transparent; outline-offset: -2px;
  mask-image: linear-gradient(rgb(0 0 0 / .45), #000 30%, #000 70%, rgb(0 0 0 / .45));
}
.wheel::-webkit-scrollbar { display: none; }
.wheel > div { height: 48px; display: grid; place-items: center; scroll-snap-align: center; font-size: 21px; font-variant-numeric: tabular-nums; color: var(--ink-3); cursor: pointer; user-select: none; }
.wheel > div.on { font-size: 25px; font-weight: 600; color: var(--ink); }
.roller-sep { font-size: 26px; font-weight: 700; color: var(--ink-2); }
.roller-unit { flex: 0 1 auto; min-width: 0; max-width: 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink-2); }
.preview { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 12px 4px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pv { display: grid; text-align: center; }
.pv b { font-size: 22px; }
.pv span { font-size: 13px; color: var(--ink-3); }
.pv:nth-child(1) b { color: var(--ink); text-decoration: underline 3px var(--carbs); text-underline-offset: 5px; }
.pv:nth-child(2) b { text-decoration: underline 3px var(--protein); text-underline-offset: 5px; }
.pv:nth-child(3) b { text-decoration: underline 3px var(--fat); text-underline-offset: 5px; }
.pv:nth-child(4) b { text-decoration: underline 3px var(--fiber); text-underline-offset: 5px; }
.sheet-grams { margin: -6px 0 0; font-size: 14px; color: var(--ink-3); text-align: center; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-actions .btn-primary { flex: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  transform: translateX(-50%); max-width: calc(100vw - 32px); width: max-content;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
.toast[hidden] { display: none; }
.toast.is-error { background: var(--over); color: #fff; }
.toast.show { animation: toast-in .22s ease-out; }
@keyframes toast-in { from { transform: translate(-50%, 12px); opacity: 0; } }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--ink-3); font-size: 12px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current=page] { color: var(--ink); }
.tab-add svg { width: 46px; height: 46px; padding: 11px; border-radius: 50%; background: var(--primary); color: var(--on-primary); stroke-width: 2.6; margin-top: -10px; }
.tab-add span { margin-top: -2px; }
@media (min-width: 600px) { .tabbar { max-width: 560px; margin: 0 auto; border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; } }

/* ---------- cards, tables, charts (trends / health / more) ---------- */
.block { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.block h2 { font-size: 18px; margin-bottom: 4px; }
.block .sub { color: var(--ink-3); font-size: 14px; margin: 0 0 12px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.stat-label { font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.stat-val { font-size: 26px; font-weight: 700; line-height: 1.15; }
.stat-val small { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-left: 1px; }
.stat-note { font-size: 13px; color: var(--ink-3); }
.stat-note.is-over { color: var(--over); font-weight: 600; }
.stat-note.is-good { color: var(--good); font-weight: 600; }
.rangepick { margin: 6px 0 14px; grid-template-columns: repeat(4, 1fr); }
.rangepick a { display: grid; place-items: center; min-height: 40px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--ink-2); text-decoration: none; }
.rangepick a[aria-current] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); stroke: none; font-size: 11px; }
.chart .limit { stroke: var(--over); stroke-width: 1.5; stroke-dasharray: 0; }
.chart .limit-label { fill: var(--over); font-size: 11px; font-weight: 700; }
.chart .bar-protein { fill: var(--protein); }
.chart .bar-fat { fill: var(--fat); }
.chart .bar-carbs { fill: var(--carbs); }
.chart .bar-kcal { fill: var(--kcal); }
.chart .bar-steps { fill: var(--ink-3); stroke: none; }
.chart .goal { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .goal-label { fill: var(--good); font-size: 11px; font-weight: 700; }
/* Halo so line labels stay readable where they cross bars */
.chart .goal-label, .chart .limit-label { stroke: var(--surface); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round; }
.chart .tick { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .dot-raw { fill: var(--protein); opacity: .38; stroke: none; }
.chart .hl { fill: var(--protein); stroke: var(--surface); stroke-width: 2; opacity: 0; pointer-events: none; }
.chart .hl.on { opacity: 1; }
.chart .line-weight { stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
/* Drag a finger sideways along a chart to read it; up/down still scrolls the page */
.chart-scrub svg { touch-action: pan-y; }
.chart-key { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 13px; color: var(--ink-3); }
.key-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--protein); opacity: .5; }
.key-line { width: 16px; height: 3px; border-radius: 2px; background: var(--protein); margin-left: 10px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 6px; }
.chart-head .chart-title { margin: 0; }
.rangepick.five { grid-template-columns: repeat(5, 1fr); }
.rangepick.six { grid-template-columns: repeat(6, 1fr); }
.rangepick.six a { font-size: 14px; }
.rangepick.mini { margin: 0; grid-template-columns: repeat(2, auto); }
.rangepick.mini a { min-height: 32px; padding: 0 12px; font-size: 14px; }
.chart-title { font-size: 15px; color: var(--ink-2); margin: 16px 0 6px; }
.fit-pick { margin-top: 4px; }
.fit-result { margin-top: 14px; display: grid; gap: 10px; }
.fit-result .table { font-size: 14px; }
.fit-result .table td { padding: 6px; }
.fit-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.fit-list .muted { color: var(--ink-3); font-size: 14px; }
.fit-fixes { max-height: 260px; overflow: auto; }
.chart .line { stroke-width: 2; fill: none; }
.chart .line-carbs { stroke: var(--carbs); }
.chart .line-weight { stroke: var(--protein); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot-carbs { fill: var(--carbs); }
.chart .dot-weight { fill: var(--protein); }
.chart .dot-lab { fill: var(--ink-2); }
.chart .line-glucose { stroke: var(--ink-2); stroke-width: 1.5; }
.chart .dot-glucose { fill: var(--ink-2); }
.chart .line-ketones { stroke: var(--good); stroke-width: 1.5; }
.chart .dot-ketones { fill: var(--good); }
.chart .dot-lab.is-flag { fill: var(--over); }
.chart .band { fill: var(--good); opacity: .1; stroke: none; }
.chart .hit { fill: transparent; stroke: none; cursor: pointer; }
.chart .hit:hover + g, .chart .is-hover { opacity: 1; }
.chart .hover-col { fill: var(--ink); opacity: 0; }
.chart .hover-col.on { opacity: .06; }
.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 14px;
  box-shadow: 0 6px 18px rgb(0 0 0 / .25); transform: translate(-50%, calc(-100% - 10px));
}
.tip b { display: block; margin-bottom: 2px; }
.tip span { display: flex; align-items: center; gap: 6px; }
.tip[hidden] { display: none; }
.chart-legend { margin-top: 10px; }

.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { text-align: left; padding: 9px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.table th { font-weight: 600; color: var(--ink-2); font-size: 14px; border-top: 0; }
.table td.r, .table th.r { text-align: right; }
.table .muted { color: var(--ink-3); }
details.tableview summary { cursor: pointer; color: var(--ink-2); font-size: 14px; font-weight: 600; margin-top: 10px; }

/* nutrient report card */
.nlist { list-style: none; margin: 0; padding: 0; }
.nrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.nrow:first-child { border-top: 0; }
.nrow-name { font-weight: 600; }
.nrow-val { color: var(--ink-2); font-size: 15px; text-align: right; }
.nrow-bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.nrow-bar i { display: block; height: 100%; background: var(--ink-2); border-radius: 0 3px 3px 0; }
.nrow.is-low .nrow-bar i { background: var(--fat); }
.nrow.is-ok .nrow-bar i { background: var(--good); }
.nrow.is-over .nrow-bar i { background: var(--over); }
.nrow-flag { grid-column: 1 / -1; font-size: 13px; color: var(--ink-3); }
.nrow.is-low .nrow-flag { color: var(--fat); font-weight: 600; }
.nrow.is-over .nrow-flag { color: var(--over); font-weight: 600; }

/* labs */
.lab { padding: 14px 0; border-top: 1px solid var(--line); }
.lab:first-of-type { border-top: 0; }
.lab-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.lab-name { font-weight: 700; }
.lab-val { font-size: 22px; font-weight: 700; white-space: nowrap; }
.lab-val small { font-size: 14px; color: var(--ink-3); font-weight: 400; }
.lab-meta { font-size: 14px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 2px 12px; }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--over); }
.flag svg { width: 14px; height: 14px; }
.delta-good { color: var(--good); font-weight: 600; }
.delta-bad { color: var(--over); font-weight: 600; }

/* menu list (More) */
.menu { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.menu li + li { border-top: 1px solid var(--line); }
.menu a, .menu button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 16px; text-decoration: none; background: none; border: 0; text-align: left; cursor: pointer; }
.menu svg { width: 22px; height: 22px; color: var(--ink-2); flex: none; }
.menu small { display: block; color: var(--ink-3); font-size: 14px; }
.appearance { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px; }
.appearance > span { flex: 1 1 auto; }
.appearance .seg { flex: 1 1 230px; }
.menu .chev { margin-left: auto; width: 18px; height: 18px; color: var(--ink-3); }

.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formgrid .full { grid-column: 1 / -1; }
.formsection { font-size: 16px; font-weight: 700; margin: 10px 0 -4px; grid-column: 1 / -1; }

/* login */
.login-body { padding-bottom: 0; display: grid; min-height: 100dvh; place-items: center; }
.login { width: 100%; max-width: 400px; padding: 32px 20px; }
.login-mark { width: 56px; height: 56px; }
.login h1 { font-size: 30px; margin: 12px 0 4px; }
.login-sub, .login-note { color: var(--ink-2); }
.login-note { font-size: 14px; color: var(--ink-3); margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 360px) {
  .meters { gap: 10px; }
  .meter-val b { font-size: 18px; }
  .hero-num { font-size: 54px; }
}
.field-label { font-size: 15px; color: var(--ink-2); font-weight: 600; margin: 0 0 -8px; }
.nrow-name { text-decoration: none; }
a.nrow-name:active { text-decoration: underline; }
.chart .line-lab { stroke: var(--ink-3); stroke-width: 1.5; }
.mealname { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

/* Daily items (supplements logged on their own) */
.sheet-daily { align-items: flex-start; padding: 6px 0; min-height: 0; }
.sheet-daily input { margin-top: 2px; flex: none; }
.sheet-daily small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); }
.supps summary { list-style: none; cursor: pointer; }
.supps summary::-webkit-details-marker { display: none; }
.supps .chev { grid-area: add; justify-self: center; width: 22px; height: 22px; fill: none; stroke: var(--ink-2); stroke-width: 2; transition: transform .2s; }
.supps[open] .chev { transform: rotate(180deg); }
.entry-compact { padding-block: 9px; }
.supps-foot { margin: 0; padding: 10px 16px 8px; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink-3); }
.supps-foot a { color: var(--ink-2); font-weight: 600; }

/* Daily Facts: the day drawn as a Supplement Facts panel. Always black on white, like the real thing. */
.facts {
  --fx-ink: #111; --fx-food: #111; --fx-supp: #a9a9a9;
  background: #fff; color: var(--fx-ink); border: 2px solid var(--fx-ink); padding: 6px 10px 10px; margin: 12px 0 8px;
  font-family: "Helvetica Neue", Helvetica, Arial, "Roboto", sans-serif; font-variant-numeric: tabular-nums;
  box-shadow: 0 10px 30px rgb(0 0 0 / .12);
}
.fx-title { font-size: clamp(40px, 12.5vw, 56px); font-weight: 900; letter-spacing: -.035em; line-height: .95; margin: 2px 0 4px; }
.fx-serv { margin: 0; font-size: 15px; line-height: 1.35; }
.fx-serv:nth-of-type(2) { display: flex; justify-content: space-between; font-size: 18px; }
.fx-rule-b { border-bottom: 11px solid var(--fx-ink); padding-bottom: 4px; margin-bottom: 2px; color: #333; }
.fx-cal { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 6px solid var(--fx-ink); padding: 2px 0 2px; }
.fx-cal span { font-size: 30px; font-weight: 900; letter-spacing: -.02em; line-height: 1; }
.fx-cal small { display: block; font-size: 13px; font-weight: 700; letter-spacing: 0; margin-bottom: 2px; }
.fx-cal b { font-size: 44px; font-weight: 900; line-height: .95; letter-spacing: -.02em; }
.fx-split { margin: 0; padding: 4px 0; font-size: 13px; border-bottom: 1px solid var(--fx-ink); }
.fx-split span { color: #555; }
.fx-head { display: flex; justify-content: flex-end; font-size: 13px; font-weight: 800; padding: 3px 0; border-bottom: 1px solid var(--fx-ink); }
.fx-row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 8px; padding: 3px 0 4px; border-bottom: 1px solid var(--fx-ink); font-size: 15px; }
.fx-bold .fx-lbl { font-weight: 800; }
.fx-sub { padding-left: 16px; }
.fx-sub2 { padding-left: 32px; }
.fx-net .fx-lbl { font-weight: 800; }
.fx-pct { font-weight: 800; text-align: right; white-space: nowrap; }
.fx-pct sup { font-size: 11px; margin-left: 1px; }
.fx-note { font-weight: 400; font-size: 13px; color: #444; }
.fx-ul { color: #b3261e; }
.fx-bar { grid-column: 1 / -1; display: flex; height: 4px; margin-top: 3px; background: #f2f2f2; border-radius: 2px; overflow: hidden; }
.fx-bar i { background: var(--fx-food); }
.fx-bar b { background: var(--fx-supp); }
.fx-thick { border-top: 11px solid var(--fx-ink); margin-top: -1px; }
.fx-sec { font-size: 15px; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; margin: 0; padding: 6px 0 3px; border-bottom: 1px solid var(--fx-ink); }
.fx-sec + .fx-row { border-top: 0; }
.fx-thick + .fx-sec { padding-top: 4px; }
.fx-row + .fx-sec { border-top: 6px solid var(--fx-ink); margin-top: -1px; }
.fx-mid { border-top: 6px solid var(--fx-ink); margin-top: -1px; }
.fx-legend { display: flex; gap: 16px; margin: 6px 0 0; font-size: 12px; }
.fx-key { display: inline-flex; align-items: center; gap: 5px; }
.fx-key i, .fx-key b { width: 16px; height: 6px; display: inline-block; }
.fx-key i { background: var(--fx-food); }
.fx-key b { background: var(--fx-supp); }
.fx-foot { font-size: 12px; line-height: 1.4; margin: 6px 0 0; color: #222; }
.fx-ingr { font-size: 12px; line-height: 1.45; margin: 8px 0 0; padding-top: 6px; border-top: 1px solid var(--fx-ink); text-transform: uppercase; letter-spacing: .01em; }
.fx-ingr b { font-weight: 900; }

/* Fill missing nutrients from USDA */
.fill-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.fill-list .saved-item { background: var(--surface-2); gap: 12px; }
.fill-list .saved-item > span:first-child { display: grid; gap: 2px; }
.fill-go { color: var(--primary); font-weight: 700; flex: none; }
.fill-yours { margin-top: 4px; }
.fill-search { display: flex; gap: 8px; margin-top: 8px; }
.fill-search input { flex: 1; min-width: 0; }
.sheet-fill { display: block; margin: 6px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: underline; }

/* ---------- one-tap remove on Today rows (with Undo) ---------- */
.entries > li { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.entries > li > .entry { flex: 1; min-width: 0; border-top: 0; padding-right: 4px; }
.entry-del {
  flex: none; width: 48px; display: grid; place-items: center; background: none; border: 0;
  color: var(--ink-3); cursor: pointer; border-radius: 10px;
}
.entry-del svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.entry-del:hover, .entry-del:focus-visible { color: var(--over); }
.entry-del:active { background: var(--over-bg); color: var(--over); }
.entries > li.is-going { opacity: .35; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 14px; }
.toast-undo { background: none; border: 0; color: inherit; font: inherit; font-weight: 800; text-decoration: underline; padding: 6px 2px; cursor: pointer; }
.change-v { margin: 0 0 2px; font-size: 13px; font-weight: 700; color: var(--ink-3); }
.change-list { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 5px; color: var(--ink-2); font-size: 15px; }
