/* css/mobile.css
   Owns: every width-dependent rule of the app (UI plan step 21). One set of breakpoints, the --bp-* tokens of
   css/tokens.css: compact 1440, small 1200, narrow 1000 (and its portrait and landscape halves) and slim 520. A
   media query cannot read a custom property, so the numbers are written here and jscheck holds them to the tokens; JS
   asks core/tokens.js media(name) and never writes a query. Loads last. Widest first; inside each block, in the load
   order of the sheets whose rules these override (shell, the stage and its parts, the pages, then the Watch stage on a
   phone). The wide-only rules (`not all and (max-width: 1000px)`, the exact complement of narrow) stay in their own
   sheets; so do the capability queries (hover, pointer, reduced motion, print, standalone). */

/* ========== ≤ 1440 (--bp-compact): the 1366-class screen, the pages one step denser ========== */
@media (max-width: 1440px) {
  .dt .hide-m { display: none; }                                                      /* kit/table.js hide: 'm' */
  .cus-body { grid-template-columns: 480px minmax(0, 1fr); }                          /* Desk › Customers */
  .fd-grid { grid-template-columns: minmax(0, 1fr) 320px; }                           /* Desk › Front desk: the bays 2 by 2 */
  .fd .tiles.fd-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pricing-grid { grid-template-columns: minmax(0, 1fr); }                            /* Manage › Pricing: one column */
  .comps-grid { grid-template-columns: minmax(0, 1fr); }                              /* Manage › Comps & tills: stacked */
  .sales-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }                  /* Manage › Sales: the figures 2 across */
}

/* ========== ≤ 1200 (--bp-small): a small laptop, a tablet held sideways ========== */
@media (max-width: 1200px) {
  .topbar-clock { padding: 0 2px; }
  .topbar-clock .clock-day { display: none; }   /* the time alone: the day would push Watch's controls to a second row */
  /* Staff on site gives up its end time first: the Watch top bar is one row from 1200 px up with it showing */
  .pill.onsite .onsite-until { display: none; }
  .cam-layout { grid-template-columns: minmax(0, 1fr); }                              /* System › a camera: the still under its tabs */
  .zv-layout { grid-template-columns: minmax(0, 1fr); }                               /* the zone editor: its list under the picture */
}

