/* Weight Journey — new frontend. Every colour and length is a token here. */
:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #16202e;
  --muted: #647085;
  --line: #d9dfe8;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #16a34a;
  --ok-soft: #e8f6ed;
  --warn: #d97706;
  --skip: #7d8697; /* skipped: a muted grey, never red */
  --skip-soft: #eef0f3;
  --danger: #dc2626;
  --ok-ink: #15803d; /* green text on white: 5.0:1 (--ok is 3.3:1) */
  /* Trends rows tinted by balance, and the text on them (WCAG on the tint):
     ok 5.9:1, danger 5.1:1, muted 5.2:1 (ok and 5.0:1 on red); the tints
     are ΔE ≥ 6.4 from white and 3.8–6.6 from each other (OKLab ×100). */
  --ok-tint: #d6f1df;
  --danger-tint: #fcdede;
  --skip-tint: #e8eaee;
  --ok-tint-ink: #166534;
  --danger-tint-ink: #b91c1c;
  --muted-tint-ink: #566175;
  --scrim: rgba(15, 23, 42, 0.45);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  --crop-shade: rgba(15, 23, 42, 0.5);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s7: 28px;
  --s8: 32px;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  --t-xs: 12px;
  --t-sm: 14px;
  --t-md: 16px;
  --t-lg: 18px;
  --t-xl: 22px;
  --t-hero: 48px;

  --hair: 1px;
  --outline: 2px;
  --icon: 22px;
  --icon-sm: 18px;
  --tap: 44px;
  --tap-sm: 44px; /* every control is at least 44 px */
  --handle: 24px;
  --thumb: 56px;
  --thumb-sm: 40px;
  --bar: 3px;
  --lh-sm: 20px; /* line height of --t-sm text */
  --header: 52px;
  --nav: 60px;
  --panel: 560px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: var(--t-md) / 1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }

/* ---------- controls ---------- */
.btn { min-height: var(--tap); padding: 0 var(--s4); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: var(--tap-sm); padding: 0 var(--s3); font-size: var(--t-sm); }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { width: var(--tap); height: var(--tap); border: 0; border-radius: var(--r-full); background: transparent; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink); flex: none; }
.icon-btn .avatar { width: 30px; height: 30px; border-radius: var(--r-full); border: var(--hair) solid var(--muted); object-fit: cover; display: block; }
.icon-btn.small { width: var(--tap-sm); height: var(--tap-sm); }
.icon-btn:disabled { opacity: 0.35; }
.icon { width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small .icon, .btn .icon, .chip .icon { width: var(--icon-sm); height: var(--icon-sm); }
.link { border: 0; background: none; padding: 0; min-height: var(--tap); color: var(--accent); cursor: pointer; text-align: left; }
.chip { min-width: var(--tap); min-height: var(--tap-sm); padding: 0 var(--s3); border: var(--hair) solid var(--line); border-radius: var(--r-full); background: var(--surface); font-size: var(--t-sm); display: inline-flex; align-items: center; gap: var(--s1); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip.add, .chip.snack { margin-left: auto; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: var(--s6) 0; }
.field-error { color: var(--danger); font-size: var(--t-sm); }

.form { display: grid; gap: var(--s3); }
.field { display: grid; gap: var(--s1); }
.field-label { font-size: var(--t-sm); color: var(--muted); }
.field input, .field select, .field textarea, .search input { width: 100%; min-height: var(--tap); padding: var(--s2) var(--s3); border: var(--hair) solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.field textarea { resize: vertical; }
/* iOS Safari gives date/time inputs and selects an intrinsic width and centres
   the value: make them plain full-width boxes like text inputs. Selects keep a
   chevron drawn from tokens. */
input[type="time"], input[type="date"], input[type="datetime-local"], select { -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; min-height: var(--tap); text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
select, .field select { padding-right: calc(var(--s3) + var(--s4)); background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - var(--s4)) 50%, calc(100% - var(--s3)) 50%; background-size: var(--s1) var(--s1); background-repeat: no-repeat; }
.number-input { display: flex; align-items: center; border: var(--hair) solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.number-input input { border: 0; min-width: 0; flex: 1; outline: none; }
.number-input:focus-within { outline: var(--outline) solid var(--accent); outline-offset: calc(-1 * var(--hair)); }
.number-input .unit { padding: 0 var(--s3); color: var(--muted); font-size: var(--t-sm); white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: var(--hair) solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.segmented button:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.segmented button:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.segmented button { min-height: var(--tap-sm); border: 0; background: var(--surface); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--surface); font-weight: 600; }
.disclosure summary { cursor: pointer; font-weight: 600; min-height: var(--tap); padding-block: var(--s3); }
.disclosure[open] summary { margin-bottom: var(--s2); }

/* Grid tracks never grow past their container (long nowrap titles). */
.dialog, .sheet, .dialog-body, .sheet-body, .entry-list, .cards, .card-body, .pick-list, .form, .entry-draft, .field { grid-template-columns: minmax(0, 1fr); }

/* ---------- shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; padding: calc(var(--header) + env(safe-area-inset-top)) 0 calc(var(--nav) + env(safe-area-inset-bottom)); }
.app-header { position: fixed; inset: 0 0 auto; z-index: 5; height: calc(var(--header) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--s2) 0 var(--s4); display: flex; align-items: center; justify-content: space-between; background: var(--bg); border-bottom: var(--hair) solid var(--line); }
.app-name { font-weight: 700; font-size: var(--t-lg); }
.tab { max-width: var(--panel); margin: 0 auto; padding: var(--s3) var(--s4) var(--s6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
.bottom-nav { position: fixed; inset: auto 0 0; z-index: 5; height: calc(var(--nav) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: var(--hair) solid var(--line); }
.nav-item { border: 0; background: none; display: grid; place-items: center; align-content: center; gap: var(--s1); font-size: var(--t-xs); color: var(--muted); cursor: pointer; }
.nav-item[aria-current="page"] { color: var(--accent); font-weight: 600; }

.date-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.date-label { display: flex; align-items: center; justify-content: center; gap: var(--s2); font-weight: 600; }
.big-number { text-align: center; }
.big-value, .big-caption { display: block; }
.big-number.tappable { width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; border-radius: var(--r-md); }
.big-value strong { font-size: var(--t-hero); line-height: 1.1; }
.big-unit { margin-left: var(--s1); color: var(--muted); font-size: var(--t-lg); }
.big-caption { color: var(--muted); font-size: var(--t-sm); line-height: var(--lh-sm); min-height: var(--lh-sm); }
.tab-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.tab-actions.single { grid-template-columns: 1fr; }

/* ---------- cards ---------- */
.cards { display: grid; gap: var(--s3); }
.card { background: var(--surface); border: var(--outline) solid var(--line); border-radius: var(--r-lg); overflow: hidden; cursor: pointer; }
.card.tone-ok { border-color: var(--ok); }
.card.tone-skip { border-color: var(--skip); }
.card.tone-accent { border-color: var(--accent); }
/* The status strip takes the colour of the card's outline. */
.card-strip { padding: var(--s1) var(--s3); font-size: var(--t-xs); font-weight: 600; background: var(--bg); color: var(--muted); }
.card.tone-ok .card-strip { background: var(--ok-soft); color: var(--ok); }
.card.tone-skip .card-strip { background: var(--skip-soft); color: var(--skip); }
.card.tone-accent .card-strip { background: var(--accent-soft); color: var(--accent); }
.card-body { padding: var(--s3) var(--s4); display: grid; gap: var(--s2); }
.card-row { display: flex; align-items: center; gap: var(--s2); min-height: var(--tap-sm); }
.card-title { font-size: var(--t-md); flex: 1; }
.card-value { color: var(--muted); font-weight: 600; }
/* Food's Snacks · Drinks: Log actions side by side (accent-tinted), no strip. */
.cards-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.card.log-card { border-color: var(--accent-soft); background: var(--accent-soft); color: var(--accent); }
.log-card .card-body { padding: 0 var(--s3); }
.log-card .card-row { justify-content: center; min-height: var(--tap); }
.log-card .card-title { flex: none; font-size: var(--t-md); font-weight: 600; color: inherit; }
.log-card .icon { flex: none; width: var(--icon-sm); height: var(--icon-sm); }
.thumb-strip { display: flex; gap: var(--s2); overflow-x: auto; }
.thumb-strip img { width: var(--thumb-sm); height: var(--thumb-sm); object-fit: cover; border-radius: var(--r-sm); flex: none; }

/* ---------- dialog stack ---------- */
.dlg { padding: 0; border: 0; margin: 0; width: 100%; height: 100%; height: 100dvh; max-width: none; max-height: none; background: transparent; }
.dlg::backdrop { background: var(--scrim); }
.dlg[open] { display: grid; grid-template-columns: minmax(0, 1fr); place-items: stretch center; }
.layer { grid-area: 1 / 1; width: 100%; max-width: var(--panel); height: 100%; min-height: 0; }
.layer-sheet { max-width: none; }
.dialog { position: relative; height: 100%; display: grid; grid-template-rows: auto 1fr auto; background: var(--bg); padding-top: env(safe-area-inset-top); }
.dialog-head { display: flex; align-items: center; gap: var(--s1); padding: var(--s1) var(--s2); border-bottom: var(--hair) solid var(--line); background: var(--surface); }
.dialog-title { flex: 1; min-width: 0; font-size: var(--t-lg); padding: 0 var(--s2); outline: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A scrolling grid: rows are sized to their content (max-content). WebKit
   otherwise sizes an auto row holding an overflow-clipped item (a segmented
   control) to its automatic minimum, 0, once the body overflows. */
.dialog-body { overflow-y: auto; padding: var(--s4); display: grid; grid-auto-rows: max-content; gap: var(--s4); align-content: start; overscroll-behavior: contain; }
.dialog-foot { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s3); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); border-top: var(--hair) solid var(--line); background: var(--surface); }
.confirm { position: absolute; inset: 0; background: var(--scrim); display: grid; place-items: center; padding: var(--s6); z-index: 2; }
.confirm-box { width: 100%; background: var(--surface); border-radius: var(--r-lg); padding: var(--s5); display: grid; gap: var(--s4); box-shadow: var(--shadow); }
.confirm-title { font-weight: 600; font-size: var(--t-lg); outline: none; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
/* A small alert on its own (Trends' open days): the confirm box over the page; the backdrop dims. */
.layer-alert .confirm { position: relative; height: 100%; background: transparent; }
.layer-alert .confirm-title { margin: 0; }
/* --kb (ui/keyboard.js): the iOS keyboard's height, so a sheet sits above it. */
.sheet-scrim { position: relative; height: 100%; padding-bottom: var(--kb, 0px); background: var(--scrim); display: grid; align-items: end; justify-items: center; }
/* A sheet opened from a tab (Skip day): its own scrim dims; the backdrop does not add a second. */
.dlg:has(> .layer:first-child.layer-sheet)::backdrop { background: transparent; }
/* A dialog opened from such a sheet (End day → Log food) dims as usual. */
.dlg:has(> .layer:first-child.layer-sheet ~ .layer-dialog:not([hidden]))::backdrop { background: var(--scrim); }
.sheet { width: 100%; max-width: var(--panel); max-height: 80%; display: grid; grid-template-rows: auto 1fr; background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; overflow: hidden; }
.sheet-body { overflow-y: auto; padding: var(--s4) var(--s4) calc(var(--s6) + env(safe-area-inset-bottom)); display: grid; grid-auto-rows: max-content; gap: var(--s3); align-content: start; }
/* ui/menu.js: a popover placed by script next to the control that opened it;
   the scrim's padding is the area it may use (safe area + 16 px gutters). The
   scrim is transparent (it only catches the tap outside); nothing dims. */
.layer-menu { max-width: none; }
.dlg:has(> .layer:first-child.layer-menu)::backdrop { background: transparent; }
.menu-scrim { position: fixed; inset: 0; z-index: 3; padding: calc(env(safe-area-inset-top) + var(--s4)) calc(env(safe-area-inset-right) + var(--s4)) calc(env(safe-area-inset-bottom) + var(--s4)) calc(env(safe-area-inset-left) + var(--s4)); }
.popover { position: fixed; outline: none; display: grid; grid-template-columns: minmax(0, 1fr); width: max-content; min-width: 200px; background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); overflow: hidden; animation: pop-in 0.12s ease-out; }
.menu-item { min-height: var(--tap); padding: 0 var(--s4); display: flex; align-items: center; gap: var(--s3); border: 0; border-top: var(--hair) solid var(--line); background: none; font-weight: 600; text-align: left; cursor: pointer; white-space: nowrap; }
.menu-item:first-child { border-top: 0; }
.menu-item .icon { flex: none; color: var(--muted); }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: 0.55; cursor: default; }
.popover .field-error { padding: var(--s2) var(--s4); border-top: var(--hair) solid var(--line); white-space: normal; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-2px); } }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(var(--nav) + var(--s4) + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - var(--s8)); padding: var(--s2) var(--s4); border-radius: var(--r-full); background: var(--ink); color: var(--surface); font-size: var(--t-sm); box-shadow: var(--shadow); }

