/* ==========================================================================
   rt-responsive.css — PHONE AND TABLET PRODUCTION PASS (10-Oct-2026)
   --------------------------------------------------------------------------
   Loaded LAST on every app page (templates/layouts/base.html, after the
   page's own extra_css), so the rules here are the final word for phones and
   tablets without having to out-guess each page stylesheet's specificity.

   Found by an audit of all 63 screens and 28 dialogs at four device sizes
   (iPhone 390x844 and 844x390, iPad 820x1180 and 1180x820, touch emulated)
   against a copy of the live data. Report:
   docs/reviews/responsive_production_pass_v1.md.

   Breakpoints are the project's three, unchanged:
     phone   max-width: 767px
     drawer  (max-width: 1024px), (pointer: coarse) and (max-width: 1366px)
     touch   pointer: coarse   (sizing only, any width)
   Nothing here applies to a desktop with a mouse.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1 · THE SHELL USES THE VISIBLE SCREEN HEIGHT
   .main-content owns the page scroll and was 100vh tall. On iPhone and iPad
   Safari 100vh is the height WITH the address and tab bars hidden; because
   the document itself never scrolls, those bars never hide, so the bottom of
   every screen (last rows, Save and Approve buttons) sat underneath Safari's
   toolbar and could not be scrolled into view. dvh is the visible height.
   -------------------------------------------------------------------------- */
@supports (height: 100dvh) {
    .app-layout { min-height: 100dvh; }
    .main-content { height: 100dvh; }
}


