/*
   CraftGrid One — Finance & Accounting no-horizontal-scroll layer.
   Loaded last by _Layout and scoped to Finance & Accounting controllers.
   Screen only: print layouts retain their existing page-width rules.
*/
@media screen {
    html:has(body.cg-accounting-shell),
    body.cg-accounting-shell {
        max-width: 100%;
        overflow-x: clip !important;
    }

    body.cg-accounting-shell .craftgrid-app-shell,
    body.cg-accounting-shell .craftgrid-app-shell main,
    body.cg-accounting-shell main,
    body.cg-accounting-shell .container,
    body.cg-accounting-shell .container-fluid,
    body.cg-accounting-shell .row,
    body.cg-accounting-shell [class*="col-"] {
        min-width: 0 !important;
        max-width: 100%;
    }

    /* Constrain every common table viewport in the Accounting module. */
    body.cg-accounting-shell .table-responsive,
    body.cg-accounting-shell .gl-table-wrap,
    body.cg-accounting-shell .tb-table-wrap,
    body.cg-accounting-shell .journal-summary-table-viewport,
    body.cg-accounting-shell .journal-lines-desktop,
    body.cg-accounting-shell .journal-lines-desktop.table-responsive,
    body.cg-accounting-shell .cg-pp-desktop-table-wrap,
    body.cg-accounting-shell .cg-master-desktop-table,
    body.cg-accounting-shell .journal-grid-card,
    body.cg-accounting-shell .card-body {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.cg-accounting-shell .table-responsive,
    body.cg-accounting-shell .journal-summary-table-viewport,
    body.cg-accounting-shell .journal-lines-desktop,
    body.cg-accounting-shell .cg-pp-desktop-table-wrap,
    body.cg-accounting-shell .cg-master-desktop-table {
        width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Override legacy report min-widths (General Ledger 1180px, Trial Balance 1120px). */
    body.cg-accounting-shell .gl-table-wrap,
    body.cg-accounting-shell .tb-table-wrap {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    body.cg-accounting-shell .gl-table,
    body.cg-accounting-shell .tb-table,
    body.cg-accounting-shell .journal-index-table {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        table-layout: fixed !important;
    }

    /* All accounting tables must be allowed to shrink and wrap long labels. */
    body.cg-accounting-shell .table-responsive > table,
    body.cg-accounting-shell .gl-table-wrap > table,
    body.cg-accounting-shell .tb-table-wrap > table,
    body.cg-accounting-shell .journal-summary-table-viewport > table,
    body.cg-accounting-shell .cg-master-desktop-table > table {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.cg-accounting-shell table:not(.receipt-print-table) th,
    body.cg-accounting-shell table:not(.receipt-print-table) td {
        min-width: 0 !important;
        max-width: 100%;
        white-space: normal !important;
        overflow-wrap: anywhere;
        word-break: normal;
        vertical-align: middle;
    }

    body.cg-accounting-shell .table-responsive .form-control,
    body.cg-accounting-shell .table-responsive select,
    body.cg-accounting-shell .table-responsive input {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100%;
    }

    body.cg-accounting-shell .table-responsive .btn-group,
    body.cg-accounting-shell .table-responsive .d-flex,
    body.cg-accounting-shell .cg-master-desktop-table .btn-group {
        min-width: 0;
        max-width: 100%;
        flex-wrap: wrap;
    }

    body.cg-accounting-shell .pagination {
        max-width: 100%;
        flex-wrap: wrap;
        row-gap: .25rem;
    }

    /* Journal transaction filters used to scroll horizontally; wrap the tabs instead. */
    body.cg-accounting-shell .journal-transaction-tabs {
        max-width: 100% !important;
        min-width: 0 !important;
        flex-wrap: wrap !important;
        overflow-x: visible !important;
        overflow-y: visible !important;
        white-space: normal !important;
    }

    /* Keep currency amounts on one line only when there is enough desktop width. */
    body.cg-accounting-shell td.text-end,
    body.cg-accounting-shell th.text-end {
        overflow-wrap: anywhere;
    }

    @media (min-width: 1200px) {
        body.cg-accounting-shell .gl-table td.text-end,
        body.cg-accounting-shell .tb-table td.text-end,
        body.cg-accounting-shell .journal-index-table td.amount-cell {
            white-space: nowrap !important;
        }
    }

    @media (max-width: 767.98px) {
        /* Use existing label-driven card layouts on receipt allocation tables. */
        body.cg-accounting-shell .cg-accounting-mobile-table {
            display: block !important;
            width: 100% !important;
            min-width: 0 !important;
            max-width: 100% !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table thead {
            display: none !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody,
        body.cg-accounting-shell .cg-accounting-mobile-table tbody tr {
            display: block !important;
            width: 100% !important;
            min-width: 0 !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody tr {
            border-bottom: 1px solid #e3e8ee;
            padding: .65rem .8rem;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td {
            display: grid !important;
            grid-template-columns: minmax(90px, 36%) minmax(0, 1fr);
            gap: .55rem;
            width: 100% !important;
            min-width: 0 !important;
            padding: .38rem 0;
            border: 0 !important;
            text-align: left !important;
            white-space: normal !important;
            overflow-wrap: anywhere;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td::before {
            content: attr(data-label);
            display: block;
            color: #64788b;
            font-size: .68rem;
            font-weight: 750;
            letter-spacing: .035em;
            line-height: 1.25;
            text-transform: uppercase;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td[data-label=""]::before,
        body.cg-accounting-shell .cg-accounting-mobile-table tbody td[colspan]::before {
            content: none !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td > * {
            min-width: 0 !important;
            max-width: 100% !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td.text-end {
            text-align: left !important;
        }

        body.cg-accounting-shell .cg-accounting-mobile-table tbody td.text-end > * {
            text-align: right !important;
        }

        /* Never show the legacy minimum-width table or a horizontal bar on phones. */
        body.cg-accounting-shell .gl-table-wrap,
        body.cg-accounting-shell .tb-table-wrap,
        body.cg-accounting-shell .table-responsive {
            overflow-x: hidden !important;
        }
    }
}