/* ---------- food ---------- */
.entry-list { list-style: none; margin: 0; padding: 0; display: grid; }
.meal-total { font-size: var(--t-xl); font-weight: 700; }
.entry-block { display: grid; gap: var(--s1); padding-block: var(--s3); border-top: var(--hair) solid var(--line); }
.entry-block:first-child { border-top: 0; padding-top: 0; }
.entry-head { display: flex; align-items: flex-start; gap: var(--s1); }
.entry-text { flex: 1; min-width: 0; overflow-wrap: anywhere; padding-top: var(--s2); }
.entry-kcal { font-weight: 600; }
.entry-block .macros { font-size: var(--t-sm); }
.entry-block .assumptions { list-style: none; padding-left: 0; gap: 0; }
.thumb-open { border: 0; padding: 0; background: none; min-width: var(--tap); min-height: var(--tap); display: grid; place-items: center; cursor: pointer; flex: none; }
.kcal-line { display: flex; align-items: center; gap: var(--s2); }
.kcal-value { font-size: var(--t-xl); font-weight: 700; }
.macros { color: var(--muted); }
.assumptions { margin: 0; padding-left: var(--s5); color: var(--muted); font-size: var(--t-sm); display: grid; gap: var(--s1); }
.entry-draft { display: grid; gap: var(--s3); padding: var(--s3); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); }
.entry-draft-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.entry-collapsed { display: flex; justify-content: space-between; gap: var(--s2); min-height: var(--tap); padding: 0 var(--s3); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); cursor: pointer; text-align: left; align-items: center; }
.ref-chip { display: flex; align-items: center; gap: var(--s2); padding-left: var(--s3); border: var(--hair) solid var(--accent); border-radius: var(--r-md); background: var(--accent-soft); }
.ref-open { flex: 1; border: 0; background: none; text-align: left; min-height: var(--tap); cursor: pointer; color: var(--accent); font-weight: 600; }
.live { font-size: var(--t-lg); font-weight: 600; }

