/* Desktop refresh (2026-09-24): tools. Rules apply outside phone mode only: prefix :root:not([data-phone="on"]) where a rule could reach the phone layout. */

/* Every rule in this sheet carries the prefix, not only the ones that obviously could
   reach a phone: phone mode must render exactly as before, and a rule that "cannot" reach
   it today is one markup change away from doing so. The prefix is also the (0,2,0) that
   lets `.foo` here beat a page's scoped `.foo[b-xxx]`. DesktopToolPagesTests pins the
   prefix and the hygiene rules tests/js applies to app.css and the scoped sheets (this
   sheet is outside that suite's reach): tokens only, the micro-type floor, z <= 30. */

/* ══ Medications (Medications.razor) ═══════════════════════════════════════════
   Sub-tabs in sentence case. The labels were always written that way in the markup —
   the tracked mono uppercase was CSS. The phone refresh dropped it too, with short labels
   on chips; the desktop keeps its underline tabs and "Concentration → Volume" in full.
   The four calculator names are quoted verbatim by the server's system prompts; only
   their case on screen changes, not their words. */
:root:not([data-phone="on"]) .dose-calc-tab {
    font-family: var(--ed-ui);
    text-transform: none;
    letter-spacing: 0;
}

/* The <=640px tier's 0.85rem stays: a narrow window needs every label on one line. */
@media (min-width: 641px) {
    :root:not([data-phone="on"]) .dose-calc-tab {
        font-size: 0.9rem;
    }
}

/* Save & continue at the foot of whatever scrolls the list — .meds-body from 901px up
   (the tool page's fixed-height column), the article from 641px. The phone fixes the same
   button above its bottom bar; with no bar here, sticky does the same job and hands the
   button back to the flow once the end of the list reaches it.

   .meds-save-bar, not the three-button .meds-actions row (review, 2026-09-24): the row
   wrapped to two rows (~123px) below ~1080px and three below 641px, and a bar that tall
   hid the field it had just scrolled to. The bar holds the one button (and a failed
   save's message, above it) — one row at every width. The two quieter actions follow it
   in flow, as they do on the phone.

   Not below 641px. There the window is phone-sized with the phone layout off: no room for
   a bar over the list, so the page keeps the flow it always had.

   The negative margins reach into .meds-body's padding (1.5rem 1.75rem, Medications.
   razor.css) so rows never show beside the bar. z 3 lifts it over positioned content in
   the rows and nowhere near the chrome band (in-article max is 30). */
@media (min-width: 641px) {
    :root:not([data-phone="on"]) .meds-page .meds-save-bar {
        position: sticky;
        bottom: 0;
        z-index: 3;
        margin-inline: -1.75rem;
        padding: 0.75rem 1.75rem;
        background: var(--ed-paper);
        border-top: 1px solid var(--ed-hairline-strong);
    }
}

/* The sticky edge is the scroller's padding edge, not its border (measured in Chromium):
   stuck at bottom: 0 inside .meds-body, the bar hovered 1.5rem up with the list scrolling
   past underneath it. -1.5rem is that padding. Only where .meds-body is the scroller —
   the article below 901px has no bottom padding, and the same inset there would push the
   bar's lower edge off the screen.

   A field the vet Tabs into must not land under the bar (browsers scroll a focused
   element to the scroller's edge, not to the edge of what is stuck over it), so the
   scroller keeps a padding the bar fits inside: 1.5rem of its own padding, a 1px rule and
   the button — 2.25rem on one line (44px on a touch screen), 3.75rem where the label
   wraps in the narrowest column (~272px at 641px with the sidebar open). ~5.5rem at most;
   6.5rem leaves the field a line clear of it. While a failed save's message sits in the
   bar it is ~4rem taller (~5rem if the message wraps), so the padding grows with it —
   measured in Chromium, 6.5rem left a Tabbed field 21-47px under a bar with the message. */
