/* pages/today.css — /dashboard/ (SPEC §5.1).
 *
 * PAGE-SCOPE RULE (§1.1, test_design check 9): every selector starts with a
 * class this file owns — `.dash*`, `.spine*`, `.env*`, `#outside` —
 * or with [data-page="dashboard"]. All eleven page files load on every page.
 *
 * The page has no hue (K18): every widget is the same grey card on the plain
 * pane (no rim, no wash). The day is named by the TAB ("Today",
 * "Fri 15 Aug": `data-page-tab` on .dash), never by a visible date (K47).
 */

/* ─────────────────────────────────────────────────────────── the grid ──
   ⚠️ A GRID, and a widget takes slots in it: one column wide, with a row
   span off a ladder (2 readings · 3 a figure over a list · 4 a window onto
   something endless). On a desktop the rows are a SHARE OF THE WINDOW: seven
   of them, always — the row count is the size dial (K52) — and the board
   fills the pane and never scrolls; the grid fills a column top to bottom and
   starts the next when the rows run out (today 4 + 3 | 3 + 2 + 2).

   The base rules below are the FLOW layout (one or more 280px columns, every
   widget as tall as its content, the pane body scrolls). The ladder switches
   on only where it pays: a window of 840px or more (§5.1) AND a pane wide
   enough for two 280px columns (2 × 280 + 16 = 576). The second condition is
   a container query on the pane body, because a split pane on a 1200px window
   is only ~500px wide, and implicit 280px columns there would scroll sideways.
   ⚠️ If SHOW_TASKS returns (17 rows, a third column), the ladder needs
   3 × 280 + 2 × 16 = 872px of pane and a 1200px window. */
[data-page="dashboard"].pane > .pane__body { container: dash / inline-size; }

.dash {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  grid-auto-flow: row dense;
  align-items: start;
  min-width: 0;
}
/* The flow layout only ever meets a pane under ~720px (a window under 840,
   or a split pane too narrow for the ladder), and two content-high columns
   there leave a hole of canvas under the shorter card of each grid row. So
   the flow is ONE column until the pane fits two 360px cards (DM L2519:
   the flow is the one-column fallback). The ladder below overrides it. */
@container dash (max-width: 719px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
}

/* The widget: an expressive card (§3.9 --xl). Every widget is the same grey
   and none takes a hue (K18). Padding 20/22 clears its own 28px corner (K29). */
.dash__widget {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  padding: 20px 22px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
}
.dash__widget > * { flex: none; margin: 0; }
/* The way out (A41, K4): `open_in_new` at the card's top-right, only on a
   widget with a page behind it (Outside has none), shown on hover or focus and
   always on touch (A17). Absolute, so it takes no height from a card that is
   a share of the window: its 40px circle is centred on the 28px corner's own
   centre (the 48px box at 4/4), which keeps it inside the curve. */
