/* health-app UI — no build step, no external assets (LAN-only, works offline). */

:root {
  color-scheme: light;
  --surface-0: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #eceae5;
  --border:    #dcdad3;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #7a7873;

  /* Categorical slots 1 and 8 from the validated palette (blue, red).
     Validated together in both modes: adjacent CVD ΔE 21.6 light / 19.2 dark. */
  --series-1: #1f9d5b;
  --series-2: #e34948;

  --good:     #0ca30c;
  --warning:  #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #252523;
    --border:    #383835;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8e8d85;
    --series-1: #3bbd78;
    --series-2: #e66767;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #252523;
  --border:    #383835;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #8e8d85;
  --series-1: #3bbd78;
  --series-2: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-0);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
header h1 { font-size: 1rem; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
header .who { color: var(--text-muted); font-size: 0.85rem; margin-left: auto; }

/* Bottom tab bar — the primary navigation. Fixed to the bottom of the viewport
   with the food-logging camera elevated in the centre. */
nav.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 2px;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
nav.tabbar .tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 2px;
}
nav.tabbar .tab svg { width: 24px; height: 24px; }
nav.tabbar .tab[aria-selected='true'] { color: var(--series-1); }
/* The centre camera button: elevated, filled, the primary action. */
nav.tabbar .tab.snap {
  flex: 0 0 auto;
  color: #fff;
  transform: translateY(-14px);
}
nav.tabbar .tab.snap .snap-circle {
  width: 56px; height: 56px; border-radius: 20px;
  background: var(--series-1);
  display: grid; place-items: center;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--series-1) 45%, transparent);
}
nav.tabbar .tab.snap[aria-selected='true'] { color: #fff; }
nav.tabbar .tab.snap svg { width: 28px; height: 28px; }

/* "More" bottom sheet for the secondary tabs. */
.sheet {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end;
}
.sheet-panel {
  width: 100%;
  background: var(--surface-1);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 8px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
}
.sheet-handle { width: 38px; height: 4px; border-radius: 99px; background: var(--border); margin: 6px auto 10px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  font: inherit; font-size: 1rem; text-align: left;
  padding: 14px 12px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text-primary); cursor: pointer;
}
.sheet-item:hover { background: var(--surface-2); }
.sheet-item svg { width: 22px; height: 22px; color: var(--text-secondary); }

/* A phone-first app: constrain to a phone-width column and centre it, so on a
   desktop it reads as an app rather than a stretched, empty page. */
main { padding: 16px 16px 96px; max-width: 480px; margin: 0 auto; }
header { max-width: 480px; margin: 0 auto; }
nav.tabbar { max-width: 480px; margin: 0 auto; }
.sheet-panel { max-width: 480px; margin: 0 auto; }
section[hidden] { display: none; }
body { background: var(--surface-0); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 4px; font-size: 0.95rem; font-weight: 650; }
.card h2 + .sub { margin: 0 0 14px; color: var(--text-muted); font-size: 0.82rem; }

/* Stat tiles — a hero number needs no chart. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 1.9rem; font-weight: 620; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .value .unit { font-size: 0.9rem; font-weight: 450; color: var(--text-secondary); margin-left: 3px; }
.tile .meta { color: var(--text-muted); font-size: 0.76rem; margin-top: 4px; }

/* Charts */
.chart-wrap { position: relative; overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
svg.chart .grid line { stroke: var(--border); stroke-width: 1; }
svg.chart .axis text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
svg.chart .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.chart .dot { stroke: var(--surface-1); stroke-width: 2; }
svg.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
svg.chart .endlabel { font-size: 11px; font-weight: 600; fill: var(--text-primary); font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text-secondary); }
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.08s;
  z-index: 5;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-date { color: var(--text-muted); margin-bottom: 3px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }

/* Forms */
label { display: block; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 4px; }
input, select, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 130px; }
.row > .narrow { flex: 0 1 100px; }

button.btn {
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  border-radius: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  white-space: nowrap;
}
button.btn:hover { border-color: var(--text-muted); }
button.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button.btn.primary:hover { filter: brightness(1.08); }
button.btn.danger { color: var(--critical); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 0.75rem; background: var(--surface-2); color: var(--text-secondary); }
.pass { color: var(--good); font-weight: 600; }
.fail { color: var(--text-muted); }

.results { list-style: none; margin: 10px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
.results li { display: flex; align-items: center; gap: 10px; padding: 8px; border-bottom: 1px solid var(--border); }
.results li:hover { background: var(--surface-2); }
.results .name { flex: 1; min-width: 0; }
.results .name small { display: block; color: var(--text-muted); }

.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 0.87rem; }
.msg.err { background: color-mix(in srgb, var(--critical) 12%, var(--surface-1)); border: 1px solid var(--critical); }
.msg.ok  { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); border: 1px solid var(--good); }
.empty { color: var(--text-muted); font-size: 0.87rem; padding: 12px 0; }

