/* =============================================================================
   css/screens/app.css
   The shell: the header that never goes away, and the area screens draw into.

   Screen files position things. They do not style them. Every value here is a
   token from tokens.css, and every component it arranges is defined in
   components.css. If a colour or a pixel number appears in this file, that is
   a bug (docs/05-ux-spec.md section 8, and CLAUDE.md rule 9).
   ============================================================================= */


/* -----------------------------------------------------------------------------
   THE FRAME
   Header on top, screen underneath, the screen scrolls and the header does not.
   100dvh rather than 100vh so the Android address bar sliding away does not
   leave a gap at the bottom.

   --app-height is set by js/app.js from the visual viewport, because on the
   tablet the first paint after login was laid out about a status bar too
   tall (100dvh had not yet taken the system bars into account) and the Save
   button sat below the edge until the page was swiped (19 September 2026).
   The measured height is the truth; 100dvh is the fallback before it is
   known. The bottom inset keeps the last row above Android's gesture bar.
   ----------------------------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app__main {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


/* -----------------------------------------------------------------------------
   HEADER
   docs/05-ux-spec.md section 4: 56px tall, logo and name at the left, then
   whose shift it is, then whether work has been sent, then the menu.
   The middle shows who is logged in once a PIN is in (AUTH-02).
   ----------------------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: none;

  height: var(--tap-min);
  padding: 0 var(--space-3);

  color: var(--color-on-header);
  background: var(--color-header);
  z-index: var(--z-sticky);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: inherit;
  text-decoration: none;
}

.app-header__logo {
  height: 32px;
  width: auto;
}

.app-header__name {
  font-size: var(--text-line);
  font-weight: var(--font-bold);
  white-space: nowrap;
}

/* Full loads not yet marked delivered (js/app.js drawLoads(),
   feature/loads-waiting): an orange pill with a truck and the count, hidden
   at nought. It pulses for a few seconds when the count goes up or someone
   logs in (data-pulse), then stays still; never under reduced motion. */
.app-header__loads {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  min-height: var(--tap-min);
  padding: 0 var(--space-3);

  font: inherit;
  font-size: var(--text-body);
  font-weight: var(--font-bold);
  color: var(--color-text);
  background: var(--color-warning);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
}

.app-header__loads[hidden] {
  display: none;
}

.app-header__loads:active {
  filter: brightness(1.1);
}

.app-header__loads[data-pulse] {
  animation: loads-pulse 1.2s ease-out 3;
}

@keyframes loads-pulse {
  0%   { box-shadow: 0 0 0 0 var(--color-warning); }
  70%  { box-shadow: 0 0 0 var(--space-3) transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .app-header__loads[data-pulse] {
    animation: none;
  }
}

/* On a phone the words go: the truck and the number say it. */
@media (max-width: 480px) {
  .app-header__loads-text {
    display: none;
  }
}

/* The sync state. A button, because tapping it explains itself (SYNC-04). */
.app-header__sync {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  min-height: var(--tap-min);
  padding: 0 var(--space-2);

  font-size: var(--text-body);
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.app-header__version {
  font-size: var(--text-small);
  opacity: 0.6;
}

/* Who is logged in (AUTH-02). A coloured dot in their tile colour, their
   first name, their role, and a way out. Tapping it goes back to the tiles.
   --tile-colour is set by js/app.js from the staff row. */
.app-header__user {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  min-height: var(--tap-min);
  padding: 0 var(--space-3);

  font-size: var(--text-body);
  font-weight: var(--font-medium);
  color: inherit;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.app-header__user:active {
  background: rgba(255, 255, 255, 0.18);
}

.app-header__user-role {
  font-size: var(--text-small);
  font-weight: var(--font-regular);
  opacity: 0.7;
}

@media (max-width: 480px) {
  .app-header__user-role {
    display: none;
  }
}

/* The header sits on navy, so its buttons have to be light on dark rather
   than the light-background versions in components.css. */
.app-header .btn--icon {
  color: inherit;
  background: none;
  border-color: transparent;
}

.app-header .btn--icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

/* On a phone the name and the version are the first things to go. */
@media (max-width: 480px) {
  .app-header__name,
  .app-header__version {
    display: none;
  }
}


/* -----------------------------------------------------------------------------
   SCREEN
   The box every screen draws into. One place to change the reading width and
   the breathing room around it.
   ----------------------------------------------------------------------------- */

.screen {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}

/* For screens that are one thing in the middle: setup, empty states, errors. */
.screen--centred {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}

@media (max-width: 480px) {
  .screen {
    padding: var(--space-4) var(--space-3);
  }
}


/* -----------------------------------------------------------------------------
   SET UP THIS DEVICE
   Seen once per tablet (AUTH-05).
   ----------------------------------------------------------------------------- */

.setup {
  width: min(460px, 100%);
}

.setup__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.setup__env {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  color: var(--color-text-muted);
}


/* -----------------------------------------------------------------------------
   HOME
   The product browser on its own, until the dashboard replaces this screen
   in phase 3. Status line on top, the browser filling the rest so its grid
   scrolls under a search box that stays put, a one-line footer.
   ----------------------------------------------------------------------------- */

.home {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  height: 100%;
  min-height: 0;
}

.home__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex: none;
  color: var(--color-text-muted);
}

.home__fresh {
  font-size: var(--text-body);
}

.home__browser {
  flex: 1 1 auto;
  min-height: 0;
}

.home__foot {
  flex: none;
  margin: 0;
  font-size: var(--text-small);
}


/* -----------------------------------------------------------------------------
   THE DAY BUTTON
   "Day open 08:12" next to the sync state (docs/05-ux-spec.md section 4).
   Tapping it opens the day, or closes it (js/app.js, js/ui/day-dialogs.js).
   When yesterday is still open it turns warning coloured, in step with the
   banner under the header (DAY-06), which is the .banner component drawn
   into [data-banner] in index.html.
   ----------------------------------------------------------------------------- */

.app-header__day {
  display: flex;
  align-items: center;
  gap: var(--space-2);

  min-height: var(--tap-min);
  padding: 0 var(--space-3);

  font-size: var(--text-body);
  font-weight: var(--font-medium);
  color: inherit;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.app-header__day:active {
  background: rgba(255, 255, 255, 0.18);
}

.app-header__day[data-state='stale'] {
  color: var(--color-warning);
}

/* On a phone the words go and the icon stays; the banner says the rest. */
@media (max-width: 480px) {
  .app-header__day-text {
    display: none;
  }
}


/* -----------------------------------------------------------------------------
   LOADS NOT DELIVERED YET
   The truck pill's list (js/ui/loads-dialog.js): each load a .unit-option
   row with three lines: what, when and its number, who and where.
   ----------------------------------------------------------------------------- */

.loads-dialog__row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  text-align: left;
}

.loads-dialog__what {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--font-bold);
}

/* -----------------------------------------------------------------------------
   THE MENU
   "Go to": the built screens as a short list (js/app.js, showMenu()).
   ----------------------------------------------------------------------------- */

.menu-dialog .dialog__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-bottom: var(--space-5);
}