/* ========== ≤ 1000 (--bp-narrow): phones and small tablets ========== */
@media (max-width: 1000px) {
  /* ---- the window and the top bar. The ☰ and the account stay on the name's line; the Watch controls take a row of
     their own under it. ---- */
  html, body { height: 100dvh; }
  .topbar { position: relative; overflow-x: clip; flex-wrap: wrap; gap: 7px; }   /* nothing in the bar may widen the page */
  .topbar-menu { display: inline-flex; order: 0; }
  .topbar .brand { order: 0; flex: 1 1 auto; min-width: 0; }
  .topbar-right { order: 1; }
  .topbar-slot { order: 2; flex: 1 1 100%; flex-wrap: wrap; }   /* LIVE and the pager cannot shrink below their words: they wrap */
  .topbar .pager { gap: 2px; }
  .topbar .pager button { padding: 2px 7px; }
  .usermenu .whoami { max-width: 11ch; }
  /* the attention pill is just "⚑ 3", and only while something is waiting; its panel covers the whole screen. Staff on
     site shows only while on (the user menu turns it on and off) */
  .pill.attn .attn-label, .pill.attn:not(.on) { display: none; }
  .pill.health .health-label { display: none; }   /* just "⚠ 1"; its panel says what */
  .pill.onsite:not(.on) { display: none; }
  .menu > .menu-onsite:not([hidden]) { display: block; }
  .topbar-clock { display: none; }   /* the date and time are for the desk's screen; a phone has its own */
  .attn-panel { top: 0; }

  /* ---- the rail slides in from the ☰; a page's bar wraps its actions under its tabs ---- */
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; top: 0; bottom: 0; left: 0; width: min(260px, 80vw); z-index: 48; padding-top: calc(env(safe-area-inset-top) + 10px);
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 8px 0 24px var(--scrim); }
  body.rail-open .rail { transform: none; }
  .rail a, .rail button { flex-direction: row; justify-content: flex-start; gap: var(--s3); padding: 12px 16px; font-size: var(--fs-base); }
  .rail a[aria-current="page"]::before { top: 6px; bottom: 6px; }
  .rail .rail-badge { position: static; margin-left: auto; }
  .rail-backdrop { position: fixed; inset: 0; z-index: 47; background: var(--scrim); }
  .page-frame { max-width: none; }
  .pagebar { flex-wrap: wrap; row-gap: 0; }
  .pagebar-tabs { flex-basis: 100%; min-height: var(--pagebar-h); }
  .pagebar-actions { flex: 1 1 100%; flex-wrap: wrap; margin-left: 0; padding: 0 0 var(--s2); }

  /* ---- a security responder's chip: the short words (css/stage.css) ---- */
  .pill.access-chip { width: 9ch; }
  .access-chip .access-long { display: none; }
  .access-chip .access-short { display: inline; }

  /* ---- the pages: one column ---- */
  .cus-body { grid-template-columns: minmax(0, 1fr); overflow-y: auto; }             /* Desk › Customers: one scroll */
  .cus-list, .cus-detail { overflow: visible; border-right: 0; }
  .fd-grid { grid-template-columns: minmax(0, 1fr); }                                 /* Desk › Front desk */
  .fd .tiles.fd-tiles { grid-template-columns: minmax(0, 1fr); }
  .fd-find input { min-width: 0; width: 100%; }
  .sales-stats, .sales-grid { grid-template-columns: minmax(0, 1fr); }                /* Manage › Sales */
  /* System's sub-nav: a row across the top (it scrolls sideways) */
  .sys-frame { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .subnav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  /* A kit table wider than the phone swipes inside its host (kit/table.js), so the page itself never scrolls sideways
     and money and dates stay whole on one line; the toolbar and the heading stay put. (Its sticky head then sticks to
     the host, which does not scroll down: it scrolls away with the page. Phones: only not broken.) */
  .dt-host { overflow-x: auto; }
  /* the legacy dialog (Help): never wider than the screen inside the scrim's 20 px padding (96vw ran 6 px off a 360 px
     screen) */
  .modal-card { max-width: calc(100vw - 40px); }

  /* ---- Watch: the stage, the side pane, the sheet and Enhance on a phone ---- */
  /* Panes fill their cells, as before step 20e: at phone sizes a 16:9 pane is too narrow for its name, badges and
     time (stage/layout.js still picks the shape). */
  .video-area { grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr)); }
  /* Small 16:9 panes, held either way (step 21; landscape's since 2026-10-27): each label keeps to one line (the name
     gives way first, the channel number goes; the pay badge stays), so the labels cover a strip of the picture, not
     half of it. */
  .pane-top { flex-wrap: nowrap; min-width: 0; gap: 5px; }
  .pane-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .pane-ch { display: none; }
  .pane-badges, .pane-pay { flex: none; }
  .pane-time { white-space: nowrap; font-size: 11px; }
  /* App-shell on mobile too: fixed to the visible viewport (dvh follows the
     browser chrome as it hides/shows), nothing scrolls the page itself. The
     video takes a set share of the height so the controls and timeline stay
     on screen together; the lists scroll inside their own panels. */
  .layout {
    display: flex; flex-direction: column; flex: 1; min-height: 0;
    grid-template-columns: none; grid-template-rows: none;
  }
  .stage { flex: 0 0 auto; min-height: 0; }
  .video-area { flex: 0 0 auto; height: 42vh; min-height: 150px; }
  .side { flex: 1 1 auto; min-height: 0; border-left: 0; border-top: 1px solid var(--line); }
  /* Six tabs at phone width: the strip scrolls sideways rather than pushing
     the page wider (a swipe reaches the rest). */
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  /* Transport goes icon-only (±10s keeps its text — it is the icon), with
     finger-sized targets; there is no Shift key to drag with, so no hint. */
  .transport .lbl { display: none; }
  .transport .tbtn { min-width: 40px; padding: 7px 9px; font-size: 15px; line-height: 20px; }   /* an icon button: 40 px */
  .transport .tbtn svg.i { width: 20px; height: 20px; }
  #btnFrame { gap: 2px; }
  #btnFrame svg.i.caret { width: 12px; height: 12px; margin-left: 0; }
  .transport .tbtn.play { min-width: 44px; }
  /* Tighter between groups, and the readout last: playback, speed and the tools share a row where they fit, and only
     the readout wraps (a landscape phone keeps its video). */
  .transport { column-gap: 4px; }
  .transport .playhead-readout { order: 1; }
  #btnBack, #btnFwd { padding-left: 6px; padding-right: 6px; }
  /* The clip being marked takes a row of its own under the span and zoom: its times on one line, finger-sized
     Start / End / Export / clear beneath. */
  .tlhead { flex-wrap: wrap; height: auto; padding: 3px 6px; }
  .clipslot { flex: 1 1 100%; }
  .clipslot:not(.has-clip) { display: none; }   /* an empty slot takes no row */
  .clipslot .selection-box { flex: 1 1 100%; margin-left: 0; flex-wrap: wrap; gap: 5px; padding: 5px 6px; }
  .clipslot #selectionLabel { flex: 1 1 100%; text-align: center; font-size: 13px; }
  .clipslot .selection-box .sel-btns { flex: 1 1 100%; justify-content: space-between; }
  .clipslot .tbtn.small { padding: 7px 10px; font-size: 13px; }
  /* Contact sheet: the stage takes the whole height so the sheet scrolls
     inside itself with the transport and timeline pinned below it; the events
     panel steps aside while scanning stills. */
  body.sheet-open .stage { flex: 1 1 auto; }
  body.sheet-open .side { display: none; }

  /* The events-split toggle is a landscape-only control. */
  #btnEvSplit { display: none; }

  /* No resizing or collapsing at phone widths: the side pane stacks (or splits in, landscape) as before. */
  .side-grip, .tabs .side-collapse, .side-open { display: none !important; }

  /* Events (20f): one row: Alerts only, Filters (one sheet with every picker, as before 20f), Live | Locked; the count
     and the word Follow give way. Controls at 30 px for a finger. */
  #evKinds, #evCams, #evScore, .ev-count, .ev-follow-label { display: none; }
  .ev-status { flex: 0 1 auto; margin-left: auto; }
  .ev-tools .tbtn, .ev-tools .seg button { height: var(--ctl-h); }
  /* never a second row (a 294 px landscape split with a filter count): the switch's buttons tighten and Alerts only
     gives way first */
  .ev-tools, .ev-filters { flex-wrap: nowrap; }
  .ev-tools .seg button { padding: 0 var(--s2); }
  #evAlerts { min-width: 0; overflow: hidden; text-overflow: ellipsis; }


  /* Enhance (20f): the whole window (fixed: the layer's padding is escaped without :has()). The picture runs edge to
     edge and stays at the top while the controls scroll under it; nothing re-centres here, so the row under the
     picture may wrap (P21). */
  .dlg.enh-dlg { position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: auto; max-height: none; border: 0; border-radius: 0; }
  .enh-dlg .dlg-head { padding: var(--s3) var(--s4) 0; }
  .enh-dlg .dlg-body { flex: 1 1 auto; overflow-y: auto; padding: 0 0 var(--s4); }
  .enh-dlg .dlg-foot { padding: var(--s2) var(--s4) var(--s3); }
  .enh-dlg .enh { display: block; }
  .enh-view { position: sticky; top: 0; z-index: var(--z-sticky); padding: var(--s2) 0; background: var(--panel);
    --enh-pic-w: min(100%, calc(45vh * var(--ar))); }
  .enh-pic { box-shadow: none; border-radius: 0; }
  .enh-under { width: 100%; height: auto; flex-wrap: wrap; white-space: normal; padding: 0 var(--s4); }
  .enh-side { max-height: none; overflow: visible; padding: 0 var(--s4); margin-top: var(--s2); }
  .enh-sliders { grid-template-columns: 1fr 1fr; }
}
/* the rail stays put for whoever asks for less motion */
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }

