/* =====================================================================
   UI SCALE — the whole page stays the same visual size at any zoom
   ---------------------------------------------------------------------
   public/js/ui-scale.js sets  html.ui-scale  and  --ui-scale
   (= viewport width / 1920) on desktop browsers. It also:
     - re-evaluates width/height @media rules against a virtual 1920px
       viewport, so 400% zoom never switches to the tablet/mobile layout;
     - rewrites vh / vw units to --ui-vh / --ui-vw, so "100vh" still means
       the full visible window inside the zoomed page.
   Everything here only applies while that class is present, so
   phones/tablets are untouched.

   One `zoom` on <body> scales header, sidebar, content, modals and
   dropdowns together, so the page looks identical at 25%, 100%, 400%
   or 500% browser zoom.
   ===================================================================== */

html.ui-scale body {
    zoom: var(--ui-scale);
}

/* Phone / tablet held sideways (html.ui-touch, set by ui-scale.js together
   with html.ui-scale). The page is the designed 1920-wide desktop page shrunk
   to the screen, so there is nothing beside it to pan to. A few pages are a
   few px wider than the window (Bootstrap .row gutters outside a container);
   with a mouse that is invisible, but a finger could drag the whole page
   sideways. Only the sideways drag is removed — the page still scrolls up and
   down and wide tables keep their own scrollbars. */
html.ui-scale.ui-touch {
    overflow-x: hidden;
    /* A double tap would zoom the browser into one block of the shrunk page
       and leave the rest off screen, which looks as if the page did not fit.
       Pinch-zoom and scrolling still work. */
    touch-action: manipulation;
}

/* DataTables writes measured column widths inline (see ui-scale.js);
   under zoom those are wrong, so let the table size its own columns. */
html.ui-scale table.dataTable > thead > tr > th,
html.ui-scale table.dataTable > thead > tr > td {
    width: auto !important;
}

/* Admin dashboard 3D scene (React Three Fiber, #canvas-container).
   R3F measures its container with getBoundingClientRect, which returns the
   already-zoomed size, and writes it back as the canvas CSS size — so the
   canvas would be zoomed twice and end up too small. The drawing buffer is
   already at the right resolution and aspect ratio, so just stretch the
   canvas to fill its container. */
html.ui-scale #canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Stage pages (<html data-ui-fit="stage">: dashboard, globes, maps — see
   ui-scale.js). The page is laid out 1920 wide and 900–1100 tall — its
   designed shape — and centred in the window like a picture fitted to it,
   with an empty band above / below (narrow window) or left / right (very
   wide, short window). The transform also makes <body> the containing
   block for position:fixed layers (full-screen canvases, HUD overlays,
   modals), so they fill the stage and not the band around it.
   ui-scale.js adds html.ui-stage only while a band exists. */
html.ui-scale.ui-stage body {
    width: var(--ui-stage-w) !important;
    max-width: none !important;
    height: var(--ui-stage-h) !important;
    min-height: 0 !important;
    margin: 0 !important;
    transform: translate(var(--ui-stage-x), var(--ui-stage-y));
}

/* A stage page is one picture: the window itself never scrolls. Some are a
   little taller than a short window (the tenants globe is ~1010 px tall in a
   ~960 px MacBook window, plus the debug bar's 30 px), and their body was
   still scrollable. The window is locked and <body> is pinned to it and clips
   whatever reaches past the bottom (overflow: clip is no scroll box, so not
   even a script or focus() can scroll it). position: absolute + inset 0 keeps
   any bottom margin a dev bar adds outside the box. The letterboxed stage
   (.ui-stage) already has an exact size and offset, so it only clips. */
html.ui-scale[data-ui-fit="stage"] {
    overflow: hidden !important;
    overscroll-behavior: none;
}
html.ui-scale[data-ui-fit="stage"]:not(.ui-stage) body {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
    overflow: clip !important;
}
html.ui-scale.ui-stage body {
    overflow: hidden !important;
    overflow: clip !important;
}
