/* Phone mode (data-phone="on"): notes-meds. Every rule here is prefixed :root[data-phone="on"] so nothing leaks to desktop. */

/* ══ Notes (SoapNote.razor) ═══════════════════════════════════════════════════
   One toolbar line: format picker, Draft, overflow. The page title goes — the
   bar's Notes slot is lit and the masthead names the patient. */

/* The header holds two position:fixed descendants in this mode (the Save bar and
   the overflow backdrop). The entry rise animates a transform, and a transformed
   ancestor becomes the containing block for fixed children — for 240ms Save would
   ride the header instead of the viewport. No rise here. */
:root[data-phone="on"] .soap-page .tool-header {
    animation: none;
    padding-top: 0.5rem;
    padding-bottom: 0.35rem;
}

:root[data-phone="on"] .soap-page .tool-header > .tool-header-icon,
:root[data-phone="on"] .soap-page .tool-header > span {
    display: none;
}

/* The pickers' labels (round 8) stay for screen readers and leave the line: on a phone the
   toolbar is one line, as it was before they existed, and each picker shows its choice. */
:root[data-phone="on"] .soap-page .soap-field-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

:root[data-phone="on"] .soap-page .tool-header-actions {
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

/* The Note type field first and elastic; Draft and the overflow keep their width beside
   it. Since round 8 the picker sits in a labelled .soap-field, which is the toolbar's flex
   item, so the field takes the order and the flex and the picker fills it. */
:root[data-phone="on"] .soap-page .soap-field--type {
    order: -2;
    flex: 1 1 10.5rem;
    min-width: 10.5rem;
}

/* Inside its field, a flex COLUMN since round 8: a flex basis here would be its height
   (it drew 10.5rem tall), so the picker takes none and fills the field's width. */
:root[data-phone="on"] .soap-page .soap-format-picker {
    /* A floor: with a zero floor the Draft label won the row and the picker
       read "Stan" (seen 2026-09-19). Draft gives way instead. 6.5rem still left
       "Standard S" at 375px (walk W9, 2026-10-04): "Standard SOAP" at the phone's
       16px is ~112px of text, and the select's padding and arrow take 49px more.
       10.5rem is 168px — with Draft at "Draft" and the 44px overflow the row needs
       ~275px of the 326px a 375px phone gives it, where the picker grows to ~218px
       (measured). On a 320px phone (271px) the overflow takes a second line, as it
       already did with the old floor. The field carries that flex now (above). */
    flex: 0 0 auto;
    min-width: 10.5rem;
    width: 100%;
    min-height: 44px;
}

/* The named-template picker (2026-10-18) takes its own line under the toolbar: at 375px
   the Note type, Draft and the overflow already fill the first one (W9's sums). */
:root[data-phone="on"] .soap-page .soap-field--template {
    flex: 1 1 100%;
}

:root[data-phone="on"] .soap-page .soap-template-picker {
    width: 100%;
    max-width: none;
    min-height: 44px;
}

/* "Draft from summary" is ~134px at the toolbar's 0.78rem; "Draft" is ~46px. The
   picker beside it names the note, and needs the difference (W9). */
:root[data-phone="on"] .soap-page .soap-draft-from {
    display: none;
}

:root[data-phone="on"] .soap-page .tool-header-actions > .btn-primary {
    order: -1;
    flex: 0 1 auto;
    min-width: 0;
    min-height: 44px;
    padding-inline: 0.5rem;
    font-size: max(0.78rem, var(--ed-fs-floor, 0rem));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

:root[data-phone="on"] .soap-page .soap-more {
    order: -1;
    flex: 0 0 auto;
    display: block;
    position: relative;
    flex: 0 0 auto;
}

:root[data-phone="on"] .soap-page .soap-more-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.25rem;
    line-height: 1;
}

/* "Set as my default" only exists while the choice differs from the stored one. It sits
   beside the Note type label (round 8); with the label off the line here, its row folds
   away and the link takes a thumb-high line under the picker rather than squeezing it. */
:root[data-phone="on"] .soap-page .soap-field-head {
    display: contents;
}

:root[data-phone="on"] .soap-page .soap-format-default {
    order: 1;
    min-height: 44px;
    text-align: left;
}

/* Outside-tap catcher. Under the menu, over the page; the bottom bar (z 100) stays
   above it, so a tap there still navigates. */
:root[data-phone="on"] .soap-more-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: transparent;
}