/* ========== narrow, portrait: a phone held upright ========== */
/* The cameras are as tall as their 16:9 panes at this width (at most 42vh, as before) instead of a flat 42vh that
   letterboxed every picture; the height they no longer waste goes to the events list (82 → 186 px at 360×740). The
   pictures keep their size: they are width-bound here. The height follows the width and the drawn shape only (the
   person's own layout, solo or turning the phone), never scrolling or arriving events, so nothing moves under someone
   watching. stage/layout.js sets --cols / --rows and measures this block's max-height for Auto (room()); the gap and
   padding are css/stage.css's 3 px. Never the TV wall (a TV may report under 1000 px). */
@media (max-width: 1000px) and (orientation: portrait) {
  /* A record's side pane (kit/sidepane.js) stacks under its table on a portrait phone (UI plan §1.5), each scrolling in
     its own share of the height, instead of a 400 px column beside it that squeezed the table to nothing and ran off
     the screen. (A landscape phone keeps the column beside the table: stacked, both would be strips ~100 px tall.) */
  .kit-split.with-pane { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 2fr) minmax(0, 3fr); }
  .kit-split .side-pane { border-left: 0; border-top: 1px solid var(--line); }
  body:not(.tv) .video-area { max-height: 42vh;
    height: calc((100vw - 6px - (var(--cols, 1) - 1) * 3px) / var(--cols, 1) * 9 / 16 * var(--rows, 1)
                 + (var(--rows, 1) - 1) * 3px + 6px); }
  /* Enhance's row under the picture (it wraps here): the note on a line of its own, then the hint beside the zoom bar
     (the hint keeps its ellipsis rather than wrapping beside the 142 px bar; width 0, so its one long line never asks
     the dialog's grid for more than the screen: 391.6 px at 390 without it). */
  .enh-under .enh-note { flex: 1 1 100%; }
  .enh-under .enh-hint { flex: 1 1 0; width: 0; white-space: nowrap; }
}