/* --------------------------------------------------------------------------
   2 · TOUCH SCREENS: NO FOCUS ZOOM, NO TAP DELAY, 40px FIELDS
   iOS zooms the whole page in when a field under 16px takes focus and does
   not zoom back out, which leaves every screen shifted sideways and cropped
   after the first search or filter. 37 screens had such fields (Email
   Notifications had 60). 16px on touch screens stops it at the source.
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
    body[data-ds="rt"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):not([type="color"]),
                           select,
                           textarea) {
        font-size: 16px !important;
    }
    body[data-ds="rt"] :is(a, button, summary, label, input, select, textarea, [role="button"], [tabindex]) {
        touch-action: manipulation;
    }
}
@media (pointer: coarse), (max-width: 900px) {
    /* A text field or dropdown is never shorter than the 40px tap floor.
       Approvals' search box measured 22px tall at every touch size. */
    body[data-ds="rt"] .main-content :is(input:is([type="text"], [type="search"], [type="email"], [type="number"], [type="tel"], [type="url"], [type="password"], [type="date"], :not([type])),
                                         select:not([multiple])):not(.flatpickr-calendar *) {
        min-height: 40px;
        box-sizing: border-box;
    }
    /* Link-styled buttons (Payroll "how this works") were 21px tall. */
    body[data-ds="rt"] .pay-linkish {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
    }
}
@media (pointer: coarse) {
    /* Drawer menu rows: 36px -> 44px. */
    body[data-ds="rt"] .sidebar .nav-item {
        min-height: 44px;
    }
    /* Dialog close buttons were drawn as 17px glyphs on some dialogs. */
    body[data-ds="rt"] :is(.paw-close, .hodv-close, .inw-close, .modal-close-btn) {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    /* Dialogs and the drawer keep their scroll to themselves instead of
       dragging the page underneath. */
    body[data-ds="rt"] :is(.modal-overlay, .modal-body, .slide-panel, .eap-ov, .eap-panelbox, .sidebar-nav) {
        overscroll-behavior: contain;
    }
}


/* --------------------------------------------------------------------------
   3 · ONE PAGE TITLE ON TABLETS TOO
   Phones already hide the page heading because the top bar carries the
   title (C8, rt-masters.css). Tablets use the same drawer and the same top
   bar, so every iPad screen printed its title twice, one under the other.
   The heading stays in the page for screen readers.
   -------------------------------------------------------------------------- */
@media (max-width: 1024px), (pointer: coarse) and (max-width: 1366px) {
    body[data-ds="rt"] .content-header h1.content-header-title {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        clip-path: inset(50%) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }
    /* With the heading gone, a left block that held only the heading must
       not keep a flex row (or a row gap) of its own. */
    body[data-ds="rt"] .content-header > .content-header-left:not(:has(> :not(h1.content-header-title))) {
        flex: 0 0 0 !important;
        min-width: 0;
        margin: 0;
        padding: 0;
    }
    /* ...and the controls then start at the left edge (after a Back link
       when the screen has one), like on a phone, with the notification bell
       kept at the far right. Right-aligned controls beside an empty left
       half read as a layout fault. */
    body[data-ds="rt"] .content-header > .content-header-right {
        flex: 1 1 auto;
        margin-left: 0;
        justify-content: flex-start;
    }
    body[data-ds="rt"] .content-header > .content-header-right > .theme-controls {
        margin-left: auto;
    }
    /* Header dropdowns size to their text. Bell Curve Review's tablet rule
       lifts their max-width, and the base `select { width: 100% }` then
       stretched both dropdowns across the whole 1100px header on an iPad
       in landscape, one per row. */
    body[data-ds="rt"] .content-header .ch-cycle {
        width: auto;
    }
}


/* --------------------------------------------------------------------------
   4 · CARD LISTS: NOTHING CUT OFF
   -------------------------------------------------------------------------- */
/* Division cards (Salary Banding, Group CFO, ED & Group CEO, MD, TNA): the
   desktop column caps (max-width + ellipsis) stayed on when the table turned
   into cards, so on an iPad a 370px card field showed "Quantity ..." and its
   label "Employee Ca". A card field has the whole card width. */
@media (max-width: 1024px) {
    body[data-ds="rt"] table.rv-dcards :is(tbody, tfoot) td {
        max-width: none !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere;
    }
    body[data-ds="rt"] table.rv-dcards :is(tbody, tfoot) td[data-label]::before {
        white-space: normal;
    }
    /* Totals row: stacked like the rows above it, read as the summary card. */
    body[data-ds="rt"] table.rv-dcards tfoot { display: block; }
    body[data-ds="rt"] table.rv-dcards tfoot tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 11px 14px;
        padding: 15px 16px;
        margin-bottom: 13px;
        background: var(--color-surface-secondary, var(--color-surface));
        border: 1px solid var(--color-border-strong, var(--color-border));
        border-radius: var(--radius-md, 8px);
        font-weight: var(--font-weight-semibold);
    }
    body[data-ds="rt"] table.rv-dcards tfoot td {
        display: block;
        min-width: 0;
        padding: 0 !important;
        border: 0 !important;
        text-align: left !important;
        background: transparent !important;
        font-variant-numeric: tabular-nums;
    }
    body[data-ds="rt"] table.rv-dcards tfoot td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        font-size: var(--fs-12, 12px);
        font-weight: 500;
        color: var(--color-text-muted);
    }
    body[data-ds="rt"] table.rv-dcards tfoot td:first-child { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
    /* Master-style tables (Reports, TNA Review) stack their rows into cards
       on a phone, but the totals row stayed a 560-620px table row hanging off
       the right edge, its last figures unreachable. */
    body[data-ds="rt"] .master-table tfoot { display: block; }
    body[data-ds="rt"] .master-table tfoot tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 10px 14px;
        padding: 12px 14px;
        margin-bottom: 10px;
        border: 1px solid var(--color-border-strong, var(--color-border));
        border-radius: var(--radius-md, 8px);
        background: var(--color-surface-secondary, var(--color-surface));
        font-weight: var(--font-weight-semibold);
    }
    body[data-ds="rt"] .master-table tfoot td {
        display: block;
        min-width: 0;
        max-width: none !important;
        padding: 0 !important;
        border: 0 !important;
        text-align: left !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        background: transparent !important;
    }
    body[data-ds="rt"] .master-table tfoot td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        font-size: var(--fs-12, 12px);
        font-weight: var(--font-weight-medium);
        color: var(--color-text-muted);
    }
    body[data-ds="rt"] .master-table tfoot td:first-child { grid-column: 1 / -1; }

    /* Submit Performance Appraisals: the employee card grid used a bare 1fr
       track, which cannot shrink below the card's longest one-line text
       (Department · Personnel Area · Sub-division), so each card was 416px in
       a 358px column with its "Locked" chip and "View appraisal" button cut
       off at the screen edge. */
    body[data-ds="rt"] .emp-cards-grid { grid-template-columns: minmax(0, 1fr) !important; }
    body[data-ds="rt"] .emp-card { min-width: 0; }

    /* Code badges (Email Notifications placeholders, Input Fields codes) are
       one long unbroken token; let them break instead of leaving the card. */
    body[data-ds="rt"] .field-code-badge {
        white-space: normal;
        overflow-wrap: anywhere;
        display: inline-block;
        max-width: 100%;
    }
}
@media (max-width: 1024px), (pointer: coarse) and (max-width: 1366px) {
    body[data-ds="rt"] .master-table td .field-code-badge,
    body[data-ds="rt"] .master-table td .role-pill {
        white-space: normal;
        overflow-wrap: anywhere;
        max-width: 100%;
    }
    /* Input Fields "Visible to": the cell was nowrap, so a third role pill
       ran under the next column. Pills wrap onto a second line instead. */
    body[data-ds="rt"] .master-table td:has(> .role-pill) {
        white-space: normal !important;
    }
    /* Executive division dialog notes ("Fewer than two ratings ...") are a
       sentence in a pill; on a phone it ran 130px past the section edge. */
    body[data-ds="rt"] .eap-pill {
        white-space: normal;
        max-width: 100%;
    }
}


