/* Touch browsers and installed apps (operator request of 2026-11-06: the iOS Safari and PWA corrections). The demo has no rules
   for these, so this sheet adds them over the demo stylesheets without changing a desktop value: on a desktop browser every inset
   below is 0 and --view-h equals 100dvh.
   - Safe areas: with viewport-fit=cover the shell keeps its content out of the notch, the status bar and the home indicator. The
     rail grows by the left inset so it keeps its usable width beside a landscape notch.
   - Visible viewport: ViewportSync (Components/Shell) writes --app-h (the visible height, kept while pinch-zoomed), --vv-top,
     --kb-h and data-keyboard on the root. Fixed frames, overlays and toasts use them, so Safari's toolbars and its keyboard never
     cover the composer, the bottom of a dialog or a bottom bar. --view-h is that height above the home indicator (which the
     keyboard covers when it is open). */

:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --view-b: var(--safe-b);
  --view-h: calc(var(--app-h, 100dvh) - var(--view-b));
  /* tokens.css --top-h (52px) plus the status bar of an installed app, so every frame computed from it stays exact. */
  --top-h: calc(52px + var(--safe-t));
}
:root[data-keyboard] { --view-b: 0px; }

/* The page itself does not bounce or chain the scroll of an inner panel; panels keep their scroll to themselves. A table's rows
   area keeps only its sideways scroll (no history swipe): its vertical scroll, when it has none or reaches an end, goes on to the
   section or page around it, so the wheel over a table that only scrolls sideways still moves the card it sits in. */
html { overscroll-behavior-y: none; }
.popover, .app-menu, .dialog-backdrop, .wizard-body, .convo-list .rows, .ep-tree, .rail-inner { overscroll-behavior: contain; }
.dt-scroll { overscroll-behavior-x: contain; }
/* A scrolling column of a fixed frame is the containing block of what it positions (operator, 2026-11-13: iOS scroll bugs in a
   conversation): a visually hidden label (.sr-only, absolute) deep in a long thread otherwise sits on the page itself, makes the
   page taller than the screen, and the whole frame (head, thread, composer) slides away under the finger. */
.fit .messages, .fit .convo-list .rows, .ws-body { position: relative; }

/* ---------- Shell ---------- */

.shell { min-height: var(--app-h, 100vh); }
.topbar { padding-top: var(--safe-t); }
main { padding-bottom: calc(47.5px + var(--safe-b)); }
main.fit { padding-bottom: calc(16px + var(--view-b)); }

@media (min-width: 861px) {
  .shell {
    grid-template-columns: calc(var(--rail-w) + var(--safe-l)) minmax(0, 1fr);
    background: linear-gradient(90deg, var(--rail-bg) calc(var(--rail-w) + var(--safe-l)), transparent calc(var(--rail-w) + var(--safe-l)));
  }
  .rail { height: var(--app-h, 100vh); }
  .rail-inner { padding: calc(10px + var(--safe-t)) 10px calc(12px + var(--safe-b)) calc(10px + var(--safe-l)); }
  .topbar { padding-right: max(20.5px, var(--safe-r)); }
  main { padding-right: max(27px, var(--safe-r)); }
  /* shell-strip.css: the policy strip sticks under the top bar, whose height now includes the status bar. */
  .shell:has(> .main-col > .shell-strip) { --top-h: calc(98px + var(--safe-t)); }
  .shell:has(> .main-col > .shell-strip) .topbar { height: calc(52px + var(--safe-t)); }
  .shell-strip { top: calc(52px + var(--safe-t)); padding-right: max(27px, var(--safe-r)); }
}

@media (max-width: 860px) {
  /* The drawer follows the visible part and scrolls on a short landscape screen. */
  .rail { top: var(--vv-top, 0px); bottom: auto; height: var(--app-h, 100%); width: calc(241.5px + var(--safe-l)); }
  .rail-inner { padding: calc(10px + var(--safe-t)) 10px calc(12px + var(--safe-b)) calc(10px + var(--safe-l)); overflow-y: auto; }
  .topbar { padding-left: max(13.5px, var(--safe-l)); padding-right: max(13.5px, var(--safe-r)); }
  main { padding-left: max(13.5px, var(--safe-l)); padding-right: max(13.5px, var(--safe-r)); padding-bottom: calc(41px + var(--safe-b)); }
  main.fit { padding-bottom: calc(16px + var(--view-b)); }
  .shell-strip { padding-left: max(13.5px, var(--safe-l)); padding-right: max(13.5px, var(--safe-r)); }
}

/* ---------- Opaque bars on touch screens (iOS 26+ Liquid Glass) ---------- */