:root[data-phone="on"] .soap-more-menu {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    z-index: 70;
    min-width: 13rem;
    display: flex;
    flex-direction: column;
    padding: 0.3rem;
    background: var(--ed-paper);
    color: var(--ed-ink);
    border: 1px solid var(--ed-hairline-strong);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--ed-hairline-strong);
}

:root[data-phone="on"] .soap-more-menu .soap-more-item,
:root[data-phone="on"] .soap-more-menu .btn-copy-plain {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--ed-ink);
    font-family: var(--ed-ui);
    font-size: 1rem;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
}

:root[data-phone="on"] .soap-more-menu .soap-more-item:active,
:root[data-phone="on"] .soap-more-menu .btn-copy-plain:active {
    background: var(--ed-paper-deep);
}

:root[data-phone="on"] .soap-more-menu .soap-more-item:disabled,
:root[data-phone="on"] .soap-more-menu .btn-copy-plain:disabled {
    color: var(--ed-mute);
}

/* The menu's separators (round 8), the phone-only one before Clear included. */
:root[data-phone="on"] .soap-more-menu .soap-more-sep {
    display: block;
    height: 1px;
    margin: 0.3rem 0.5rem;
    background: var(--ed-hairline);
}

/* Provenance: what the note draws on, and whether the record holds it. */
:root[data-phone="on"] .soap-provenance {
    display: block;
    padding: 0 var(--ed-sp-pad-x, 1rem) 0.4rem;
    font-size: max(0.8rem, var(--ed-fs-floor, 0rem));
    color: var(--ed-mute);
}

/* No consult summary: the line is the way to the summary box (errors #11). A thumb's
   height, and the line's own size rather than .ed-text-btn's. */
:root[data-phone="on"] .soap-provenance-cta {
    min-height: 44px;
    font-size: inherit;
    text-align: left;
}

/* "· saved" wraps whole, never leaving the line ending on its dot. */
:root[data-phone="on"] .soap-provenance-tail {
    white-space: nowrap;
}

/* The reopened note's "Start a new note", and Discharge's "Start a new handout" beside its
   reopened handout (taps #3): a thumb's height too. */
:root[data-phone="on"] .soap-reopened-note .ed-text-btn,
:root[data-phone="on"] .discharge-reopened-note .ed-text-btn {
    min-height: 44px;
}

:root[data-phone="on"] .soap-provenance-unsaved {
    color: var(--ed-terracotta);
    font-weight: 600;
}

:root[data-phone="on"] .soap-provenance-saved {
    color: var(--ed-eucalypt);
    font-weight: 600;
}

/* The menu's Copy failed: said under the status line, on its gutter (errors #7). */
:root[data-phone="on"] .soap-copy-failed {
    display: block;
    padding: 0 var(--ed-sp-pad-x, 1rem) 0.4rem;
}

/* Save rides above the bar — the same geometry as the Review screen's actions
   (4.9rem clears the raised Record slot; z 60 is over content, under the bar).
   Once the note on screen is the one saved, the bar is the next step instead
   (taps #8 / W10): same place, same look; Save hides until the next edit. */
