/* Layouts: how pages and groups place their parts. Component appearance belongs in components.css.
   Screens compose these; the only breakpoint is the shared 800px phone/desktop switch. */

/* App root and the two shells. Each screen renders a mobile-shell and a desktop-shell; one shows. */
/* app-frame: the mount of every page that renders the shells (the app, Manage account). On desktop it is the
   sunken ground the centred DesktopShell sits on; pages without the shell keep the page surface. */
.app-frame { min-height:100dvh; }
.mobile-shell { width:100%; min-height:100dvh; }
.mobile-page { display:grid; gap:var(--space-3); min-width:0; padding:0 0 calc(var(--tab-bar-height) + var(--space-6) + env(safe-area-inset-bottom)); }
.screen-main { display:grid; align-content:start; gap:var(--space-4); width:100%; min-width:0; }
/* Mobile focus: a phone page without the tab bar, such as Finish; its pinned ActionBar needs room below. */
.mobile-focus { display:grid; min-height:100dvh; padding-bottom:calc(var(--action-bar-height) + var(--space-3)); }
.mobile-shell > .screen-main { padding:var(--space-4) var(--space-4) var(--space-6); }
@media(min-width:800px) { .mobile-shell { display:none; } }
@media(max-width:799px) { .desktop-shell { display:none; } }

/* DesktopShell: Nav, then the content and an optional side column. The side column wraps under the content
   when there is no room for both; wide-side gives it a fixed width and the full window height (Routines). */
@media(min-width:800px) {
  .app-frame { background:var(--surface); }
  .desktop-shell { display:grid; grid-template-columns:var(--nav-width) minmax(0,1fr); max-width:var(--shell-max); min-height:100dvh; margin-inline:auto; background:var(--surface); }
}
.desktop-shell-nav { min-width:0; }
.desktop-shell-main { display:flex; flex-wrap:wrap; align-items:flex-start; align-content:flex-start; column-gap:var(--page-gutter); min-width:0; padding:0 var(--page-gutter); }
.page-content { flex:2 1 var(--content-basis); min-width:0; max-width:var(--content-max); padding:var(--page-top) 0; }
.page-content > .screen-main { padding:0; }
.page-side { display:flex; flex:1 1 var(--side-column); flex-direction:column; align-items:stretch; gap:var(--space-4); min-width:0; padding:var(--page-gutter) 0; }
.desktop-shell-main-wide-side { align-items:stretch; padding-right:0; }
.desktop-shell-main-wide-side > .page-content { max-width:none; }
.desktop-shell-main-wide-side > .page-side { display:flex; flex:0 1 var(--side-column-wide); flex-direction:column; min-height:100dvh; padding:0; border-left:var(--rule-width) solid var(--line-subtle); background:var(--surface-raised); }

/* Standalone page: a page without app navigation, such as one opened from a shared link. */
.page-standalone { display:grid; align-content:start; gap:var(--space-4); width:min(100%,var(--content-max)); min-height:100dvh; margin:0 auto; padding:var(--space-6) var(--page-gutter) var(--space-8); }
/* A small centred page, such as start-up and sign-in. */
.page-centered { display:grid; gap:var(--space-3); width:min(100% - 2 * var(--space-4), var(--overlay-width)); margin:var(--space-8) auto; }
/* page-splash: one thing in the middle of the window, such as the app's loading wordmark alone. */
.page-splash { display:grid; place-content:center; justify-items:center; gap:var(--space-4); min-height:100dvh; padding:var(--space-8) var(--space-4); }
/* page-brand: the signed-out pages (sign-in, reset, invitation). The accent fills the window and
   the page-centered column sits in its middle, with more room between the wordmark and the panel. */
.page-brand { display:grid; align-content:center; min-height:100dvh; padding:var(--space-8) 0; overflow-x:clip; background:var(--brand-ground); }
.page-brand > .page-centered { gap:var(--space-8); margin:0 auto; }
/* The app reserves the scrollbar's room, so pages long enough to scroll don't shift sideways against short ones. */
html:has(.app-frame) { scrollbar-gutter:stable; }

