/* Phones use the original desktop layout viewport. Only the outer window
   framing changes here; native cells, controls, hidden states and exports keep
   their authored rules. The bootstrap never enables this class on map pages. */
@media screen and (min-width: 901px) {
    html.ag-mobile-desktop-view {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        --ag-mobile-desktop-status-height: 0px;
    }

    html.ag-mobile-desktop-view body:has(#agro-status-bar) {
        --ag-mobile-desktop-status-height: var(--ag-mobile-status-height, 28px);
    }

    /* Keep the desktop rail above the workspace toolbar, while native modal
       overlays retain their own ordering above it, including nested pickers. */
    html.ag-mobile-desktop-view .sidebar {
        z-index: 1100 !important;
    }

    html.ag-mobile-desktop-view body :is(.main-content, .workspace,
        .page-layout, .sub-content-wrapper, .ag-content-scroll) {
        box-sizing: border-box;
        min-width: 0;
        max-width: none;
        margin: 0 !important;
        padding: 0 !important;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    html.ag-mobile-desktop-view body .actions-container {
        margin: 0 !important;
        padding: 0 !important;
    }

    html.ag-mobile-desktop-view body .actions-bar {
        border-radius: 0;
    }

    html.ag-mobile-desktop-view body.ag-public-auth,
    html.ag-mobile-desktop-view body :is(.public-main, .pending-shell,
        .pending-card, .login-wrapper, .auth-card, .login-card, .sheet, .mfa-card) {
        box-sizing: border-box;
        width: 100% !important;
        max-width: none !important;
        min-width: 0;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    html.ag-mobile-desktop-view body :is(.report-container,
        .official-preview-shell, .tech-register-shell, .stock-page,
        .stock-report-card, .procurement-page, .procurement-list-card,
        .lease-total-screen, .lease-total-main, .lease-total-workspace-card,
        .lease-total-workspace-body, .act-workspace, .act-workspace > .workspace-card,
        .auto-page, .gps-registry-page, .purge-page, .dashboard-v2,
        .saas-admin-page, .plans-admin-page, .security-page, .help-shell,
        .legal-page, .rent-schedule-screen, .lease-payments-screen,
        .rent-allocation-screen, .sowing-structure-screen, .tech-layout,
        .register-nomen-layout, .meteo-page, .scale-point-page, .scale-page,
        .harvest-page, .audit-page, .purchase-register-page,
        .subscription-page, .team-page) {
        box-sizing: border-box;
        width: 100% !important;
        max-width: none !important;
        min-width: 0;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    html.ag-mobile-desktop-view body .report-container {
        height: 100%;
    }

    html.ag-mobile-desktop-view body :is(.report-body,
        .official-preview-scroll, .official-sheet, .lease-total-preview-space,
        .lease-total-sheet) {
        box-sizing: border-box;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    /* Wide desktop documents keep their native column widths and remain
       reachable in the same document scroll region. */
    html.ag-mobile-desktop-view body :is(.report-body,
        .official-preview-scroll, .lease-total-workspace-body) {
        overflow: auto;
    }

    /* Display, visibility, aria-hidden and hidden remain owned by the native
       modal controller. Geometry also overrides stored desktop drag offsets. */
    html.ag-mobile-desktop-view body :is(.modal-overlay,
        .purge-modal-overlay, .auto-modal-backdrop, .report-field-picker-overlay,
        .field-register-picker-overlay, .help-dialog-overlay,
        .calc-drilldown-modal, .meteo-modal, .appearance-shell) {
        box-sizing: border-box;
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        align-items: stretch;
        justify-content: stretch;
    }

    html.ag-mobile-desktop-view body :is(.modal-overlay,
        .purge-modal-overlay, .auto-modal-backdrop, .report-field-picker-overlay,
        .field-register-picker-overlay, .help-dialog-overlay,
        .calc-drilldown-modal, .meteo-modal, .appearance-shell) > :is(.modal-card,
        .modal-card-small, .modal-card-settings, .procurement-modal,
        .scale-modal-card, .purge-modal, .auto-modal, .report-field-picker-modal,
        .field-register-picker-card, .help-dialog, .calc-drilldown-dialog,
        .material-detail-card, .settings-card, .sowing-modal-card,
        .meteo-modal-dialog, .appearance-panel),
    html.ag-mobile-desktop-view body #modal-form > #draggable-card,
    html.ag-mobile-desktop-view body #modal-procurement > .procurement-modal,
    html.ag-mobile-desktop-view body #material-detail-modal > .material-detail-card,
    html.ag-mobile-desktop-view body #stock-op-modal > #stock-op-card,
    html.ag-mobile-desktop-view body #stock-transfer-modal > #stock-transfer-card,
    html.ag-mobile-desktop-view body #settings-modal > #settings-card,
    html.ag-mobile-desktop-view body #batch-history-modal > #batch-history-card,
    html.ag-mobile-desktop-view body dialog {
        box-sizing: border-box;
        position: fixed !important;
        inset: 0 0 var(--ag-mobile-desktop-status-height) !important;
        width: 100vw !important;
        min-width: 0 !important;
        max-width: 100vw !important;
        height: calc(100vh - var(--ag-mobile-desktop-status-height)) !important;
        height: calc(100dvh - var(--ag-mobile-desktop-status-height)) !important;
        min-height: 0 !important;
        max-height: calc(100dvh - var(--ag-mobile-desktop-status-height)) !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        flex-direction: column;
        overflow: hidden;
        resize: none !important;
    }

    /* These two native cards use block layout on desktop; their controller
       opens the containing overlay. Explicitly hidden cards remain hidden. */
    html.ag-mobile-desktop-view body :is(.purge-modal-overlay, .auto-modal-backdrop)
        > :is(.purge-modal, .auto-modal):not([hidden]):not([aria-hidden="true"]):not([style*="display:none"]):not([style*="display: none"]) {
        display: flex;
    }

    html.ag-mobile-desktop-view body :is(.modal-overlay,
        .purge-modal-overlay, .auto-modal-backdrop, .report-field-picker-overlay,
        .field-register-picker-overlay, .help-dialog-overlay,
        .calc-drilldown-modal, .meteo-modal, .appearance-shell) > :is(.modal-card,
        .modal-card-small, .modal-card-settings, .procurement-modal,
        .scale-modal-card, .purge-modal, .auto-modal, .report-field-picker-modal,
        .field-register-picker-card, .help-dialog, .calc-drilldown-dialog,
        .material-detail-card, .settings-card, .sowing-modal-card,
        .meteo-modal-dialog, .appearance-panel) > :is(.modal-body,
        .procurement-modal-body, .scale-modal-body, .purge-modal-body,
        .auto-modal-body, .calc-drilldown-body, .help-dialog-body,
        .report-field-picker__body, .field-register-picker-workspace,
        .material-detail-body, .settings-body, .sowing-modal-table-wrap,
        .appearance-body) {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        min-width: 0;
        max-height: none !important;
        overflow: auto !important;
    }

    html.ag-mobile-desktop-view body :is(.modal-overlay,
        .purge-modal-overlay, .auto-modal-backdrop, .report-field-picker-overlay,
        .field-register-picker-overlay, .help-dialog-overlay,
        .calc-drilldown-modal, .meteo-modal, .appearance-shell) :is(.modal-header,
        .modal-footer, .procurement-modal-header, .procurement-modal-footer,
        .scale-modal-header, .scale-modal-footer, .purge-modal-head,
        .purge-modal-footer, .auto-modal-header, .auto-modal-footer,
        .help-dialog-header, .help-dialog-footer, .report-field-picker__header,
        .report-field-picker__footer, .material-detail-header,
        .material-detail-footer, .settings-head, .settings-footer,
        .sowing-modal-head, .sowing-modal-toolbar, .sowing-modal-footer, .appearance-header,
        .appearance-footer) {
        flex: 0 0 auto;
        border-radius: 0 !important;
    }

    /* This native weather form has no separate scrolling body. */
    html.ag-mobile-desktop-view body .meteo-modal > .meteo-modal-dialog {
        overflow: auto;
    }

    html.ag-mobile-desktop-view body dialog[open]:not([hidden]):not([aria-hidden="true"]) {
        display: flex;
        flex-direction: column;
    }

    html.ag-mobile-desktop-view body dialog > :is(form, .dialog-body,
        .rent-history-body, .map-field-inspection-body) {
        flex: 1 1 auto;
        min-height: 0;
        overflow: auto;
    }
}

/* Window chrome follows the phone shell, including adaptive map forms. The
   document retains its native viewport; only its commands compensate for the
   browser's initial fit-to-width scale, so a 44px target is physically 44px. */
html.ag-phone-main-registers body {
    --ag-modal-phone-unit: var(--ag-phone-control-scale, 1);
    --modal-chrome-header-action-size: calc(44px * var(--ag-modal-phone-unit));
    --modal-chrome-header-min-height: calc(44px * var(--ag-modal-phone-unit));
    --modal-chrome-header-padding: calc(8px * var(--ag-modal-phone-unit)) calc(12px * var(--ag-modal-phone-unit));
    --modal-chrome-footer-min-height: calc(44px * var(--ag-modal-phone-unit));
    --modal-chrome-footer-padding: calc(8px * var(--ag-modal-phone-unit)) calc(12px * var(--ag-modal-phone-unit));
    --modal-chrome-footer-gap: calc(8px * var(--ag-modal-phone-unit));
    --modal-chrome-action-height: calc(44px * var(--ag-modal-phone-unit));
    --modal-chrome-action-padding: 0 calc(12px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers body :is(.modal-header, .scale-modal-header,
    .procurement-modal-header, .stock-op-header, .settings-head, .auto-modal-header,
    .material-detail-header, .sowing-modal-head, .purge-modal-head) {
    min-width: 0;
    flex-wrap: wrap !important;
    gap: calc(8px * var(--ag-modal-phone-unit)) !important;
    font-size: calc(16px * var(--ag-modal-phone-unit)) !important;
    line-height: 1.3 !important;
}

html.ag-phone-main-registers body :is(.modal-header, .scale-modal-header,
    .procurement-modal-header, .stock-op-header, .settings-head, .auto-modal-header,
    .material-detail-header, .sowing-modal-head, .purge-modal-head)
    :is(#modal-title, .modal-title, [id$="-title"], .procurement-modal-title, strong, h2, h3) {
    flex: 1 1 calc(150px * var(--ag-modal-phone-unit));
    min-width: 0;
    max-width: 100%;
    font-size: calc(16px * var(--ag-modal-phone-unit)) !important;
    line-height: 1.3 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
}

html.ag-phone-main-registers body :is(.modal-header-actions, .scale-modal-header-actions,
    .lease-modal-header-actions, .procurement-modal-header-actions,
    .history-modal-header-actions, .material-detail-header-actions,
    .agro-modal-minimize-actions) {
    max-width: 100%;
    flex-wrap: wrap !important;
    gap: calc(6px * var(--ag-modal-phone-unit)) !important;
}

html.ag-phone-main-registers body :is(.modal-header > i.fa-xmark,
    .modal-header > div > i.fa-xmark, .modal-header .icon-btn,
    .modal-header-action, .scale-modal-header-action, .lease-modal-header-btn,
    .procurement-modal-action, .history-modal-action, .material-detail-header-action,
    .modal-close-btn, .procurement-modal-close, .stock-op-close, .settings-close,
    .sowing-modal-close, .auto-modal-close, .agro-modal-minimize-button) {
    box-sizing: border-box !important;
    width: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-width: calc(44px * var(--ag-modal-phone-unit)) !important;
    height: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-height: calc(44px * var(--ag-modal-phone-unit)) !important;
    flex: 0 0 auto !important;
    padding: 0 !important;
    border-width: calc(1px * var(--ag-modal-phone-unit)) !important;
    border-radius: calc(8px * var(--ag-modal-phone-unit)) !important;
    font-size: calc(18px * var(--ag-modal-phone-unit)) !important;
    line-height: 1 !important;
}

html.ag-phone-main-registers body :is(.modal-header-action, .scale-modal-header-action,
    .lease-modal-header-btn, .procurement-modal-action, .history-modal-action,
    .material-detail-header-action, .modal-close-btn, .procurement-modal-close,
    .stock-op-close, .settings-close, .sowing-modal-close, .auto-modal-close,
    .agro-modal-minimize-button) > i {
    font-size: inherit !important;
}

html.ag-phone-main-registers body :is(.modal-footer, .scale-modal-footer,
    .procurement-modal-footer, .stock-op-footer, .settings-foot,
    .auto-modal-footer, .material-detail-footer, .sowing-modal-footer, .field-inspection-footer) {
    flex: 0 0 auto !important;
    gap: calc(8px * var(--ag-modal-phone-unit)) !important;
    padding: var(--modal-chrome-footer-padding) !important;
    max-height: none !important;
}

html.ag-phone-main-registers body :is(.modal-footer, .scale-modal-footer,
    .procurement-modal-footer, .stock-op-footer, .settings-foot,
    .auto-modal-footer, .material-detail-footer, .sowing-modal-footer, .field-inspection-footer)
    :is(button, a.btn-sm, a[onclick], .stock-op-reset-link) {
    box-sizing: border-box !important;
    min-width: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-height: calc(44px * var(--ag-modal-phone-unit)) !important;
    height: auto !important;
    padding: 0 calc(10px * var(--ag-modal-phone-unit)) !important;
    border-radius: calc(8px * var(--ag-modal-phone-unit)) !important;
    font-size: calc(14px * var(--ag-modal-phone-unit)) !important;
    line-height: 1.3 !important;
    white-space: normal !important;
}

html.ag-phone-main-registers body :is(.modal-footer, .scale-modal-footer,
    .procurement-modal-footer, .stock-op-footer, .settings-foot,
    .auto-modal-footer, .material-detail-footer, .sowing-modal-footer, .field-inspection-footer)
    :is(button, a.btn-sm) :is(i, svg) {
    font-size: calc(18px * var(--ag-modal-phone-unit)) !important;
    width: calc(18px * var(--ag-modal-phone-unit)) !important;
    height: calc(18px * var(--ag-modal-phone-unit)) !important;
}

html.ag-phone-main-registers body :is(.modal-footer-actions, .stock-op-footer-actions,
    .settings-foot-actions) {
    gap: calc(8px * var(--ag-modal-phone-unit)) !important;
}

html.ag-phone-main-registers body :is(.modal-shortcuts, .modal-footer-info,
    .modal-footer .shortcut-hint, .modal-footer .modal-shortcut-note) {
    display: none !important;
}

html.ag-phone-main-registers body :is(.modal-shortcuts, .modal-footer-info):has(button, a[onclick]) {
    display: inline-flex !important;
}

html.ag-phone-main-registers body :is(.modal-shortcuts, .modal-footer-info) > span,
html.ag-phone-main-registers body :is(.modal-footer, .scale-modal-footer,
    .procurement-modal-footer, .stock-op-footer, .settings-foot,
    .auto-modal-footer, .material-detail-footer, .sowing-modal-footer, .field-inspection-footer)
    :is(.modal-shortcut, .modal-shortcut-note) {
    display: none !important;
}

/* Minimized drafts stay reachable with the same touch geometry as the window
   commands. The tray remains the native controller's restore/discard surface. */
html.ag-phone-main-registers body:has(.agro-status-bar.has-minimized-modals) {
    --ag-mobile-desktop-status-height: calc(44px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers .agro-status-bar.has-minimized-modals {
    height: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-height: calc(44px * var(--ag-modal-phone-unit)) !important;
    max-height: none !important;
}

html.ag-phone-main-registers .agro-status-bar.has-minimized-modals
    :is(.agro-status-bar-left, .agro-status-bar-right) {
    display: none !important;
}

html.ag-phone-main-registers :is(.agro-minimized-modal-tray, .agro-minimized-modal-entry,
    .agro-minimized-modal-tools) {
    height: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-height: calc(44px * var(--ag-modal-phone-unit)) !important;
    max-height: none !important;
    gap: calc(6px * var(--ag-modal-phone-unit));
    padding-top: 0;
    padding-bottom: 0;
    border-radius: calc(8px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers .agro-minimized-modal-item {
    min-width: calc(118px * var(--ag-modal-phone-unit));
    max-width: calc(240px * var(--ag-modal-phone-unit));
    min-height: calc(44px * var(--ag-modal-phone-unit));
    padding: 0 calc(10px * var(--ag-modal-phone-unit));
    border-radius: calc(8px * var(--ag-modal-phone-unit));
    font-size: calc(13px * var(--ag-modal-phone-unit));
    flex: 1 1 auto;
}

html.ag-phone-main-registers .agro-minimized-modal-entry {
    flex: 0 1 calc(284px * var(--ag-modal-phone-unit));
    min-width: calc(162px * var(--ag-modal-phone-unit));
    max-width: calc(284px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers .agro-minimized-modal-count {
    font-size: calc(12px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers .agro-minimized-modal-item i {
    font-size: calc(18px * var(--ag-modal-phone-unit));
}

html.ag-phone-main-registers :is(.agro-minimized-modal-discard, .agro-minimized-modal-clear) {
    width: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-width: calc(44px * var(--ag-modal-phone-unit)) !important;
    height: calc(44px * var(--ag-modal-phone-unit)) !important;
    min-height: calc(44px * var(--ag-modal-phone-unit)) !important;
    border-radius: calc(8px * var(--ag-modal-phone-unit));
    font-size: calc(18px * var(--ag-modal-phone-unit));
}
