/* =========================================================================
   PHONES, AND THE ATRIUM INTRANET APP (2026-10-28)

   Alex, on the iPhone app: "every little portion of it [should behave] like a
   mobile app ... There are still portions that have both side and down
   scrolling, and diagonal scrolling is available. Pages like the office camera
   show up in microscopic text."

   Linked from _theme_head.html, AHEAD of each page's own sheets, so a page's
   rule wins wherever the two disagree. Two layers:

   1. EVERY PHONE (a screen 760px and under), in the app or in a browser.
      `screen` because a printout from a desktop lays out at about 739px, and
      none of this belongs on paper.
      The page never pans sideways. Something wider than the screen does not
      just add a sideways scroll on an iPhone: WebKit zooms the whole page OUT
      until the wide thing fits, and every word on it goes microscopic. That
      is exactly what the Office Camera did: a 2,300px strip of day chips
      stretched its grid column to 1,500px, so a 375px phone drew the page at
      a quarter of its size.
      The clip below is a floor, not the fix. Every page still lays itself out
      to fit (each page's own @media block); the clip only stops a future
      stray pixel from turning into a pannable, zoomed-out page.
      `clip`, never `hidden`: hidden makes <body> a scroll container, and every
      position: sticky header inside it stops sticking.

   2. THE APP (html.in-app). _theme_head.html sets it from the
      "AtriumIntranetApp/" token both apps add to their user agent
      (platform/ios IntranetWebView.swift, platform/android MainActivity.java),
      and locks the zoom there. A native app does not flash grey under a
      finger, does not offer "Open Link / Copy Link" on a long press, does not
      select the words on a button, and answers a press.
   ========================================================================= */

@media screen and (max-width: 760px) {
    html, body { overflow-x: clip; }
    /* iOS inflates text in landscape unless told not to. */
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    /* A long address or URL breaks rather than pushing the page wide. */
    body { overflow-wrap: break-word; }
    /* Media never outgrows its column. */
    img, video, canvas, iframe, embed, object { max-width: 100%; }
    video { height: auto; }
    pre { max-width: 100%; overflow-x: auto; }
}

/* Under 16px, iOS Safari zooms the whole page into a field when it is tapped,
   and leaves it zoomed. The app locks zoom instead (_theme_head.html), but the
   same people also open the Intranet in Safari. !important because every page
   sizes its own fields more specifically than this sheet can reach. */
@media screen and (max-width: 760px) and (pointer: coarse) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]),
    select, textarea {
        font-size: max(16px, 1em) !important;
    }
}

/* ---------- the app ---------- */
html.in-app { -webkit-tap-highlight-color: transparent; }
html.in-app a,
html.in-app button,
html.in-app img { -webkit-touch-callout: none; }
html.in-app button,
html.in-app [role="button"],
html.in-app [role="tab"],
html.in-app [role="menuitem"],
html.in-app summary,
html.in-app label,
html.in-app nav,
html.in-app .ham-btn,
html.in-app .side-nav,
html.in-app .pill-btn,
html.in-app .path-card {
    -webkit-user-select: none;
    user-select: none;
}
/* A press answers at once, the way a native control dims under a finger.
   Opacity only: transforms belong to the pages' own motion, and a transition
   set here would replace theirs. */
html.in-app :is(button, [role="button"], [role="tab"], [role="menuitem"], summary, .pill-btn, .path-card):not(:disabled):active,
html.in-app a[href]:active {
    opacity: .72;
}
/* Keyboard-only hints (Esc, ⌘K, "Keyboard shortcuts") mean nothing on a
   phone. Mark them .kbd-only. */
@media (hover: none) and (pointer: coarse) {
    .kbd-only { display: none !important; }
}

/* =========================================================================
   THE APP'S TAB BAR (2026-10-28)

   Inside the iPhone and Android apps, on a phone screen, a labelled bar along
   the bottom moves between the sections, the iPhone way, and its Menu button
   takes over from the bare menu icon at the top left. templates/_tab_bar.html
   draws it (in the apps only, so nothing here reaches Safari or a desktop);
   static/tab_bar.js moves it.

   ROOM FOR IT. Every page gets the bar's height back at its foot, so its last
   row scrolls clear of it. Anything a page pins to the bottom of the screen
   adds the same space to its own offset:
       bottom: calc(14px + var(--app-tabbar-space, 0px));
   The space is 0 everywhere the bar is not: a desktop, Safari, a page with no
   menu. Sheets, dialogs and an open Marty cover the bar on purpose: the bar
   sits at 59, under every overlay a page opens over itself (60 and up), and
   over a closed Marty launcher (58), which tucks away behind it.
   ========================================================================= */
