body { height: 100dvh; }
#portal-content { overscroll-behavior-y: contain; }
body.portal-modal-open :is(#portal-content, #truck-list, #detail-body) { overflow: hidden; }

body :is(.files-modal-backdrop, .driver-modal-backdrop, .load-modal-backdrop, .revrec-modal-backdrop,
    .expenses-modal-backdrop, .fuel-v2-edit-backdrop, .fm-target-modal-backdrop,
    .hos-logs-backdrop, .geotab-share-backdrop, .load-odom-backdrop) {
    top: var(--portal-overlay-top, 0px);
    bottom: auto;
    height: var(--portal-overlay-height, 100dvh);
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
    align-items: center;
}

body [role="dialog"][aria-modal="true"] {
    max-height: calc(var(--portal-overlay-height, 100dvh) - 24px);
    min-height: 0;
    overscroll-behavior: contain;
}

body :is(.files-modal, .files-packet-modal, .files-image-editor-modal, .driver-modal,
    .driver-email-modal, .driver-confirm-modal, .dispatcher-rate-modal, .fuel-v2-edit-modal,
    .revrec-modal) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

body :is(.files-modal-head, .files-modal-actions, .driver-modal-head, .driver-modal-actions,
    .load-modal-head, .load-modal-footer, .revrec-modal-head, .revrec-modal-actions,
    .fuel-v2-edit-head, .fuel-v2-edit-actions) { flex-shrink: 0; }

body :is(.files-packet-body, .files-image-editor-body, .driver-modal-body, .driver-email-form, .dispatcher-rate-form,
    .revrec-modal-body, .fuel-v2-edit-grid, .load-modal-body, .expenses-form, .fm-target-editor-wrap) {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

body .files-packet-body { max-height: none; }
body .files-packet-modal > .files-modal-actions { padding: 12px 20px; background: #fff; border-top: 1px solid #dbe8e8; }
body .files-modal > .files-upload-form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
body .files-upload-form > .files-modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
body .files-upload-form > .files-modal-actions { flex-shrink: 0; }
body .files-image-editor-modal > .files-image-editor-tools { flex-shrink: 0; }
body .fuel-v2-add-grid { max-height: none; }
body .revrec-modal > form:not(.revrec-modal-body) { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
body :is(.invoice-email-layout, .invoice-detail-body) { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
body :is(.driver-confirm-modal > p, .files-confirm-modal, .load-doc-picker) { overflow: auto; overscroll-behavior: contain; }
body :is(.hos-logs-body, .geotab-share-modal, .load-odom-modal) { overscroll-behavior: contain; }

.driver-history-mobile-back { display: none; }

@media (max-width: 1000px) {
    .driver-history-list, .driver-pay-sidebar {
        max-height: min(360px, 45dvh);
        min-height: 120px;
        overflow: auto;
        overscroll-behavior: contain;
    }
    .driver-history-shell.has-selected-settlement > .driver-history-list { display: none; }
    .driver-history-shell:not(.has-selected-settlement) > .driver-history-detail { display: none; }
    .driver-history-mobile-back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; }
    .driver-history-detail { scroll-margin-top: 12px; }
    .brokers-list, .fm-asset-list, .revrec-table-wrap { overscroll-behavior: contain; }
}

@media (max-width: 767px) {
    body :is(.files-modal-backdrop, .driver-modal-backdrop, .load-modal-backdrop, .revrec-modal-backdrop,
        .expenses-modal-backdrop, .fuel-v2-edit-backdrop, .fm-target-modal-backdrop) { padding: 8px; }
    body [role="dialog"][aria-modal="true"] { max-height: calc(var(--portal-overlay-height, 100dvh) - 16px); max-width: calc(100vw - 16px); }
    body [aria-modal="true"] :is(input, select, textarea) { font-size: 16px; }
    body :is(.files-modal-head, .driver-modal-head, .revrec-modal-head) { padding: 12px; gap: 8px; }
    body :is(.files-modal-head h2, .driver-modal-head h2) { font-size: 18px; overflow-wrap: anywhere; }
    body .files-packet-body { padding: 12px; }
    body .files-packet-modal > .files-modal-actions { padding: 10px 12px; }
    body .files-image-editor-stage { min-height: 180px; max-height: 40dvh; }
    body .driver-confirm-modal > p { min-height: 0; }
}