.photo-row { display: flex; gap: var(--s2); overflow-x: auto; }
.photo-thumb { position: relative; flex: none; }
.photo-open { display: block; width: var(--thumb); height: var(--thumb); padding: 0; border: 0; border-radius: var(--r-sm); overflow: hidden; cursor: pointer; background: var(--line); }
.photo-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-remove { position: absolute; top: calc(-1 * var(--tap) / 2); right: calc(-1 * var(--tap) / 2); width: var(--tap); height: var(--tap); padding: 0; border: 0; background: transparent; color: var(--surface); display: grid; place-items: center; cursor: pointer; }
.photo-remove .icon { width: var(--icon); height: var(--icon); padding: var(--s1); border-radius: var(--r-full); background: var(--ink); }
.photo-row { padding: calc(var(--tap) / 2) calc(var(--tap) / 2) 0 0; }
.photo-add { min-height: var(--thumb); padding: 0 var(--s3); border: var(--hair) dashed var(--line); border-radius: var(--r-sm); background: var(--surface); display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; flex: none; }
.crop-frame { position: relative; display: block; width: 100%; aspect-ratio: 1; overflow: hidden; background: var(--line); border-radius: var(--r-sm); }
.crop-frame img { width: 100%; height: 100%; object-fit: cover; }
.empty-thumb { display: grid; place-items: center; color: var(--muted); }

.pinned { position: sticky; top: calc(-1 * var(--s4)); z-index: 1; margin: calc(-1 * var(--s4)) calc(-1 * var(--s4)) 0; padding: var(--s4); background: var(--bg); display: grid; gap: var(--s3); }
.search { display: flex; align-items: center; gap: var(--s2); border: var(--hair) solid var(--line); border-radius: var(--r-sm); background: var(--surface); padding-left: var(--s3); color: var(--muted); }
.search input { border: 0; color: var(--ink); }
.search-row { display: flex; gap: var(--s2); align-items: stretch; }
.search-row .search { flex: 1; min-width: 0; }
.segmented.compact { flex: none; grid-template-columns: auto auto; }
.segmented.compact button { padding: 0 var(--s3); font-size: var(--t-sm); white-space: nowrap; }
.chips.filters .chip { padding: 0 var(--s2); }
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.pick-row { width: 100%; display: grid; grid-template-columns: var(--thumb) 1fr; gap: var(--s3); align-items: center; padding: var(--s2); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; text-align: left; }
.pick-row:disabled { opacity: 0.55; cursor: default; color: inherit; }
.pick-text { display: grid; gap: var(--s1); }
/* Meal prep: the estimate's rows under Ingredients, then the total. */
.prep-rows { display: grid; gap: var(--s1); margin: 0; }
.prep-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); margin: 0; font-size: var(--t-sm); }
.prep-row > :last-child { flex: none; white-space: nowrap; }
.prep-total { margin: 0; font-weight: 600; }
.pick-name { font-weight: 600; }
.food-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: var(--s3); }
.food-card { display: grid; gap: var(--s1); align-content: start; padding: var(--s2); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.food-card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-card-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--s1); }

