/* Scene: a team working on one dashboard (scenes/collab.js).
   These rules apply only once the scene has staged the page (body.is-staged), so opened on its
   own with scripts off the dashboard simply shows its finished state. The scene sets, every frame:
     --open     on the dashboard: 0 no KPI row, 1 the row has its place
     --box      on each tile: its card and placeholder arriving
     --content  on each tile: the real figures replacing the placeholder
     --draw     on each tile: the sparkline drawing on, left to right
     --grow     on each dashboard state: its charts drawing in after the period is switched to it
     --bars, --line  on each dashboard state: the daily chart as bars or as a line (see the foot) */

/* The row always keeps its place in the layout. While it is "closed", everything after it is
   slid up over that place instead (the row's 154px and the 24px gap under it). Sliding is a
   transform, which the browser can do without laying the page out again. */
:is(.is-staged, .embed) [data-inspect-id="kpi-row"] ~ * { transform: translate3d(0, calc((var(--open, 1) - 1) * 178px), 0); will-change: transform; }

:is(.is-staged, .embed) [data-inspect-id="kpi-row"] > div { position: relative; opacity: var(--box, 1); transform: translate3d(0, calc((1 - var(--box, 1)) * 6px), 0); }
:is(.is-staged, .embed) [data-inspect-id="kpi-row"] > div > :not(.kpi-skeleton) { opacity: var(--content, 1); transform: translate3d(0, calc((1 - var(--content, 1)) * 4px), 0); }

/* Embedded in another page, this one is painted before the scene's script has run. It starts
   as the scene starts, with no KPI row, so nothing jumps when the script takes over. */
.embed .dashboard:not([data-state]) { --open: 0; --box: 0; }

/* The placeholder lies over the tile and goes as the content arrives. */
.kpi-skeleton { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 9px; padding: 18px 16px 16px; opacity: calc(1 - var(--content, 1)); --c: var(--mat-lavender-deep); }
.kpi-skeleton i { display: block; }

.is-staged [data-inspect-id="kpi-row"] .area path:last-child { stroke-dasharray: 1; stroke-dashoffset: calc(1 - var(--draw, 1)); }
.is-staged [data-inspect-id="kpi-row"] .area path:first-child { opacity: var(--draw, 1); }

/* Switching the period: the new figures are simply there, as in the app; the two big charts
   draw in. Bars rise from their foot, lines and areas come up with them. */
.is-staged :is([data-inspect-id="daily-profit"], [data-inspect-id="weekday"]) .bars path { transform-box: fill-box; transform-origin: 50% 100%; transform: scaleY(var(--grow, 1)); }
.is-staged :is([data-inspect-id="daily-profit"], [data-inspect-id="weekday"]) :is(.area, .line, .dots) { opacity: var(--grow, 1); }

/* The chart change: the daily profit bars become a line through the same days' figures (the
   scene draws the line from the bars themselves). The bars drop to their foot as the line draws
   on, and the line redraws with the chart when the period is switched. The scene sets --bars
   (1 bars, 0 none) and --line (0 none, 1 drawn) on each dashboard state. */
.is-staged [data-inspect-id="daily-profit"] .bars path { transform: scaleY(calc(var(--grow, 1) * var(--bars, 1))); }
.profit-line { fill: none; stroke: var(--good); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: calc(1 - var(--line, 0) * var(--grow, 1)); }