/* Page toolbar: filters and fields under a PageHeader. A switch keeps its own width; a field takes the rest. */
.page-toolbar { display:flex; flex-wrap:wrap; align-items:flex-end; gap:var(--space-3); }
.page-toolbar > * { flex:0 1 var(--list-max); min-width:0; }
.page-toolbar > .segmented-control { flex:none; }
.page-toolbar > .combobox { flex:1 1 var(--routine-tile-min); }
/* Page stack: a vertical run of panels, such as the exercises in a workout record. */
.page-stack { display:grid; gap:var(--space-4); }
/* columns-flow: panels flow down two columns when there is room for both, one otherwise. */
.columns-flow { columns:2 var(--column-min); column-gap:var(--space-4); }
.columns-flow > * { break-inside:avoid; margin-bottom:var(--space-4); }
.columns-flow > :last-child { margin-bottom:0; }
/* Page form: a page that is one form keeps a readable line length. */
.page-form { max-width:var(--form-max); }
/* Page list: rows that carry their own dividers, stacked with no gap. */
.page-list { display:grid; gap:0; }

/* Stack: children in a column. Tight is for denser groups. */
.stack,.stack-tight { display:grid; align-content:start; gap:var(--space-4); min-width:0; }
.stack-tight { gap:var(--space-3); }
/* Cluster: a wrapping row, such as a group of buttons. Spread pushes the ends apart. */
.cluster { display:flex; flex-wrap:wrap; align-items:center; gap:var(--space-2); }
.cluster-spread { justify-content:space-between; }
/* Form stack: a form's fields stacked, with its buttons at their own width. */
.form-stack { display:grid; gap:var(--space-3); margin:0; }
.form-stack > .ui-button,.form-stack > .segmented-control { justify-self:start; }
/* Field row: fields side by side, as many as fit, each at least --field-min wide. */
.field-row { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,var(--field-min)),1fr)); align-items:end; gap:var(--space-3); min-width:0; }
/* A load and its unit take a whole row, so the number keeps a full field's width. */
.field-with-unit { display:grid; grid-column:1 / -1; grid-template-columns:minmax(0,1fr) auto; align-items:end; gap:var(--space-3); min-width:0; }
/* Split: a picture or main column beside its side column, stacking when there is no room for both. */
.split { display:flex; flex-wrap:wrap; align-items:flex-start; gap:var(--space-6); }
.split > * { min-width:0; }
.split-main { flex:999 1 var(--side-column); }
.split-media { flex:1 1 var(--media-basis); max-width:var(--media-max); }
/* Columns: equal columns that drop to one when narrow. Tight rows touch and a few items keep their width;
   pair is at most two columns. */
.columns { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,var(--column-min)),1fr)); gap:var(--space-4); }
.columns-tight { grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--column-min)),1fr)); gap:0 var(--space-2); }
.columns-pair { display:grid; grid-template-columns:repeat(auto-fit,minmax(max(var(--routine-tile-min),calc((100% - var(--space-4)) / 2)),1fr)); gap:var(--space-4); }
/* Settings: a main column and a narrower side column. */
.settings-layout { display:flex; flex-wrap:wrap; align-items:flex-start; gap:var(--space-6); }
.settings-column { display:grid; flex:1 1 var(--column-narrow); align-content:start; gap:var(--space-6); min-width:0; }
.settings-column:first-child { flex:2 1 var(--content-basis); }
/* Desktop only: what a phone does another way (the swipe), such as Remove exercise next to Change. */
.only-desktop { display:none; }
@media(min-width:800px) { .only-desktop { display:contents; } }

/* bleed-phone: on phones its child spans the whole screen width (a list in an edge Panel). */
@media(max-width:799px) {
.bleed-phone { margin-inline:calc(-1 * var(--space-4)); }
}

/* Fixed feedback and optional rest dock share a stack, clear of each other and navigation. */
.dock-stack { position:fixed; z-index:var(--layer-sticky); display:grid; gap:var(--space-2); left:var(--space-4); right:var(--space-4); bottom:calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + var(--space-2)); }
@media(min-width:800px) {
.dock-stack { left:calc(max(0 * var(--space-1), (100% - var(--shell-max)) / 2) + var(--nav-width) + var(--page-gutter)); right:calc(max(0 * var(--space-1), (100% - var(--shell-max)) / 2) + var(--page-gutter)); bottom:var(--space-4); max-width:var(--content-max); }
}