/* thumbnail-crop.mjs editor (kept as-is); its help line is hidden. */
.crop-host .help:not([role]) { display: none; }
.food-thumbnail-crop-dialog { display: grid; gap: var(--s3); }
.food-thumbnail-crop-stage { position: relative; width: 100%; aspect-ratio: 1; background: var(--ink); overflow: hidden; touch-action: none; border-radius: var(--r-md); }
.food-thumbnail-crop-source { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; }
.food-thumbnail-crop-box { position: absolute; border: var(--outline) solid var(--surface); box-shadow: 0 0 0 100vmax var(--crop-shade); cursor: move; touch-action: none; }
.food-thumbnail-crop-handle { position: absolute; width: var(--tap); height: var(--tap); border: 0; background: transparent; padding: 0; display: grid; place-items: center; }
.food-thumbnail-crop-handle::after { content: ""; width: var(--handle); height: var(--handle); border: var(--outline) solid var(--accent); border-radius: var(--r-full); background: var(--surface); }
.crop-nw { left: calc(-1 * var(--tap) / 2); top: calc(-1 * var(--tap) / 2); }
.crop-ne { right: calc(-1 * var(--tap) / 2); top: calc(-1 * var(--tap) / 2); }
.crop-sw { left: calc(-1 * var(--tap) / 2); bottom: calc(-1 * var(--tap) / 2); }
.crop-se { right: calc(-1 * var(--tap) / 2); bottom: calc(-1 * var(--tap) / 2); }
.food-thumbnail-crop-dialog .actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.food-thumbnail-crop-dialog .button { min-height: var(--tap); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); font-weight: 600; }
.food-thumbnail-crop-dialog .run-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }

/* ---------- sign-in / onboarding ---------- */
.auth { max-width: 24rem; margin: 0 auto; padding: var(--s8) var(--s4); display: grid; gap: var(--s4); }
.auth h1 { font-size: var(--t-xl); }
.step { color: var(--muted); font-size: var(--t-sm); }
.row-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s3); }
.review { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); margin: 0; }
.review dt { color: var(--muted); }
.review dd { margin: 0; }
.icon-more { stroke-width: 3.5; }

/* Inside the open dialog (top layer), above the footer. */
.toast.in-dialog { bottom: calc(var(--tap) + var(--s8) + env(safe-area-inset-bottom)); }
/* Dialogs without a footer keep their last row clear of the home indicator. */
.dialog.no-foot .dialog-body { padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }
.sheet-scrim { padding-top: env(safe-area-inset-top); }
.crop-host .actions { display: none; }

/* ---------- train ---------- */
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.toggle { width: 100%; min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 0; border: 0; background: none; cursor: pointer; text-align: left; }
.switch { position: relative; flex: none; width: var(--s8); height: var(--s5); border-radius: var(--r-full); background: var(--line); transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: var(--outline); left: var(--outline); width: calc(var(--s5) - 2 * var(--outline)); height: calc(var(--s5) - 2 * var(--outline)); border-radius: var(--r-full); background: var(--surface); box-shadow: var(--shadow); transition: transform 0.15s; }
.toggle[aria-checked="true"] .switch { background: var(--accent); }
.toggle[aria-checked="true"] .switch::after { transform: translateX(calc(var(--s8) - var(--s5))); }
.steps-fields { display: grid; gap: var(--s2); }
.checks { display: grid; gap: var(--s1); }
.exercise-rows { display: grid; gap: var(--s3); }
.exercise-row { display: grid; gap: var(--s2); padding: var(--s3); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); }
.row-tools { display: flex; justify-content: flex-end; gap: var(--s1); }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.exercise-tile { width: 100%; min-height: var(--tap); display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; text-align: left; }
.circuit { display: grid; gap: var(--s2); padding: var(--s2); border-radius: var(--r-md); background: var(--accent-soft); }
.circuit-label { padding: 0 var(--s1); font-size: var(--t-sm); font-weight: 600; color: var(--accent); }
.tile-text { display: grid; gap: var(--s1); min-width: 0; }
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-thumb { width: var(--thumb-sm); height: var(--thumb-sm); flex: none; border-radius: var(--r-sm); overflow: hidden; background: var(--line); display: grid; place-items: center; color: var(--muted); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prescription { font-weight: 600; }
.media-image { display: block; width: 100%; padding: 0; border: 0; background: var(--line); border-radius: var(--r-md); overflow: hidden; cursor: zoom-in; }
.media-image img { width: 100%; display: block; }
.media-video, .media-embed { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--r-md); background: var(--ink); display: block; }
.media-link { width: 100%; text-decoration: none; color: var(--accent); }
.instructions { white-space: pre-line; }
.attribution { color: var(--muted); font-size: var(--t-xs); }
.zoom { overflow: auto; }
.zoom-toggle { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; width: 100%; }
.zoom-toggle img.fit { width: 100%; display: block; }
.zoom-toggle img.actual { max-width: none; display: block; cursor: zoom-out; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); margin: 0 0 var(--s3); }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.notes { white-space: pre-line; }
.preset-list { display: grid; gap: var(--s2); }
.preset-card { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border: var(--hair) solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.preset-text { flex: 1; min-width: 0; display: grid; gap: var(--s1); }
.preset-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-row.plain { grid-template-columns: 1fr; min-height: var(--tap); }
/* Log workout choice screen and the route flow (train-route.js). */
.pick-row.choice-row { grid-template-columns: 1fr auto; padding: var(--s2) var(--s3); }
.choice-row .icon { color: var(--muted); }
.choice-row:disabled { opacity: 0.55; cursor: default; }
/* Where? → New place, expanded in place: the Place field and a small Save. */
.new-place { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: end; }
.new-place .field-error { grid-column: 1 / -1; margin: 0; }
.step-title { margin: 0; font-size: var(--t-lg); }
/* Log workout first step: the muted "Saved" heading over the most-used saved workouts. */
.step-title.muted { font-size: var(--t-sm); font-weight: 600; margin-bottom: calc(-1 * var(--s2)); }
.step-sub { margin: calc(-1 * var(--s3)) 0 0; }
.lap-stepper { display: flex; align-items: center; justify-content: center; gap: var(--s6); padding-block: var(--s4); }
.stepper-btn { width: var(--tap); padding: 0; border-radius: var(--r-full); }
.lap-count { min-width: 2ch; font-size: var(--t-hero); font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.route-estimate { margin: 0; text-align: center; font-weight: 600; }
.route-summary { margin: 0; font-weight: 600; }
.route-details { display: grid; gap: var(--s3); justify-items: start; }
.route-details > * { width: 100%; }
.route-details > .btn { width: auto; }
.route-details p { margin: 0; }
.route-line { margin: 0; font-size: var(--t-sm); }
.card-body > .route-line { margin-top: calc(-1 * var(--s3)); }
.spinning .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- weigh-in form ---------- */
.unit-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3); align-items: end; }
.unit-toggle { grid-template-columns: repeat(2, minmax(var(--tap), 1fr)); }