/* Operator request of 2026-11-08. Complements app.css `.topbar` and shell-strip.css `.shell-strip`
   (the demo's translucent bars: --bg at 82% under backdrop-filter: saturate(1.4) blur(12px)) and persona.css
   `.composer-wrap .agent-status` (88% under blur(8px)); desktop keeps them as the demo draws them.
   - The fix: navigation bars paint the opaque page ground with no backdrop-filter, and the installed iOS app's top bar is sticky
     at top: 0 (Breckly's always is), checked on WebKit computed styles, not an iPhone. Installed iOS 26/27 web apps can draw a
     system scroll-edge blur over a relatively positioned header even when its own background is opaque; a sticky top-edge
     colour source, paired with status-bar-style=default in the entry document, avoids that path. Understood, not measured here: Safari 26 tints its status-bar area from an opaque bar at the top edge, while a
     translucent, blurred one lets it blur and tint the page scrolled underneath, the blurred header the operator saw in Breckly.
   - Assumed: the same on the bottom pill over the composer, so nothing pinned to an edge is translucent on iOS.
   The demo itself drops the blur for an opaque --bg the same way while the rail animates (kit.css `.rail-anim .topbar`), so the
   look is unchanged but for the see-through. Touch screens (and every iOS device, whatever its pointer) as for the text fields
   below: an Android phone loses a blur it does not need, nothing else. */
@media (pointer: coarse) {
  .topbar, .shell-strip { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .composer-wrap .agent-status { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@supports (-webkit-touch-callout: none) {
  .topbar, .shell-strip { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .composer-wrap .agent-status { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ---------- Browser and status bar colour ---------- */

/* The colour at the top edge of the screen, which breckly.js writes into every theme-color hint (Safari's status-bar area,
   an installed app's status bar under status-bar-style=default, Android's address bar): the page ground of the theme in use,
   and on a phone's sign-in the Ink brand stage that starts there (kit.css `.auth-brand`, var(--encre) in both themes), so the
   clock does not sit on a light strip above a dark panel. */
:root { --chrome-top: var(--bg); }
@media (max-width: 860px) { :root:has(.auth) { --chrome-top: var(--encre); } }

/* In an installed app there is no browser back button: the top bar offers one on pages below a section (AppShell BackHref). */
.icon-btn.top-back { display: none; }
:root[data-standalone] .icon-btn.top-back { display: grid; }
@media (max-width: 860px) { :root[data-standalone] .icon-btn.top-back { margin-left: -7px; } :root[data-standalone] .top-back + .menu-btn { margin-left: 0; } }

/* While the keyboard is open a fixed frame may be shorter than its usual minimum, and a narrow conversation folds its
   Conversation / Workspace switch, so the composer stays above the keyboard. */
:root[data-keyboard] .fit .convo-layout, :root[data-keyboard] main.fit > .page.frame,
:root[data-keyboard] .fit .ops-docs-page, :root[data-keyboard] main.fit > .ep-fit { min-height: 0; }
@media (max-width: 960px) { :root[data-keyboard] .fit .thread-head .ws-switch { display: none; } }

/* While the keyboard covers the bottom of the page, the page gets that much room under its content, so a field near its end
   (or a fixed frame taller than what is left, a phone in landscape) can still be scrolled into view (ViewportSync reveal). */
:root[data-keyboard] body { padding-bottom: calc(var(--kb-h, 0px) + var(--kb-room, 0px)); }

/* ---------- Overlays ---------- */

/* Modal layers cover exactly the visible part, so their bottom is never under the keyboard or a toolbar. A layer taller than
   that scrolls inside the scrim instead of being cut. */
#dialogHost, .map-host, .wizard-backdrop { top: var(--vv-top, 0px); bottom: auto; height: var(--app-h, 100%); }
.dialog-backdrop {
  overflow-y: auto;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(16px, var(--view-b)) max(16px, var(--safe-l));
}
.dialog-backdrop > .dialog, .dialog-backdrop > .wizard-layer { margin: auto; }
.wizard-layer { max-height: calc(var(--app-h, 100dvh) - max(16px, var(--safe-t)) - max(16px, var(--view-b))); }
.app-menu { max-height: calc(var(--app-h, 100vh) - 68px); }

/* The toast rides above the home indicator and above the keyboard. */
.toast { bottom: calc(20.5px + var(--view-b) + var(--kb-h, 0px)); }
.composer { bottom: calc(13.5px + var(--view-b)); }

/* ---------- Sign-in ---------- */

.auth { min-height: var(--app-h, 100vh); }
@media (max-width: 860px) {
  .auth-brand { padding: max(18px, var(--safe-t)) max(20px, var(--safe-r)) 18px max(20px, var(--safe-l)); }
  .auth-panel { padding: 24px max(18px, var(--safe-r)) calc(40px + var(--safe-b)) max(18px, var(--safe-l)); }
}

/* ---------- Text fields on touch screens ---------- */

/* iOS zooms into any field under 16px when it is focused, and the layout stays zoomed after the keyboard closes. Touch screens
   (and every iOS device, whatever its pointer) set fields at 16px; desktop keeps its 13px density. */
@media (pointer: coarse) {
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="button"], [type="submit"], [type="reset"], [type="image"]),
  textarea, select, [contenteditable="true"] { font-size: max(16px, 1em) !important; }
}
@supports (-webkit-touch-callout: none) {
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="button"], [type="submit"], [type="reset"], [type="image"]),
  textarea, select, [contenteditable="true"] { font-size: max(16px, 1em) !important; }
}

/* A dialog focused as a whole on a touch screen (floating.js trap) shows no ring. */
.dialog:focus, .wizard-layer:focus { outline: none; }