.dash__widget { position: relative; }
.dash__widget > .dash__out {
  position: absolute;
  top: 4px;
  right: 4px;
  margin: 0;
  opacity: 0;
}
.dash__widget:is(:hover, :focus-within) > .dash__out { opacity: 1; }
@media (hover: none), (pointer: coarse) { .dash__widget > .dash__out { opacity: 1; } }
.dash__widget:has(> .dash__out) > .dash__head { padding-inline-end: 40px; }
:is(.dash, .dash__widget,.dash__allday, .spine__row, .spine__what, #outside, .env__body, .env__now, .env__facts, .env__row)[hidden] { display: none; }

@media (min-width: 840px) {
  @container dash (min-width: 576px) {
    /* The board fills the WHOLE pane: "a taller screen makes every row
       taller rather than leaving grey under the last widget" (DM L4560). The
       pane body keeps the FAB's end-reserve (--fabreach) for a scroller, but
       a board that never scrolls has nothing to reach, so the grid grows
       through it (a negative end margin keeps the body from scrolling) and
       the FAB floats over the last card's corner, as it would over any
       content. The last card's own list keeps the reserve instead, below. */
    .dash {
      height: calc(100% + var(--fabreach, 0px));
      margin-bottom: calc(-1 * var(--fabreach, 0px));
      grid-template-columns: none;
      grid-template-rows: repeat(7, minmax(0, 1fr));     /* seven rows, always: the dial */
      grid-auto-flow: column dense;
      grid-auto-columns: minmax(280px, 1fr);
      align-items: stretch;
    }
    /* The ladder. Nothing else sizes a widget. */
    .dash__widget--2 { grid-row: span 2; }
    .dash__widget--3 { grid-row: span 3; }
    .dash__widget--4 { grid-row: span 4; }
    /* A card's list scrolls INSIDE the card rather than clipping (pages-a
       §2(e)2–3). Outside's scroller is its BODY, below the head, so that card
       keeps its title like the other four (.spine and .rows are in app.css's
       fade lists at the short 20px, .env__body joins below).
       ⚠️ A LIST THAT IS CUT MUST SHOW IT, and a card's height is a share of
       the window, so it can end anywhere: in the blank between two rows,
       too. Stopped there, the next row lay wholly below the scroller, the
       fade had nothing to fade, and the card looked complete with two of
       four accounts hidden (review: rv-today/mail-700.png). No fade length
       fixes that — the cut position is arbitrary. So the cut is not left to
       chance: .dash__list (_day/_mail/_health/_tasks.html) is a SIZE
       container that runs through the card's bottom padding to its edge
       (the card clips), and the list inside is capped so that its end
       always falls in a row's GOOD ZONE, --_lo to --_hi into the row: past
       --_lo, at least 14px of the cut row's headline shows inside the 20px
       fade; up to --_hi, the cut row's last line is still in the fade, so
       it visibly fades; and the row above is never in the fade. A box whose
       end lands outside the zone gives up the overshoot (under 40px, the
       card's own blank). A list whose TEXT fits is never capped: the
       template writes its row count (--_n), so the box knows where the
       last line ends (--_text) and takes the cap only when that is past
       its end; then, and only then, it also gets the card's 20px of end
       air for when it is scrolled to the end. (The `* 1000` clamps are
       the switch: 0 on one side of the comparison, the full value a
       fraction of a px past it.) Rows must keep ONE pitch for this (56;
       the spine's 48): every line in them is nowrap. */
    .dash__widget > .dash__list {
      flex: 1 1 0;
      min-height: 0;
      margin-bottom: -20px;
      container: dashlist / size;
    }
    .dash__list > :is(.spine, .rows) {
      --_pitch: 56px;  --_lo: 28px;  --_hi: 46px;  --_foot: 10px;   /* a one-line row's text is 18–38, a two-line row's 10–46 */
      --_text: calc(var(--_n, 0) * var(--_pitch) - var(--_foot));
      --_cap: calc(100cqh - max(0px, mod(100cqh + 1px - var(--_lo), var(--_pitch)) - 1px - (var(--_hi) - var(--_lo))));
      box-sizing: border-box;
      max-height: 100%;                                   /* where mod() is missing */
      /* (A list whose text fits may stand up to its last row's blank foot
         past the box, into the card's clip: scrolled by those few px it
         would fade its own last line.) */
      max-height: max(var(--_cap), clamp(0px, (100cqh - var(--_text)) * 1000, max(100cqh, var(--_n, 0) * var(--_pitch))));
      padding-bottom: clamp(0px, (var(--_text) - 100cqh) * 1000, 20px);
    }
    .dash__list > .spine { --_pitch: 48px; --_lo: 18px; --_hi: 40px; --_foot: 8px; }   /* a spine row's text is 4–40 */
    .dash__widget > #outside { flex: 1 1 auto; }
    .dash__list > :is(.spine, .rows),
    #outside > .env__body {
      min-height: 0;
      overflow-x: hidden;
      overflow-y: auto;
      overscroll-behavior: contain;
    }
    /* Outside's reading has no pitch (a figure, facts, meters), so its body
       takes the plain run-through and the LONG fade (§4.13's other length):
       its widest text-to-text gap is 24px, more than the short fade, so 40
       keeps the line above a cut visibly fading. */
    #outside > .env__body {
      flex: 1 1 auto;
      margin-bottom: -20px;
      padding-bottom: 20px;
      --m3-fade: 40px;
    }
    /* ⚠️ THE BOTTOM-RIGHT CORNER BELONGS TO THE FAB (K6). The board runs
       through the FAB's reserve, so the last card stands under it: its shape
       may, its content may not. The FAB reaches 42px into the card's content
       box sideways (80 FAB − 16 pane padding − 22 card padding) and ~44px up, so
       the last card's scroller keeps a STRIP down its end side, the reach
       plus the usual 16px of clear air (reserve 96 − 38 = 58px): nothing
       ever rests under the FAB, scrolled or not, and when the undo bar lifts
       the FAB it is still over the strip. A strip, not a bottom band: a band
       would take 44px of height from a card that is a share of the window
       (Outside's 154px at 1440×700 could no longer show its 48px ask button);
       the width is the cheap side. In a pane without the FAB (--fabreach 0)
       there is no strip. */
    .dash__widget:last-child > .dash__list > :is(.spine, .rows) {
      padding-inline-end: max(0px, calc(var(--fabreach, 0px) - 38px));
    }
    /* (.env__body's box already stands 6px past the content edge, below.) */
    .dash__widget:last-child > #outside > .env__body {
      padding-inline-end: max(6px, calc(var(--fabreach, 0px) - 32px));
    }

    /* Outside's body joins the fade list here (a page scroller joins in its
       page file, §4.13), and only in the ladder, the one place it scrolls: a
       mask clips to the box, so anywhere else it would only cut things. */
    @supports (animation-timeline: scroll(self)) {
      .env__body {
        mask-image: linear-gradient(to bottom, transparent 0, black var(--m3-fade-start),
                                    black calc(100% - var(--m3-fade-end)), transparent 100%);
        animation-name: m3-fade-start, m3-fade-end;
        animation-duration: auto, auto;
        animation-timing-function: linear, linear;
        animation-fill-mode: both, both;
        animation-timeline: scroll(self block), scroll(self block);
        animation-range: 0px var(--m3-fade, 40px), calc(100% - var(--m3-fade, 40px)) 100%;
      }
    }
  }
}
.env__body { scrollbar-width: none; }
.env__body::-webkit-scrollbar { display: none; }