/* ---------- settings ---------- */
.settings-list { display: grid; background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.settings-row { min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 0 var(--s2) 0 var(--s4); border: 0; border-bottom: var(--hair) solid var(--line); background: none; color: var(--ink); text-decoration: none; font-weight: 600; cursor: pointer; text-align: left; }
.settings-row:last-child { border-bottom: 0; }
.settings-row.danger { color: var(--danger); }
.settings-row .icon { color: var(--muted); }
.settings-heading { margin: var(--s2) 0 calc(-1 * var(--s2)); }
.group { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s3); margin: 0; padding: 0; border: 0; min-width: 0; }
.group legend, .group h3 { font-size: var(--t-md); font-weight: 700; padding: 0; margin-bottom: var(--s1); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.plain-list > li { min-height: var(--tap); display: flex; align-items: center; }
.connection-row { justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s3); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); }
.connection-row .pick-text { min-width: 0; }
.copy-row { display: flex; align-items: end; gap: var(--s2); }
.copy-row input { flex: 1; min-width: 0; min-height: var(--tap); padding: var(--s2) var(--s3); border: var(--hair) solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.copy-row .grow { flex: 1; min-width: 0; }
.checks { margin: 0; padding: 0; border: 0; min-width: 0; }
.check-row { min-height: var(--tap); display: flex; align-items: center; gap: var(--s3); cursor: pointer; }
.check-row input { width: var(--icon); height: var(--icon); margin: 0; accent-color: var(--accent); }
.class-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.class-row { display: grid; gap: var(--s1); padding: var(--s2) var(--s3); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-md); }
.fields.week { grid-template-columns: repeat(2, auto 1fr); }

/* ---------- today ---------- */
/* Today fills the screen between header and nav; the Logged rows scroll
   inside their section (the heading and the total stay), which grows with its
   rows up to the space left and never stretches. */
