/* Desktop remains a native grid; mobile list records use the shared card contract below. */
.erp-mobile-list-controls { display: none; }
.erp-mobile-open-cell { display: none !important; }
.erp-mobile-list, .erp-mobile-list-body { min-width: 0; max-width: 100%; width: 100%; }
.app-shell .erp-mobile-grid-hint { display: none; }
@media (max-width: 800px) {
    .app-shell .erp-mobile-grid-hint {
        display: block;
        margin: 0 0 8px;
        color: #526274;
        font-size: .8rem;
    }

    .app-shell .grid-panel,
    .app-shell .erp-grid-wrap {
        min-width: 0 !important;
        width: 100%;
        box-sizing: border-box;
    }

    /* Beats the legacy .commercial-ficha-card rule that resets min-width:0.
       Only the table scrolls; the card, actions and totals fit the viewport. */
    .app-shell .commercial-ficha-card .commercial-lines-wrap {
        max-width: 100% !important;
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }

    .app-shell .commercial-ficha-card .commercial-lines-table {
        width: 1280px !important;
        min-width: 1280px !important;
        table-layout: fixed !important;
    }

    .app-shell .commercial-ficha-card .commercial-lines-table :is(th, td) {
        padding: 10px 8px !important;
        font-size: 12px !important;
        line-height: 1.3 !important;
    }

    .app-shell .commercial-ficha-card .commercial-lines-table .line-detail-text {
        white-space: normal !important;
        overflow-wrap: anywhere;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    .app-shell .commercial-ficha-card .commercial-lines-table .line-action-buttons .erp-row-icon-btn {
        width: 36px !important;
        min-width: 36px !important;
        height: 44px !important;
        min-height: 44px !important;
    }

    .app-shell .grid-panel,
    .app-shell .grid-panel-fluid,
    .app-shell .erp-grid-wrap,
    .app-shell .informe-table-wrap {
        max-width: 100%;
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }

    .app-shell .erp-grid .dxbl-grid-container,
    .app-shell .dxbl-grid .dxbl-grid-container,
    .app-shell .erp-grid-fluid .dxbl-grid-container,
    .app-shell .commercial-grid .dxbl-grid-container {
        max-width: 100% !important;
        overflow-x: auto !important;
        scrollbar-width: thin;
    }

    .app-shell .erp-grid .dxbl-grid-table,
    .app-shell .dxbl-grid .dxbl-grid-table:has(tr > :nth-child(5)),
    .app-shell .erp-grid-fluid .dxbl-grid-table,
    .app-shell .commercial-grid .dxbl-grid-table {
        width: max-content !important;
        min-width: 880px !important;
        table-layout: fixed !important;
    }

    .app-shell .purchase-invoices-list-page .dxbl-grid-table {
        min-width: 1180px !important;
    }

    .app-shell .erp-grid .dxbl-grid-table th,
    .app-shell .dxbl-grid .dxbl-grid-table th,
    .app-shell .dxbl-grid .dxbl-grid-table td,
    .app-shell .erp-grid .dxbl-grid-table td,
    .app-shell .erp-grid-fluid .dxbl-grid-table th,
    .app-shell .erp-grid-fluid .dxbl-grid-table td {
        min-width: 72px;
        padding: 8px 7px !important;
        font-size: 12px !important;
        line-height: 1.3 !important;
        white-space: nowrap !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-shell .erp-grid .dxbl-grid-table tr > :first-child,
    .app-shell .erp-grid-fluid .dxbl-grid-table tr > :first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        min-width: 42px;
        background: #fff;
        box-shadow: 1px 0 0 #d9e1ec;
    }

    .app-shell .erp-grid .dxbl-grid-table thead tr > :first-child,
    .app-shell .erp-grid-fluid .dxbl-grid-table thead tr > :first-child {
        z-index: 4;
        background: #f4f7fb;
    }

    .app-shell .informe-table {
        width: max-content;
        min-width: 780px;
    }

    .app-shell .informe-table th,
    .app-shell .informe-table td {
        padding: 8px 9px;
        white-space: nowrap;
    }

    .app-shell .dxbl-grid .dxbl-pager,
    .app-shell .erp-ribbon,
    .app-shell .list-toolbar-actions {
        flex-wrap: wrap !important;
    }
}

/* All ERP data grids share the order-lines mobile presentation.
   Explicit native-table classes avoid calendars and rich-text editor tables.
   Popup roots also cover DevExpress portals outside the application shell. */
@media (max-width: 800px) {
    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid-container,
    body .app-shell :has(> table:is(.data-table, .erp-data-grid, .erp-table, .erp-lines-table, .informe-table, .commercial-lines-table, .client-contacts-table, .az-cart-table, .rectificativa-table, .rrhh-consulta-table, .ai-budget-table, .fiscal-period-grid, .fiscal-documents-table, .fiscal-catalog-table, .invoice-import-table)) {
        min-width: 0 !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid .dxbl-grid-table,
    body .app-shell table:is(.data-table, .erp-data-grid, .erp-table, .erp-lines-table, .informe-table, .commercial-lines-table, .client-contacts-table, .az-cart-table, .rectificativa-table, .rrhh-consulta-table, .ai-budget-table, .fiscal-period-grid, .fiscal-documents-table, .fiscal-catalog-table, .invoice-import-table) {
        width: max-content !important;
        min-width: 640px !important;
        table-layout: fixed !important;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid .dxbl-grid-table:has(tr > :nth-child(5)),
    body .app-shell table:is(.data-table, .erp-data-grid, .erp-table, .erp-lines-table, .informe-table, .commercial-lines-table, .client-contacts-table, .az-cart-table, .rectificativa-table, .rrhh-consulta-table, .ai-budget-table, .fiscal-period-grid, .fiscal-documents-table, .fiscal-catalog-table, .invoice-import-table):has(tr > :nth-child(5)) {
        min-width: 1280px !important;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid .dxbl-grid-table :is(th, td),
    body .app-shell table:is(.data-table, .erp-data-grid, .erp-table, .erp-lines-table, .informe-table, .commercial-lines-table, .client-contacts-table, .az-cart-table, .rectificativa-table, .rrhh-consulta-table, .ai-budget-table, .fiscal-period-grid, .fiscal-documents-table, .fiscal-catalog-table, .invoice-import-table) :is(th, td) {
        padding: 10px 8px !important;
        font-size: 12px !important;
        line-height: 1.3 !important;
        vertical-align: middle;
        white-space: normal !important;
        overflow-wrap: anywhere;
        text-overflow: clip !important;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid .dxbl-grid-table th,
    body .app-shell table:is(.data-table, .erp-data-grid, .erp-table, .erp-lines-table, .informe-table, .commercial-lines-table, .client-contacts-table, .az-cart-table, .rectificativa-table, .rrhh-consulta-table, .ai-budget-table, .fiscal-period-grid, .fiscal-documents-table, .fiscal-catalog-table, .invoice-import-table) th {
        background: #f8fafc;
        color: #64748b;
        font-weight: 700;
        text-transform: uppercase;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) .dxbl-grid .dxbl-grid-table :is(.dxbl-grid-text-container, .dxbl-grid-header-content),
    body .app-shell :is(.line-detail-text, .client-name-text) {
        white-space: normal !important;
        overflow-wrap: anywhere;
        text-overflow: clip !important;
        overflow: visible !important;
    }

    body :is(.app-shell, .erp-popup, .master-editor-popup) :is(.dxbl-grid, .erp-grid-wrap, .grid-panel, .az-table-wrap) .erp-row-icon-btn {
        width: 36px !important;
        min-width: 36px !important;
        height: 44px !important;
        min-height: 44px !important;
    }
}

/* Native grid cells keep their Blazor bindings, selection, menus and row events.
   Table mode exposes the unchanged header filters, sorting and select-all controls. */
@media (max-width: 800px) {
    body .erp-mobile-list { width: 100%; min-width: 0; max-width: 100%; }
    body .erp-mobile-list-controls {
        display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
    }
    body .erp-mobile-list-controls button {
        flex: 1 1 130px; min-width: 0; min-height: 44px; padding: 10px;
        border: 1px solid #cbd5e1; border-radius: 8px; background: #fff;
        color: #17304e; font: inherit; font-size: 14px; white-space: normal;
    }
    body .erp-mobile-list-controls button:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }
    body .erp-mobile-list.is-cards .dxbl-grid { height: auto !important; max-height: none !important; }
    body .erp-mobile-list.is-cards :is(.dxbl-grid-container, .dxbl-scroll-viewer, .dxbl-scroll-viewer-content) {
        width: 100% !important; min-width: 0 !important; max-width: 100% !important;
    }
    body .erp-mobile-list.is-cards.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) {
        display: block !important; width: 100% !important; min-width: 0 !important;
        max-width: 100% !important; table-layout: auto !important;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) > :is(thead, tbody, tfoot) {
        display: block; width: 100%;
    }
    /* Vendor height filler is not a record; keep no-data messages and table mode intact. */
    body .erp-mobile-list.is-cards .dxbl-grid-table > tbody:has(> tr.erp-mobile-record) > tr.dxbl-grid-empty-row {
        display: none;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) colgroup,
    body .erp-mobile-list.is-cards .erp-mobile-table-controls { display: none !important; }
    body .erp-mobile-list.is-cards tr.erp-mobile-record {
        display: flex !important; flex-wrap: wrap; align-items: center;
        width: 100% !important; height: auto !important; min-height: 0;
        margin: 0 0 10px; padding: 8px 12px 12px; gap: 4px 10px; box-sizing: border-box;
        border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
    }
    body .erp-mobile-list.is-cards tr.erp-mobile-record:has(input:checked) {
        outline: 2px solid #2563eb; outline-offset: -2px;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td.erp-mobile-cell {
        display: flex !important; flex-direction: column; align-items: flex-start; gap: 2px;
        position: static !important; width: auto !important; min-width: 0 !important;
        max-width: 100% !important; height: auto !important; padding: 3px 0 !important;
        box-sizing: border-box; border: 0 !important; box-shadow: none !important;
        white-space: normal !important; overflow-wrap: anywhere; overflow: visible;
        font-size: 14px !important; line-height: 1.4 !important; text-align: left !important;
        order: 8; flex: 1 1 calc(50% - 10px); background: transparent !important;
    }
    body .erp-mobile-list.is-cards .erp-mobile-cell::before {
        content: attr(data-mobile-label); color: #526274; font-size: 12px; font-weight: 600;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td.erp-mobile-title {
        flex: 1 0 100%; order: 5; font-weight: 700;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > .erp-mobile-control {
        flex: 1 1 100%; order: 10; flex-direction: row; flex-wrap: wrap; align-items: center;
    }
    body .erp-mobile-list.is-cards .erp-mobile-title::before,
    body .erp-mobile-list.is-cards .erp-mobile-control::before { content: none; }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td.erp-mobile-amount {
        flex: 1 1 130px; order: 9; flex-direction: column; align-items: flex-start; gap: 2px;
        text-align: left !important;
        background: #eaf2fb !important; color: #17304e;
        border-radius: 8px; padding: 8px 10px !important;
        font-size: 21px !important; font-weight: 700; font-variant-numeric: tabular-nums;
        margin-top: 6px;
    }
    body .erp-mobile-list.is-cards:not(.all-fields) table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > .erp-mobile-secondary {
        display: none !important;
    }
    body .erp-mobile-list.is-cards .erp-mobile-cell :is(.dxbl-grid-text-container, .dxbl-grid-cell-display-template) {
        width: 100%; min-width: 0; white-space: normal !important; overflow-wrap: anywhere;
        overflow: visible !important; text-overflow: clip !important;
    }
    body .erp-mobile-list.is-cards .erp-mobile-cell input[type="checkbox"] { min-width: 22px; min-height: 22px; }
    body .erp-mobile-list.is-cards .erp-mobile-cell :is(button, a.erp-row-icon-btn) { min-height: 44px; }
    body .grid-panel:has(> .erp-mobile-list.is-cards) > .erp-mobile-grid-hint { display: none; }

    /* A compact header, not one labelled box for each piece of metadata. */
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td.erp-mobile-control:has(input[type="checkbox"]) {
        flex: 0 0 36px; order: 0; min-height: 44px; justify-content: center;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td[data-mobile-role="identity"] {
        flex: 0 1 auto; order: 1; font-weight: 700; font-size: 16px !important;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td[data-mobile-role="series"] {
        flex: 0 1 auto; order: 2; flex-direction: row; gap: 4px; align-items: baseline;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td[data-mobile-role="date"] {
        flex: 0 1 auto; order: 3; margin-left: auto; font-size: 13px !important; color: #526274;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td[data-mobile-role="lock"] {
        flex: 0 0 18px; order: 4;
    }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td:is([data-mobile-role="status"], [data-mobile-role="payment"]) {
        flex: 1 1 auto; order: 6; font-size: 13px !important;
    }
    body .erp-mobile-list.is-cards td:is([data-mobile-role="identity"], [data-mobile-role="date"], [data-mobile-role="lock"], [data-mobile-role="status"], [data-mobile-role="payment"])::before { content: none; }
    body .erp-mobile-list.is-cards tr.erp-mobile-record > td:empty,
    body .erp-mobile-list.is-cards tr.erp-mobile-record > :is(.dxbl-grid-indent-cell, .dxbl-grid-empty-cell, .dxbl-grid-hidden-empty-cell):not(:has(button, input, a, [role="button"])) { display: none !important; }
    body .erp-mobile-list.is-cards table:is(.dxbl-grid-table, .erp-native-mobile-table) tr.erp-mobile-record > td.erp-mobile-open-cell {
        display: flex !important; order: 10; flex: 0 0 auto; width: auto !important; min-width: 0 !important;
        height: auto !important; min-height: 50px; max-height: none !important; overflow: visible !important;
        padding: 6px 0 0 !important; margin-left: auto; border: 0 !important; background: transparent !important;
    }
    body .erp-mobile-list.is-cards .erp-mobile-open-cell :is(.dxbl-grid-cell-display-template, .dxbl-grid-text-container) {
        height: auto !important; max-height: none !important; overflow: visible !important;
    }
    body .erp-mobile-list.is-cards .erp-mobile-open-button {
        --erp-action-primary: #1264b0;
        --erp-action-height: 44px;
        --erp-action-min-width: 120px;
        min-height: 44px; min-width: 120px; white-space: nowrap;
    }
}
