/*
 * Tablet & mobile view (owner 21-11-2026, responsive-tablet-mobile.html — all defaults + owner notes).
 *
 * RULES OF THIS FILE (checked by tests/Feature/ResponsiveCssTest.php):
 *  - every rule sits inside a media query with max-width ≤ 1279px, so a computer screen (1280 px and wider,
 *    1366 × 768 / 1920 × 1080) never gets one rule of this file — the desktop stays exactly as it is;
 *  - every selector starts with :root:not(.vx-desktop-view), so "Desktop view" (user menu, responsive.js) shows the
 *    normal VitalOS layout on a tablet / phone (the viewport is also set to 1366 px then);
 *  - nothing here hides a menu, a field, a column or a button; only sizes / positions change.
 * Breakpoints: phone ≤ 599 · tablet standing 600–1023 · tablet lying / small laptop 1024–1279 · computer 1280 +.
 * Loaded after every other style (layouts/guest).
 *
 * Phase P1 (shell): slide-in menu, compact sticky header, popups sized for the screen, touch sizes.
 */

/* ---------------------------------------------------------------- P1 · touch sizes (tablet + phone, touch only) */
@media (max-width: 1279px) and (pointer: coarse) {
    :root:not(.vx-desktop-view) .hospital-app-shell input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="color"]),
    :root:not(.vx-desktop-view) .hospital-app-shell select,
    :root:not(.vx-desktop-view) dialog input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="color"]),
    :root:not(.vx-desktop-view) dialog select {
        min-height: 36px;
    }
    :root:not(.vx-desktop-view) .hospital-app-shell input[type="checkbox"],
    :root:not(.vx-desktop-view) .hospital-app-shell input[type="radio"],
    :root:not(.vx-desktop-view) dialog input[type="checkbox"],
    :root:not(.vx-desktop-view) dialog input[type="radio"] {
        min-width: 18px;
        min-height: 18px;
    }
    :root:not(.vx-desktop-view) .hospital-button,
    :root:not(.vx-desktop-view) .vx-pp-btn,
    :root:not(.vx-desktop-view) .hospital-user-action {
        min-height: 36px;
    }
    :root:not(.vx-desktop-view) .hospital-sidebar-link,
    :root:not(.vx-desktop-view) .hospital-sidebar-summary {
        min-height: 38px;
    }
}

