/* Phone mode (data-phone="on"): shell. Every rule here is prefixed :root[data-phone="on"] so nothing leaks to desktop. */

/* ── Text fields: never under 16px (QoL 2026-10-04, phone#1 / taps#11) ──────
   iOS zooms the page into any field whose font-size is under 16px, and it stays
   zoomed with the fixed Save and the bar half off-screen until the vet pinches
   back. Measured: the SOAP note 13.6px (15.1px in comfort view), a medication's
   Notes 14.45px, the case editor 15.3px, both patient searches 15.3px, the roster
   paste box 14.45px, the date fields 14.3-14.45px, the Upload panel's transcript
   14.45px. app.css's 16px tier only reaches .form-control, and only at <=640px;
   these are sized by scoped sheets, whose .foo[b-xxx] outranks it. One rule at
   (0,3,0), after the scoped bundle, beats every one of them. The two result
   editors are 16px at phone width already (textarea.form-control wins); listed so
   a landscape phone gets it too. So are Bootstrap's own small fields, 0.875rem:
   at 641px and wider (landscape; the manifest allows any orientation) a
   medication row's drug, frequency, duration and route, the Discharge email, the
   SOAP format picker and the vet switcher's "Add a name" measured 14.875px.
   tests/js/phone-polish.test.js fails when a new field is sized under 16px and is
   not listed here, or is sized through a bare input/textarea/select the list
   cannot name. */
:root[data-phone="on"] :is(.soap-note-editor, .med-notes, .cv-input,
    .mv-search, .rb-search, .today-import-textarea, .today-date-input, .cases-date-input,
    .tool-result-edit, .live-consult-summary-edit, .upload-transcript,
    .form-control-sm, .form-select-sm) {
    font-size: max(1rem, 16px);
}

/* ── Masthead: chip, vet, account ────────────────────────────────────────────
   The vet switcher's pill never fitted ("Who's usi…"), so in the mode it is a
   ringed initials disc and the patient chip gets the width back. :root on
   everything: VetProfileMenu and ConsultStepper are styled in SCOPED sheets,
   and .foo[b-xxx] beats a bare selector from any global file. */
:root[data-phone="on"] .vet-switcher {
    flex: 0 0 auto;
}

:root[data-phone="on"] .vet-switcher-trigger {
    /* 44px thumb target; the visible disc is the 2rem span inside it. */
    min-width: 44px;
    min-height: 44px;
    max-width: none;
    padding: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
}

:root[data-phone="on"] .vet-switcher-trigger .ic,
:root[data-phone="on"] .vet-switcher-trigger .vet-switcher-chevron {
    display: none;
}

/* Hidden from the eye, kept for the screen reader: it is the button's name. */
:root[data-phone="on"] .vet-switcher-trigger .vet-switcher-name {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

:root[data-phone="on"] .vet-switcher-initials {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--ed-terracotta);
    color: var(--ed-paper);
    font-family: var(--ed-ui);
    font-size: max(0.75rem, var(--ed-fs-floor, 0rem));
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1;
    box-shadow: 0 0 0 2px var(--ed-paper), 0 0 0 3.5px var(--ed-terracotta);
}

/* Nobody chosen: the "?" disc is hollow, so it reads as a question to answer
   and not as a person called "?". */
:root[data-phone="on"] .vet-switcher-trigger--unset .vet-switcher-initials {
    background: var(--ed-paper);
    color: var(--ed-terracotta);
}

/* Its menu opens right-anchored to the masthead (QoL 2026-10-04, phone#15). Anchored
   left:0 to the disc like the desktop pill's, it spanned x 247→507 on a 375px screen:
   ⨯ remove and Add off the edge, and the page scrolling sideways. Anchored right:0 to
   the disc instead, a long name (the rows don't wrap; they set the menu's width) grew
   it past the LEFT edge, the disc's right edge being at x 291 (measured). So the
   switcher is static here and the menu's anchor is .top-row, the masthead's full width
   (position: relative in MainLayout.razor.css): it opens under the masthead against
   its right gutter and is never wider than the screen. The case switcher's menu, at
   the row's left end, keeps its own anchor (app.css). Rows get the thumb floor; ⨯
   remove was a 34px sliver at the end of each. */
:root[data-phone="on"] .vet-switcher {
    position: static;
}

:root[data-phone="on"] .vet-switcher-menu {
    left: auto;
    right: 0.6rem;
    min-width: min(260px, calc(100vw - 1.2rem));
    max-width: calc(100vw - 1.2rem);
}