.app-tabbar { display: none; }

@media screen and (max-width: 760px) {
    html.in-app:has(#app-tabbar) {
        --app-tabbar-space: calc(56px + env(safe-area-inset-bottom, 0px));
        scroll-padding-bottom: var(--app-tabbar-space);
    }
    html.in-app:has(#app-tabbar) body { padding-bottom: var(--app-tabbar-space); }

    html.in-app .app-tabbar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 59;
        display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
        height: var(--app-tabbar-space);
        padding: 0 4px env(safe-area-inset-bottom, 0px);
        /* A bar above the content: translucent, the page blurring beneath. */
        background: color-mix(in srgb, var(--atrium-bg) 93%, transparent);
        -webkit-backdrop-filter: saturate(1.6) blur(24px);
        backdrop-filter: saturate(1.6) blur(24px);
        border-top: 1px solid var(--atrium-line);
        /* Kept still while the page under it changes (styles.css slides the
           rest of the page): see the view transitions at the end. */
        view-transition-name: app-tabbar;
        transition: transform .26s cubic-bezier(.2,.7,.2,1), opacity .2s ease;
    }
    html.in-app .app-tab {
        position: relative; z-index: 1;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px; min-width: 0; height: 56px; margin: 0; padding: 0 2px;
        background: none; border: 0; border-radius: 0;
        color: var(--atrium-muted);
        font: 500 12px/15px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
        letter-spacing: .01em; text-decoration: none;
        cursor: pointer;
        transition: color .2s ease;
    }
    html.in-app .app-tab .ic { flex: 0 0 auto; }
    html.in-app .app-tab-label {
        display: block; max-width: 100%;
        overflow: clip; white-space: nowrap; text-overflow: ellipsis;
    }
    /* The lit tab: the selection, in red, the one thing red means here. */
    html.in-app .app-tab.is-on { color: var(--atrium-red); }
    html.in-app .app-tab:focus-visible { outline: 2px solid var(--atrium-red); outline-offset: -4px; border-radius: 14px; }

    /* The indicator: a soft capsule behind the lit tab, sliding between them.
       Every tab is the same width, so where it goes is arithmetic: the n-th
       of --tabs, set by the template and moved by tab_bar.js. */
    html.in-app .app-tab-pill {
        position: absolute; top: 5px; left: 4px; height: 46px;
        width: calc((100% - 8px) / var(--tabs, 5));
        transform: translateX(calc(var(--at, 0) * 100%));
        transition: transform .32s cubic-bezier(.2,.8,.2,1);
        pointer-events: none;
        view-transition-name: app-tab-pill;
    }
    html.in-app .app-tab-pill::before {
        content: ""; position: absolute; inset: 0 5px;
        border-radius: 14px;
        background: color-mix(in srgb, var(--atrium-red) 14%, transparent);
    }

    /* Menu reads Close while the menu is open: icon and word cross-fade. */
    html.in-app .app-tab-swap { display: grid; justify-items: center; }
    html.in-app .app-tab-swap > * {
        grid-area: 1 / 1;
        transition: opacity .2s ease, transform .26s cubic-bezier(.2,.8,.2,1);
    }
    html.in-app .app-tab-swap > .tb-shut { opacity: 0; transform: rotate(-45deg) scale(.7); }
    html.in-app .app-tab-label.app-tab-swap > .tb-shut { transform: translateY(4px); }
    html.in-app .app-tabbar.is-menu-open .app-tab-swap > .tb-open { opacity: 0; transform: rotate(45deg) scale(.7); }
    html.in-app .app-tabbar.is-menu-open .app-tab-label.app-tab-swap > .tb-open { transform: translateY(-4px); }
    html.in-app .app-tabbar.is-menu-open .app-tab-swap > .tb-shut { opacity: 1; transform: none; }

    /* The keyboard is up (tab_bar.js): the bar steps down out of its way. */
    html.in-app.app-typing .app-tabbar {
        transform: translateY(100%); opacity: 0; pointer-events: none;
    }

    /* ---- the menu, now that the bar opens it ----
       The bare menu icon at the top left goes; Menu on the bar opens the same
       menu, and Close on the bar shuts it. The lane every page header kept
       clear for the icon (a 52-64px margin on its brand) is handed back. */
    html.in-app:has(#app-tabbar) .ham-btn { display: none; }
    html.in-app:has(#app-tabbar) .brand[style*="margin-left"] { margin-left: 0 !important; }
    html.in-app:has(#app-tabbar) .side-brand { padding-left: 12px; }
    html.in-app:has(#app-tabbar) .me-bar { padding-left: 16px; }
    /* The menu opens above the bar, which stays lit and tappable over the
       dimmed page, so Close is always there. */
    html.in-app:has(#app-tabbar) .side-nav { bottom: var(--app-tabbar-space); }
    html.in-app:has(#app-tabbar) body.nav-open .app-tabbar { z-index: 98; }
    /* The links the bar already carries (tab_bar.js marks them). */
    html.in-app:has(#app-tabbar) .side-nav:not(.menu-editing) [data-in-tabbar] { display: none; }

    /* ---- Changing it: the bar is each person's own ----
       Pressing and holding a tab (any page), or Customize on the home page,
       puts the bar into the state an iPhone's Dock takes: every tab wiggles
       with a minus to take it off, a free place says Add, a tab drags along
       the bar, and a line above it carries Add and Done. Nothing is lit
       while it is being arranged. Menu still opens the menu, where pages
       are dragged out from. */
    html.in-app .app-tabbar.is-editing .app-tab-pill { opacity: 0; }
    /* The line above the bar takes room too, so the last door clears it. */
    html.in-app:has(.app-tabbar.is-editing) body { padding-bottom: calc(var(--app-tabbar-space) + 52px); }
    /* A press held on the bar or a menu link is the bar's, never iOS's link
       preview or a text selection. */
    html.in-app .app-tabbar,
    html.in-app:has(#app-tabbar) #side-nav a.side-link {
        -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
    }
    /* Marty steps aside while the bar is being changed: his button sat on
       the line above it. Done brings him back. */
    html.in-app body.tabbar-editing #marty-root { opacity: 0; visibility: hidden; pointer-events: none; }
    html.in-app .app-tabbar.is-editing .app-tab[data-key] {
        cursor: grab; touch-action: none;
        animation: app-tab-wiggle .3s ease-in-out infinite alternate;
    }
    html.in-app .app-tabbar.is-editing .app-tab[data-key]:nth-of-type(2n) { animation-delay: -.15s; }
    html.in-app .app-tab.is-lifted {
        z-index: 3; cursor: grabbing; animation: none !important;
        color: var(--atrium-text);
        transition: none;
    }
    html.in-app .app-tab.is-lifted::before {
        content: ""; position: absolute; inset: 5px 5px; z-index: -1;
        border-radius: 14px;
        background: var(--atrium-surface-2);
        box-shadow: 0 10px 26px rgba(0,0,0,.35);
    }
    /* The minus that takes a tab off, at the icon's top right corner (Alex:
       "press the minus in the top-right corner"): neutral, not red. A tab
       taken off is one tap from coming back, so it is not a loss to warn
       about. */
    html.in-app .app-tab-x {
        position: absolute; top: 3px; right: calc(50% - 32px);
        width: 22px; height: 22px; margin: 0; padding: 0;
        border: 1px solid var(--atrium-line); border-radius: 50%;
        background: var(--atrium-surface-2); color: var(--atrium-text);
        cursor: pointer;
    }
    /* A finger-sized target around the small badge. */
    html.in-app .app-tab-x::after { content: ""; position: absolute; inset: -10px; }
    html.in-app .app-tab-x::before {
        content: ""; position: absolute; left: 5px; right: 5px; top: 50%;
        height: 2px; margin-top: -1px; border-radius: 1px; background: currentColor;
    }
    html.in-app .app-tab-add {
        color: var(--atrium-muted);
    }
    html.in-app .app-tab-add .ic {
        width: 24px; height: 24px; padding: 2px;
        border: 1.5px dashed var(--atrium-dim); border-radius: 8px;
    }
    html.in-app .app-tabbar-caption {
        position: absolute; left: 0; right: 0; bottom: 100%;
        display: flex; align-items: center; gap: 8px;
        min-height: 44px; padding: 6px 8px 6px 16px;
        background: color-mix(in srgb, var(--atrium-bg) 94%, transparent);
        -webkit-backdrop-filter: saturate(1.6) blur(24px);
        backdrop-filter: saturate(1.6) blur(24px);
        border-top: 1px solid var(--atrium-line);
        font: 400 12px/1.35 "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
        color: var(--atrium-muted);
        animation: app-caption-in .26s cubic-bezier(.2,.8,.2,1);
    }
    html.in-app .atc-text { flex: 1 1 auto; min-width: 0; }
    html.in-app .atc-add, html.in-app .atc-reset, html.in-app .atc-done {
        flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px;
        min-height: 36px; padding: 0 14px; margin: 0;
        border: 1px solid var(--atrium-line); border-radius: 999px;
        background: var(--atrium-surface); color: var(--atrium-text);
        font: 500 13px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    }
    /* Add, labelled, at the leading edge, as an iPhone puts its + at the top
       left of a wiggling home screen. */
    html.in-app .atc-add { padding-left: 10px; }
    html.in-app .atc-add .ic { width: 18px; height: 18px; }
    /* Done is the one thing to do next: the filled button. */
    html.in-app .atc-done { border-color: transparent; background: var(--atrium-red); color: var(--atrium-on-red); font-weight: 600; }
    html.in-app .atc-reset[hidden], html.in-app .atc-done[hidden] { display: none; }

    /* A link lifted out of the menu, under the finger, on its way to the bar. */
    html.in-app .app-tab-ghost {
        position: fixed; left: 0; top: 0; z-index: 130;
        display: flex; flex-direction: column; align-items: center; gap: 3px;
        width: 72px; padding: 8px 4px 7px; border-radius: 14px;
        background: var(--atrium-surface-2); color: var(--atrium-text);
        border: 1px solid var(--atrium-line);
        box-shadow: 0 14px 34px rgba(0,0,0,.45);
        font: 500 12px/15px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
        pointer-events: none; will-change: transform;
    }
    html.in-app .app-tab-ghost > span {
        max-width: 100%; overflow: clip; white-space: nowrap; text-overflow: ellipsis;
    }
    /* Where it would land: the tabs part around an empty place... */
    html.in-app .app-tab-slot::before {
        content: ""; position: absolute; inset: 7px 6px;
        border: 1.5px dashed var(--atrium-dim); border-radius: 14px;
    }
    /* ...or, on a full bar, the tab it would replace steps back. */
    html.in-app .app-tabbar.is-editing .app-tab.is-swap { animation: none; opacity: .4; transform: scale(.9); }
    html.in-app .app-tab.is-swap::after {
        content: ""; position: absolute; inset: 5px 5px; border-radius: 14px;
        border: 1.5px solid var(--atrium-red);
    }

    /* While the bar wiggles, every menu link says it can go on it: a plus,
       or a check when it is there already. A tap adds it. */
    html.in-app body.tabbar-editing #side-nav a.side-link { position: relative; padding-right: 48px; }
    html.in-app .side-tab-add {
        position: absolute; right: 10px; top: 50%; margin-top: -14px;
        display: inline-flex; align-items: center; justify-content: center;
        width: 28px; height: 28px; border-radius: 50%;
        border: 1px solid var(--atrium-line); background: var(--atrium-surface-2);
        color: var(--atrium-text);
    }
    html.in-app .side-tab-add .ic { width: 16px; height: 16px; }
    html.in-app a.side-link[data-tab-on] .side-tab-add { color: var(--atrium-muted); background: none; }

    /* Add: a sheet from the bottom with the person's other sections. */
    html.in-app .app-tab-sheet {
        position: fixed; inset: auto 0 0 0; margin: 0;
        width: 100%; max-width: 100%; max-height: 80dvh;
        padding: 6px 0 calc(12px + env(safe-area-inset-bottom, 0px));
        border: 0; border-top: 1px solid var(--atrium-line);
        border-radius: 18px 18px 0 0;
        background: var(--atrium-surface); color: var(--atrium-text);
        box-shadow: 0 -18px 48px rgba(0,0,0,.45);
        overflow-y: auto; overscroll-behavior: contain;
        animation: app-sheet-in .3s cubic-bezier(.2,.8,.2,1);
    }
    html.in-app .app-tab-sheet.is-leaving { animation: app-sheet-out .2s cubic-bezier(.4,0,1,1) forwards; }
    html.in-app .app-tab-sheet::backdrop { background: rgba(0,0,0,.5); }
    html.in-app .ats-head {
        display: flex; align-items: center; justify-content: space-between;
        padding: 8px 8px 8px 20px;
    }
    html.in-app .ats-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
    html.in-app .ats-cancel {
        min-height: 44px; padding: 0 14px; border: 0; background: none;
        color: var(--atrium-red); font: 500 15px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    }
    html.in-app .ats-row {
        display: flex; align-items: center; gap: 14px; width: 100%;
        min-height: 56px; padding: 0 20px; margin: 0;
        border: 0; border-top: 1px solid var(--atrium-line); background: none;
        color: var(--atrium-text); text-align: left;
        font: 500 16px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    }
    html.in-app .ats-row .ic { color: var(--atrium-muted); flex: 0 0 auto; }
    html.in-app .ats-row[aria-disabled="true"] { opacity: .5; }
    html.in-app .ats-row[hidden], html.in-app .ats-group[hidden] { display: none; }
    html.in-app .ats-words { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
    html.in-app .ats-name { overflow: clip; white-space: nowrap; text-overflow: ellipsis; }
    html.in-app .ats-sub { font-size: 13px; font-weight: 400; color: var(--atrium-muted); }
    html.in-app .ats-group {
        margin: 0; padding: 18px 20px 8px;
        font: 600 12px/1.2 "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
        letter-spacing: .06em; text-transform: uppercase; color: var(--atrium-muted);
    }
    html.in-app .ats-search {
        display: flex; align-items: center; gap: 8px;
        margin: 2px 16px 6px; padding: 0 12px; min-height: 44px;
        border: 1px solid var(--atrium-line); border-radius: 12px;
        background: var(--atrium-bg); color: var(--atrium-muted);
    }
    html.in-app .ats-search input {
        flex: 1 1 auto; min-width: 0; height: 42px; border: 0; padding: 0;
        background: none; color: var(--atrium-text); outline: none;
        font: 400 16px "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    }
    html.in-app .ats-full, html.in-app .ats-wait {
        margin: 8px 20px; font-size: 14px; line-height: 1.45; color: var(--atrium-muted);
    }
    html.in-app .ats-full { color: var(--atrium-text); }
}
/* The narrowest phones (320px): five tabs are 62px each, and "Directory"
   beside "Resources" touched. The house floor is 11px. A page's name longer
   than a section's ("Maintenance") is 11px everywhere. */
@media screen and (max-width: 359px) {
    html.in-app .app-tab { font-size: 11px; letter-spacing: 0; }
}
@media screen and (max-width: 760px) {
    html.in-app .app-tab.app-tab-long { font-size: 11px; letter-spacing: -.01em; }
}
/* There, too, the line above the bar puts its words on a row of their own,
   over Add, Reset and Done, rather than four lines squeezed between them. */
@media screen and (max-width: 359px) {
    html.in-app .app-tabbar-caption { flex-wrap: wrap; row-gap: 4px; padding-top: 8px; }
    html.in-app .atc-text { order: -1; flex: 1 0 100%; }
    html.in-app .atc-add { margin-right: auto; }
    html.in-app:has(.app-tabbar.is-editing) body { padding-bottom: calc(var(--app-tabbar-space) + 76px); }
}
@media screen and (max-width: 760px) and (prefers-reduced-motion: reduce) {
    html.in-app .app-tabbar { transition: opacity .15s ease; }
    html.in-app.app-typing .app-tabbar { transform: none; }
    html.in-app .app-tab-pill { transition: none; }
    html.in-app .app-tab-swap > * { transition: opacity .15s ease; transform: none !important; }
    /* Customize without the wiggle: the badges and the caption say it. */
    html.in-app .app-tabbar.is-editing .app-tab[data-key] { animation: none; }
    html.in-app .app-tabbar-caption { animation: app-fade-in .15s ease; }
    html.in-app .app-tab-sheet { animation: app-fade-in .15s ease; }
    html.in-app .app-tab-sheet.is-leaving { animation: none; }
}
@keyframes app-tab-wiggle {
    from { transform: rotate(-1.6deg); }
    to   { transform: rotate(1.6deg); }
}
@keyframes app-caption-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes app-sheet-in   { from { transform: translateY(100%); } to { transform: none; } }
@keyframes app-sheet-out  { to { transform: translateY(100%); } }
@keyframes app-fade-in    { from { opacity: 0; } to { opacity: 1; } }
/* Between pages the bar stays put while the page under it changes, and the
   indicator glides from the old page's tab to the new one's. */
::view-transition-group(app-tab-pill) {
    animation-duration: .32s;
    animation-timing-function: cubic-bezier(.2,.8,.2,1);
}
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(app-tab-pill) { animation: none; }
}
