/* pages/health.css — /nutrition/, /exercise/, /sleep/, /body/ (SPEC §5.7–§5.10).
 *
 * THE HEALTH GRAMMAR (K45), shared by the four pages: the day's name on the
 * page's fixed top (.page-top, app.css), and everything else on the
 * sheet below it (.page-scroll), each part an EXPRESSIVE card (#1E1F20, 28,
 * padding 20/22). Records inside a card are segmented lists (m3.css .rows),
 * forms are M3 filled fields (m3.css .m3-textfield), the food picker is a
 * standard list of M3 list items. This file only lays them out and draws the
 * figures: the rings, the sparklines and the route.
 *
 * COLOUR (answer 1, K21): the rings stay GREY and lap by stepping the ink
 * (muted first lap, bright second lap). The page hue (--h) is ink only: the
 * sparkline, its end dot and the route line. Nothing here fills a shape with it.
 *
 * PAGE-SCOPE RULE (§1.1, test_design check 9): every selector starts with a
 * class this file owns — `.rings`, `.ring*`, `.trends`, `.trend*`, `.meal`,
 * `.setform*`, `.picker*`, `.pick*`, `.route*`, `.bodycols*`, `.scorenote`,
 * `#food-log`, `#gym-log` — or with [data-page="nutrition"|"exercise"|"sleep"|
 * "body"]. All eleven page files load on every page. (The water row's `.water*`
 * and the diary's `#food-diary` ride on [data-page="nutrition"] / #food-log.)
 */

/* ═══════════════════════════════════════════════════════ THE GRAMMAR ══ */

/* The visible head is the DAY (A42): title-large, on-surface. The page's
   name is sr-only (the tab says it). The head sits in .page-top, whose own
   padding is the spacing, so the shown head's bottom margin is dropped. */
:is([data-page="nutrition"], [data-page="exercise"], [data-page="sleep"], [data-page="body"]) .page-top .head {
  margin: 0;
}
:is([data-page="nutrition"], [data-page="exercise"], [data-page="sleep"], [data-page="body"]) .head__sub {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: var(--md-sys-typescale-title-large-weight);
  font-variant-numeric: tabular-nums;
}

/* The sheet: one 16px rhythm between its cards.
   ⚠️ "EVERY CHILD BUT THE FIRST", never `> * + *`. The two pick the same
   elements, but `* + *` is a sibling rule about ANY element after ANY element,
   and with one in the document Chromium answers every element put between two
   others — anywhere, on any page — by restyling everything after it: a line
   added in the middle of a long note in Knowledge restyled half the note
   (measured 2026-10-11: 3,700 elements and 21 ms for this rule alone, 1 element
   without it). `:where()` keeps the specificity `* + *` had: none. */
:is([data-page="nutrition"], [data-page="exercise"], [data-page="sleep"], [data-page="body"]) .page-scroll > :where(:not(:first-child)) {
  margin-top: 16px;
}

/* Every .panel on these pages is an expressive card (§3.9 --xl): the
   legacy panel's 12 / 16·20 and its own bottom margin give way. */
:is([data-page="nutrition"], [data-page="exercise"], [data-page="sleep"], [data-page="body"]) .panel {
  margin-bottom: 0;                     /* the sheet's 16px rhythm (above) sets the top */
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 20px 22px;
}

/* "Still live in the old page" (test-pinned): the last line of every page. */
.scorenote {
  margin: 0;
  max-inline-size: 62ch;
  color: var(--app-color-on-surface-low);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-weight: var(--md-sys-typescale-body-small-weight);
}

/* ═══════════════════════════════════════════ NUTRITION: THE FIVE RINGS ══
   ⚠️ The outline is the day's allowance; the arc is what has been had. A
   second, BRIGHTER lap means he went past it. Each ring is an expressive card
   (the markup carries m3-card m3-card--xl; .ring lays it out). */
.rings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}
.rings[hidden] { display: none; }
.ring {
  margin: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
}
.ring[hidden] { display: none; }
.ring svg { display: block; width: 96px; height: 96px; transform: rotate(-90deg); }
.ring--energy svg { width: 112px; height: 112px; }
/* ⚠️ `pathLength` is an SVG ATTRIBUTE and belongs on the element, not here —
   in CSS it is ignored, the dasharray fractions get measured against the
   circle's real length (~264 units), and every ring draws as a solid circle. */
