/* ===========================================================================
   PANES — the pages that ARE the viewport, sized without arithmetic.
   (2026-09-04. New file rather than more of app.css: this is one mechanism,
   and it should be possible to read it in one screen and delete it in one
   command.)

   THE BUG THIS ENDS. Every full-height page in the portal said the same thing
   in CSS — "I am the viewport, less the app bar" — and said it as a number:

       height: calc(100dvh - 48px)                        - the room, the tools page
       height: calc(100dvh - var(--mud-appbar-height))    - 64px, so 16 too much
       height: calc(100dvh - (var(--mud-appbar-height)
                    - var(--mud-appbar-height)/4))        - right, as of today

   The last of those IS the right number today, and the meetings page still
   scrolled. It scrolls because the number was never the problem: on the dev
   site the Lens recording shim, when its bar is up, injects

       body { padding-top: 40px !important; }

   and a page sized to the whole viewport inside a body pushed down 40px is 40px
   taller than the room left for it. The document scrolls by exactly the height
   of a banner the page has never heard of. Subtracting --delve-shim-height too
   (which .meeting-page does) fixes that one banner and leaves the next one.

   THE MECHANISM. A pane stops measuring anything. <body> gets the class
   `moment-pane` (see panes.js and PortalPane.razor) and becomes a fixed-height
   flex column; MudLayout and MudMainContent become flex boxes inside it; the
   page is the growing item at the end of the chain. Each box takes what the box
   above has left, so:

     - the app bar's height arrives as MudBlazor's own padding-top on
       .mud-main-content (.mud-appbar-dense ~ .mud-main-content resolves it),
       inside a border-box the page fills — dense or not, themed or not;
     - the shim's 40px arrives as padding on a border-box body, so the layout
       simply starts lower and ends in the same place;
     - anything that takes a strip of window in future costs nobody an edit.

   `min-height: 0` appears on every link of the chain on purpose. A flex item's
   default min-height is `auto`, which means "never smaller than my content" —
   and content is exactly what a scrolling region has too much of. Without it
   the chain refuses to shrink and the overflow simply moves up a level.

   HOW TO ADOPT A PAGE. Put <PortalPane /> in its markup, then give its root
   `flex: 1 1 auto; min-height: 0; height: auto` under `.moment-pane` below.
   Leave the page's own `height: calc(...)` rule where it is: it stays the
   fallback if the class never lands, and this file outranks it (two classes
   beats one, and panes.css is linked after app.css).
   ======================================================================== */

/* --- The chain ---------------------------------------------------------- */

body.moment-pane {
    /* dvh, not vh: on a phone the toolbars come and go, and the pane should
       end at the bottom of what is actually visible. */
    height: 100dvh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* The document itself never scrolls on a pane. This is the assertion the
       whole file exists to make; if a pane ever overflows again it will be
       clipped here rather than quietly turning the page into a document. */
    overflow: hidden;
}