/* ───────────────────────────────────────────── the card's own parts ──
   One title tier for all five cards (pages-a §2(e)1): title-small, sentence
   case, no letter-spacing (K23). Outside's head is the shared .panel__head
   (the fragment is swapped whole by environment.js), styled to match. */
.dash__head,
#outside .panel__head h2 {
  margin: 0;
  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);
  letter-spacing: 0;
}
#outside .panel__head { margin: 0; }

/* The figure: headline-large, tabular; its unit in label-large beside it. */
.dash__figure {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-headline-large-size);
  line-height: var(--md-sys-typescale-headline-large-line-height);
  font-weight: var(--md-sys-typescale-headline-large-weight);
  font-variant-numeric: tabular-nums;
}
.dash__figure span {
  margin-inline-start: 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-ref-typeface-plain);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-label-large-weight);
}
.dash__sub {
  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);
  font-variant-numeric: tabular-nums;
}

/* Rows in a widget: a STANDARD list (§3.10), overriding the segmented alias
   the legacy .rows carries — transparent items, no tiles, no gaps, the M3
   one-line floor of 56. */
.dash__widget .rows { gap: 0; }
.dash__widget .rows > .row {
  --_container: transparent;
  border-radius: 0;
  min-height: var(--app-list-h-1);
  padding: 8px 0;
  gap: 16px;
}
.dash__widget .row__main b {
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-ref-typeface-weight-medium);
}
.dash__widget .row__main em {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
}
.dash__widget .rows > .row--empty { min-height: 0; padding: 8px 0; }
/* One line each, so every row keeps the 56 pitch the ladder's cap counts in
   (a wrapped headline would make a row taller and the cap land mid-text). */
