/* Shared phone/tablet presentation. Desktop data and printed documents keep their layout. */
.dpr-responsive { min-width: 0; }
.dpr-responsive .table-responsive { max-width: 100%; }
.dpr-mobile-roworder { display: none; }

@media screen and (max-width: 991.98px) {
    /* The template hides .user-menu entirely at this breakpoint. Keep search, branch and
       account access available in two rows, with secondary actions in the account menu. */
    .dpr-app > .header { height: 110px; }
    .dpr-app .header .main-header {
        display: grid; grid-template-columns: 44px minmax(0, 1fr) auto;
        grid-template-rows: 44px 44px; gap: 6px; padding: 8px 12px;
    }
    .dpr-app .header .header-left { display: none !important; }
    .dpr-app .header #mobile_btn {
        display: flex; position: static; grid-column: 1; grid-row: 1;
        align-items: center; justify-content: center; width: 44px; height: 44px;
        border: 0; border-radius: 8px; background: transparent; margin: 0; padding: 8px;
    }
    .dpr-app .header .header-user, .dpr-app .header .header-user .user-menu { display: contents; }
    .dpr-app .header .header-search { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; margin: 0 !important; }
    .dpr-app .header .dpr-header-actions { grid-column: 3; grid-row: 1; gap: 2px; }
    .dpr-app .header .dpr-header-extra { display: none; }
    .dpr-app .header .dpr-header-actions :is(.btn-menubar, .dropdown-toggle, .dpr-support) {
        min-width: 36px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; margin: 0;
    }
    .dpr-app .header .dpr-branchswitch { grid-column: 2; grid-row: 1; min-width: 0; width: 100%; max-width: 260px; margin: 0; }
    .dpr-app .header .dpr-branchswitch .form-select { min-width: 0; width: 100%; min-height: 44px; font-size: 14px; padding-left: 24px; }
    .dpr-app .header .dpr-omni { width: 100%; max-width: none; }
    .dpr-app .header .dpr-omni .form-control { height: 44px; font-size: 16px; }
    .dpr-app .header .dpr-omni__panel { max-width: 100%; max-height: calc(100dvh - 124px); overflow-y: auto; }
    .dpr-app .header .dropdown-menu { min-width: 0 !important; width: min(340px, calc(100vw - 24px)); max-width: calc(100vw - 24px); max-height: calc(100dvh - 64px); overflow-y: auto; }
    .dpr-app .header .dropdown-item { min-height: 44px; align-items: center; white-space: normal; }
    .dpr-app > .page-wrapper { margin-left: 0 !important; padding-top: 110px; min-width: 0; }
    .dpr-app .sidebar { top: 0; height: 100dvh; width: min(280px, 85vw); margin-left: -100vw; z-index: 1045; }
    .dpr-app.slide-nav .sidebar { margin-left: 0; }
    .dpr-app .sidebar .sidebar-inner { height: calc(100dvh - 60px); padding-bottom: env(safe-area-inset-bottom); }
    .sidebar-overlay.opened { z-index: 1040; }
    .dpr-app #sidebar-menu a { min-height: 44px; }
    .dpr-responsive .row > * { min-width: 0; }
    .dpr-responsive :is(.card, .card-body, .card-header, .card-footer, .dpr-profile__id) { min-width: 0; }
    .dpr-responsive .table-responsive { overscroll-behavior-x: contain; }
    .dpr-responsive :is(.dpr-visit-section, [id^="reception-"], #dpr-template-editor, #dpr-template-document) { scroll-margin-top: 124px; }
}