.today { --today-h: calc(100vh - var(--header) - var(--nav) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - var(--s3) - var(--s6)); display: flex; flex-direction: column; gap: var(--s4); height: var(--today-h); }
@supports (height: 100dvh) { .today { --today-h: calc(100dvh - var(--header) - var(--nav) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - var(--s3) - var(--s6)); } }
.today > * { flex: none; }
.today > .today-group.logged { flex: 0 1 auto; min-height: calc(var(--tap) * 4); display: flex; flex-direction: column; }
.ledger { display: flex; flex-direction: column; min-height: 0; flex: 0 1 auto; }
.ledger-rows { min-height: 0; flex: 0 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.ledger > .ledger-row.total { flex: none; }
/* Log weight · Skip in equal halves, or Log weight / Edit weigh-in full width. */
.today-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
/* Under Logged (outside its scroller): End day · Skip day in equal halves, or one of End day / Unskip full width. */
.day-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
.day-actions.pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.skip-day, .end-day { width: 100%; }
/* The End day sheet: a row per open item, its Log / Skip at the right (accent-tinted). */
.end-rows { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.end-row { display: flex; align-items: center; gap: var(--s2); min-height: calc(var(--tap) + var(--s2)); border-bottom: var(--hair) solid var(--line); }
.end-row:last-child { border-bottom: 0; }
.end-row .row-title { flex: 1; min-width: 0; }
.end-act { min-width: 64px; padding: 0 var(--s3); border-color: var(--accent-soft); background: var(--accent-soft); color: var(--accent); }
.end-status { margin: 0; }
/* The Skip day sheet: the choice and the line saying what it means, close together. */
.skip-choice { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
.skip-note { margin: 0; font-size: var(--t-sm); line-height: var(--lh-sm); }
.today-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
.today-heading { color: var(--muted); font-size: var(--t-sm); font-weight: 600; }
.today-list { background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.row-line { font-size: var(--t-sm); }
.row-text { flex: 1; min-width: 0; display: grid; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ui/keyboard.js: focused for a moment to raise the iOS keyboard; never seen. */
.kbd-primer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; font-size: 16px; pointer-events: none; }

/* Logged table: signed kcal (+ eaten red, − burned green), the base burn
   tinted and the total under a heavier rule. */
.ledger-row { width: 100%; min-height: var(--tap); padding: 0 var(--s3); display: flex; align-items: center; gap: var(--s3); border: 0; border-top: var(--hair) solid var(--line); background: none; text-align: left; font-variant-numeric: tabular-nums; }
.ledger-row:first-child { border-top: 0; }
button.ledger-row { cursor: pointer; }
.ledger-row.two-line { padding-block: var(--s2); }
/* A row with an Estimate icon: the text is its own full-height button (the
   row's padding moves into it); the 44 px icon overhangs the padding so the
   row keeps its height. */
.ledger-row.split { padding: 0; gap: 0; }
.ledger-tap { flex: 1; min-width: 0; align-self: stretch; display: flex; align-items: center; gap: var(--s3); padding: 0 0 0 var(--s3); border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.ledger-row.split.two-line .ledger-tap { padding-block: var(--s2); }
.ledger-row.split > .icon-btn { margin-block: calc(-1 * var(--s2)); }
.ledger-estimate { color: var(--accent); }
.ledger-estimate .icon { width: 24px; height: 24px; }
.ledger-amount { color: var(--muted); font-weight: 600; text-align: right; white-space: nowrap; }
.ledger-amount.in { color: var(--danger); }
.ledger-amount.out { color: var(--ok-ink); }
.ledger-row.due { background: var(--accent-soft); color: var(--accent); }
.ledger-amount.due { color: var(--accent); }
.ledger-row.baseline { background: var(--bg); }
.ledger-row.baseline .row-title { color: var(--muted); }
.ledger-row.total { padding-block: var(--s2); border-top: var(--outline) solid var(--line); justify-content: space-between; }
.ledger-row.total .row-title { font-weight: 700; }
.ledger-total { display: grid; justify-items: end; white-space: nowrap; }
.ledger-change { font-size: var(--t-sm); }

/* ---------- trends ---------- */
/* Trends-only warmth (global tokens untouched): a warm amber for the
   targets (the On pace / Needed dashed lines), a cream footer under each
   chart. */
.trends { --trend-warm: var(--warn); --trend-cream: #fcfaf6; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
/* One card style for the tab: the chart cards and the summary. */
.trend-card { width: 100%; min-width: 0; min-height: var(--tap); padding: var(--s3) var(--s4); display: grid; gap: var(--s2); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-lg); color: var(--ink); font: inherit; text-align: left; }
/* The period line (tap → Goal). */
.trend-head { width: 100%; min-height: var(--tap-sm); padding: 0; display: grid; align-content: center; justify-items: center; gap: var(--s1); border: 0; border-radius: var(--r-md); background: none; color: inherit; font: inherit; cursor: pointer; }
.trend-period { color: var(--muted); font-size: var(--t-sm); line-height: var(--lh-sm); }
/* Chart card: the title (and unit) at the left, the 7 · 14 · Goal toggle at the right. */
.chart-card { padding-bottom: 0; gap: 0; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.chart-title { margin: 0; min-width: 0; font-size: var(--t-lg); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-title .chart-unit { color: var(--muted); font-size: var(--t-xs); font-weight: 400; }
.chart-days { margin-left: auto; }
.chart-days button { min-width: var(--tap-sm); padding: 0 var(--s2); font-variant-numeric: tabular-nums; }
.chart-days button { color: var(--muted); }
.chart-days button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
/* The goal line under the Weight title (tap → Goal): a muted line, a full-width target. */
.goal-line { width: 100%; min-height: var(--tap-sm); margin: calc(-1 * var(--s2)) 0 calc(-1 * var(--s1)); padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: var(--t-sm); text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-card .chart { margin-top: var(--s3); }
/* The card's footer: two cells on cream, a hairline over them and between them. */
.trend-foot { margin: var(--s3) calc(-1 * var(--s4)) 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--trend-cream); border-top: var(--hair) solid var(--line); border-radius: 0 0 calc(var(--r-lg) - var(--hair)) calc(var(--r-lg) - var(--hair)); }
.trend-stat { min-width: 0; padding: var(--s3) var(--s4); display: grid; align-content: start; gap: 2px; }
.trend-stat + .trend-stat { border-left: var(--hair) solid var(--line); }
.stat-label { color: var(--muted); font-size: var(--t-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { color: var(--ink); font-size: var(--t-xl); font-weight: 700; line-height: 1.2; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-unit { color: var(--muted); font-size: var(--t-xs); font-weight: 400; }
.stat-note { color: var(--muted); font-size: var(--t-xs); }
/* Charts: inline SVG at the measured width; text in the text tokens. */
.chart { position: relative; min-width: 0; }
.chart svg { display: block; max-width: 100%; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; outline: none; }
.chart svg:focus-visible { outline: var(--outline) solid var(--accent); outline-offset: var(--s1); border-radius: var(--r-sm); }
.chart text { font-size: var(--t-xs); fill: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; -webkit-user-select: none; user-select: none; }
.chart .chart-label { fill: var(--ink); font-weight: 600; }
.chart .chart-muted { fill: var(--muted); font-weight: 400; }
.chart .halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis, .chart-zero { stroke: var(--skip); stroke-width: 1; }
.chart-cross { stroke: var(--muted); stroke-width: 1; }
.chart .fill-accent { stop-color: var(--accent); }
.chart .fill-ok { stop-color: var(--ok); }
.chart .fill-danger { stop-color: var(--danger); }
.chart-area { stroke: none; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-goal { stroke: var(--trend-warm); stroke-width: 1.5; stroke-dasharray: 4 4; stroke-linecap: round; }
.chart-goal.chart-average { stroke: var(--accent); }
.chart-tip { position: absolute; z-index: 2; transform: translate(-50%, -100%); padding: var(--s1) var(--s2); display: grid; justify-items: center; background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow); white-space: nowrap; pointer-events: none; font-size: var(--t-xs); line-height: 1.3; }
.chart-tip.below { transform: translate(-50%, 0); }
.chart-tip strong { font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.chart-tip span { color: var(--muted); }
/* Daily table: about 7 rows tall (a half row peeks), the header pinned, the rows scroll inside. */
.trend-table { display: grid; align-content: start; max-height: calc(var(--s8) + 7.5 * var(--tap) + 2 * var(--hair)); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--r-lg); }
.trend-row { width: 100%; min-height: var(--tap); padding: 0 var(--s3); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 0.8fr) minmax(0, 1.5fr); align-items: center; gap: var(--s2); border: 0; border-top: var(--hair) solid var(--line); background: none; color: var(--ink); font: inherit; text-align: right; font-variant-numeric: tabular-nums; cursor: pointer; }
.trend-row > :first-child { text-align: left; }
.trend-row.head { position: sticky; top: 0; z-index: 1; min-height: var(--s8); border-top: 0; background: var(--surface); color: var(--muted); font-size: var(--t-xs); font-weight: 600; cursor: default; box-shadow: 0 var(--hair) 0 var(--line); }
.trend-date { font-weight: 600; }
.trend-kcal { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trend-row[data-tone="deficit"] { background: var(--ok-tint); }
.trend-row[data-tone="surplus"] { background: var(--danger-tint); }
.trend-row[data-tone="skipped"] { background: var(--skip-tint); }
.trend-row[data-tone] .muted { color: var(--muted-tint-ink); }
.trend-row[data-tone="deficit"] .trend-kcal { color: var(--ok-tint-ink); }
.trend-row[data-tone="surplus"] .trend-kcal { color: var(--danger-tint-ink); }
.trend-row[data-tone="skipped"] .trend-kcal { color: var(--muted-tint-ink); }
.trend-row[data-status="open"] .trend-kcal { color: var(--muted); font-weight: 400; font-size: var(--t-sm); }
.trend-row.head + .trend-row { border-top: 0; }
.summary-card { gap: var(--s3); }
.summary-card p { margin: 0; white-space: pre-line; }
.summary-date { color: var(--muted); font-size: var(--t-sm); }