:root[data-phone="on"] .soap-page .tool-header-actions > .save-hold,
:root[data-phone="on"] .soap-page .tool-header-actions > .soap-next-step {
    position: fixed;
    left: 0.6rem;
    right: 0.6rem;
    bottom: calc(4.9rem + var(--phone-bar-float) + env(safe-area-inset-bottom));
    z-index: 60;
    min-height: 48px;
    margin: 0;
    background: var(--ed-eucalypt);
    border-color: var(--ed-eucalypt);
    color: var(--ed-paper);
    border-radius: 12px;
    box-shadow: 0 4px 14px var(--ed-hairline-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

:root[data-phone="on"] .soap-page .tool-header-actions > .save-hold.soap-save--done {
    display: none;
}

/* Opaque when disabled: a translucent fixed bar lets the note read through it. */
:root[data-phone="on"] .soap-page .tool-header-actions > .save-hold:disabled {
    opacity: 1;
    background: var(--ed-paper-deep);
    border-color: var(--ed-hairline-strong);
    color: var(--ed-mute);
    box-shadow: none;
}

/* The last in-flow content clears the fixed Save. */
:root[data-phone="on"] .soap-page .soap-column {
    padding-bottom: 5.5rem;
}

/* ══ Meds (Medications.razor) ═════════════════════════════════════════════════
   Sub-tabs: one swipeable chip row. Measured before: five tracked-uppercase
   labels wrapped into three centred rows and pushed the first medication a
   whole screen down. */
:root[data-phone="on"] .meds-page .tool-header {
    display: none;
}

/* The strip that swipes is .meds-tab-strip, the tablist and the Drug Book chip after it
   (QoL 2026-10-04, phone#12): the chip cannot sit inside the tablist, and it has to
   scroll with the tabs. The tablist is sized to its chips inside it. */
:root[data-phone="on"] .meds-page .meds-tab-strip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.7rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

:root[data-phone="on"] .meds-page .meds-tab-strip::-webkit-scrollbar {
    display: none;
}

:root[data-phone="on"] .meds-page .dose-calc-tabs {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0.4rem;
    padding: 0;
    border-bottom: none;
}

/* The last chip: the Drug Book, a link styled as the tabs beside it. */
:root[data-phone="on"] .meds-page .meds-drugbook-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--ed-hairline-strong);
    border-radius: 999px;
    color: var(--ed-ink-soft);
    font-family: var(--ed-ui);
    font-size: max(0.9rem, var(--ed-fs-floor, 0rem));
    text-decoration: none;
    white-space: nowrap;
}

:root[data-phone="on"] .meds-page .dose-calc-tab {
    flex: 0 0 auto;
    min-height: 44px;
    margin-bottom: 0;
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--ed-hairline-strong);
    border-radius: 999px;
    font-family: var(--ed-ui);
    font-size: max(0.9rem, var(--ed-fs-floor, 0rem));
    text-transform: none;
    letter-spacing: 0;
    color: var(--ed-ink-soft);
}

:root[data-phone="on"] .meds-page .dose-calc-tab.active {
    background: var(--ed-ink);
    border-color: var(--ed-ink);
    color: var(--ed-paper);
}

/* Emergency keeps its rust so it is found in a hurry. */
:root[data-phone="on"] .meds-page .dose-calc-tab--emergency {
    border-color: var(--ed-rust);
    color: var(--ed-rust);
}

:root[data-phone="on"] .meds-page .dose-calc-tab--emergency.active {
    background: var(--ed-rust);
    border-color: var(--ed-rust);
    color: var(--ed-paper);
}

:root[data-phone="on"] .meds-page .meds-body {
    padding: 0.5rem 0.7rem 6rem;
}

/* Complaint and weight on one line. */
:root[data-phone="on"] .meds-for {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.15rem 0.45rem;
    margin: 0 0 0.6rem;
    padding: 0.5rem 0.7rem;
    background: var(--ed-paper-deep);
    color: var(--ed-ink);
    border-radius: 8px;
    font-size: 0.92rem;
}

:root[data-phone="on"] .meds-for > strong {
    font-family: var(--ed-mono);
    font-size: max(0.72rem, var(--ed-fs-floor, 0rem));
    font-weight: 600;
    color: var(--ed-mute);
}

:root[data-phone="on"] .meds-for-weight {
    font-family: var(--ed-mono);
    font-weight: 600;
    white-space: nowrap;
}