@media (min-width: 901px) {
    :root:not([data-phone="on"]) .meds-page .meds-save-bar {
        bottom: -1.5rem;
    }

    :root:not([data-phone="on"]) .meds-page .meds-body {
        scroll-padding-bottom: 6.5rem;
    }

    :root:not([data-phone="on"]) .meds-page .meds-body:has(> .meds-save-bar > [role="alert"]) {
        scroll-padding-bottom: 11rem;
    }
}

/* 641-900px the tool page flows inside the article and .meds-body grows to its content,
   but its overflow-y: auto still makes it a scroll container — the nearest one — so the
   bar above would stick inside a box that never scrolls, i.e. not at all. clip across
   rather than visible: clip is not a scroll container either, and a row wider than the
   column still cannot push the whole page sideways (the 2026-07-25 iPad-portrait defect).
   The article is the scroller, so it carries the padding. */
@media (min-width: 641px) and (max-width: 900px) {
    :root:not([data-phone="on"]) .content:has(> .meds-page) {
        scroll-padding-bottom: 6.5rem;
    }

    :root:not([data-phone="on"]) .content:has(> .meds-page .meds-save-bar > [role="alert"]) {
        scroll-padding-bottom: 11rem;
    }

    /* While the recording capsule shows, app.css pads the article's foot by 5.5rem so a
       page's last lines scroll clear of it, and the bar sticks to that padding edge: it
       rides 5.5rem up, just over the capsule. scroll-padding counts from the scrollport,
       not the padding edge, so both paddings above grow by the same 5.5rem. Without it a
       Tabbed field stopped 6.5rem up, inside the lifted bar: measured at 768px in
       Chromium with the real sheets, 12 of 40 fields landed under it, the worst by 44px
       (review of the 2026-10-15 sweep, shell-brand-pwa#15; found again as finding 9 of the
       review of the 2026-10-15 fixes). The app.css rule also sets the article's own
       scroll-padding-bottom and outranks the two above, so without these it would put them
       back to 5.5. From 901px .meds-body is the scroller and the article's padding is
       outside it, so nothing changes there. */
    :root:not([data-phone="on"]) body:has(.live-capsule) .content:has(> .meds-page) {
        scroll-padding-bottom: 12rem;
    }

    :root:not([data-phone="on"]) body:has(.live-capsule) .content:has(> .meds-page .meds-save-bar > [role="alert"]) {
        scroll-padding-bottom: 16.5rem;
    }

    :root:not([data-phone="on"]) .meds-page .meds-body {
        overflow-x: clip;
        overflow-y: visible;
    }
}

/* Below 641px the bar is a plain block, so the quieter row needs the gap the one flex row
   gave the three buttons when it wrapped. Above it the bar's own padding is that gap. The
   phone mode's bar is empty (its button is fixed), so the rule stays out of it too. */
@media (max-width: 640.98px) {
    :root:not([data-phone="on"]) .meds-page .meds-save-bar + .meds-actions {
        margin-top: 0.5rem;
    }
}

/* ══ SOAP Note (SoapNote.razor), >=1200px ══════════════════════════════════════
   From 1200px since round 8 (Brad's mockup, 2026-11-08, drawn at a 1360px window with the
   sidebar open): it was 1400px, so the laptop the mockup was drawn on got one column.
   The note on the left, the source panel (record picker + consult summary) on the right,
   sticky, so the summary a draft reads from sits beside the note it drafts instead of
   below 26 rows of it. .soap-note-area / .soap-note-foot are display: contents at every
   other width (SoapNote.razor.css); here they become the left column's two grid areas.
   "foot" takes the flexible row, so a source panel taller than the note lengthens the
   left column below its Copy/Export row instead of prising the note and its actions
   apart. The inner flex columns repeat .soap-column's own 0.85rem gap, which the
   children had as its flex items. */