.gate { max-width: 420px; margin: 12vh auto; }
.toggle-theme { background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--text-secondary); cursor: pointer; padding: 4px 9px; font-size: 0.8rem; }

@media (max-width: 560px) {
  main { padding: 12px; }
  .tile .value { font-size: 1.6rem; }
  header .who { display: none; }
}

/* One-tap drink shortcuts. Sized for a thumb: the whole point is that logging
   a glass of water costs one deliberate tap and no decisions. */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.quick-add {
  font: inherit;
  cursor: pointer;
  padding: 14px 10px;
  min-height: 60px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  line-height: 1.2;
}
.quick-add:hover { background: var(--surface-2); }
.quick-add:active { transform: scale(0.97); }
.quick-add .kcal { font-size: 0.75rem; color: var(--text-muted); }
/* Confirmation has to be visible without moving the thumb or reading text. */
.quick-add.logged {
  border-color: var(--series-1);
  background: var(--surface-2);
}

/* Fasting clock. Big enough to read at arm's length — it is the one number on
   this tab you check without intending to interact. */
.fasting-card { text-align: center; }
.fasting-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.fasting-value {
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.1;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums; /* digits must not jitter as it ticks */
}
.fasting-meta { font-size: 0.85rem; color: var(--text-secondary); }

/* Timeline of everything consumed. The rail is a single continuous line so
   gaps between entries read as elapsed time rather than as list spacing. */
.timeline { position: relative; margin: 0; padding: 0 0 0 62px; list-style: none; }
.timeline::before {
  content: '';
  position: absolute;
  left: 54px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--border);
}
.tl-item { position: relative; padding: 7px 0; }
.tl-time {
  position: absolute;
  left: -62px;
  width: 44px;
  text-align: right;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.tl-item::before {
  content: '';
  position: absolute;
  left: -12px; top: 13px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--series-1);
  border: 2px solid var(--surface-1);
}
.tl-item.drink::before { background: var(--text-muted); }
.tl-name { font-size: 0.95rem; }
.tl-sub { font-size: 0.78rem; color: var(--text-muted); }
/* A fasting window between two meals, shown on the rail itself. */
.tl-gap {
  position: relative;
  padding: 6px 0 6px 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Timeline rows are individually removable — a photographed plate often
   catches something you didn't actually eat. */
.tl-line { display: flex; align-items: center; gap: 8px; }
.tl-item-name { flex: 1 1 auto; }
.tl-del {
  flex: 0 0 auto;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  /* 30px is the smallest comfortable touch target that doesn't dominate the
     row; the padding does the work, not the glyph. */
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
}
.tl-del:hover, .tl-del:focus-visible {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-primary);
}

/* Edit control sits opposite the time on a timeline row. Quiet until wanted —
   editing time/meal is occasional, not the primary action. */
.tl-item { display: flex; flex-wrap: wrap; }
.tl-edit {
  margin-left: auto;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
}
.tl-edit:hover, .tl-edit:focus-visible {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-primary);
}
.tl-item .tl-name, .tl-item .tl-sub { flex-basis: 100%; }

/* Inline edit form — native datetime-local gives a real picker on iOS with no
   library, in the phone's own 12-hour format. */