:root[data-phone="on"] .meds-for-weight:not(:first-of-type)::before {
    content: "· ";
    color: var(--ed-mute);
}

/* The carried-context box is empty on a phone when all it held was the complaint
   (now on the "For" line above). */
:root[data-phone="on"] .meds-page .meds-context:not(:has(.meds-chip)) {
    display: none;
}

/* "Currently on file" (QoL 2026-10-04, phone#10). Name, Drug Book, dose and "＋ carry
   forward" shared one line that never wrapped: on rechecks the dose read one word per
   line in a 45-67px column, and with wide type carry forward ran past the column and
   the list scrolled sideways. The row wraps; the dose goes last and takes a line of its
   own under the name, its card and carry forward. */
:root[data-phone="on"] .meds-page .meds-onfile > li {
    flex-wrap: wrap;
}

:root[data-phone="on"] .meds-page .meds-onfile-dose {
    order: 1;
    flex-basis: 100%;
    overflow-wrap: anywhere;
}

/* "Mentioned in notes, not on the list" (QoL 2026-10-04, phone#9). The text box's 14rem
   basis and the two buttons never fitted a 303px row, so Add and Not now wrapped under
   every item: 160-180px each, three items 640-684px above the first prescription row.
   The text box is flattened into the row: the name, the dose and the note's sentence
   (kept: the review wanted it read before Add) take a line each, and the source label
   shares the last line with the buttons. NotedMedicationsCard keeps the source label
   last in the box and the buttons after it (MedicationsPhonePolishTests). */
:root[data-phone="on"] .noted-med-main {
    display: contents;
}

:root[data-phone="on"] .noted-med-main > * {
    flex: 1 1 100%;
    min-width: 0;
}

:root[data-phone="on"] .noted-med-main > .noted-med-src {
    flex: 1 1 0;
}

:root[data-phone="on"] .noted-med-actions {
    flex: 0 0 auto;
}

/* Its footnote is a line and a "?" here (HelpLine). The root carries .phone-mode-only,
   which is inline in the mode; it is a block. */
:root[data-phone="on"] .noted-meds-help {
    display: block;
    margin-top: 0.4rem;
}

:root[data-phone="on"] .noted-meds-help .help-line-text {
    margin-bottom: 0;
}

/* Medication rows lead with the dose — the number to draw up — in the mono face
   and eucalypt. Re-ordering only: the same inputs, the same bindings, whatever the
   row shows today. */
:root[data-phone="on"] .meds-page .med-row {
    padding: 0.6rem;
    border-radius: 10px;
}

:root[data-phone="on"] .meds-page .med-row-line {
    gap: 0.4rem;
}

:root[data-phone="on"] .meds-page .med-row-line > .med-dose {
    order: -1;
    flex: 1 1 100%;
    min-height: 48px;
    font-family: var(--ed-mono);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ed-eucalypt);
}

:root[data-phone="on"] .meds-page .med-row-line > .drug-name-field {
    flex: 1 1 100%;
}

:root[data-phone="on"] .meds-page .med-row-line > .med-route {
    flex: 1 1 28%;
}

:root[data-phone="on"] .meds-page .med-row-line > .med-freq,
:root[data-phone="on"] .meds-page .med-row-line > .med-duration {
    flex: 1 1 30%;
    min-width: 0;
}

:root[data-phone="on"] .meds-page .med-row-line > .form-control,
:root[data-phone="on"] .meds-page .med-row-line > .form-select,
:root[data-phone="on"] .meds-page .med-row-line > .btn,
:root[data-phone="on"] .meds-page .med-row .med-notes,
:root[data-phone="on"] .meds-page .med-care-btn {
    min-height: 44px;
}

:root[data-phone="on"] .meds-page .med-row-line > .btn {
    min-width: 44px;
}