body.moment-pane > .mud-layout {
    /* MudBlazor ships .mud-layout { height: 100% }, which against an auto-height
       body resolves to auto — i.e. to its content. As a flex item it takes the
       leftover instead. */
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

body.moment-pane .mud-main-content {
    /* .mud-main-content already carries flex: 1 1 auto from MudBlazor — it just
       never had a flex parent. It also already carries the app bar's height as
       padding-top, which is the whole point: we keep that and fill what is left
       inside it. max-height is reset because the shim sets one in viewport units
       (calc(100vh - 40px)) that this chain no longer needs and that would clamp
       the box a second time. */
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    max-height: none;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* The pane owns its own scrolling regions. MainLayout's overflow-y-auto is
       for ordinary document pages. */
    overflow: hidden;
}

/* Whatever the page put at the top level of the content box — including the
   layouts that wrap it, like Manage's — may shrink. Only the elements named
   below GROW; everything else keeps its natural height, which is how a warning
   banner or a tab strip stays exactly as tall as it is. */
body.moment-pane .mud-main-content > * {
    min-height: 0;
}

/* --- The panes ---------------------------------------------------------- */

/* Each block is: fill the leftover, be allowed to shrink, and forget your own
   viewport arithmetic (height: auto beats the calc(); min-height: 0 beats the
   floors that were there to stop a short window collapsing a layout — with a
   flex chain there is nothing left to collapse). */

.moment-pane .meetings-page,
.moment-pane .chat-shell,
.moment-pane .mt-page,
.moment-pane .artifacts-page,
.moment-pane .ph-page,
.moment-pane .tools-shell,
.moment-pane .meeting-page {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}

/* The client chat sits inside the gutter container with the tab strip above it,
   so its shell is a grandchild rather than a child; and its old rule took a
   further 60px off for the tabs, which the chain now measures for it. */
.moment-pane .mud-container:has(> .chat-shell-client),
.moment-pane .mud-container:has(> .chat-shell) {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.moment-pane .chat-shell-client {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}

/* Manage's own shell is two columns — the section nav and the page — and the
   report page is a pane inside the right one. Both columns become part of the
   chain so the report's own flex layout has a definite box to sit in; the nav
   keeps its sticky top, which now has nothing to be sticky against and simply
   stretches. */
.moment-pane .manage-shell {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
}

.moment-pane .manage-body {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.moment-pane .report-shell {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}

/* The tools page keeps its warning banner at natural height above the columns —
   a flex item that neither grows nor is told to shrink is exactly as tall as
   its text — and the columns keep their own overflow-y: auto inside the shell. */
.moment-pane .tools-body {
    min-height: 0;
}

/* --- The wall displays -------------------------------------------------- */
/*
   A monitor by the door has no mouse and nobody standing at it, so a display
   that is taller than the screen is a display with a part nobody will ever see.
   Both faces therefore stop at the bottom edge: the shell fills the viewport
   and hides its overflow, and the rows inside are told they may be shorter than
   their content (minmax(0, 1fr) / min-height: 0) so a busy day SHRINKS the rows
   first and only clips once there is nothing left to give. That order matters:
   shrinking loses whitespace, clipping loses meetings.
*/

.moment-pane .board-display,
.moment-pane .caldisplay {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* The monitor face is one grid: a row of day headings, then a row of day
   columns. The headings keep their height and the columns take the rest — so
   four days of cards get shorter as the day fills rather than pushing the last
   card past the bottom of the screen. */
.moment-pane .board-display .board-week.is-meetings {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
}

.moment-pane .board-display .board-week-cell {
    min-height: 0;
    overflow: hidden;
}

/* The cards themselves do NOT shrink, and this is where the shrink-then-clip
   order stops. A day column is a flex column, so by default its cards would
   squash to fit — and a squashed card loses the time and the faces from the
   bottom of itself while still occupying the screen, so eight meetings become
   eight titles and no answers. Holding the cards at their natural height means
   a genuinely overloaded day is cut off at the bottom of its column instead:
   the meetings that are shown are shown whole, in the order they happen, which
   is the right thing to lose last on a screen by the door.

   MEASURED (scratchpad/scrollcheck/board_fixture.py, 1920x1080, four columns):
   two or four meetings a day fit with room to spare; eight used to make the
   page 502px taller than a monitor nobody can scroll, and now fills the column
   and clips the seventh and eighth. */
.moment-pane .board-display .board-card {
    flex: 0 0 auto;
}

/* The calendar face already stacks weeks at flex: 1 1 0 with min-height: 0 and
   clips inside a day, so it only needed the shell to stop growing. */
.moment-pane .caldisplay-weeks {
    min-height: 0;
}

/* --- The one page that stops being a pane ------------------------------- */
/*
   app.css already says `@media (max-width: 900px) { .tools-shell { height: auto } }`:
   below that width the tools page's three columns stack, and three stacked
   columns are taller than any phone. That page is meant to become an ordinary
   scrolling document there, and a pane that clips its overflow would hide two
   of the three columns entirely — which is the opposite failure to the one this
   file exists to fix, and a worse one.

   So the chain steps aside rather than the page fighting it. Written as a
   :has() on <body> so it is the LAYOUT that relaxes, not just the shell: the
   assertion "the document never scrolls" is the whole mechanism, and the honest
   way to make an exception is to say so at the top.
*/
@media (max-width: 900px) {
    body.moment-pane:has(.tools-shell) {
        height: auto;
        min-height: 100dvh;
        display: block;
        overflow: visible;
    }

    body.moment-pane:has(.tools-shell) > .mud-layout,
    body.moment-pane:has(.tools-shell) .mud-main-content {
        height: auto;
        display: block;
        overflow: visible;
    }

    .moment-pane .tools-shell {
        flex: 0 0 auto;
        height: auto;
    }
}