.tl-edit-form { flex-basis: 100%; display: flex; flex-direction: column; gap: 10px; }
.tl-edit-names { font-size: 0.85rem; color: var(--text-secondary); }
.tl-edit-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--text-muted); }
.tl-edit-form input, .tl-edit-form select {
  font: inherit;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.tl-edit-actions { display: flex; gap: 8px; }

/* Count stepper on the photo-confirm screen. The user corrects what the model
   counted — a known fact, not a portion guess. */
.stepper { display: inline-flex; align-items: center; gap: 0; }
.step-btn {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.step-btn:first-child { border-radius: 8px 0 0 8px; }
.step-btn:last-child { border-radius: 0 8px 8px 0; }
.step-btn:active { background: var(--surface-2); }
.step-val {
  font: inherit;
  width: 44px;
  height: 32px;
  text-align: center;
  border: 1px solid var(--border);
  border-left: 0; border-right: 0;
  background: var(--surface-1);
  color: var(--text-primary);
  -moz-appearance: textfield;
}
.step-val::-webkit-outer-spin-button,
.step-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Shared macro footer under both consumption timelines (Today and Photo).
   Four equal cells so the day's numbers read at a glance. */
.macro-footer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.macro-cell { text-align: center; }
.macro-val { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.macro-unit { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); margin-left: 1px; }
.macro-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* History: one tappable row per day. Calories lead; macros trail small. */
.history-row {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.history-row:hover, .history-row:focus-visible { background: var(--surface-2); }
.history-date { font-weight: 600; }
.history-meta { font-size: 0.8rem; color: var(--text-muted); margin: 2px 0 6px; }
.history-macros {
  display: flex; gap: 12px; align-items: baseline;
  font-size: 0.82rem; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.history-kcal { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); }
.history-kcal small { font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }

/* Meal thumbnail on a timeline row. Small by default; tap to view larger via
   the browser's own image controls (it's already low-res, so this is enough). */
.tl-photo {
  display: block;
  margin-top: 8px;
  max-width: 140px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* "fix" — correct a wrong food match on a logged item. */
.tl-fix {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
}
.tl-fix:hover, .tl-fix:focus-visible {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-primary);
}
.tl-fix-box { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tl-fix-input {
  flex: 1 1 180px;
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.tl-fix-results { flex-basis: 100%; display: flex; flex-direction: column; gap: 4px; }
.tl-fix-hit {
  text-align: left;
  font: inherit;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.tl-fix-hit:hover { background: var(--surface-2); }
.tl-fix-hit small { color: var(--text-muted); }

/* "+ add photo" on a meal that has none yet. */
.tl-addphoto {
  margin-top: 8px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-secondary);
}
.tl-addphoto:hover { background: var(--surface-2); color: var(--text-primary); }

/* Tap a meal thumbnail to view the full-resolution original. */
.tl-photo { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.lightbox-msg { color: #fff; font-size: 0.9rem; }

/* Timeline filter: All / Meals / Exercise. */
.tl-filter { display: flex; gap: 6px; margin-bottom: 12px; }
.tl-filter button {
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
}
.tl-filter button.active {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
/* Pure CSS filtering — no re-render, just hide the type not wanted. */
.tl-wrap.filter-meals .tl-event.exercise { display: none; }
.tl-wrap.filter-exercise .tl-event.meal,
.tl-wrap.filter-exercise .tl-gap,
.tl-wrap.filter-exercise .macro-footer { display: none; }
/* Exercise events get a distinct rail dot. */
.tl-item.exercise::before { background: var(--series-2); }

/* ============================================================================
   v2 redesign — photo-forward, SnapCalorie-inspired. Appended so these win the
   cascade without surgically editing the rules above.
   ============================================================================ */
:root { --radius: 18px; }

/* A card that carries a title but no box — lets its children (meal cards) be
   the visual units, sitting on the page background. */
.card.bare { background: transparent; border: 0; box-shadow: none; padding: 0; }
.card.bare > h2 { padding: 0 4px; }
.card.bare > .sub { padding: 0 4px; }

/* Timeline: a stack of cards, not a dotted rail. */
.timeline { padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline::before { display: none; }
.tl-item::before { display: none; }
.tl-item {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 20px rgba(0,0,0,.05);
}
.tl-time {
  position: static; left: auto; width: auto; text-align: left;
  font-size: 0.8rem; font-weight: 700; color: var(--text-secondary);
}
.tl-edit { margin-left: auto; }
.tl-gap { text-align: center; color: var(--text-muted); padding: 0; margin: -2px 0; }

/* Macro colours (protein / carbs / fats), used by the chips and bars. */
:root { --protein: #e0574c; --carbs: #2f9dc4; --fats: #e2a63a; }

/* Meal card: a small left thumbnail, calories, macro chips — then the item
   list (with fix/delete) below. Matches the reference. */
.tl-item.meal { padding: 12px; }
.mc-head { display: flex; align-items: center; gap: 12px; width: 100%; }
.mc-thumb {
  width: 64px; height: 64px; flex: 0 0 auto;
  border-radius: 14px; overflow: hidden; position: relative;
}
.mc-thumb .tl-photo {
  width: 100%; height: 100%; object-fit: cover; margin: 0; border: 0; border-radius: 14px;
  max-width: none;
}
.mc-empty {
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); color: var(--text-muted); border: 1px dashed var(--border);
}
.mc-empty svg { width: 22px; height: 22px; }
.mc-time {
  position: absolute; left: 4px; bottom: 4px;
  font-size: 9px; font-weight: 700; color: #fff;
  background: rgba(0,0,0,.5); padding: 1px 5px; border-radius: 5px;
}
.mc-main { flex: 1 1 auto; min-width: 0; }
.mc-cal { font-size: 0.98rem; font-weight: 800; letter-spacing: -.01em; }
.mc-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }
.mc-chips { display: flex; gap: 10px; margin-top: 7px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.74rem; font-weight: 700; color: var(--text-secondary); }
.chip b { width: 16px; height: 16px; border-radius: 50%; color: #fff; font-size: 9px; display: grid; place-items: center; }
.chip.p b { background: var(--protein); }
.chip.c b { background: var(--carbs); }
.chip.f b { background: var(--fats); }
.tl-item.meal .tl-edit { align-self: flex-start; flex: 0 0 auto; }
/* Item list under the summary. */
.mc-items { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.mc-items:empty { display: none; }
.mc-items .tl-line { font-size: 0.85rem; }
.tl-item.drink .mc-items { border-top: 0; margin-top: 0; padding-top: 0; }
.tl-addphoto { margin-top: 10px; }

/* Fasting hero — big and green, the first thing on Today. */
.fasting-card { padding: 26px 20px 24px; }
.fasting-label { color: var(--series-1); }
.fasting-value { font-size: 3.1rem; line-height: 1; color: var(--series-1); margin: 8px 0 6px; }

/* Round, prominent snap button; slimmer bar. */
nav.tabbar { padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
nav.tabbar .tab { font-size: 0.6rem; gap: 2px; }
nav.tabbar .tab svg { width: 23px; height: 23px; }
nav.tabbar .tab.snap { transform: translateY(-16px); }
nav.tabbar .tab.snap .snap-circle { width: 60px; height: 60px; border-radius: 50%; }

/* More sheet: hug its content, don't sprawl. */
.sheet-panel { padding: 6px 14px calc(14px + env(safe-area-inset-bottom)); }
.sheet-item { padding: 13px 12px; font-size: 0.98rem; }

/* Stat tiles a touch rounder to match. */
.tile { border-radius: var(--radius); }

/* Label under the "+" so it reads as the log action. */
nav.tabbar .tab.snap .snap-lbl {
  display: block; font-size: 0.6rem; font-weight: 700; color: var(--series-1); margin-top: 3px;
}

/* Prominent "Log a meal" action on Today — logging must never depend on the
   bottom bar, which iOS Safari's toolbar can obscure. */
.log-cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin: 4px 0 16px;
  font: inherit; font-size: 1rem; font-weight: 700;
  padding: 15px; border-radius: var(--radius); border: 0; cursor: pointer;
  background: var(--series-1); color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--series-1) 40%, transparent);
}
.log-cta svg { width: 20px; height: 20px; }

/* Keep the More sheet compact — it only holds a few items. */
.sheet-item { padding: 12px; gap: 14px; }
.sheet-panel { gap: 2px; }

/* More: a compact popup above the bar, NOT a half-screen sheet that buries the
   page behind it. Sized to its few items; tap anywhere off it to dismiss. */
.sheet { background: transparent; }
.sheet-panel {
  position: absolute; bottom: 84px; right: 12px; left: auto;
  width: auto; min-width: 220px; max-width: 260px; margin: 0;
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 12px 34px rgba(0,0,0,.28); padding: 6px;
}
.sheet-handle { display: none; }
.sheet-item { padding: 11px 12px; font-size: 0.92rem; gap: 12px; }
.sheet-item svg { width: 20px; height: 20px; }

/* CRITICAL: `.sheet { display: flex }` overrode the `hidden` attribute, so the
   More popup never hid — it sat over the page and its invisible layer ate every
   tap (that's why "Log a meal" did nothing). Make hidden actually hide it. */
.sheet[hidden] { display: none !important; }

/* ── Fasting gauge hero + macro bars ─────────────────────────────────────── */
.fasting-hero { text-align: center; padding: 22px 20px 20px; }
.gauge { position: relative; width: 240px; max-width: 90%; margin: 0 auto; }
.gauge-svg { width: 100%; height: auto; display: block; overflow: visible; }
.gauge-track { fill: none; stroke: var(--surface-2); stroke-width: 15; stroke-linecap: round; }
.gauge-fill {
  fill: none; stroke: var(--series-1); stroke-width: 15; stroke-linecap: round;
  transition: stroke-dasharray 0.6s ease;
}
.gauge-center { position: absolute; left: 0; right: 0; top: 46%; }
.fasting-hero .fasting-value {
  /* As big as fits: scales with the phone width but capped, so a double-digit
     "13h 20m" never overgrows the gauge. */
  font-size: clamp(1.9rem, 8.5vw, 2.35rem); line-height: 1; color: var(--series-1);
  font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
  margin: 0; white-space: nowrap;
}
/* Small, muted "h"/"m" units keep the digits the focus and the string compact. */
.fasting-value .u {
  font-size: 0.5em; font-weight: 700; letter-spacing: 0;
  opacity: 0.6; margin-left: 0.04em; margin-right: 0.02em;
}
.gauge-cap {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 4px;
}
.gauge-goal { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.macbars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 20px; }
.mb { text-align: center; }
.mb-g { font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.mb-g span { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); margin-left: 1px; }
.mb-track { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.mb-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }
.mb.p .mb-fill { background: var(--protein); }
.mb.c .mb-fill { background: var(--carbs); }
.mb.f .mb-fill { background: var(--fats); }
.mb-lbl { font-size: 0.72rem; font-weight: 700; color: var(--text-secondary); }