@media screen and (max-width: 767.98px) {
    .dpr-app .page-wrapper > .content { padding: 12px; min-height: calc(100dvh - 160px); }
    .dpr-app .footer { padding: 16px 12px !important; overflow-wrap: anywhere; }
    .dpr-portal__bar { gap: 12px; padding: 12px; flex-wrap: wrap; }
    .dpr-portal__brand, .dpr-portal__user { min-width: 0; max-width: 100%; }
    .dpr-portal__brand { flex-wrap: wrap; }
    .dpr-portal__nav { order: 3; width: 100%; max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .dpr-portal__link { min-height: 44px; flex-shrink: 0; }
    .dpr-portal__body { padding: 12px; min-width: 0; }
    .dpr-responsive :is(.form-control, .form-select, .input-group-text) { min-height: 44px; min-width: 0; max-width: 100%; font-size: 16px; }
    .dpr-responsive :is(input[type="date"], input[type="datetime-local"], input[type="time"]) { max-width: 100%; }
    .dpr-responsive .btn { min-height: 44px; white-space: normal; }
    .dpr-responsive .btn:is(.btn-sm, .btn-icon) { min-width: 44px; }
    .dpr-responsive .btn-close { min-width: 36px; min-height: 36px; padding: 8px; }
    .dpr-responsive .input-group { min-width: 0; flex-wrap: nowrap; }
    .dpr-responsive .input-group > .btn { flex-shrink: 0; }
    .dpr-responsive :is(.card-header, .card-footer) { flex-wrap: wrap; gap: 10px; }
    .dpr-responsive .card-header > :is(.d-flex, .dpr-search-inline) { min-width: 0; max-width: 100%; }
    .dpr-responsive .card-header .dpr-search-inline { width: 100%; }
    .dpr-responsive .card-header > .form-select { width: 100% !important; }
    .dpr-responsive .dpr-page-head { flex-wrap: wrap; align-items: stretch; gap: 12px; }
    .dpr-responsive .dpr-page-head > * { min-width: 0; max-width: 100%; }
    .dpr-responsive .dpr-page-head > .d-flex { width: 100%; }
    .dpr-responsive .dpr-page-head .btn { flex: 1 1 auto; justify-content: center; }
    .dpr-responsive .dpr-segmented { display: flex; flex-wrap: wrap; max-width: 100%; }
    .dpr-responsive .dpr-segmented__btn { min-height: 44px; flex: 1 1 auto; white-space: normal; }
    .dpr-responsive :is(.dpr-rte__toolbar, .dpr-rte__group) { display: flex; flex-wrap: wrap; max-width: 100%; }
    .dpr-responsive .dpr-rte__group .form-select { flex: 1 1 80px; min-width: 0; max-width: 100%; }
    .dpr-responsive .dpr-rte__editor { max-width: 100%; overflow-x: auto; overflow-wrap: anywhere; }
    .dpr-responsive :is(.nav-tabs, .nav-pills) { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
    .dpr-responsive :is(.nav-tabs, .nav-pills) .nav-item { flex-shrink: 0; }
    .dpr-responsive .nav-link { min-height: 44px; white-space: nowrap; }
    .dpr-responsive .dpr-profile { flex-wrap: wrap; gap: 12px; }
    .dpr-responsive .dpr-profile__id { flex: 1 1 180px; overflow-wrap: anywhere; }
    .dpr-responsive .dpr-profile__actions { width: 100%; max-width: none; flex-wrap: wrap; }
    .dpr-responsive .dpr-profile__actions .btn { flex: 1 1 130px; justify-content: center; }
    .dpr-responsive :is(.breadcrumb, .dpr-barcode) { overflow-wrap: anywhere; white-space: normal; }
    .dpr-responsive .dpr-steps { flex-wrap: wrap; gap: 14px 4px; }
    .dpr-responsive .dpr-steps__item { flex: 0 0 calc(33.333% - 4px); min-width: 0; }
    .dpr-responsive .dpr-steps__item::before { display: none; }
    .dpr-responsive .dpr-steps__label { white-space: normal; overflow-wrap: anywhere; }
    .dpr-responsive .dpr-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .dpr-responsive .dpr-stat { min-width: 0; flex-wrap: wrap; padding: 12px; }
    .dpr-responsive .dpr-stat__value { overflow-wrap: anywhere; font-size: 20px; }
    .dpr-responsive .dpr-stat__label { white-space: normal; }
    .dpr-responsive :is(.dpr-cal__head, .dpr-cal__grid) { grid-template-columns: repeat(7, minmax(0, 1fr)); }
    .dpr-responsive .dpr-cal__cell { min-width: 0; min-height: 80px; padding: 4px; }
    .dpr-responsive :is(.dpr-cal__count, .dpr-cal__late) { max-width: 100%; min-width: 0; padding: 3px; font-size: 11px; overflow-wrap: anywhere; white-space: normal; }
    .dpr-responsive .dpr-pager { flex-wrap: wrap; align-items: stretch; gap: 12px; padding: 12px; }
    .dpr-responsive .dpr-pager > * { max-width: 100%; }
    .dpr-responsive .dpr-pager nav { overflow-x: auto; }
    .dpr-responsive .pagination .page-link { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
    .dpr-responsive :is(.dpr-rowactions, .dpr-grouphead__actions) { flex-wrap: wrap; }
    .dpr-responsive .dpr-rowactions .btn { width: auto; min-width: 44px; height: auto; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .dpr-responsive .dpr-grouphead { flex-wrap: wrap; gap: 10px; }
    .dpr-responsive .dpr-grouphead__id { flex: 1 1 calc(100% - 60px); }
    .dpr-responsive .dpr-grouphead__id .text-truncate { white-space: normal; }
    .dpr-responsive .dpr-grouphead__toggle { width: 44px; height: 44px; }
    .dpr-responsive .dpr-grouphead__progress { width: 100%; flex: 1 1 100%; }
    .dpr-responsive .dpr-grouphead__actions { width: 100%; }
    .dpr-responsive .dpr-grouphead__actions .btn { width: 100%; justify-content: center; }
    .dpr-responsive .dpr-recv-band { flex-wrap: wrap; gap: 8px; }
    .dpr-responsive .dpr-recv-band__id { flex: 1 1 calc(100% - 100px); }
    .dpr-responsive .dpr-recv-band__id .text-truncate { white-space: normal; }
    .dpr-responsive .dpr-recv-band__toggle { min-width: 44px; min-height: 44px; }
    .dpr-responsive .dpr-recv-bar { flex-wrap: wrap; position: sticky; bottom: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); z-index: 10; }
    .dpr-responsive .dpr-recv-bar .btn { flex: 1 1 auto; }
    .dpr-mobile-roworder { display: flex; flex-wrap: wrap; gap: 6px; }
    .dpr-responsive [data-testid="reorder-hint"] { display: none; }
    .dpr-responsive td.dpr-col-drag > .dpr-draghandle { display: none; }
    .dpr-responsive td.dpr-col-drag:not(:has(.dpr-mobile-roworder)) { display: none; }

    /* Progressive list cards: headers are their source of truth. Sortable headers remain
       visible as a touch-sized sort strip; grouped/detail/empty rows remain full width. */
    table[data-mobile-layout="cards"], table[data-mobile-layout="cards"] > :is(tbody, tfoot) { display: block; width: 100%; min-width: 0 !important; }
    table[data-mobile-layout="cards"] > thead { display: none; }
    table[data-mobile-layout="cards"] > thead[data-mobile-sort="true"] { display: block; padding: 8px; border-bottom: 1px solid var(--border-color, #e2e4e6); }
    table[data-mobile-layout="cards"] > thead > tr { display: flex; flex-wrap: wrap; gap: 4px; }
    table[data-mobile-layout="cards"] > thead th { display: none; }
    table[data-mobile-layout="cards"] > thead th[data-mobile-sort="true"] { display: inline-flex; align-items: center; min-height: 44px; width: auto !important; min-width: 0 !important; padding: 8px 10px; white-space: normal; }
    table[data-mobile-layout="cards"] > :is(tbody, tfoot) > tr { display: block; width: auto; }
    table[data-mobile-layout="cards"] > tbody > tr[data-mobile-row="item"] { margin: 10px; border: 1px solid var(--border-color, #e2e4e6); border-radius: 10px; }
    table[data-mobile-layout="cards"] > :is(tbody, tfoot) > tr > :is(td, th) {
        display: block; position: relative; width: 100% !important; min-width: 0 !important;
        min-height: 42px; padding: 10px 12px 10px 106px !important; text-align: left !important;
        white-space: normal !important; overflow-wrap: anywhere; border-bottom: 1px solid var(--border-color, #e2e4e6);
    }
    table[data-mobile-layout="cards"] [data-mobile-label]::before { content: attr(data-mobile-label); position: absolute; left: 12px; top: 10px; width: 82px; font-size: 12px; font-weight: 600; color: var(--gray-600, #657582); }
    table[data-mobile-layout="cards"] [data-mobile-primary="true"],
    table[data-mobile-layout="cards"] [data-mobile-label=""],
    table[data-mobile-layout="cards"] tr[data-mobile-row="band"] > td { padding: 12px !important; }
    table[data-mobile-layout="cards"] [data-mobile-primary="true"]::before { position: static; display: block; width: auto; margin-bottom: 6px; }
    table[data-mobile-layout="cards"] [data-mobile-label=""]::before { display: none; }
    table[data-mobile-layout="cards"] td:last-child { border-bottom: 0; }
    table[data-mobile-layout="cards"] td .text-truncate { white-space: normal; overflow-wrap: anywhere; }
    table[data-mobile-layout="cards"] td :is(.d-flex, .d-inline-flex) { flex-wrap: wrap; min-width: 0; max-width: 100%; }
    table[data-mobile-layout="cards"] td :is(.badge, code) { white-space: normal; overflow-wrap: anywhere; }
    table[data-mobile-layout="scroll"] { display: block; width: 100%; min-width: 0 !important; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }

    /* Dialogs use the visible phone viewport, including when the keyboard is open. */
    .dpr-responsive .modal-dialog { width: 100%; max-width: none !important; margin: 0; min-height: 100dvh; align-items: stretch; }
    .dpr-responsive .modal-content { max-height: 100dvh; min-height: 100dvh; border-radius: 0; }
    .dpr-responsive .modal-content > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
    .dpr-responsive .modal-body { overflow-y: auto; min-height: 0; overscroll-behavior-y: contain; }
    .dpr-responsive .modal-footer { flex-shrink: 0; gap: 8px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .dpr-responsive .modal-footer > .btn { flex: 1 1 120px; margin: 0; }
}

/* ============================================================
   Laptop / desktop wide tables (768px and up, e.g. 1366 × 768)
   ------------------------------------------------------------
   A list with many columns is wider than a laptop screen. Its row actions stay pinned
   to the right edge, a patient band stays inside the visible part of the scroll box,
   and dpr-mobile.js adds a floating scrollbar at the bottom of the window — so nobody
   has to scroll to the end of the table to reach the actions or to scroll sideways.
   ============================================================ */
@media screen and (min-width: 768px) {
    /* Row actions: pinned to the right of the scroll box. */
    .dpr-responsive .table-responsive > .table:has(> tbody > tr > td:last-child > .dpr-rowactions) > thead > tr > th:last-child,
    .dpr-responsive .table-responsive > .table > tbody > tr > td:last-child:has(> .dpr-rowactions) {
        position: sticky;
        right: 0;
        z-index: 2;
    }
    .dpr-responsive .table-responsive > .table > tbody > tr > td:last-child:has(> .dpr-rowactions) {
        background-color: var(--white, #fff);
    }
    .dpr-responsive .table-responsive > .table:has(> tbody > tr > td:last-child > .dpr-rowactions) > thead > tr > th:last-child {
        background-color: var(--white, #fff);
    }
    .dpr-responsive .table-responsive > .dpr-table:has(> tbody > tr > td:last-child > .dpr-rowactions) > thead > tr > th:last-child {
        background-color: #F7FAFB;
    }
    /* A coloured status row keeps its colour under the pinned cell (the tint is see-through). */
    .dpr-responsive .table-responsive > .table > tbody > tr.dpr-statusrow--tint > td:last-child:has(> .dpr-rowactions) {
        background: linear-gradient(var(--dpr-status-tint), var(--dpr-status-tint)), var(--white, #fff) !important;
    }
    /* The edge shadow only when the table is actually wider than its box. */
    .dpr-responsive .table-responsive[data-overflowing="true"] > .table > tbody > tr > td:last-child:has(> .dpr-rowactions),
    .dpr-responsive .table-responsive[data-overflowing="true"] > .table:has(> tbody > tr > td:last-child > .dpr-rowactions) > thead > tr > th:last-child {
        box-shadow: -10px 0 12px -10px rgba(15, 23, 42, .28);
    }

    /* Patient band (grouped lists): stays the width of the visible box, so its buttons
       ("New Visit", "Enter Results", …) never sit off-screen with the far columns. */
    .dpr-responsive .table-responsive:has(> .dpr-grouped) { container-type: inline-size; }
    .dpr-responsive .table-responsive > .dpr-grouped > tbody > .dpr-grouprow > td > .dpr-grouphead {
        position: sticky;
        left: 16px;
        width: calc(100cqi - 32px);
        max-width: calc(100cqi - 32px);
        box-sizing: border-box;
    }
    .dpr-responsive .table-responsive > .dpr-grouped > tbody > tr[data-testid="group-more"] > td > a {
        position: sticky;
        left: 16px;
    }

    /* Floating horizontal scrollbar (created by dpr-mobile.js, one for the page). */
    .dpr-hscroll {
        position: fixed;
        bottom: 0;
        z-index: 1035;
        height: 18px;
        overflow-x: scroll;
        overflow-y: hidden;
        background: var(--white, #fff);
        border-top: 1px solid var(--border-color, #E2E4E6);
        box-shadow: 0 -4px 12px rgba(15, 23, 42, .08);
        border-radius: 6px 6px 0 0;
        display: none;
    }
    .dpr-hscroll.is-shown { display: block; }
    .dpr-hscroll > div { height: 1px; }
}

/* Laptop widths: a little tighter so more lists fit without scrolling at all. */
@media screen and (min-width: 768px) and (max-width: 1599.98px) {
    .dpr-responsive .dpr-table > tbody td { font-size: 13px; }
    .dpr-responsive .dpr-table--dense > thead th,
    .dpr-responsive .dpr-table--dense > tbody td {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
    .dpr-responsive .dpr-table > tbody td.dpr-col-clip { max-width: 150px; }
}

@media print {
    .dpr-hscroll { display: none !important; }
}