.dash__widget .row__main b {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ────────────────────────────────────────────────────────────── the day ──
   All-day events are label chips (§3.6: 24 tall, 8 corner, #333537 on the
   card): grey, with the event's CALENDAR colour as a 3px inset edge (K22) —
   never blue. --cal-color is written inline by _day.html. */
.dash__allday {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  min-width: 0;
}
.dash__allday li {
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  padding: 4px 8px;
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-highest);
  box-shadow: inset 3px 0 0 var(--cal-color, transparent);
  color: var(--md-sys-color-on-surface);
  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);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* The spine: time · a 3px bar in the calendar's colour · what. Containment
   reads here too: a nested event's bar is dimmer, not narrower. */
.spine {
  margin: 0;
  padding: 0;
  list-style: none;
  min-width: 0;
}
.spine__row {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 44px 3px minmax(0, 1fr);
  column-gap: 12px;
  align-items: start;
  min-height: 48px;
  padding: 4px 0;
}
.spine__row time {
  padding-top: 2px;            /* label-medium's 16px line, centred on the title's 20px one */
  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);
  font-variant-numeric: tabular-nums;
}
.spine__bar {
  align-self: stretch;
  width: 3px;
  border-radius: var(--app-shape-corner-mark);
  background: var(--cal-color, var(--md-sys-color-outline));
}
.spine__row.is-nested .spine__bar { background: var(--md-sys-color-outline-variant); }
.spine__what { display: grid; min-width: 0; }
.spine__what b {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-ref-typeface-weight-medium);
}
.spine__what em {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  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);
}
.spine__empty { padding: 8px 0; }     /* the one muted line (§3.21), on the card's text edge */

/* ─────────────────────────────────────────────────────────── outside ──
   core/_environment.html, swapped into #outside by environment.js.
   ⚠️ TWO METERS WITH OPPOSITE MEANINGS sit in this card: air quality (0–100,
   higher is CLEANER) and pollen (0–5, higher is WORSE). The direction is
   handled where the number is read — never by inverting a width here, which
   would put the knowledge in two places. A fill is never a warning colour
   (§3.20): the pollen meter is ink like the air one, and its VALUE text
   carries the red (.meter--warn, set on every pollen meter by
   _environment.html). */
#outside {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}
#outside > * { flex: none; }
/* The body's box stands 6px past the text edge on both sides: the ask
   button's 48px target reaches 4px past it, and its focus ring (3px at −2)
   1px further, which a scroller's clip or mask would cut flat. */
.env__body {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  margin-inline: -6px;
  padding-inline: 6px;
}
.env__ask { margin: 0; }
.env__why {
  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);
}
.env__err {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
}
:is(.env__err, .env__note) a { color: var(--app-color-accent); }
:is(.env__err, .env__note) a .ico {          /* the clickability mark in text (§3.24, K4) */
  --_icon: var(--app-icon-size-medium);
  --_opsz: 20;
  margin-inline-start: 4px;
  vertical-align: -4px;
}
.env__now {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 12px;
  margin: 0;
}
.env__temp {
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-display-medium-size);
  line-height: var(--md-sys-typescale-display-medium-line-height);
  font-weight: var(--md-sys-typescale-display-medium-weight);
}
.env__text {
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
}
.env__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  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;
}
.env__row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: center;
  min-height: 32px;
}
.env__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  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);
}
.env__row .meter { --_ground: var(--md-sys-color-surface-container); }   /* the gap after the bar is the card */
.env__value {
  color: var(--md-sys-color-on-surface);
  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);
  font-variant-numeric: tabular-nums;
}
.env__row .meter--warn + .env__value { color: var(--md-sys-color-error); }
.env__value--quiet { grid-column: 2 / -1; color: var(--app-color-on-surface-low); }
.env__note,
.env__read {
  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);
}
.env__read { color: var(--app-color-on-surface-low); font-variant-numeric: tabular-nums; }