/* --------------------------------------------------------------------------
   5 · DIALOG HEADERS ON A PHONE
   The rating form, the appraisal viewer and the increment wizard put the
   employee's name beside four header buttons, which left the name 100-150px
   wide and broken over four lines ("Appraisal: / Abdullah / Bin Khalfan /
   Al Maskari"). On a phone the title takes the first row with the close
   button, and the other buttons sit on the row below.
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    body[data-ds="rt"] :is(.paw-title, .hodv-header, .inw-head) {
        flex-wrap: wrap !important;
        align-items: flex-start !important;
        row-gap: 8px;
        column-gap: 8px;
    }
    body[data-ds="rt"] :is(.hodv-head-actions, .inw-head-actions) {
        display: contents !important;
    }
    body[data-ds="rt"] :is(.paw-title-text, .hodv-title, .inw-head > :first-child) {
        flex: 1 1 calc(100% - 56px) !important;
        min-width: 0 !important;
        order: 0;
    }
    body[data-ds="rt"] :is(.paw-close, .hodv-close, .inw-close) {
        order: 1;
        flex: none;
        margin-left: auto;
    }
    body[data-ds="rt"] .paw-title > :not(.paw-title-text):not(.paw-close),
    body[data-ds="rt"] .hodv-head-actions > :not(.hodv-close),
    body[data-ds="rt"] .inw-head-actions > :not(.inw-close) {
        order: 2;
    }

    /* Finance Approval division dialog: name, status, progress and three
       buttons wrapped into five ragged rows with the close button alone on
       the last. Row 1 = division name + close; row 2 = status pill and
       progress; row 3 = Guide Me and the bulb. */
    body[data-ds="rt"] .fnrm-h { align-items: center; row-gap: 8px; }
    body[data-ds="rt"] .fnrm-h > .fnrm-who { flex: 1 1 calc(100% - 56px); min-width: 0; order: 0; }
    body[data-ds="rt"] .fnrm-h > .fnrm-x { order: 1; margin-left: auto; min-width: 40px; min-height: 40px; }
    body[data-ds="rt"] .fnrm-h > :is(.fnrb-pill, .fnrm-prog) { order: 2; }
    body[data-ds="rt"] .fnrm-h > .fnrm-prog { flex: 1 1 auto; }
    body[data-ds="rt"] .fnrm-h > :is(.guide-me-modal, .bright-bulb-modal) { order: 3; }

    /* Group CFO / ED & Group CEO / MD division dialog: the three filters were
       left-aligned at three different widths, and the three footer buttons
       stacked right-aligned at three different widths. */
    body[data-ds="rt"] .eap-mdl-tb > * { flex: 1 1 100% !important; min-width: 0; }
    body[data-ds="rt"] .eap-mdl-tb .eap-sel { flex: 1 1 calc(50% - 4px) !important; width: auto; }
    body[data-ds="rt"] .eap-mdl-f .info { flex: 1 1 100%; margin-right: 0; }
    body[data-ds="rt"] .eap-mdl-f .btn { flex: 1 1 140px; }
    body[data-ds="rt"] .eap-mdl-f .btn.btn-primary { flex-basis: 100%; }
}