.ring circle { fill: none; stroke-width: 9; }
.ring__track { stroke: var(--md-sys-color-surface-container-highest); }
.ring__arc { stroke: var(--app-color-on-surface-low); stroke-linecap: round; }     /* the muted first lap */
.ring__over { stroke: var(--md-sys-color-on-surface); stroke-linecap: round; }     /* the bright second lap */

.ring figcaption { display: grid; justify-items: center; text-align: center; margin-top: 8px; }
.ring figcaption b {
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: var(--md-sys-typescale-emphasized-title-large-weight);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
  font-variant-numeric: tabular-nums;
}
.ring figcaption span {
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-variant-numeric: tabular-nums;
}
.ring figcaption em {
  margin-top: 4px;
  font-style: normal;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line-height);
  font-weight: var(--md-sys-typescale-label-medium-weight);
}

/* ═══════════════════════════════════════════════════ THE LOG FORMS ══
   The meal form (#food-log) and the gym log (#gym-log): one .setform each, a
   grid of M3 filled fields (56px) with the filled Log button (M, 56) level
   with them at the END of the last row.
   The grid is sized by the CARD, not the window (a container query), so the
   same form reads right in a full pane, in half a split and on a phone, and
   no row ever leaves a hole before a wide field:
   - under 440px: two columns; the day and the wide field (Food, Exercise)
     take a row each, the short fields pair up (the phone, SPEC §5.7);
   - 440px and up: three columns; the food takes its own row;
   - 760px and up: one row per question. The meal: when (day, time, meal,
     food) over how much (portion, kcal, protein, carbs, fat, Log). The gym
     log: one row of eight. */