:root[data-phone="on"] .vet-switcher-item {
    min-height: 44px;
}

:root[data-phone="on"] .vet-switcher-remove {
    min-width: 44px;
}

/* The account menu's rows (QoL 2026-10-04, phone#12): 0.45rem of padding round a
   0.88rem line made them 37.7px, and the menu is the phone's way to the Drug Book,
   Backup and the display toggles. Flex keeps the label centred in the taller row. */
:root[data-phone="on"] .account-menu-item {
    display: flex;
    align-items: center;
    min-height: 44px;
}

/* The patient chip: name AND short signalment. The 640px tier hides the
   signalment because the old masthead had no room; the disc gave it back. The
   signalment only takes the room the name leaves (app.css), so it is what elides;
   a name too long on its own elides too (2026-10-15). */
:root[data-phone="on"] .case-switcher-trigger .case-switcher-meta {
    display: inline;
}

/* The consult chip (QoL 2026-10-04, W7). Measured at 375px with these sheets:
   "⤺ UNFINISHED" was 132px wide and ran 15px under the account button (x 182→314
   against its 299), and it and "✎ REVIEW" (99px) squeezed the patient chip's
   signalment to 5-15px. The two label chips are their icon in a 44px pill here,
   as the vet switcher is a disc beside them; their words stay with the screen
   reader (the 640px tier's display:none dropped the name from it too). The
   recording chip keeps its dot and clock: it is the can't-forget-to-stop one. */
:root[data-phone="on"] .live-chip {
    min-height: 44px;
}

:root[data-phone="on"] .live-chip--review,
:root[data-phone="on"] .live-chip--unfinished {
    min-width: 44px;
    padding: 0;
    gap: 0;
    justify-content: center;
}

:root[data-phone="on"] .live-chip--review .live-chip-icon,
:root[data-phone="on"] .live-chip--unfinished .live-chip-icon {
    font-size: 1.15rem;
}

:root[data-phone="on"] .live-chip--review .live-chip-label,
:root[data-phone="on"] .live-chip--review .live-chip-name,
:root[data-phone="on"] .live-chip--unfinished .live-chip-label,
:root[data-phone="on"] .live-chip--unfinished .live-chip-name {
    display: inline;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ── Stepper: one line, "path · step", a dot per step ────────────────────── */
:root[data-phone="on"] .consult-stepper {
    gap: 0.35rem;
    padding: 0 var(--ed-sp-gutter, 0.75rem);
    overflow: hidden;
}

:root[data-phone="on"] .consult-step,
:root[data-phone="on"] .consult-step-link {
    display: none;
}

:root[data-phone="on"] .consult-path-chip {
    /* Still the button that changes the consult type, still 44px tall: it just
       stops looking like a pill competing with the line it now heads. */
    min-height: 44px;
    margin-right: 0;
    padding: 0;
    border-color: transparent;
    border-radius: 0.4rem;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
}

:root[data-phone="on"] .consult-path-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

:root[data-phone="on"] .consult-stepline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--ed-ui);
    font-size: max(0.78rem, var(--ed-fs-floor, 0rem));
    color: var(--ed-ink-soft);
}

:root[data-phone="on"] .consult-stepline-step {
    color: var(--ed-ink);
    font-weight: 600;
    white-space: nowrap;
}

:root[data-phone="on"] .consult-stepline-dots {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
    flex: none;
}

:root[data-phone="on"] .consult-stepline-dot {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ed-hairline-strong);
}

:root[data-phone="on"] .consult-stepline-dot.is-on {
    background: var(--ed-terracotta);
}

/* ── Bottom bar: it knows what is happening ──────────────────────────────── */
:root[data-phone="on"] .phone-chrome-item {
    position: relative;   /* anchors the Notes dot */
}

/* Record while a consult is capturing: rust slot, mono clock, saffron dot.
   The one place saffron is allowed ("live recording" only, per the token). */
:root[data-phone="on"] .phone-chrome-item--live,
:root[data-phone="on"] .phone-chrome-item--live.active {
    background: var(--ed-rust);
    color: var(--ed-paper);
    justify-content: center;
    gap: 0.3rem;
}

:root[data-phone="on"] .phone-chrome-timer {
    font-family: var(--ed-mono);
    font-variant-numeric: tabular-nums;
    font-size: max(0.8rem, var(--ed-fs-floor, 0rem));
    font-weight: 600;
}

:root[data-phone="on"] .phone-chrome-live-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--ed-saffron);
    animation: phone-chrome-live-pulse 1.6s ease-in-out infinite;
}