/* --------------------------------------------------------------------------
   6 · PAYROLL PROCESSING ACTION BAR ON A PHONE
   "Confirm payroll" and "Handover trail" kept their desktop nowrap width and
   ran 120px past the right edge of the screen.
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    body[data-ds="rt"] .pay-actions { align-items: stretch; }
    body[data-ds="rt"] .pay-actions > * { flex: 1 1 100%; }
    body[data-ds="rt"] .pay-actions form { display: block; }
    body[data-ds="rt"] .pay-actions .pay-btn {
        width: 100%;
        white-space: normal;
        text-align: center;
    }
    body[data-ds="rt"] .pay-actions .pay-status { justify-content: flex-start; }
    body[data-ds="rt"] .pay-actions-spacer { display: none; }
}


/* --------------------------------------------------------------------------
   7 · THE 40px TAP FLOOR, FOR THE CONTROLS THE EARLIER PASSES MISSED
   Measured after sections 1-6 on every screen at three touch sizes. These
   were 15-34px tall under a finger: "Back to Settings" (30px, on all 35
   Settings screens), the Overview "Review for sign-off" button (28px), the
   Count / Avg % switches on the executive gates (28px), Audit Trail's
   "n fields changed" toggles (20px), the shared filter triggers (32-34px),
   the table/cards switch (30px), TNA Review's segment buttons (32px) and
   sortable column headers (31px). Chart bars that are also buttons
   (Increment Dashboard, Management Summary) keep their drawn height.
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
    body[data-ds="rt"] .main-content :is(
        a.rt-back, a.pd-open, .ms-trigger, .ms-filter-btn, .ms-linkish,
        .vt-btn, .tnd-seg-btn, .hod-btn-sm, .rv-strap-more, #hscChecksBtn,
        .eap-seg button, [role="tablist"] > button, .seg-btn
    ) {
        min-height: 40px;
        box-sizing: border-box;
    }
    body[data-ds="rt"] .main-content :is(a.rt-back, a.pd-open) {
        display: inline-flex;
        align-items: center;
    }
    body[data-ds="rt"] .main-content .vt-btn { min-width: 40px; }
    body[data-ds="rt"] .main-content details > summary {
        min-height: 40px;
        display: flex;
        align-items: center;
    }
    body[data-ds="rt"] .main-content th.rv-csort,
    body[data-ds="rt"] .main-content th.sortable {
        height: 40px;
    }
}


/* --------------------------------------------------------------------------
   8 · SMALL SECTION HEADERS ON A PHONE
   Performance Appraisal Approvals' list header squeezed "Employees" and its
   count line onto one row ("Employees3 employees shown").
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    body[data-ds="rt"] .hod-table-header-bar {
        flex-wrap: wrap;
        row-gap: 2px;
    }
    body[data-ds="rt"] .hod-table-header-bar > .hod-table-count {
        flex: 1 1 100%;
        margin-left: 0;
        text-align: left;
    }
    /* Stuck & Orphan Records: title, count and a four-line explanation
       shared one 358px row, leaving the explanation right-aligned in a
       130px column. The explanation drops under the title. */
    body[data-ds="rt"] .wfx-head { flex-wrap: wrap; row-gap: 4px; }
    body[data-ds="rt"] .wfx-head > .wfx-title { flex: 1 1 auto; min-width: 0; }
    body[data-ds="rt"] .wfx-head > .wfx-desc {
        flex: 1 1 100%;
        max-width: none;
        margin-left: 0;
        text-align: left;
    }
}
