/* resp-accounts-b — responsive layout for its pages. Loaded after app.css (and before pos.css / Radzen theme,
   so selectors are doubled-up with an ab- class to win on specificity instead of order).
   Pages: ProfitLoss, Coa, Journals, TrialBalance, BalanceSheet, BankStatement. */

/* ------------------------------------------------------------------
   Filter / form rows  (.ab-filters = date + branch + action buttons)
   ------------------------------------------------------------------ */
.ab-filters {
    row-gap: 0.75rem;
}

.ab-filters > .rz-form-field {
    min-width: 0;
}

.ab-toolbar {
    row-gap: 0.5rem;
}

.ab-toolbar > label {
    margin: 0;
}

.ab-file {
    max-width: 100%;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.ab-file::file-selector-button {
    margin-right: 0.65rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: inherit;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* ------------------------------------------------------------------
   Summary tiles (.ab-stats) — layered on the shared .pos-bill-list-stats.
   Column layout (1 / 2 / 4 across, 12-col track on desktop) comes from resp-shell.css;
   here: compact tiles, unwrapped amounts, and two-up on phones.
   ------------------------------------------------------------------ */
.ab-stats .pos-bill-list-stat {
    padding: 0.8rem 0.9rem;
    gap: 0.65rem;
    min-width: 0;
}

.ab-stats .pos-bill-list-stat__body {
    min-width: 0;
}

.ab-stats .pos-bill-list-stat__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ab-stats .pos-bill-list-stat__value {
    font-size: 1.3rem;
    white-space: nowrap;
    overflow-wrap: normal;
    font-variant-numeric: tabular-nums;
}

/* phones: two tiles per row, icon above the label so the amount gets the whole tile width */
@media (max-width: 479.98px) {
    .app-page .pos-bill-list-stats.ab-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.6rem;
    }

    .app-page .pos-bill-list-stats.ab-stats > :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .ab-stats .pos-bill-list-stat {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
        padding: 0.7rem 0.75rem;
    }

    .ab-stats .pos-bill-list-stat__icon {
        width: 30px;
        height: 30px;
    }

    .ab-stats .pos-bill-list-stat__icon .rz-icon {
        font-size: 1rem;
    }

    .ab-stats .pos-bill-list-stat__body {
        width: 100%;
    }

    .ab-stats .pos-bill-list-stat__value {
        font-size: 1.1rem;
    }
}

/* ------------------------------------------------------------------
   Profit & loss sections: income | expense (auto-fit, no orphan gaps)
   ------------------------------------------------------------------ */
.ab-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 1rem;
    align-items: stretch;
}

.ab-section {
    min-width: 0;
}

.ab-section > .app-page__card {
    height: 100%;
    margin-bottom: 0;
}

.ab-section .rz-stack.rz-justify-content-space-between {
    gap: 0.75rem;
    align-items: baseline;
    border-bottom: 1px solid var(--border-subtle);
}

.ab-section .rz-stack.rz-justify-content-space-between:last-child {
    border-bottom: 0;
}

.ab-line__name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ab-line__amt {
    flex: none;
    white-space: nowrap;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------
   Balance sheet: assets | (liabilities over equity); stacks on narrow
   ------------------------------------------------------------------ */
.ab-bs {
    display: grid;
    /* at most two columns, collapse to one when each would drop under ~380px */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(380px, calc(50% - 0.5rem))), 1fr));
    gap: 1rem;
    align-items: stretch;
}

.ab-bs > div {
    min-width: 0;
}

.ab-bs > div > .app-page__card {
    height: 100%;
    margin-bottom: 0;
}

@media (min-width: 776px) {
    .ab-bs__assets {
        grid-row: span 2;
    }
}

/* ------------------------------------------------------------------
   Report tables — scroll inside their card, never the page
   ------------------------------------------------------------------ */
.app-page__card.ab-report {
    min-width: 0;
    max-width: 100%;
}

.ab-report .rz-data-grid,
.ab-report .app-datagrid {
    max-width: 100%;
}