/* Paused: the dot holds still and hollows out. Motion means "listening". */
:root[data-phone="on"] .phone-chrome-live-dot--paused {
    animation: none;
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--ed-saffron);
}

/* The microphone has stopped (sweep 2026-10-15, shell-brand-pwa#2): still, and rust.
   A pulsing dot over a capture feeding silence said "listening". */
:root[data-phone="on"] .phone-chrome-live-dot--failed {
    animation: none;
    background: var(--ed-rust);
}

@keyframes phone-chrome-live-pulse {
    50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
    :root[data-phone="on"] .phone-chrome-live-dot { animation: none; }
}

/* Notes: a draft somewhere is unsaved. */
:root[data-phone="on"] .phone-chrome-dot {
    position: absolute;
    top: 0.3rem;
    right: 0.7rem;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--ed-terracotta);
    box-shadow: 0 0 0 2px var(--ed-paper);
}

/* ── Navigation labels lose tracked uppercase ────────────────────────────────
   Tracked caps at the legibility floor are the hardest text on the phone to
   read, and these are labels a vet scans, not decoration. */
:root[data-phone="on"] .nav-section-label,
:root[data-phone="on"] .case-switcher-section-title,
:root[data-phone="on"] .vet-switcher-section-title,
:root[data-phone="on"] .phone-chrome-label {
    text-transform: none;
    letter-spacing: 0;
}

/* ── The update pill: a block in the flow, under the masthead (QoL 2026-10-04,
   phone#14 and the review of 3D) ─────────────────────────────────────────────
   Lifted over the bar to 4.4rem it sat on the fixed Save rows (z 1080 over their
   60) until dismissed, and app.css's left:50% + translateX(-50%) capped its width
   at half the screen: 230px, the text a 49px column four lines long, 112px tall
   over SOAP's, Review's or Meds' Save (227-250px "after this consult"). Fixed
   full width under the masthead instead, it lay over the first rows of every
   masthead menu (the masthead is a z 40 stacking context, the pill 1080), the
   stepper's path chip, and, once the page scrolled, the second row of a sticky
   result bar (Discharge's Export PDF). So in the mode it leaves the overlay band:
   MainLayout mounts it at the top of main before the article, and here it is a
   static block there that pushes the page down, scrolls away with the masthead
   on a phone, and keeps its height in the 641px+ column the article scrolls in.
   The menus, positioned in the masthead's stacking context, paint over it. In
   that column it is a flex item, and a flex item's z-index stacks even when it
   is static, so app.css's 1080 goes too: kept, it painted over the menus again in
   landscape (measured at 812x375). Its own keyframes, because app.css's slide
   carries the translateX(-50%). */
:root[data-phone="on"] .update-pill {
    position: static;
    z-index: auto;
    display: flex;
    flex: none;
    margin: 0.5rem var(--ed-sp-gutter, 0.6rem) 0;
    transform: none;
    border-radius: 14px;
    animation-name: update-pill-drop;
}

/* The stale-store banner (app.css) is fixed over the top of the screen, 96-119px
   tall, and covered the pill's Refresh and ×. Its Reload is the one that matters
   while it is up, and the pill comes back after it: the worker is still waiting. */
:root[data-phone="on"]:has(.fauna-stale-banner) .update-pill {
    display: none;
}

/* The words give way before the buttons, which keep their 44px. */
:root[data-phone="on"] .update-pill-text {
    flex: 1 1 auto;
    min-width: 0;
}

:root[data-phone="on"] .update-pill-btn,
:root[data-phone="on"] .update-pill-dismiss {
    flex: 0 0 auto;
}

:root[data-phone="on"] .update-pill--leaving {
    transform: translateY(-4px);
}

@keyframes update-pill-drop {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    :root[data-phone="on"] .update-pill { animation: none; }
    :root[data-phone="on"] .update-pill--leaving { transform: none; }
}

/* ── The floating masthead (2026-10-17, "stronger glass") ─────────────────────────
   Below 641px the phone's page is the scroller and the masthead used to scroll away
   with it. Now it is a fixed glass capsule 10px off the sides and the notch, and the
   page runs up under it: app.css "Floating bar clearance" pads the article (or main,
   when the stepper or the update pill sits between) by --shell-bar-clear, the root's
   scroll padding keeps focus and anchors below it, and --shell-sticky-top stops sticky
   headers under it rather than behind it. From 641px (a landscape phone) the desktop
   capsule in MainLayout.razor.css applies instead, absolute over the article.

   Fixed, the row is still no containing block for fixed descendants (no transform,
   filter or contain; the blur is on its ::before), and still the z 40 stacking context
   its dropdowns rely on. (0,3,0) here beats the scoped .top-row[b-xxx]. */