:is(#food-log, #gym-log) { container-type: inline-size; }
.setform {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  margin: 0;
  padding: 0;
  min-width: 0;
}
.setform[hidden] { display: none; }
.setform label:is(:has(.setform__in--day), :has(.setform__in--wide)) { grid-column: 1 / -1; }
.setform > :is(.m3-btn, .btn) { grid-column: -2 / -1; justify-self: end; }
#gym-log .setform + #gym-sets { margin-top: 16px; }  /* the sets, below the form */
/* ⚠️ The phone's meal form pairs Day with Time and gives MEAL the row: in half
   of a 360 phone the select's value clipped to "Breakfas". */
@container (max-width: 439.98px) {
  #food-log .setform label:has(.setform__in--day) { grid-column: auto; }
  #food-log .setform label:has(select) { grid-column: 1 / -1; }
}
@container (min-width: 440px) {
  .setform { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .setform label:has(.setform__in--day) { grid-column: auto; }
}
/* The gym log between 440 and 760: Day + Exercise, then Set, kg, Reps and Log
   on ONE row (twelve tracks), so the Log button never gets a row to itself. */
@container (min-width: 440px) and (max-width: 759.98px) {
  #gym-log .setform { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  #gym-log .setform > label { grid-column: span 3; }
  #gym-log .setform label:has(.setform__in--day) { grid-column: span 4; }
  #gym-log .setform label:has(.setform__in--wide) { grid-column: span 8; }
  #gym-log .setform > .m3-btn { grid-column: span 3; }
}
@container (min-width: 760px) {
  #food-log .setform { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #food-log .setform label:has(.setform__in--wide) { grid-column: span 3; }
  #gym-log .setform { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  #gym-log .setform label:has(.setform__in--wide) { grid-column: span 3; }
}
/* The food picker under the meal form. ⚠️ It must not reserve height while it
   is empty: the server renders it with whitespace only, which :empty misses. */
.picker { margin-top: 8px; }
.picker:not(:has(*)) { display: none; }
.picker__head {
  margin: 0 0 4px;
  padding: 0 16px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line-height);
  font-weight: var(--md-sys-typescale-label-medium-weight);
}
.picker__list { max-height: 320px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
/* A pick is an M3 list item (state layer, shape morph, inner focus ring).
   The name may run to two lines rather than lose the words that tell two
   foods apart; the brand is quieter. */
.pick .pick__name { white-space: normal; }
.pick__name em { font-style: normal; color: var(--md-sys-color-on-surface-variant); }
/* ⚠️ The provenance line is DIMMER BUT PRESENT. "lab-measured by the MRI" and
   "derived by formula" are not the same claim, and the picker is where that
   difference can still change which row he takes. */
.pick__src {
  color: var(--app-color-on-surface-low);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
}

/* The diary's meal groups: a list subheader, sentence case. */
.meal {
  margin: 16px 0 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
}
#food-log #food-diary > .formerr { margin: 16px 0 0; }

/* A ROW'S DELETE (the diary, the gym log): an S standard icon button, the
   row's last part. ⚠️ DELETE NEVER ASKS — the row goes and the undo bar holds
   the write (views, HELD WRITES). Revealed on hover or focus like a task
   card's buttons, so thirty rows are not thirty bins; always shown on touch
   (K16). The 48px box fits the two-line row's 72 without moving it. */
:is(#food-log, #gym-log) .row > .m3-icon-btn { opacity: 0; }
:is(#food-log, #gym-log) .row:is(:hover, :focus-within) > .m3-icon-btn { opacity: 1; }
@media (hover: none), (pointer: coarse) {
  :is(#food-log, #gym-log) .row > .m3-icon-btn { opacity: 1; }
}
@media (prefers-reduced-motion: no-preference) {
  :is(#food-log, #gym-log) .row > .m3-icon-btn {
    transition-property: opacity, border-radius, background-color, color, box-shadow;
    transition-duration:
      var(--md-sys-motion-spring-fast-effects-duration), var(--md-sys-motion-spring-default-effects-duration),
      var(--md-sys-motion-spring-fast-effects-duration), var(--md-sys-motion-spring-fast-effects-duration),
      var(--md-sys-motion-spring-fast-effects-duration);
    transition-timing-function:
      var(--md-sys-motion-spring-fast-effects), var(--md-sys-motion-spring-default-effects),
      var(--md-sys-motion-spring-fast-effects), var(--md-sys-motion-spring-fast-effects),
      var(--md-sys-motion-spring-fast-effects);
  }
}

/* ══════════════════════════════════ NUTRITION: A GLASS OF WATER, ONE TAP ══
   Under the rings it moves (_water.html), an expressive card like its
   neighbours. The drop glyph and the word name the row; the five chips ACT
   (the "+" says so — nothing here selects). A tap is held by the undo bar,
   not written, and the ring counts it at once (views.log_water). */
[data-page="nutrition"] .water__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 12px;
  margin: 0;
}
[data-page="nutrition"] .water__ico {
  --_icon: var(--app-icon-size-medium);
  --_opsz: 20;
  color: var(--md-sys-color-on-surface-variant);
}
[data-page="nutrition"] .water__label {
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
}
/* The chips take the rest of the line; their 48px targets keep the group's
   own inset (m3-chip-group). */
[data-page="nutrition"] .water__sips { flex: 1 1 auto; }
/* On a phone the five share ONE line under the name, in equal columns: at
   their natural 16px padding they wrapped 4 + 1 at 412 (measured), and a lone
   "+1" on a line of its own reads as a different control. */
@media (max-width: 720px) {
  [data-page="nutrition"] .water__sips {
    flex-basis: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0 8px;
  }
  [data-page="nutrition"] .water__sips > .m3-chip { --_pad-s: 0px; --_pad-e: 0px; justify-content: center; }
}

/* ══════════════════════════════════════════ SPARKLINES (Exercise, Sleep, Health)
   Each an expressive card: the name and the last value on one line, the range
   under them, then a 40px plot in the page hue. ⚠️ The scale is each series'
   own min/max (views._spark). */
.trends {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}
.trends[hidden] { display: none; }
.trends--single { grid-template-columns: minmax(0, 1fr); }
.trend { margin: 0; min-width: 0; }
.trend figcaption {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 2px 8px;
  margin-bottom: 12px;
}
.trend figcaption b {
  min-width: 0;
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
}
.trend figcaption span {
  justify-self: end;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: var(--md-sys-typescale-title-large-weight);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.trend figcaption em {
  grid-column: 1 / -1;
  font-style: normal;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-variant-numeric: tabular-nums;
}
/* The plot is stretched to the card (preserveAspectRatio="none"); the path
   keeps its width (non-scaling stroke) and the end dot is a round box placed
   OVER it in percent, so it stays a circle at any card width (pages-b §2e6). */
.trend__plot { position: relative; height: 40px; }
.trend__plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.trend path {
  fill: none;
  stroke: var(--h);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.trend__dot {
  position: absolute;
  width: var(--app-badge-dot);
  height: var(--app-badge-dot);
  border-radius: var(--md-sys-shape-corner-full);
  translate: -50% -50%;
  background: var(--h);
  pointer-events: none;
}

/* ═══════════════════════════════════════════ EXERCISE: A WORKOUT'S ROUTE
   The slot is the row's next sibling in the segmented list, filled on demand
   (a live Google call) and drawn as the row's own continuation tile. While
   the call is out it is the M3E loading host (m3.css), so it must show then
   even though it is still empty. */
.route__slot {
  list-style: none;
  padding: 8px 16px 16px 48px;          /* the text column of the row above */
  background: var(--md-sys-color-surface-container-high);
  border-start-start-radius: var(--_rt, var(--md-sys-shape-corner-extra-small));
  border-start-end-radius: var(--_rt, var(--md-sys-shape-corner-extra-small));
  border-end-start-radius: var(--_rb, var(--md-sys-shape-corner-extra-small));
  border-end-end-radius: var(--_rb, var(--md-sys-shape-corner-extra-small));
}
.route__slot:empty:not(.htmx-request) { display: none; }
.route__slot.htmx-request:empty { min-height: 64px; }
/* A hidden empty slot is still the list's last child, so the row above it
   takes the list's bottom corners. */
[data-page="exercise"] .rows > .row:has(+ .route__slot:last-child:empty:not(.htmx-request)) {
  --_rb: var(--md-sys-shape-corner-large);
}
.route { display: block; width: 100%; max-width: 360px; height: auto; margin: 0 0 8px; }
.route polyline { stroke: var(--h); stroke-width: 3; }
.route__note {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
}
.route__note a { color: var(--app-color-accent); }
.route__note a .ico { --_icon: var(--app-icon-size-medium); --_opsz: 20; vertical-align: -4px; margin-inline-start: 4px; }

/* ═══════════════════════════════════════════════ HEALTH (/body/): TWO COLUMNS
   The heart's daily readings beside the measurements taken now and then.
   Each column is an expressive card; inside it the sparklines stack as a
   segmented group of #282A2C tiles, like the measurement rows beside them. */
.bodycols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.bodycols[hidden] { display: none; }
.bodycols__head {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-sys-typescale-title-medium-weight);
}
.bodycols .trends--single { gap: 2px; }
.bodycols .trend {
  --_container: var(--md-sys-color-surface-container-high);
  padding: 12px 16px 16px;
  border-radius: var(--md-sys-shape-corner-extra-small);
}
.bodycols .trend:first-child {
  border-start-start-radius: var(--md-sys-shape-corner-large);
  border-start-end-radius: var(--md-sys-shape-corner-large);
}
.bodycols .trend:last-child {
  border-end-start-radius: var(--md-sys-shape-corner-large);
  border-end-end-radius: var(--md-sys-shape-corner-large);
}
/* The weigh-in (_measured.html), under the measurements it adds to: the meal
   form's M3 filled fields, sized by the CARD (a container), so Day, Time,
   Weight and Log share one row from 440px and pair up below it. */
.bodycols__measured { container-type: inline-size; }
.bodycols__weigh.setform { margin-top: 16px; }
.bodycols__err { margin: 16px 0 0; }
@container (min-width: 440px) {
  .bodycols__weigh.setform { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ═════════════════════════════════════════════════════════ THE PHONE ══ */
@media (max-width: 720px) {
  .bodycols { grid-template-columns: minmax(0, 1fr); }
  /* Two rings a row; the day's energy, the third, takes a row of its own. */
  .rings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ring--energy { grid-column: 1 / -1; }
  .ring svg { width: 72px; height: 72px; }
  .ring--energy svg { width: 88px; height: 88px; }
}