@media (min-width: 1200px) {
    :root:not([data-phone="on"]) .soap-column {
        max-width: 84.5rem;
        display: grid;
        grid-template-columns: minmax(0, 1fr) clamp(20rem, 38%, 28rem);
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "note side"
            "foot side";
        column-gap: 1.75rem;
        row-gap: 0.85rem;
        align-items: start;
    }

    :root:not([data-phone="on"]) .soap-note-area,
    :root:not([data-phone="on"]) .soap-note-foot {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
        min-width: 0;
    }

    :root:not([data-phone="on"]) .soap-note-area {
        grid-area: note;
    }

    :root:not([data-phone="on"]) .soap-note-foot {
        grid-area: foot;
    }

    /* Sticky inside .soap-single, the page's own scroller at this width. The max-height
       keeps an open panel inside the scroller's height (top row 3.5rem, stepper ~2.4rem
       and a tool header that wraps to two lines at 1400px ~6.5rem, plus the 1rem inset
       and a margin below), so its last line never waits for the note to finish
       scrolling; past that the panel scrolls on its own. A viewport budget is safe here
       because it only caps an inner panel — it sizes no page container, so it cannot
       open the phantom scroll band the app-shell contract warns about. */
    :root:not([data-phone="on"]) .soap-source {
        grid-area: side;
        position: sticky;
        top: 1rem;
        max-height: calc(100dvh - 15rem);
        overflow-y: auto;
    }
}

/* ══ Today (Today.razor), >=1400px ═════════════════════════════════════════════
   The roster on the left; the vaccination register, the month's hazards and end of day
   in a right-hand column (.today-side, display: contents at every other width).

   By width alone, whatever the day holds (review, 2026-09-24). Keyed on the side column
   having something in it, the page fell back to the centred 1080px column on every date
   hop's loading render — end of day waits for the load — and on every empty day, and the
   header's ‹ › arrows at the roster's right edge jumped ~300px sideways under the pointer
   of a vet stepping back through the days. An empty right-hand track on an empty day is
   the price of a header that stays where the pointer left it.

   The roster's own children stay .today-container's children (the phone's flex-order
   rules select them as such), so the side column spans every row of the grid: one
   auto row per possible roster-side child — Working on, header, day closed, action row,
   add, import, the list: seven, plus a spare — and a flexible last row that takes a tall
   side column's extra height, so it lengthens the page below the list instead of
   spreading the header and the list apart. None of those children carries a top margin,
   so losing block-flow margin collapse costs nothing.

   The side track's 22rem floor is the register's: a wrapped row's second line (below)
   is ~18.7rem — "overdue 12 days" in 1.05rem mono, the Open case pill, clear, two gaps —
   inside the section's ~2.3rem of padding and border. At 20rem (1400px to ~1510px,
   the 1536px laptop included) there was ~300px of content and the row crushed the name
   into the next item and broke the date over three lines. */
@media (min-width: 1400px) {
    :root:not([data-phone="on"]) .today-container {
        max-width: 84.5rem;
        display: grid;
        grid-template-columns: minmax(0, 1fr) clamp(22rem, 30%, 26rem);
        grid-template-rows: repeat(8, auto) 1fr;
        column-gap: 2.5rem;
        align-items: start;
    }

    :root:not([data-phone="on"]) .today-container > * {
        grid-column: 1;
    }

    /* A real box now, so app.css's page rise reaches it as well as the sections inside
       it (Today.razor.css) — once is enough. */
    :root:not([data-phone="on"]) .today-container > .today-side {
        display: block;
        grid-column: 2;
        grid-row: 1 / -1;
        min-width: 0;
        animation: none;
    }

    /* The sections carry an inline 2rem top margin that spaced them below the list; at
       the top of their own column it would drop the register 2rem below the roster's
       first line. !important because the margin is an inline style. */
    :root:not([data-phone="on"]) .today-side > :first-child {
        margin-top: 0 !important;
    }

    /* A register row in the side column: the name on a line of its own (it wraps there
       like prose, never overflowing into the next item), then the due label whole with
       Open case and clear pushed to the right. On one line the four shared ~300px and
       flex shrink left the name ~68px and the label ~58px. The row's gap-2 (Bootstrap,
       !important) spaces the lines as it spaces the items. */
    :root:not([data-phone="on"]) .today-side .today-vax-row {
        flex-wrap: wrap;
    }

    :root:not([data-phone="on"]) .today-side .today-vax-who {
        flex: 1 0 100%;
    }

    :root:not([data-phone="on"]) .today-side .today-vax-due {
        white-space: nowrap;
        margin-right: auto;
    }

    :root:not([data-phone="on"]) .today-side .today-vax-row > .ed-pill {
        white-space: nowrap;
    }
}