@media (max-width: 640.98px) {
    :root[data-phone="on"] {
        --shell-bar-inset: calc(10px + env(safe-area-inset-top, 0px));
        --shell-bar-side: 10px;
        --shell-sticky-top: var(--shell-bar-clear);
    }

    :root[data-phone="on"] .top-row {
        position: fixed;
        top: var(--shell-bar-inset);
        left: var(--shell-bar-side);
        right: var(--shell-bar-side);
        height: var(--shell-bar-h);
        padding-left: 0.6rem !important;
        padding-right: 0.45rem !important;
        border: 1px solid var(--glass-float-edge);
        border-radius: 22px;
        background: var(--glass-bar);
        --shell-chip: var(--glass-chip);
        box-shadow: inset 0 1px 0 var(--glass-float-light), 0 12px 32px var(--glass-float-shade);
    }

    :root[data-phone="on"] .top-row::before {
        backdrop-filter: var(--glass-bar-filter);
        -webkit-backdrop-filter: var(--glass-bar-filter);
    }

    /* The masthead's menus hang from a FIXED bar now, so a long one can no longer be
       scrolled into view with the page: each scrolls inside itself and stops above the
       bottom capsule (its raised Record slot included). That is also what keeps a menu's
       glass off the bottom bar's: the two blurs never share a pixel. */
    :root[data-phone="on"] .account-menu-panel,
    :root[data-phone="on"] .case-switcher-menu,
    :root[data-phone="on"] .vet-switcher-menu {
        max-height: calc(100dvh - var(--shell-bar-clear) - 5.6rem - var(--phone-bar-float) - env(safe-area-inset-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

/* A dialog's pane stays above the bottom capsule too (and its raised Record slot). */
:root[data-phone="on"] {
    --shell-dialog-bottom: calc(5.6rem + var(--phone-bar-float) + env(safe-area-inset-bottom));
}

/* The update pill is a static row in the page here, so it scrolls up under the glass
   masthead like any content: it drops its own blur (no glass under glass) and keeps a
   solid dark fill, so its cream words never depend on what is behind it. */
:root[data-phone="on"] .update-pill {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--color-sidebar-to);
}

/* ── The same fix for a narrow screen that is NOT in phone mode (2026-10-11) ──────
   At 375px without the mode, the vet pill kept its full 169px and the patient chip
   was squeezed to 0px wide, its label spilling over "Who's using this?". The pill
   becomes the mode's initials disc here too (its name stays the button's accessible
   name) and its menu takes the masthead as its anchor, for the reason given above. */
@media (max-width: 640px) {
    :root:not([data-phone="on"]) .vet-switcher {
        flex: 0 0 auto;
        position: static;
    }

    :root:not([data-phone="on"]) .vet-switcher-trigger {
        min-width: 44px;
        min-height: 44px;
        max-width: none;
        padding: 0;
        justify-content: center;
        border-color: transparent;
        background: transparent;
    }

    :root:not([data-phone="on"]) .vet-switcher-trigger .ic,
    :root:not([data-phone="on"]) .vet-switcher-trigger .vet-switcher-chevron {
        display: none;
    }

    :root:not([data-phone="on"]) .vet-switcher-trigger .vet-switcher-name {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    :root:not([data-phone="on"]) .vet-switcher-initials {
        display: grid;
        place-items: center;
        width: 2rem;
        height: 2rem;
        border-radius: 50%;
        background: var(--ed-terracotta);
        color: var(--ed-paper);
        font-family: var(--ed-ui);
        font-size: max(0.75rem, var(--ed-fs-floor, 0rem));
        font-weight: 700;
        letter-spacing: 0;
        line-height: 1;
        box-shadow: 0 0 0 2px var(--ed-paper), 0 0 0 3.5px var(--ed-terracotta);
    }

    :root:not([data-phone="on"]) .vet-switcher-trigger--unset .vet-switcher-initials {
        background: var(--ed-paper);
        color: var(--ed-terracotta);
    }

    /* The patient chip may still be narrower than its label: the NAME span elides
       (app.css) and this clip is only the backstop that keeps it off its neighbour.
       The text-overflow that sat here did nothing: a flex container clips but never
       elides, so the name was cut hard with its ▾ pushed out of sight (sweep
       2026-10-15, shell-brand-pwa#11). */
    :root:not([data-phone="on"]) .case-switcher-trigger {
        max-width: 100%;
        overflow: hidden;
    }
}