.ab-report .rz-data-grid-data {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* the one un-sized text column collapses to 0 inside table-layout:fixed, so give the table a floor */
.ab-report .rz-grid-table {
    min-width: var(--ab-min, 0);
}

.ab-report--tb { --ab-min: 560px; }
.ab-report--bs { --ab-min: 0; }
.ab-report--coa { --ab-min: 580px; }
.ab-report--jr { --ab-min: 660px; }
.ab-report--jl { --ab-min: 450px; }
.ab-report--bank { --ab-min: 780px; }

/* amounts: right aligned, never wrapped */
.ab-report .rz-grid-table td.rz-text-align-right,
.ab-report .rz-grid-table th.rz-text-align-right,
.ab-report .rz-grid-table td[style*="text-align:right"],
.ab-report .rz-grid-table th[style*="text-align:right"] {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ab-report .rz-grid-table td.rz-text-align-right .rz-cell-data,
.ab-report .rz-grid-table td.rz-text-align-right > * {
    white-space: nowrap;
}

/* Bank match column: suggestion pill + account picker + Match button need ~340px.
   Radzen writes width / flex-wrap as inline styles, hence the !important. */
.ab-report--bank .rz-grid-table col:nth-child(4) {
    width: 360px !important;
}

.ab-report--bank .rz-grid-table td .rz-stack {
    flex-wrap: wrap !important;
    row-gap: 0.35rem;
}

/* "no rows" message stays inside the visible part of a scrolling table */
.ab-report .rz-grid-table .rz-datatable-emptymessage {
    text-align: left;
}

.ab-report .rz-grid-table .rz-datatable-emptymessage > span {
    position: sticky;
    left: 0.75rem;
    display: inline-block;
    max-width: calc(100vw - 6.5rem);
}

/* text columns may wrap rather than blow the table out */
.ab-report .rz-grid-table td {
    overflow-wrap: anywhere;
}

.ab-report .rz-grid-table td.rz-text-align-right {
    overflow-wrap: normal;
}

/* ------------------------------------------------------------------
   Journals composer lines (flex: Radzen's .rz-display-flex is !important, so no grid here)
   desktop: [ account ........ ][ debit ][ credit ][x]
   phone:   [ account .................... ]
            [ debit ....][ credit ....][x]
   ------------------------------------------------------------------ */
.ab-jline {
    row-gap: 0.5rem;
}

.ab-jline .ab-jline__acct {
    flex: 1 1 14rem;
    min-width: 0;
}

.ab-jline .rz-numeric {
    flex: 0 0 7rem;
    width: 7rem;
    min-width: 0;
}

.ab-filters > .rz-button,
.ab-actions > .rz-button,
.ab-toolbar > .rz-button {
    white-space: nowrap;
}

.ab-actions > .rz-button {
    min-width: 0;
}

/* ------------------------------------------------------------------
   Tablet / narrow desktop (sidebar still open): drop the least useful columns
   ------------------------------------------------------------------ */
@media (max-width: 1100px) {
    .ab-report--coa .rz-grid-table :is(col, th, td):nth-child(4),
    .ab-report--jr .rz-grid-table :is(col, th, td):nth-child(3),
    .ab-report--jr .rz-grid-table :is(col, th, td):nth-child(6) {
        display: none;
    }

    .ab-report--coa { --ab-min: 500px; }
    .ab-report--jr { --ab-min: 480px; }
    .ab-report--bank { --ab-min: 800px; }
}

/* ------------------------------------------------------------------
   Phones
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
    /* filter rows: fields share a row when they fit, otherwise fill it; buttons fill their row */
    .ab-filters > .rz-form-field {
        flex: 1 1 140px;
    }

    .ab-filters > .rz-form-field.ab-field-wide {
        flex-basis: 100%;
    }

    .ab-filters > .rz-form-field .rz-datepicker,
    .ab-filters > .rz-form-field .rz-dropdown,
    .ab-filters > .rz-form-field .rz-textbox,
    .ab-filters > .rz-form-field .rz-inputtext:not(.rz-datepicker input) {
        width: 100%;
    }

    .ab-filters > .rz-button,
    .ab-actions > .rz-button {
        flex: 1 1 auto;
        min-height: 40px;
    }

    .ab-filters > .rzi {
        display: none;
    }

    .ab-file {
        flex: 1 1 100%;
    }

    .ab-file::file-selector-button {
        min-height: 40px;
    }

    .ab-toolbar > * {
        min-height: 40px;
    }

    .ab-toolbar > label {
        display: inline-flex;
        align-items: center;
    }

    .ab-toolbar > .rz-button {
        margin-left: auto;
    }

    /* composer lines: account on its own row, debit | credit | delete below */
    .ab-jline {
        padding-bottom: 0.65rem;
        border-bottom: 1px solid var(--border-subtle);
    }

    .ab-jline .ab-jline__acct {
        flex: 1 1 100%;
    }

    .ab-jline .rz-numeric {
        flex: 1 1 6rem;
        width: auto;
    }

    .ab-jline .rz-button {
        min-width: 40px;
        min-height: 40px;
    }

    /* tighter cards around scrolling tables */
    .app-page__card.ab-report:not(.ab-report--bs) {
        padding: 0.5rem;
    }

    .app-page__card.ab-report.app-page__card--flush {
        padding: 0;
    }

    .ab-sections,
    .ab-bs {
        gap: 0.75rem;
    }

    .ab-report .rz-button {
        min-width: 40px;
        min-height: 40px;
    }

    /* phones: trial balance drops its Type column, balance sheet its Code column */
    .ab-report--tb .rz-grid-table :is(col, th, td):nth-child(3),
    .ab-report--bs .rz-grid-table :is(col, th, td):nth-child(1) {
        display: none;
    }

    .ab-report--tb { --ab-min: 440px; }
    .ab-report--coa { --ab-min: 500px; }
    .ab-report--jr { --ab-min: 470px; }
    .ab-report--jl { --ab-min: 440px; }
    .ab-report--bank { --ab-min: 800px; }
}