/* ══ Drug Book (DrugBook.razor), >=761px: a stationary card ═══════════════════════
   Brad, round 6 (2026-09-27): scrolling down the list to pick a drug carried the card
   off the top of the screen, so every pick meant scrolling back up to read it. From
   761px, where the scoped sheet's one-pane rule (max-width: 760px) stops, the card sticks
   1rem below the top of article.content and scrolls on its own; the list keeps scrolling
   with the page. The .soap-source precedent above: the max-height keeps the stuck card
   inside the scroller (top row 3.5rem, the stepper ~2.4rem when a case is open, the 1rem
   inset and 1rem below), and a viewport budget is safe because it caps an inner panel,
   never a page container. The page keys the card on the open drug, so a new pick starts
   at its top rather than wherever the last one was scrolled to. */
@media (min-width: 761px) {
    /* 2026-11-15: the page's header bar now floats too (Brad), so the card sticks below it
       rather than sliding under it. --drugbook-bar-h is the bar's height: one row of title
       and actions, two when the actions wrap to their own row (app.css, max-width: 820px). */
    :root:not([data-phone="on"]) .drugbook-page { --drugbook-bar-h: 4.4rem; }

    /* The strip between the masthead capsule and the bar: without this the list reads
       through it as it scrolls by. A shadow, so the bar's own box and height do not change. */
    :root:not([data-phone="on"]) .drugbook-bar { box-shadow: 0 -1.75rem 0 0 var(--ed-paper); }

    :root:not([data-phone="on"]) .drugbook-mono {
        position: sticky;
        top: calc(var(--drugbook-bar-h) + 0.75rem);
        max-height: calc(100dvh - 8rem - var(--drugbook-bar-h));
        overflow-y: auto;
    }
}

/* Up to 820px the header's actions take a row of their own (app.css): the bar is two rows.
   Above that it is held to ONE row whatever the width, so --drugbook-bar-h is true and the
   card never tucks under the bar: the title gives way (ellipsis) before the buttons wrap. */
@media (min-width: 761px) and (max-width: 820px) {
    :root:not([data-phone="on"]) .drugbook-page { --drugbook-bar-h: 7.4rem; }
}

@media (min-width: 821px) {
    :root:not([data-phone="on"]) .drugbook-bar,
    :root:not([data-phone="on"]) .drugbook-bar .tool-header-actions { flex-wrap: nowrap; }

    :root:not([data-phone="on"]) .drugbook-bar > span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ══ Wide screens, >=1600px: the page column ════════════════════════════════════
   The 1,180px reading column left a third of a 1920px screen empty (audit, 2026-09-24).
   84.5rem is ~1,440px at the 17px root and follows comfort view's larger root, as every
   rem measure here does. .cv-spread is the case screen's column (CaseView.razor.css) —
   the 1,180px column the audit named; .ed-spread is app.css's shared editorial column, kept in
   step so a page that picks it up later gets the same width. SOAP and Today widen from
   1400px above, with their second column. */
@media (min-width: 1600px) {
    :root:not([data-phone="on"]) .cv-spread,
    :root:not([data-phone="on"]) .ed-spread {
        max-width: 84.5rem;
    }
}
