/* Shared ERP action contract. Editor arrows and spinners are not actions. */
.app-shell .erp-list-result-count {
    display: inline-block;
    margin-top: 4px;
    color: #526274;
    font-size: .8rem;
}
body .app-shell .header-actions :is(.erp-result-count, .badge) {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f1f5f9;
    color: #111827 !important;
    font-size: .78rem;
    font-weight: 650;
}
:is(.app-shell, .erp-popup) {
    --erp-action-height: 36px;
    --erp-action-min-width: 120px;
    --erp-action-radius: 6px;
    --erp-action-primary: #e86118;
    --erp-action-border: #cbd5e1;
    --erp-action-text: #334155;
}

body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):where(:not([class*="dxbl-edit-btn"]):not([class*="dxbl-spin"]):not(.dxbl-pager *):not(.dxbl-calendar *)) {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--erp-action-height) !important;
    min-height: var(--erp-action-height) !important;
    padding: 0 12px !important;
    gap: 7px;
    border: 1px solid var(--erp-action-border) !important;
    border-radius: var(--erp-action-radius) !important;
    background: #fff !important;
    color: var(--erp-action-text) !important;
    font-size: .82rem !important;
    font-weight: 650 !important;
    box-shadow: none !important;
}

/* Standard actions share a minimum footprint. Linked pickers and grid-only
   icon controls are intentionally compact, matching their adjacent editor. */
body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):where(:not(.master-link-button):not(.az-client-picker-btn):not(.az-grid-picker-btn):not(.erp-row-icon-btn):not(.dxbl-popup-header-button):not([class*="dxbl-edit-btn"]):not([class*="dxbl-spin"]):not(.dxbl-pager *):not(.dxbl-calendar *)) {
    min-width: var(--erp-action-min-width) !important;
    flex-shrink: 0;
}

body .app-shell :is(.erp-ribbon, .erp-ribbon-group, .header-actions, .pedido-actionbar) {
    flex-wrap: wrap !important;
    gap: 8px;
}

body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):is(.erp-action-primary, .dxbl-btn-primary, .btn-primary):not(:disabled) {
    border-color: var(--erp-action-primary) !important;
    background: var(--erp-action-primary) !important;
    color: #fff !important;
}

body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):is(.commercial-delete-action, .erp-ribbon-danger, .danger, .dxbl-btn-danger, .btn-danger):not(:disabled) {
    border-color: #e7bac1 !important;
    background: #fff !important;
    color: #a92335 !important;
}

body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):where(:not([class*="dxbl-edit-btn"]):not([class*="dxbl-spin"]):not(.dxbl-pager *):not(.dxbl-calendar *)) :is(.erp-icon, .dxbl-image) {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
}

body :is(.app-shell, .erp-popup) .dxbl-btn :is(.dxbl-btn-caption, [class*="dx-icon"]) {
    color: inherit !important;
}

body :is(.app-shell, .erp-popup) .erp-action-button > :is(span, .erp-icon) {
    color: inherit !important;
}

body :is(.app-shell, .erp-popup) .erp-action-primary:disabled {
    background: #f1f5f9 !important;
    color: #475569 !important;
    border-color: #cbd5e1 !important;
    opacity: 1;
}

body :is(.app-shell, .erp-popup) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn, .btn):focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* One set of buttons: inline on desktop, expandable on mobile. No duplicated
   handlers or alternate permission checks. CSS controls only presentation. */
body .app-shell .erp-responsive-actions,
body .app-shell .erp-responsive-actions-content {
    display: contents;
}

/* Form actions share one right-aligned group. Field pickers stay beside inputs. */
body :is(.app-shell, .erp-popup) :is(.header-actions, .form-actions, .sap-actions, .commercial-bottom-actions, .popup-actions, .popup-footer-actions, .list-toolbar-actions) {
    justify-content: flex-end !important;
    margin-left: auto;
    gap: 8px;
    flex-wrap: wrap;
}

body .app-shell .erp-responsive-actions > .erp-responsive-actions-toggle {
    display: none !important;
    background: #eaf2fb !important;
    border-color: #bdd2e9 !important;
    color: #17304e !important;
}