/* ---------------------------------------------------------------- P1 · shell below 1024 px (tablet standing + phone) */
@media (max-width: 1023px) {
    /* The page itself scrolls (vitalos.css already lets the shell grow below 1024 px); the shell's glass blur and its
       entry animation are dropped here because they would pin the fixed menu / header to the shell, not the screen. */
    :root:not(.vx-desktop-view) .hospital-dashboard {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        overflow-x: clip;
    }
    :root:not(.vx-desktop-view) .hospital-dashboard-shell,
    :root:not(.vx-desktop-view) .hospital-app-shell {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        animation: none;
        transform: none;
        background: rgba(255, 255, 255, 0.9);
    }

    /* Header: sticky at the top; logo box only as wide as the logo. */
    :root:not(.vx-desktop-view) .hospital-app-header--brand {
        position: sticky;
        top: 0;
        grid-template-columns: auto auto minmax(0, 1fr) auto;
        align-items: center;
        padding-top: env(safe-area-inset-top, 0px);
    }
    :root:not(.vx-desktop-view) .hospital-header-logo {
        align-self: stretch;
        padding: 6px 10px;
    }
    :root:not(.vx-desktop-view) .hospital-header-logo img {
        height: 30px;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-app-hospital {
        justify-content: flex-start;
        text-align: left;
        padding: 6px 8px;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-app-hospital-name {
        font-size: 17px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: normal;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-header-tools {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 6px 10px 6px 0;
        padding-right: max(10px, env(safe-area-inset-right, 0px));
    }
    /* The ≤ 640 px rule of vitalos.css puts the user menu in the page flow; keep it a dropdown as on the computer. */
    :root:not(.vx-desktop-view) .hospital-user-menu,
    :root:not(.vx-desktop-view) .hospital-user-trigger {
        width: auto;
    }
    :root:not(.vx-desktop-view) .hospital-user-panel {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        width: 220px;
        margin-top: 0;
    }
    :root:not(.vx-desktop-view) .hospital-bell-panel {
        position: fixed;
        top: 56px;
        left: 8px;
        right: 8px;
        width: auto;
        max-height: calc(100dvh - 72px);
        overflow-y: auto;
    }

    /* Content takes the full width; the sidebar becomes the slide-in menu (☰). */
    :root:not(.vx-desktop-view) .hospital-app-shell .hospital-app-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    :root:not(.vx-desktop-view) .hospital-app-shell .hospital-sidebar {
        display: block;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 70;
        width: min(320px, 86vw);
        padding: 12px 10px;
        padding-top: max(12px, env(safe-area-inset-top, 0px));
        padding-left: max(10px, env(safe-area-inset-left, 0px));
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
        border-right: 1px solid rgba(96, 112, 137, 0.2);
        border-bottom: 0;
        background: #f8fbff;
        box-shadow: 10px 0 28px rgba(15, 23, 42, 0.18);
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .22s ease-out, visibility 0s linear .22s;
    }
    :root.vx-nav-open:not(.vx-desktop-view) .hospital-app-shell .hospital-sidebar {
        transform: none;
        visibility: visible;
        transition: transform .22s ease-out;
    }
    /* The menu inside looks as on the computer (vitalos.css ≤ 1023 px made it a centred 2-column grid). */
    :root:not(.vx-desktop-view) .hospital-sidebar-nav {
        grid-template-columns: 1fr;
    }
    :root:not(.vx-desktop-view) .hospital-sidebar-link,
    :root:not(.vx-desktop-view) .hospital-sidebar-summary {
        justify-content: flex-start;
        text-align: left;
    }
    :root:not(.vx-desktop-view) .hospital-sidebar-subnav {
        padding-left: 10px;
    }
    :root:not(.vx-desktop-view) .vx-nav-dim {
        position: fixed;
        inset: 0;
        z-index: 69;
        background: rgba(15, 23, 42, 0.38);
    }
    :root.vx-nav-open:not(.vx-desktop-view) body {
        overflow: hidden;
    }

    :root:not(.vx-desktop-view) .hospital-app-content {
        padding: 12px;
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    /* Popups: never wider / taller than the screen; long ones scroll inside, their footer stays in view. */
    :root:not(.vx-desktop-view) dialog:modal {
        max-width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
        overflow: auto;
        overscroll-behavior: contain;
    }
    :root:not(.vx-desktop-view) dialog:modal > footer,
    :root:not(.vx-desktop-view) dialog:modal > form > footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
    }
    :root:not(.vx-desktop-view) .vx-pop {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
    }
    :root:not(.vx-desktop-view) .vx-pp-box {
        width: calc(100vw - 16px);
        height: calc(100dvh - 16px);
    }
}

/* ---------------------------------------------------------------- P1 · phone (≤ 599 px) */
@media (max-width: 599px) {
    :root:not(.vx-desktop-view) .hospital-header-logo {
        padding: 6px 8px;
    }
    :root:not(.vx-desktop-view) .hospital-header-logo img {
        height: 26px;
    }
    :root:not(.vx-desktop-view) .hospital-sidebar-toggle {
        margin-left: 8px;
        width: 36px;
        height: 36px;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-app-hospital-name {
        font-size: 14px;
    }
    :root:not(.vx-desktop-view) .hospital-app-hospital-logo {
        height: 22px;
        max-width: 56px;
    }
    /* The user name stays, shortened. */
    :root:not(.vx-desktop-view) .hospital-user-copy {
        max-width: 72px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    /* The pharmacy store box stays in the header, smaller. */
    :root:not(.vx-desktop-view) .hospital-store-pick label {
        display: none;
    }
    :root:not(.vx-desktop-view) .hospital-store-pick select {
        max-width: 110px;
    }
    :root:not(.vx-desktop-view) .hospital-app-content {
        padding: 10px;
        padding-left: max(10px, env(safe-area-inset-left, 0px));
        padding-right: max(10px, env(safe-area-inset-right, 0px));
    }

    /* Popups as a sheet from the bottom: full width, as tall as needed (up to the full screen). */
    :root:not(.vx-desktop-view) dialog:modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 100dvh;
        margin: auto 0 0;
        border-radius: 14px 14px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    :root:not(.vx-desktop-view) .vx-pop,
    :root:not(.vx-desktop-view) .vx-pop--small,
    :root:not(.vx-desktop-view) .vx-pop--wide {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }
    :root:not(.vx-desktop-view) .vx-pp-box {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
}


/*
 * Phase P2 (lists). responsive.js marks the tables (nothing is marked on a computer):
 *  - table.vx-cards (phone, list tables without typing boxes, "Cards" chosen): every row a card, every column inside it
 *    with its heading as the label (data-label); the heading row stays as small chips, so sorting / "select all" still work;
 *  - table.vx-stick (tablet / phone table view, only when the table is wider than its box): first column (and an Action
 *    column at the end) stay in view while the middle scrolls sideways.
 * Filters of the lists wrap onto more lines on the phone. Nothing is hidden.
 */
@media (max-width: 1279px) {
    :root:not(.vx-desktop-view) table.vx-stick > thead > tr > th:first-child,
    :root:not(.vx-desktop-view) table.vx-stick > tbody > tr > td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
    }
    /* Solid colours (measured by responsive.js), so the scrolling columns never show through. */
    :root:not(.vx-desktop-view) table.vx-stick > thead > tr > th:first-child,
    :root:not(.vx-desktop-view) table.vx-stick-end > thead > tr > th:last-child {
        background-color: var(--vx-head-bg, #f1f5f9);
        background-image: var(--vx-head-img, none);
    }
    :root:not(.vx-desktop-view) table.vx-stick > tbody > tr > td:first-child {
        background-color: var(--vx-row-bg, #fff);
        box-shadow: 1px 0 0 #e2e8f0;
    }
    :root:not(.vx-desktop-view) table.vx-stick-end > thead > tr > th:last-child,
    :root:not(.vx-desktop-view) table.vx-stick-end > tbody > tr > td:last-child {
        position: sticky;
        right: 0;
        z-index: 2;
    }
    :root:not(.vx-desktop-view) table.vx-stick-end > tbody > tr > td:last-child {
        background-color: var(--vx-row-bg, #fff);
        box-shadow: -1px 0 0 #e2e8f0;
    }
    :root:not(.vx-desktop-view) table.vx-stick-end > tbody > tr > td:last-child:has(details[open]),
    :root:not(.vx-desktop-view) table.vx-stick-end > tbody > tr > td:last-child:focus-within {
        z-index: 6;
    }
    :root:not(.vx-desktop-view) .vx-xscroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 599px) {
    /* Cards / Table switch above a list. */
    :root:not(.vx-desktop-view) .vx-listview {
        display: inline-flex;
        margin: 0 0 6px auto;
        border: 1px solid #cbd5e1;
        border-radius: 8px;
        overflow: hidden;
        background: #fff;
        font-size: 12px;
        font-weight: 600;
    }
    :root:not(.vx-desktop-view) .vx-listview-row {
        display: flex;
        justify-content: flex-end;
    }
    :root:not(.vx-desktop-view) .vx-listview button {
        min-height: 32px;
        padding: 0 12px;
        border: 0;
        background: transparent;
        color: #334155;
        font: inherit;
        cursor: pointer;
    }
    :root:not(.vx-desktop-view) .vx-listview button[aria-pressed="true"] {
        background: #0f766e;
        color: #fff;
    }

    /* Card view. */
    :root:not(.vx-desktop-view) table.vx-cards {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        border: 0;
        background: transparent;
        table-layout: auto;
    }
    :root:not(.vx-desktop-view) table.vx-cards > thead,
    :root:not(.vx-desktop-view) table.vx-cards > tbody,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot {
        display: block;
    }
    :root:not(.vx-desktop-view) table.vx-cards > thead > tr {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 6px;
        background: transparent;
    }
    :root:not(.vx-desktop-view) table.vx-cards > thead > tr > th {
        display: block;
        position: static;
        width: auto !important;
        min-width: 0 !important;
        padding: 3px 8px;
        border: 0;
        border-radius: 999px;
        background: #e2e8f0;
        color: #0f172a;
        font-size: 11px;
        white-space: nowrap;
    }
    :root:not(.vx-desktop-view) table.vx-cards > thead > tr > th * {
        color: inherit;
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr {
        display: block;
        margin: 0 0 8px;
        padding: 6px 10px;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        background-color: #fff;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr > td,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > td,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > th {
        display: block;
        position: relative;
        left: auto;
        right: auto;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        min-height: 22px;
        padding: 4px 0 4px 38% !important;
        border: 0;
        border-bottom: 1px dashed #eef2f7;
        text-align: left !important;
        white-space: normal;
        overflow: visible;
        box-shadow: none;
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr > td:last-child,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > td:last-child {
        border-bottom: 0;
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr > td::before,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > td::before,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > th::before {
        content: attr(data-label);
        position: absolute;
        top: 5px;
        left: 0;
        width: calc(38% - 10px);
        color: #64748b;
        font-size: 11.5px;
        font-weight: 600;
        overflow-wrap: anywhere;
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr > td.vx-nolabel,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > td.vx-nolabel {
        padding-left: 0 !important;
    }
    :root:not(.vx-desktop-view) table.vx-cards > tbody > tr > td.vx-nolabel::before,
    :root:not(.vx-desktop-view) table.vx-cards > tfoot > tr > td.vx-nolabel::before {
        display: none;
    }
    /* Cells the screen itself hides stay hidden. */
    :root:not(.vx-desktop-view) table.vx-cards td.vx-was-hidden,
    :root:not(.vx-desktop-view) table.vx-cards th.vx-was-hidden {
        display: none;
    }
    :root:not(.vx-desktop-view) .vx-cards-box {
        overflow: visible;
        border: 0;
        background: transparent;
        max-height: none;
    }

    /* List filters wrap (flex or grid forms alike). */
    :root:not(.vx-desktop-view) .hospital-app-content form[class*="filter"],
    :root:not(.vx-desktop-view) .hospital-app-content form[role="search"] {
        flex-wrap: wrap;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 6px;
    }
    :root:not(.vx-desktop-view) .hospital-app-content form[class*="filter"] > *,
    :root:not(.vx-desktop-view) .hospital-app-content form[role="search"] > * {
        min-width: 0;
        max-width: 100%;
    }
}

/*
 * Phase P4 (care screens, for ward rounds on a tablet): OP Patient Care (Doctor Desk, .cx-*), IP Nursing Desk /
 * IP Patient Care (.pc-*, medicine order .pm-*), Lab result entry, Radiology reporting, Record Discharge Summary.
 * Below 1024 px the page scrolls as one (no boxes scrolling inside boxes) and the Save / Complete bar stays at the
 * bottom of the screen; on the phone the boxes take fewer columns. Same boxes, same buttons, same order.
 */
@media (max-width: 1023px) {
    /* Doctor Desk: one page scroll, footer bar (Save Draft / Print / Complete …) always in view. */
    :root:not(.vx-desktop-view) .cx-page,
    :root:not(.vx-desktop-view) .cx-main {
        overflow: visible;
        min-height: 0;
        height: auto;
    }
    :root:not(.vx-desktop-view) .cx-foot {
        position: sticky;
        bottom: 0;
        z-index: 20;
        flex-wrap: wrap;
        row-gap: 6px;
        padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    }

    /* Medicine order + MAR (Nursing Desk / IP Patient Care): list above, order form below, no fixed height. */
    :root:not(.vx-desktop-view) .pm-grid,
    :root:not(.vx-desktop-view) .pcx .pmx .pm-grid,
    :root:not(.vx-desktop-view).pmx-full .pcx .pmx .pm-grid {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        min-height: 0;
    }
    :root:not(.vx-desktop-view) .pm-pane,
    :root:not(.vx-desktop-view) .pm-body {
        overflow: visible;
        min-height: 0;
    }
    :root:not(.vx-desktop-view) .pcx .pmx .pmx-work,
    :root:not(.vx-desktop-view) .pcx .pmx .pm-card.pmx-work {
        max-height: none;
        overflow: visible;
    }
    :root:not(.vx-desktop-view) .pm-foot,
    :root:not(.vx-desktop-view) .pc-ti .hd,
    :root:not(.vx-desktop-view) .pcx .pmx-tools {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    :root:not(.vx-desktop-view) .pcx .pmx-tabs {
        overflow-x: auto;
        overflow-y: hidden;
    }

    /* Lab result entry / Radiology reporting: panels one under another, the page scrolls. */
    :root:not(.vx-desktop-view) .lab-entry-scroll,
    :root:not(.vx-desktop-view) .lab-param-scroll {
        max-height: none;
    }
    :root:not(.vx-desktop-view) .rad-report {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        min-height: 0;
    }
    /* Lab collection / result entry / approval: the list or result table first, the sample / action panel below it. */
    :root:not(.vx-desktop-view) .lab-split,
    :root:not(.vx-desktop-view) .lab-split--wide,
    :root:not(.vx-desktop-view) .lab-split--even {
        grid-template-columns: minmax(0, 1fr);
    }
    :root:not(.vx-desktop-view) .lab-split input.num {
        min-width: 64px;
    }
}

@media (max-width: 599px) {
    /* Doctor Desk vitals: 3 boxes a row (the computer has 11 / 13), so every value is readable. */
    :root:not(.vx-desktop-view) .cx-vit,
    :root:not(.vx-desktop-view) .cx-vit--child {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    :root:not(.vx-desktop-view) .cx-h {
        flex-wrap: wrap;
        row-gap: 4px;
    }
    :root:not(.vx-desktop-view) .cx-kv--addr {
        max-width: 100%;
    }
    /* Footer bar: the "Started … · Last saved …" line on one short line, the buttons share the width (2 rows at most). */
    :root:not(.vx-desktop-view) .cx-foot {
        gap: 6px;
        padding: 6px 8px max(6px, env(safe-area-inset-bottom, 0px));
    }
    :root:not(.vx-desktop-view) .cx-foot .info {
        flex: 1 1 60%;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 11px;
    }
    :root:not(.vx-desktop-view) .cx-foot .sp {
        flex: 0 0 0;
    }
    :root:not(.vx-desktop-view) .cx-foot .cx-fb {
        flex: 1 1 auto;
        justify-content: center;
    }
    :root:not(.vx-desktop-view) .cx-foot .cx-fb--icon {
        flex: 0 0 auto;
    }

    /* Label / value lists (visit notes, details): a narrower label column instead of a fixed wide one. */
    :root:not(.vx-desktop-view) .hospital-app-content dl {
        grid-template-columns: minmax(84px, 38%) minmax(0, 1fr);
    }

    /* Medicine hours: 6 a row, big enough to tap. */
    :root:not(.vx-desktop-view) .pm-hgrid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 5px;
    }
    :root:not(.vx-desktop-view) .pm-h span {
        height: 36px;
    }
    :root:not(.vx-desktop-view) .pm-reason {
        flex: 1 1 100%;
        flex-wrap: wrap;
    }
    :root:not(.vx-desktop-view) .pm-reason input {
        min-width: 0;
        width: 100%;
    }

    /* Record Discharge Summary: vitals 2 a row, follow-up one column (vitalos does 4 / 3 columns). */
    :root:not(.vx-desktop-view) .dsr-vt,
    :root:not(.vx-desktop-view) .ds-view .vt {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    :root:not(.vx-desktop-view) .dsr-fu,
    :root:not(.vx-desktop-view) .dsc-row {
        grid-template-columns: minmax(0, 1fr);
    }
}

/*
 * Phase P3 (forms): OPD Registration, IP Admission, Edit Details, Add / Edit masters (popups), Hospital Details,
 * Configuration. Most of these already fold to one or two columns below 1024 px (vitalos.css / screen CSS); here only
 * what is still too tight on a phone. Same boxes, same order, same buttons.
 */
@media (max-width: 599px) {
    /* Patient Identity (OPD Registration / IP Admission / Edit details): photo first, then each box full width. */
    :root:not(.vx-desktop-view) .opd3-g:has(.opd3-identity) {
        grid-template-columns: minmax(0, 1fr);
    }
    :root:not(.vx-desktop-view) .opd3-g:has(.opd3-identity) > *,
    :root:not(.vx-desktop-view) .opd3-g:has(.opd3-identity) .opd3-identity > * {
        grid-column: 1 / -1;
    }
    /* "Existing Patient" search: the full width, so a UHID / name / mobile can be typed. */
    :root:not(.vx-desktop-view) .ph-search-strip.opd3-search {
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
    }
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any {
        display: flex;
        flex: 1 1 100%;
        width: 100%;
        max-width: none;
    }
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any .ph5-any {
        flex: 1 1 auto;
        min-width: 0;
    }
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any .hospital-input {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 1023px) {
    /* "Existing Patient" search on a standing tablet too (the computer keeps its compact box). */
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any {
        flex: 1 1 320px;
        max-width: none;
    }
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any .ph5-any {
        flex: 1 1 auto;
        min-width: 0;
    }
    :root:not(.vx-desktop-view) .ph5 .ph5-field--any .hospital-input {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 599px) {
    /* Add / Edit master forms (also inside the Add / Edit popups): one box a line on the phone. */
    :root:not(.vx-desktop-view) .dm-grid,
    :root:not(.vx-desktop-view) .dm-cols,
    :root:not(.vx-desktop-view) .ed-grid,
    :root:not(.vx-desktop-view) .dd-grid,
    :root:not(.vx-desktop-view) .ob-grid,
    :root:not(.vx-desktop-view) .ipa-policy-grid,
    :root:not(.vx-desktop-view) .service-edit-grid,
    :root:not(.vx-desktop-view) .ncr-grid,
    :root:not(.vx-desktop-view) .ps-grid,
    :root:not(.vx-desktop-view) .ph-grid,
    :root:not(.vx-desktop-view) .hospital-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    :root:not(.vx-desktop-view) .dm-grid > *,
    :root:not(.vx-desktop-view) .dm-cols > *,
    :root:not(.vx-desktop-view) .ed-grid > *,
    :root:not(.vx-desktop-view) .dd-grid > *,
    :root:not(.vx-desktop-view) .hospital-form-grid > * {
        grid-column: 1 / -1;
        min-width: 0;
    }
}

@media (max-width: 1023px) {
    /* vitalos.css (≤ 1023 px) stacks every .hospital-field label; a radio / tick box keeps its text beside it. */
    :root:not(.vx-desktop-view) .hospital-field label:has(> input[type="radio"]),
    :root:not(.vx-desktop-view) .hospital-field label:has(> input[type="checkbox"]) {
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }
    :root:not(.vx-desktop-view) .dm-titles {
        flex-wrap: wrap;
    }
}

/*
 * Phase P5 (bills & reports): OP Bill, IP Partial / Final Bill, Bill Audit, Pharmacy Sale, GRN / PO (entry grids keep
 * every column and scroll sideways; responsive.js marks the name column .vx-scell and a Delete column .vx-ecell while
 * the grid is wider than its box), Dashboard, OP/IP Reports, GST. Calculations, rights and buttons are untouched.
 */
@media (max-width: 1279px) {
    :root:not(.vx-desktop-view) table .vx-scell {
        position: sticky;
        left: 0;
        z-index: 2;
        background-color: var(--vx-row-bg, #fff);
        box-shadow: 1px 0 0 #e2e8f0;
    }
    :root:not(.vx-desktop-view) table .vx-ecell {
        position: sticky;
        right: 0;
        z-index: 2;
        background-color: var(--vx-row-bg, #fff);
        box-shadow: -1px 0 0 #e2e8f0;
    }
    :root:not(.vx-desktop-view) table th.vx-scell,
    :root:not(.vx-desktop-view) table th.vx-ecell {
        background-color: var(--vx-head-bg, #f1f5f9);
        background-image: var(--vx-head-img, none);
        z-index: 7;
    }
    /* A name box being typed in (its suggestion list) stays above the other cells. */
    :root:not(.vx-desktop-view) table .vx-scell:focus-within {
        z-index: 8;
    }
}

@media (max-width: 1023px) {
    /* Reports / long lists: the page scrolls, not a short box inside it. */
    :root:not(.vx-desktop-view) .report-table-scroll,
    :root:not(.vx-desktop-view) .hospital-app-content:has(.ph-report-tabs) .report-table-scroll,
    :root:not(.vx-desktop-view) .ins-scroll,
    :root:not(.vx-desktop-view) .ins-scroll--report {
        max-height: none;
    }
    :root:not(.vx-desktop-view) .ins-two > .ot-col,
    :root:not(.vx-desktop-view) .ins-two > section.ot-card,
    :root:not(.vx-desktop-view) .ins-corp > .ot-col {
        max-height: none;
    }
}

@media (max-width: 599px) {
    /* Dashboard: tiles 2 a row, ward lines with a shorter name column. */
    :root:not(.vx-desktop-view) .dsh-tile {
        flex-basis: calc(50% - 6px);
        min-width: 0;
    }
    :root:not(.vx-desktop-view) .dsh-ward {
        grid-template-columns: 80px minmax(0, 1fr) 48px;
        gap: 6px;
    }
}

@media (max-width: 1023px) {
    /* Pharmacy workspaces (GRN / PO, Sale, Returns, Adjustment, GST, stock screens) and the ledgers: no fixed screen
       height, the page scrolls; the entry grid keeps its own sideways scroll. */
    :root:not(.vx-desktop-view) .pw,
    :root:not(.vx-desktop-view) .ps,
    :root:not(.vx-desktop-view) .pr,
    :root:not(.vx-desktop-view) .prx,
    :root:not(.vx-desktop-view) .pam,
    :root:not(.vx-desktop-view) .ap2,
    :root:not(.vx-desktop-view) .gst,
    :root:not(.vx-desktop-view) .sst-cmp,
    :root:not(.vx-desktop-view) .sl .sst-cmp,
    :root:not(.vx-desktop-view) .pso-grid {
        height: auto;
        min-height: 0;
    }
    :root:not(.vx-desktop-view) .pw-head,
    :root:not(.vx-desktop-view) .pw > .pw-head {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    :root:not(.vx-desktop-view) .pw-hdr,
    :root:not(.vx-desktop-view) .pam-hdr {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    :root:not(.vx-desktop-view) .ps-paytop,
    :root:not(.vx-desktop-view) .ps-kv,
    :root:not(.vx-desktop-view) .pam-kv {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 599px) {
    :root:not(.vx-desktop-view) .pw-hdr,
    :root:not(.vx-desktop-view) .pam-hdr {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    :root:not(.vx-desktop-view) .pw-hdr > :first-child,
    :root:not(.vx-desktop-view) .pam-hdr > :first-child {
        grid-column: 1 / -1;
    }
    :root:not(.vx-desktop-view) .pw-bottom,
    :root:not(.vx-desktop-view) .pw-sum,
    :root:not(.vx-desktop-view) .pw-kv,
    :root:not(.vx-desktop-view) .ap2-kv {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 599px) {
    /* Header on the phone: when the right side (store box, bells, user) does not fit, it goes to a second line
       instead of squeezing the logo or running off the screen. */
    :root:not(.vx-desktop-view) .hospital-app-header--brand {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-header-logo {
        flex: none;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-app-hospital {
        flex: 1 1 0;
        min-width: 60px;
    }
    :root:not(.vx-desktop-view) .hospital-app-header--brand .hospital-header-tools {
        flex: 0 1 auto;
        flex-wrap: wrap;
        justify-content: flex-end;
        margin-left: auto;
        max-width: 100%;
    }
    /* Workspace action bars (Cancel / Save Draft / Post …): buttons wrap instead of running off the screen. */
    :root:not(.vx-desktop-view) .pw-actbar,
    :root:not(.vx-desktop-view) [class*="-actbar"] {
        flex-wrap: wrap;
        row-gap: 6px;
    }
}

/*
 * P5 check 21-11 (OP Bill, Pharmacy Sale, Dashboard dumps at 390 / 820 / 1180): the Pharmacy Sale title line
 * (Indent, Return, Drafts, Sale List, DC List, Shortcuts, Store) and the Customer / Document type line wrap instead of
 * being cut at the right; the bottom (payment lines + Bill Summary + Settlement) grows with its content.
 */
@media (max-width: 1279px) {
    :root:not(.vx-desktop-view) .ps .ps-head {
        flex-wrap: wrap;
        row-gap: 6px;
    }
}

@media (max-width: 1023px) {
    :root:not(.vx-desktop-view) .ps .ps-mode,
    :root:not(.vx-desktop-view) .ps .ps-payfoot {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    :root:not(.vx-desktop-view) .ps .ps-bottom {
        height: auto;
    }
}

@media (max-width: 599px) {
    /* Pharmacy Sale on the phone: patient boxes two per line (the first one full width), the bottom cards one
       under the other. */
    :root:not(.vx-desktop-view) .ps .ps-cust[data-for] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    :root:not(.vx-desktop-view) .ps .ps-cust[data-for] > :first-child {
        grid-column: 1 / -1;
    }
    :root:not(.vx-desktop-view) .ps .ps-bottom {
        grid-template-columns: minmax(0, 1fr);
    }
    /* OP Bill: the Patient search box fits the card (it was 300 px beside its label) and its result list stays on
       the screen. */
    :root:not(.vx-desktop-view) .opb .ob-search.ob-search--one {
        flex-wrap: wrap;
        width: 100%;
        margin: 0;
        white-space: normal;
    }
    :root:not(.vx-desktop-view) .opb .ob-search--one .opb-q {
        flex: 1 1 200px;
        width: auto;
    }
    :root:not(.vx-desktop-view) .opb .ob-search--one .ob-results {
        right: 0;
        width: auto;
    }
    /* OP / OPD Billing / credit note lists: date, search and doctor boxes go on two lines instead of being squeezed. */
    :root:not(.vx-desktop-view) .opl7 .opl7-left {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    :root:not(.vx-desktop-view) .opl7 .opl7-left > * {
        flex: 1 1 150px;
        min-width: 0;
    }
    /* List filters whose columns are set on the form itself (Sale List …): same wrapping as the other filters. */
    :root:not(.vx-desktop-view) .hospital-app-content form[class*="filter"][style*="grid-template-columns"] {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    }
}

/*
 * Sign-in screens (login, two-step code, forgot password, "Already signed in"; owner 21-11-2026 "login screen bhi"):
 * below 1024 px the blue welcome block becomes a short band above the sign-in card, so the boxes are on the first
 * screen of a tablet / phone; the card keeps its full width inside the screen. Same text, boxes and buttons.
 */
@media (max-width: 1023px) {
    :root:not(.vx-desktop-view) .auth-login {
        grid-template-columns: minmax(0, 1fr);
        width: min(640px, calc(100% - 32px));
        height: auto;
        min-height: 0;
        margin: 16px auto;
    }
    :root:not(.vx-desktop-view) .auth-login-brand {
        gap: 8px;
        padding: 20px 24px;
    }
    :root:not(.vx-desktop-view) .auth-login-logo {
        width: 200px;
    }
    :root:not(.vx-desktop-view) .auth-login-brand h1,
    :root:not(.vx-desktop-view) .auth-login-brand h1.auth-login-title {
        margin-top: 4px;
        font-size: 1.2rem;
    }
    :root:not(.vx-desktop-view) .auth-login-lead {
        font-size: 13px;
    }
    :root:not(.vx-desktop-view) .auth-login-panel {
        padding: 22px 24px;
    }
    :root:not(.vx-desktop-view) .auth-login-card {
        max-width: 420px;
        min-width: 0;
    }
    :root:not(.vx-desktop-view) .auth-login-label {
        flex-wrap: wrap;
        gap: 2px 8px;
    }
}

@media (max-width: 599px) {
    :root:not(.vx-desktop-view) .auth-login {
        width: 100%;
        min-height: 100dvh;
        margin: 0;
        border-radius: 0;
        border: 0;
    }
    :root:not(.vx-desktop-view) .auth-login-brand {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top, 0px));
    }
    :root:not(.vx-desktop-view) .auth-login-logo {
        width: 140px;
        padding: 6px 10px;
    }
    :root:not(.vx-desktop-view) .auth-login-brand h1,
    :root:not(.vx-desktop-view) .auth-login-brand h1.auth-login-title {
        font-size: 1.05rem;
    }
    :root:not(.vx-desktop-view) .auth-login-lead {
        font-size: 12px;
    }
    :root:not(.vx-desktop-view) .auth-login-panel {
        justify-content: flex-start;
        padding: 18px 16px;
        padding-bottom: max(18px, env(safe-area-inset-bottom, 0px));
    }
    /* 16 px text in the boxes: phones do not zoom in when a box is tapped. */
    :root:not(.vx-desktop-view) .auth-login-input input {
        font-size: 16px;
    }
}