/* ========== narrow, landscape: a phone held sideways ========== */
/* Landscape phone: one row of header; the cameras at 16:9, as tall as the room under it allows, with the events
   beside them (on unless turned off with the split button, remembered); the transport and timeline across the whole
   width under both, always visible -- no page to scroll. */
@media (max-width: 1000px) and (orientation: landscape) {
  /* The header in one row: the Watch controls beside the ☰ and the name (the name gives way), not on a row of their
     own -- a row the cameras need. */
  .topbar { flex-wrap: nowrap; }
  .topbar .brand { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .topbar .brand #driverBadge { display: none; }
  .topbar-slot { order: 1; flex: 0 0 auto; flex-wrap: nowrap; }
  .topbar-right { order: 2; flex: 0 0 auto; margin-left: auto; }
  /* The stage column is as wide as the panes need at this height (stage/layout.js sizeGrid sets --stage-w); the
     events take the rest. */
  .layout { display: grid; grid-template-columns: var(--stage-w, 50%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  body:not(.evsplit) .layout, body.sheet-open .layout { grid-template-columns: minmax(0, 1fr); }
  .stage { grid-column: 1; grid-row: 1; min-height: 0; }
  .deck { grid-column: 1 / -1; grid-row: 2; }
  /* 16:9 panes (the phone's fill-the-cell rule letterboxed them here: black bars beside every picture) */
  .video-area { flex: 1 1 auto; height: auto; min-height: 0;
    grid-template-columns: repeat(var(--cols, 1), var(--cell-w, minmax(0, 1fr)));
    grid-template-rows: repeat(var(--rows, 1), var(--cell-h, minmax(0, 1fr))); }
  .side { grid-column: 2; grid-row: 1; min-height: 0; border-top: 0; border-left: 1px solid var(--line); }
  body:not(.evsplit) .side { display: none; }
  #btnEvSplit { display: inline-flex; align-items: center; justify-content: center; }
  /* A short screen: a marked clip takes the header's one row (the span and − / + step aside) on one line, its times
     shortened before a button is, so the video keeps its height. */
  .tlhead.clipping { flex-wrap: nowrap; }
  .tlhead.clipping .tlspan, .tlhead.clipping .tlzoom { display: none; }
  .clipslot .selection-box { flex-wrap: nowrap; padding: 2px 3px 2px 6px; }
  .clipslot #selectionLabel { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-size: 12px; }
  .clipslot .selection-box .sel-btns { flex: none; justify-content: flex-end; }
  .clipslot .tbtn.small { padding: 4px 8px; font-size: 12px; }
  /* With the sheet up, it fills the row; the events split stays out of the way. */
  body.sheet-open .side { display: none; }

  /* Enhance (20f): the picture beside the controls, as wide; only the controls column scrolls. The chrome here is the
     phone's smaller head and foot. */
  .enh-dlg { --enh-chrome: calc(102px + var(--enh-row-h)); --enh-frame: 98px; }   /* 128 with a 26 px row, 142 with a finger's */
  .enh-dlg .dlg-body { overflow: hidden; padding: 0 var(--s3) var(--s2); }
  .enh-dlg .enh { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 40%); gap: var(--s3); }
  .enh-view { position: static; padding: 0; --enh-pic-w: min(100%, calc((100vh - var(--enh-chrome)) * var(--ar))); }
  .enh-pic { box-shadow: 0 0 0 1px var(--line); border-radius: var(--radius); }
  .enh-under { width: var(--enh-pic-w); height: var(--enh-row-h); flex-wrap: nowrap; white-space: nowrap; padding: 0; }
  .enh-side { max-height: calc(100vh - var(--enh-frame)); max-height: calc(100dvh - var(--enh-frame)); overflow-y: auto; padding: 0 var(--s1) 0 0; margin-top: 0; }
  /* the full-window dialog is the visible height (the browser's bar showing): size from it where dvh exists (a custom
     property is not checked when parsed, so it needs @supports; the TV never shows Enhance) */
  @supports (height: 100dvh) {
    .enh-view { --enh-pic-w: min(100%, calc((100dvh - var(--enh-chrome)) * var(--ar))); }
  }
  .enh-sliders { grid-template-columns: 1fr; }
}

/* ========== ≤ 520 (--bp-slim): a phone held upright ========== */
/* Portrait phone: the frame viewer's −10s / +10s drop under Previous / Next (five controls need ~480 px); its title
   takes a line of its own above the zoom, Download and ✕, which then fit a 360 px screen. */
@media (max-width: 520px) {
  /* The header on a portrait phone: the Watch controls in one line down to 360 px (there is no day picker since
     2026-10-27) -- tighter gaps and pills; the driver's name (the camera panes carry their own SIM badge) gives way so
     the name, ☰ and the account fit the row above. */
  .topbar .brand #driverBadge { display: none; }
  .topbar-slot { column-gap: 5px; margin-left: 0; }   /* on its own row here: no gap from the name to keep */
  #btnLive { padding-left: 8px; padding-right: 8px; }
  .topbar .pager button { padding: 2px 5px; }
  /* The frame viewer's bar: the camera and time with ✕ across from them, then ID Vehicle, Save to Stills and Download
     on the line below. No −/%/+ zoom here (Wade, 2026-11-18): a pinch zooms, a double-tap zooms in or back out. */
  .fv-bar { flex-wrap: wrap; row-gap: 6px; padding: 6px 10px; }
  .fv-meta { flex: 1 1 calc(100% - 56px); order: 0; }
  #frameClose { order: 1; }
  .fv-bar .fv-spacer, .fv-bar .fv-zbtn, .fv-bar .fv-zoom { display: none; }
  #frameIdentify, #frameSave, #frameDownload { order: 2; }
  .fv-stepctl { display: grid; grid-template-columns: repeat(3, auto); justify-content: center; }
  #fvBack { grid-area: 2 / 1; justify-self: start; }
  #fvFwd  { grid-area: 2 / 3; justify-self: end; }
}

/* The assistant on a narrow screen (shell/assistant.js): no room in the top bar, so a round button in the corner,
   clear of the transport deck; its panel takes the whole width. */
@media (max-width: 1000px) {
  .ask-bar { display: none !important; }
  .ask-fab:not([hidden]) { display: grid; place-items: center; position: fixed; right: 14px;
    bottom: calc(env(safe-area-inset-bottom) + 84px); width: 52px; height: 52px; border-radius: 50%; border: 0;
    background: var(--accent); color: var(--on-accent); font-size: 22px; box-shadow: 0 6px 18px var(--scrim);
    z-index: calc(var(--z-dialog) - 3); cursor: pointer; }
  .ask-fab[aria-expanded="true"] { display: none; }
  .ask-panel { width: 100vw; border-left: 0; }
  /* The keyboard is up (shell/assistant.js fitKeyboard): the panel fills the screen above it, over the top bar. */
  .ask-panel.kb { top: var(--ask-kb-top, 0px); bottom: auto; height: var(--ask-kb-h, 50vh); z-index: var(--z-dialog); }
}