/* Save & continue rides above the bar, so the raised Record slot can never cover
   it (the overlap measured on 21 August). The two quieter actions stay in flow.
   The button lives in .meds-save-bar since the desktop refresh (2026-09-24), a box of
   its own that the desktop sticks; the quieter two are still .meds-actions.

   The BAR is what is fixed (QoL 2026-10-04, phone#16), not just its button: a failed
   save's message sits in the bar above the button, and with only the button fixed it
   stayed in flow at the end of the list, so "Save & continue" pressed mid-list looked
   dead. Whatever the bar holds now rides with the button, bottom-anchored, growing
   upward. */
:root[data-phone="on"] .meds-page .meds-save-bar {
    position: fixed;
    left: 0.6rem;
    right: 0.6rem;
    bottom: calc(4.9rem + var(--phone-bar-float) + env(safe-area-inset-bottom));
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

/* .alert-warning's tint is translucent; over the list the rows read through it. The
   rail keeps the tone. */
:root[data-phone="on"] .meds-page .meds-save-bar > [role="alert"] {
    background: var(--ed-paper-warm);
    box-shadow: 0 4px 14px var(--ed-hairline-strong);
}

/* "⚠ Drug Book lists N interactions" (QoL 2026-10-04, phone#13): one line over Save
   while the interaction check, under the last row, has hits; a tap brings the check
   into view. The terracotta of the check's own marks, on an opaque surface. */
:root[data-phone="on"] .meds-page .meds-rx-pin {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    min-height: 44px;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--ed-terracotta);
    border-radius: 12px;
    background: var(--ed-paper-warm);
    color: var(--ed-ink);
    font-family: var(--ed-ui);
    font-size: 0.92rem;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 14px var(--ed-hairline-strong);
}

/* The list clears the taller bar while it holds the line, a message, or both. */
:root[data-phone="on"] .meds-page .meds-body:has(> .meds-save-bar > .meds-rx-pin) {
    padding-bottom: 8rem;
}

:root[data-phone="on"] .meds-page .meds-body:has(> .meds-save-bar > [role="alert"]) {
    padding-bottom: 10rem;
}

:root[data-phone="on"] .meds-page .meds-body:has(> .meds-save-bar > .meds-rx-pin):has(> .meds-save-bar > [role="alert"]) {
    padding-bottom: 13rem;
}

/* Out of the flow, the bar's own 1.5rem no longer spaces the quieter row from the list. */
:root[data-phone="on"] .meds-page .meds-save-bar + .meds-actions {
    margin-top: 1.5rem;
}

:root[data-phone="on"] .meds-page .meds-save-bar > .btn-primary {
    min-height: 48px;
    background: var(--ed-eucalypt);
    border-color: var(--ed-eucalypt);
    color: var(--ed-paper);
    border-radius: 12px;
    box-shadow: 0 4px 14px var(--ed-hairline-strong);
}

:root[data-phone="on"] .meds-page .meds-save-bar > .btn-primary:disabled {
    opacity: 1;
    background: var(--ed-paper-deep);
    border-color: var(--ed-hairline-strong);
    color: var(--ed-mute);
}

/* .meds-save-bar is a .meds-body child and so carries the entry rise; its transform
   would capture the fixed button for the length of the animation. The quieter row never
   rose either (it was the same box until 2026-09-24). */
:root[data-phone="on"] .meds-page .meds-save-bar,
:root[data-phone="on"] .meds-page .meds-actions {
    animation: none;
}

/* The bar's button too: as a .meds-actions child it always matched this rule, which
   comes later at the same specificity and so beat the 48px above — the fixed button has
   rendered 44px tall since 2026-09-19. Moving it into .meds-save-bar keeps that; 48px
   would be a phone change of its own, not a side effect of the desktop one. */
:root[data-phone="on"] .meds-page .meds-save-bar > .btn,
:root[data-phone="on"] .meds-page .meds-actions > .btn {
    min-height: 44px;
}

/* Browser pass, 2026-09-19: picker + Draft + overflow measured 331px in a 326px
   row, so the overflow wrapped alone onto a second line. 44px square is the
   thumb floor and all it needs. */
:root[data-phone="on"] .soap-page .soap-more > button {
    width: 44px;
    min-width: 44px;
    padding-inline: 0;
}