@media (max-width: 720px) {
    body :is(.app-shell, .erp-popup) {
        --erp-action-height: 44px;
        --erp-action-min-width: 0px;
    }

    body .app-shell .commercial-ficha-header .header-actions,
    body .app-shell .commercial-bottom-actions.sap-actions,
    body .app-shell :is(.header-actions, .erp-ribbon, .list-toolbar-actions),
    body .erp-popup :is(.popup-actions, .popup-footer-actions) {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 120px)) !important;
        width: 100% !important;
        min-width: 0 !important;
        gap: 8px !important;
        justify-content: end !important;
    }

    body .app-shell :is(.header-actions, .commercial-bottom-actions) > :is(.badge, .erp-result-count),
    body .app-shell .erp-ribbon-info {
        grid-column: 1 / -1;
        order: -1;
        justify-self: start;
        margin: 0 !important;
    }

    body .app-shell :is(.header-actions, .commercial-bottom-actions, .erp-ribbon, .pedidos-search-actions, .list-toolbar-actions) :is(.erp-action-button, .erp-ribbon-button, .dxbl-btn),
    body .erp-popup :is(.popup-actions, .popup-footer-actions) :is(.erp-action-button, .dxbl-btn) {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 8px !important;
        font-size: .8rem !important;
        white-space: normal;
        line-height: 1.15;
    }

    body .app-shell .erp-ribbon > .erp-ribbon-group {
        display: contents !important;
    }

    body :is(.app-shell, .erp-popup) :is(.master-link-button, .az-client-picker-btn, .az-grid-picker-btn) {
        height: 32px !important;
        min-height: 32px !important;
        width: 32px !important;
        min-width: 32px !important;
    }

    body .app-shell .erp-responsive-actions {
        display: grid;
        grid-column: 1 / -1;
        order: 3;
        min-width: 0;
        gap: 8px;
    }

    body .app-shell .erp-responsive-actions > .erp-responsive-actions-toggle {
        display: inline-flex !important;
        width: 100% !important;
        justify-self: stretch;
    }

    body .app-shell .erp-responsive-actions-content {
        display: none;
    }

    /* List creation and disclosure share a row; form disclosures keep their own row. */
    body .app-shell .erp-ribbon {
        grid-template-columns: minmax(0, 120px) minmax(0, 180px) !important;
    }

    body .app-shell .erp-ribbon > .erp-responsive-actions,
    body .app-shell .list-page > .page-header:not(.commercial-ficha-header) .header-actions > .erp-responsive-actions {
        grid-column: auto;
        order: 0;
    }

    body .app-shell .erp-ribbon > .erp-responsive-actions:has(.is-expanded),
    body .app-shell .list-page > .page-header:not(.commercial-ficha-header) .header-actions > .erp-responsive-actions:has(.is-expanded) {
        grid-column: 1 / -1;
    }

    body .app-shell .erp-responsive-actions-content.is-expanded {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    body .app-shell .erp-responsive-actions-content :is(.erp-ribbon-group, .commercial-action-workflow, .commercial-action-utilities) {
        display: contents !important;
    }

    body .app-shell :is(.commercial-ficha-header .header-actions, .commercial-bottom-actions) > .erp-action-primary {
        order: 2;
    }

    body .app-shell .commercial-bottom-actions.sap-actions {
        padding: 12px !important;
    }
}

/* Native checkbox and its label form one clickable, vertically centred unit. */
body :is(.app-shell, .erp-popup) .erp-checkbox-label,
.app-shell .commercial-document-v2 .sap-form .sap-field > label.erp-checkbox-label {
    display: inline-flex !important;
    align-items: center;
    justify-content: flex-start;
    gap: 7px;
    width: auto !important;
    min-width: 0 !important;
    margin: 0;
    line-height: 20px;
    overflow: visible;
    cursor: pointer;
}

body :is(.app-shell, .erp-popup) .erp-checkbox-label input[type="checkbox"],
.app-shell .commercial-ficha-card .commercial-header-form .erp-checkbox-label input[type="checkbox"] {
    appearance: auto;
    width: 18px !important;
    min-width: 18px !important;
    max-width: 18px !important;
    height: 18px !important;
    min-height: 18px !important;
    max-height: 18px !important;
    padding: 0;
    margin: 0;
    flex: 0 0 18px;
    accent-color: var(--erp-action-primary);
}

body :is(.app-shell, .erp-popup) .erp-checkbox-label input:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Preserve DevExpress behaviour; size only the visible check and hit area.
   This prevents legacy input rules (height:31px/width:100%) distorting checks. */
body :is(.app-shell, .erp-popup) .dxbl-checkbox {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 7px !important;
    vertical-align: middle;
}

body :is(.app-shell, .erp-popup) .dxbl-checkbox .dxbl-checkbox-check-element,
body :is(.app-shell, .erp-popup) .dxbl-checkbox .dxbl-checkbox-check-element input[type="checkbox"] {
    width: 18px !important;
    min-width: 18px !important;
    max-width: 18px !important;
    height: 18px !important;
    min-height: 18px !important;
    max-height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
    flex: 0 0 18px;
}

body :is(.app-shell, .erp-popup) .dxbl-checkbox label {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 20px;
    align-self: center;
}
