/* invoice-list.css: one pattern for the invoice screens Sprzedaż and Zakupy (task #105, decision D25):
   view switch (.subnav), quick filter chips, the phone „Filtry” fold, column switch, popover menus,
   drawn checkboxes, row badges, bulk bar, white panel cards and the phone card layout of the table.
   Markup: index.html (Sprzedaż), js/invoice-list.js, js/sales.js, js/purchases.js. Layout follows
   .mockups/kalkulator-v2 (components.css .segmented, .menu; views.css .quick, .bulk). Colours, spacing
   and type only from css/variables.css. Only domain parts stay in tab-sprzedaz.css / tab-zakupy.css. */

/* The wide table scrolls inside its card, never the page (flex / grid items default to min-width: auto) */
.list-screen, .list-view { min-width: 0; max-width: 100%; }
.list-screen > .subnav-wrap { margin-bottom: 0; }
/* Zakupy builds its switch inside the list root: the same 16 px rhythm as the container gap in Sprzedaż */
.ledger-root:has(> .subnav-wrap) { display: flex; flex-direction: column; gap: var(--spacing-4); }
.ledger-root > .subnav-wrap { margin-bottom: 0; }

/* ---------- View switch: segmented tabs (role="tablist") ---------- */
.subnav-wrap { position: relative; align-self: flex-start; max-width: 100%; margin-bottom: var(--spacing-4); }
.subnav {
    display: inline-flex; width: fit-content; max-width: 100%; gap: var(--spacing-1); padding: var(--spacing-1);
    background: var(--color-slate-100); border-radius: var(--radius-xl); overflow-x: auto; scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav__btn {
    display: inline-flex; align-items: center; gap: var(--spacing-2); flex: none; min-height: 36px; padding: 0 var(--spacing-4);
    border: 0; border-radius: var(--radius-lg); background: transparent; color: var(--color-text-secondary);
    font: inherit; font-size: var(--font-size-sm); font-weight: 600; white-space: nowrap; cursor: pointer;
}
.subnav__btn:hover { color: var(--color-text); }
.subnav__btn[aria-selected="true"] { background: var(--color-bg-card); color: var(--color-text); box-shadow: var(--shadow-md); }
.subnav__btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.subnav__count { background: var(--color-slate-200); color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.subnav__count[hidden] { display: none; }
.subnav__btn[aria-selected="true"] .subnav__count { background: var(--color-primary-100); color: var(--color-primary-700); }
/* „Do kategoryzacji” with a queue: the count in the warning colour, also on the active tab */
.subnav__btn.has-todo .subnav__count, .subnav__btn.has-todo[aria-selected="true"] .subnav__count { background: var(--status-warning-bg); color: var(--status-warning-fg); }

/* Edge fade while more tabs are hidden to the side (phone): the switch itself fades out, so a cut tab never
   ends with a hard edge (the classes come from InvoiceList.bindTabs) */
.subnav-wrap.has-more-start .subnav {
    -webkit-mask-image: linear-gradient(to right, transparent, var(--color-text) var(--spacing-12));
    mask-image: linear-gradient(to right, transparent, var(--color-text) var(--spacing-12));
}
.subnav-wrap.has-more-end .subnav {
    -webkit-mask-image: linear-gradient(to left, transparent, var(--color-text) var(--spacing-12));
    mask-image: linear-gradient(to left, transparent, var(--color-text) var(--spacing-12));
}
.subnav-wrap.has-more-start.has-more-end .subnav {
    -webkit-mask-image: linear-gradient(to right, transparent, var(--color-text) var(--spacing-12), var(--color-text) calc(100% - var(--spacing-12)), transparent);
    mask-image: linear-gradient(to right, transparent, var(--color-text) var(--spacing-12), var(--color-text) calc(100% - var(--spacing-12)), transparent);
}

/* ---------- Sum tile link (e.g. „w tym kwoty zbiorcze” → the manual view) ---------- */
.stat-tile__link {
    align-self: flex-start; padding: 0; border: 0; background: none; font: inherit; font-size: var(--font-size-xs);
    color: var(--color-primary-700); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; text-align: left;
}

/* ---------- Quick filter chips ---------- */
.list-chips-wrap { position: relative; }
.list-chips { display: flex; flex-wrap: wrap; gap: var(--spacing-2); padding: var(--spacing-4) var(--spacing-5) 0; }
.list-chip { flex: none; background: var(--color-bg-card); color: var(--color-text-secondary); font-family: inherit; cursor: pointer; }
.list-chip:hover { border-color: var(--color-slate-500); color: var(--color-text); }
.list-chip[aria-pressed="true"] { background: var(--color-primary-50); color: var(--color-primary-700); border-color: var(--color-primary-500); }
.list-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.list-chip__count { background: var(--color-slate-100); color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.list-chip[aria-pressed="true"] .list-chip__count { background: var(--color-bg-card); color: var(--color-primary-700); }
.list-chips-wrap + .ledger-toolbar { padding-top: var(--spacing-3); }

/* ---------- Filters: on a computer the wrapper is transparent to the toolbar layout ---------- */
.list-filters { display: contents; }
.ledger-toolbar .list-filters-btn { display: none; }
.list-filters-btn__count {
    display: inline-flex; align-items: center; justify-content: center; min-width: 1.4rem; height: 1.4rem; padding: 0 var(--spacing-2);
    border-radius: var(--radius-full); background: var(--color-primary-600); color: var(--btn-primary-fg); font-size: var(--font-size-xs);
}
.list-filters-btn__count[hidden] { display: none; }

/* ---------- Column switch ---------- */
.list-columns { align-self: flex-end; }
.list-columns-btn { width: 40px; min-height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-secondary); }
.list-columns-btn .icon { width: 1.1rem; height: 1.1rem; color: var(--color-text-secondary); }
.list-columns-btn:hover .icon { color: var(--color-text); }

/* ---------- Popover menu (row „⋮”, columns): top layer, placed by js/invoice-list.js ---------- */
.list-menu {
    position: fixed; inset: auto; margin: 0; min-width: 13rem; max-width: 20rem; padding: var(--spacing-2);
    background: var(--color-bg-card); color: var(--color-text); border: 1px solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
    z-index: var(--z-dropdown);
}
.list-menu[popover]:not(:popover-open) { display: none; }
.list-menu__item {
    display: flex; align-items: center; gap: var(--spacing-3); width: 100%; min-height: 40px; padding: 0 var(--spacing-3); border: 0; border-radius: var(--radius-lg);
    background: transparent; color: var(--color-text); font: inherit; font-size: var(--font-size-sm); font-weight: 500; text-align: left; cursor: pointer;
}
.list-menu__item .icon { width: 1.05rem; height: 1.05rem; color: var(--color-text-muted); }
.list-menu__item:hover, .list-menu__item:focus-visible { background: var(--color-primary-50); outline: none; }
.list-menu__item--danger, .list-menu__item--danger .icon { color: var(--status-danger-fg); }
.list-menu__item--danger:hover { background: var(--status-danger-bg); }
.list-menu__heading {
    padding: var(--spacing-2) var(--spacing-3) var(--spacing-1); font-size: var(--font-size-2xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted);
}
.list-menu__check {
    display: flex; align-items: center; gap: var(--spacing-3); min-height: 40px; padding: 0 var(--spacing-3); border-radius: var(--radius-lg);
    font-size: var(--font-size-sm); font-weight: 500; cursor: pointer;
}
.list-menu__check:hover { background: var(--color-primary-50); }
.list-more__icon { width: 1.15rem; height: 1.15rem; fill: currentColor; stroke: none; }

/* ---------- Checkbox: drawn, so the border stays visible in both themes (≥ 3:1) ---------- */
.list-check, .list-menu__check input {
    appearance: none; display: inline-grid; place-content: center; flex: none; width: 1.125rem; height: 1.125rem; margin: 0;
    border: 2px solid var(--color-text-muted); border-radius: var(--radius-sm); background: var(--color-bg-card); vertical-align: middle; cursor: pointer;
}
.list-check::before, .list-menu__check input::before {
    content: ''; width: .55rem; height: .3rem; border: solid var(--btn-primary-fg); border-width: 0 0 2px 2px;
    transform: translateY(-1px) rotate(-45deg); opacity: 0;
}
.list-check:checked, .list-menu__check input:checked { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); }
.list-check:checked::before, .list-menu__check input:checked::before { opacity: 1; }
.list-check:indeterminate { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); }
.list-check:indeterminate::before { opacity: 1; height: 0; border-width: 0 0 2px; transform: none; }
.list-check:focus-visible, .list-menu__check input:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Table: three layouts by the width of the list card, not the screen (#105) ----------
   The card is a size container: above 70rem (1440 px screen and wider) the full table; 59.375–70rem (about 1280 px)
   the compact table (date under the number, „Netto / VAT” in one column, sticky „⋮”); below 59.375rem
   (1024 px and the phone) the rows become cards with a sort bar. Fixed column widths: no jumps when filtering. */
.ledger-root .ledger-card { container: list / inline-size; }
.list-alt { display: none; }

@container list (min-width: 59.375rem) {
    .ledger-root .ledger-table:has(.col-select) { table-layout: fixed; min-width: 70rem; }
    .ledger-root .ledger-table thead th[data-key="select"] { width: 3rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="number"] { width: 10.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="date"] { width: 8.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="net"] { width: 7.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="vat"] { width: 6.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="gross"] { width: 8.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="kind"] { width: 12rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="status"] { width: 9.5rem; }
    .ledger-root .ledger-table:has(.col-select) thead th[data-key="actions"] { width: 3.25rem; }
    .ledger-root .ledger-table:has(.col-select) .col-contractor { min-width: 0; max-width: none; overflow-wrap: break-word; }
    .ledger-root .ledger-table:has(.col-select) .col-number { min-width: 0; overflow-wrap: anywhere; }
    .ledger-root .ledger-table:has(.col-select) .kind-btn { max-width: 100%; }
    /* The expense type is never cut: a long subcategory wraps to a second line */
    .ledger-root .ledger-table:has(th.col-kind) .kind-btn__sub { white-space: normal; overflow-wrap: break-word; line-height: 1.25; }
    .ledger-root .ledger-table:has(th.col-kind) .kind-btn--none .type-mark { height: auto; min-height: 1.25rem; white-space: normal; text-align: left; line-height: 1.25; padding: 2px 6px; }
    /* Zakupy has one more column (Rodzaj wydatku): tighter cells, so the whole row fits the full layout */
    .ledger-root .ledger-table:has(th.col-kind) { min-width: 70rem; }
    .ledger-root .ledger-table:has(th.col-kind) :is(thead th, tbody td, tbody th, tfoot td, tfoot th):not(:first-child):not(:last-child) { padding-left: var(--spacing-2); padding-right: var(--spacing-2); }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="number"] { width: 9.25rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="date"] { width: 6.75rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="net"] { width: 6.5rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="vat"] { width: 5.5rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="gross"] { width: 7.25rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="kind"] { width: 10.25rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="status"] { width: 9.5rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="actions"] { width: 3rem; }
}

/* Compact table: the date column and the VAT column keep their place (the footer colspan counts them) at zero width */
@container list (min-width: 59.375rem) and (max-width: 70rem) {
    /* :has(th.col-select) weighs as much as the Zakupy :has(th.col-kind) rules above, so these win by order */
    .ledger-root .ledger-table:has(th.col-select) { min-width: 0; }
    .ledger-root .ledger-table:has(th.col-select) thead th:is([data-key="date"], [data-key="vat"]) { width: 0; padding: 0; overflow: hidden; font-size: 0; border-left: 0; border-right: 0; }
    .ledger-root .ledger-table:has(th.col-select) :is(tbody, tfoot) :is(td.col-date, td[data-label="VAT"]) { padding: 0; overflow: hidden; font-size: 0; }
    .ledger-root .ledger-table:has(th.col-select) tbody td.col-date > * { display: none; }
    /* Wide enough for „dd.mm.rrrr” + „Faktura ręczna” on one line under the number */
    .ledger-root .ledger-table:has(th.col-select) thead th[data-key="number"] { width: 11.75rem; }
    .ledger-root .ledger-table:has(th.col-select) thead th[data-key="net"] { width: 7.5rem; }
    /* Zakupy: „Netto / VAT” needs only the amount width; the rest keeps a seller name on one line */
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="net"] { width: 5.75rem; }
    .ledger-root .ledger-table:has(th.col-kind) thead th[data-key="kind"] { width: 9.75rem; }
    .ledger-root .ledger-table:has(th.col-select) thead th[data-key="net"] .ledger-sort > span:first-child::after { content: ' / VAT'; }
    .ledger-root .ledger-table:has(th.col-select) .list-alt--vat { display: block; }
    .ledger-root .ledger-table:has(th.col-select) .list-alt--date { display: flex; flex-wrap: wrap; align-items: center; gap: var(--spacing-1) var(--spacing-2); margin-top: var(--spacing-1); font-weight: 400; color: var(--color-text); }
    .ledger-root .ledger-table:has(th.col-select) .list-alt--date .doc-badge { margin-top: 0; }
    .ledger-root .ledger-table:has(th.col-select) .list-alt--date .list-badge { margin: 0; }
    .ledger-root .ledger-table:has(th.col-select) .list-alt__keep { display: inline-flex; align-items: center; gap: var(--spacing-2); white-space: nowrap; }
    /* „⋮” stays in sight even if a long name still widens the table (no own background on hover / selection) */
    :where(.ledger-root) .ledger-table :is(thead th[data-key="actions"], tbody td.col-actions) { position: sticky; right: 0; background: var(--color-bg-card); }
}

.ledger-root .ledger-table .col-select { padding-right: 0; }
.ledger-root .ledger-table tbody tr:has(.list-check:checked) > * { background: var(--color-primary-50); }
.ledger-root .ledger-table:has(th.col-select) .col-date { color: var(--color-text); }
.ledger-root .ledger-table .col-number .ledger-number { display: inline; margin-right: var(--spacing-1); }
.list-src { display: flex; flex-wrap: wrap; gap: var(--spacing-1); margin-top: var(--spacing-1); }
.list-src .doc-badge { margin-top: 0; }
.list-badge { margin: var(--spacing-1) var(--spacing-1) 0 0; background: var(--status-neutral-bg); color: var(--status-neutral-fg); vertical-align: middle; }
.list-badge--warn { background: var(--status-warning-bg); color: var(--status-warning-fg); }
.list-badge--accent { background: var(--status-accent-bg); color: var(--status-accent-fg); }
.list-mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: var(--font-size-2xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Absolutely positioned bits in the table (hidden caption, checkbox marks) stay inside the scroller */
.ledger-root .ledger-scroll { position: relative; }

/* ---------- Bulk bar ---------- */
.list-bulk {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--spacing-2) var(--spacing-4); padding: var(--spacing-3) var(--spacing-5);
    background: var(--color-primary-50); color: var(--color-primary-700); font-size: var(--font-size-sm); border-bottom: 1px solid var(--color-border);
}
.list-bulk[hidden] { display: none; }
.list-bulk__sum { color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.list-bulk__actions { display: flex; flex-wrap: wrap; gap: var(--spacing-2); margin-left: auto; }
.list-bulk__actions .btn { display: inline-flex; align-items: center; gap: var(--spacing-2); }
.list-bulk__actions .icon { width: 1rem; height: 1rem; }

/* ---------- Manual views: notice on top, white panel cards with a plain header ---------- */
.list-manual > .notice { margin-bottom: var(--spacing-4); }
.list-manual .notice a { color: inherit; font-weight: 600; }
.zk-manual.list-manual > .notice { margin-bottom: 0; }
.panel-card { padding: var(--spacing-5) var(--spacing-6); border-radius: var(--radius-card); box-shadow: var(--shadow-card); min-width: 0; }
.panel-card__head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: var(--spacing-2) var(--spacing-4); margin-bottom: var(--spacing-4); }
.panel-card__title { margin: 0; font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); color: var(--color-text); letter-spacing: var(--letter-spacing-normal); }
.panel-card__sub { margin: 0; font-size: var(--font-size-sm); color: var(--color-text-muted); }

/* ---------- Cards: the list card narrower than 59.375rem (1024 px screen, phone) ----------
   The same card layout as css/ledger.css gives every table on the phone, here driven by the card width */
@container list (max-width: 59.374rem) {
    .ledger-root .ledger-scroll { overflow: visible; background: var(--color-bg-card); }
    .ledger-root .ledger-table, .ledger-root .ledger-table tbody, .ledger-root .ledger-table tfoot { display: block; }
    .ledger-root .ledger-table tbody tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--spacing-3); row-gap: 4px; align-items: center;
        grid-template-areas: "contractor gross" "number number" "date kind" "status actions";
        padding: var(--spacing-3) var(--spacing-4); border-bottom: 1px solid var(--color-border);
    }
    .ledger-root .ledger-table tbody tr:last-child { border-bottom: 0; }
    .ledger-root .ledger-table tbody tr > *, .ledger-root .ledger-table tbody tr > *:first-child, .ledger-root .ledger-table tbody tr > *:last-child { display: block; padding: 0; border: 0; min-width: 0; max-width: none; }
    .ledger-root .ledger-table tbody tr:hover > * { background: transparent; }
    .ledger-root .ledger-table tbody .col-contractor { grid-area: contractor; }
    .ledger-root .ledger-table tbody .col-gross { grid-area: gross; text-align: right; }
    .ledger-root .ledger-table tbody .col-number { grid-area: number; display: flex; align-items: center; gap: var(--spacing-2); flex-wrap: wrap; }
    .ledger-root .ledger-table tbody .col-date { grid-area: date; }
    .ledger-root .ledger-table tbody .col-status { grid-area: status; }
    /* The expense type gets its own line: next to the date it widened the amount column and squeezed the name */
    .ledger-root .ledger-table tbody .col-kind { grid-area: kind; justify-self: start; }
    .ledger-root .ledger-table tbody .col-actions { grid-area: actions; width: auto; justify-self: end; }
    .ledger-root .ledger-table tbody td[data-label="Netto"], .ledger-root .ledger-table tbody td[data-label="VAT"] { display: none; }
    .ledger-root .ledger-table .ledger-contractor { font-weight: 600; }
    .ledger-root .ledger-table .row-actions { justify-content: flex-end; margin-top: -2px; }
    .ledger-root .ledger-table tfoot tr { display: flex; flex-wrap: wrap; gap: 2px var(--spacing-4); padding: var(--spacing-3) var(--spacing-4); background: var(--color-bg-subtle); }
    .ledger-root .ledger-table tfoot tr > *, .ledger-root .ledger-table tfoot tr > *:first-child { display: block; padding: 0; border: 0; background: transparent; }
    .ledger-root .ledger-table tfoot .ledger-total__label { flex-basis: 100%; }
    .ledger-root .ledger-table tfoot td:empty { display: none; }
    .ledger-root .ledger-table tfoot td[data-label]::before { content: attr(data-label) ' '; font-weight: 500; color: var(--color-text-muted); }
    .ledger-root .ledger-table tfoot .list-alt { display: none; }
    /* No contractor: the kind of evidence („Paragon”) is the card title, as on the phone */
    .ledger-root .ledger-contractor--none { color: var(--color-text); }
    .ledger-root .ledger-contractor--none .ledger-contractor__dash { display: none; }
    .ledger-root .ledger-contractor--none .ledger-contractor__alt { display: inline; }
    /* Phone: the head is only for screen readers */
    .ledger-root .ledger-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

    /* Cards: selection box on the left, the source badge next to the date, the expense type opposite it; 15 px content */
    .ledger-root .ledger-table:has(.col-select) { font-size: var(--font-size-base); }
    .ledger-root .ledger-table:has(.col-select) tbody tr {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "select contractor gross" ". number number" ". date date" ". status actions";
    }
    /* Zakupy: one more line for the expense type */
    .ledger-root .ledger-table:has(th.col-kind) tbody tr { grid-template-areas: "select contractor gross" ". number number" ". date date" ". kind kind" ". status actions"; }
    .ledger-root .ledger-table tbody tr:has(.list-check:checked) { background: var(--color-primary-50); }
    .ledger-root .ledger-table tbody tr:has(.list-check:checked) > * { background: transparent; }
    .ledger-root .ledger-table tbody .col-select { grid-area: select; align-self: start; margin: calc(-1 * var(--spacing-2)) 0 0 calc(-1 * var(--spacing-2)); }
    .ledger-root .ledger-table tbody .col-select .list-check { width: 1.375rem; height: 1.375rem; margin: var(--spacing-2) var(--spacing-1) var(--spacing-2) var(--spacing-2); }
    .ledger-root .ledger-table:has(.col-select) tbody .col-date { display: flex; flex-wrap: wrap; align-items: center; gap: var(--spacing-1) var(--spacing-2); font-size: var(--font-size-sm); }
    .ledger-root .ledger-table:has(.col-select) tbody .col-date .ledger-sub { flex-basis: 100%; }
    .ledger-root .ledger-table:has(.col-select) .ledger-number { font-size: var(--font-size-sm); }
    .ledger-root .ledger-table:has(.col-select) .ledger-sub { font-size: var(--font-size-sm); }
    .ledger-root .ledger-table:has(.col-select) .pay-pill { font-size: var(--font-size-sm); min-height: 32px; }
    .ledger-root .ledger-table:has(.col-select) .kind-btn { font-size: var(--font-size-sm); min-height: 36px; }
    .ledger-root .ledger-table tbody .list-src { margin-top: 0; }
    .ledger-root .ledger-table:has(.col-select) tbody .col-number .ledger-sub { flex-basis: 100%; }

}

/* Cards on a wider card (1024 px screen): the head becomes a sort bar with „Zaznacz wszystkie” */
@container list (min-width: 30rem) and (max-width: 59.374rem) {
    .ledger-root .ledger-table thead { position: static; display: block; width: auto; height: auto; overflow: visible; clip: auto; }
    .ledger-root .ledger-table thead tr { display: flex; flex-wrap: wrap; align-items: center; gap: var(--spacing-2) var(--spacing-4); padding: var(--spacing-3) var(--spacing-4); border-bottom: 1px solid var(--color-border); }
    .ledger-root .ledger-table thead tr::before { content: 'Sortuj:'; order: -1; font-size: var(--font-size-xs); color: var(--color-text-muted); }
    .ledger-root .ledger-table thead th, .ledger-root .ledger-table thead th:first-child { display: block; width: auto; min-width: 0; max-width: none; padding: 0; border: 0; }
    .ledger-root .ledger-table thead th[data-key="select"] { order: -2; margin-right: var(--spacing-2); }
    .ledger-root .ledger-table thead th:not([data-key="select"]):not(:has(.ledger-sort)) { display: none; }
    /* Net and VAT under the gross amount (the card has no columns for them) */
    .ledger-root .ledger-table tbody .list-alt--netvat { display: block; white-space: nowrap; }
}

/* ---------- Phone ---------- */
@media (max-width: 767px) {
    .subnav-wrap { align-self: stretch; }
    .subnav { display: flex; width: 100%; }
    .subnav__btn { flex: 1 0 auto; justify-content: center; min-height: 44px; padding: 0 var(--spacing-3); font-size: var(--font-size-base); }

    .list-chips { flex-wrap: nowrap; overflow-x: auto; padding: var(--spacing-3) var(--spacing-4) 0; scrollbar-width: none; }
    .list-chips::-webkit-scrollbar { display: none; }
    /* More chips to the right: the row fades out at the edge */
    .list-chips-wrap.has-more-end .list-chips {
        -webkit-mask-image: linear-gradient(to right, var(--color-text) calc(100% - var(--spacing-12)), transparent);
        mask-image: linear-gradient(to right, var(--color-text) calc(100% - var(--spacing-12)), transparent);
    }

    /* Search stays; the selects fold under „Filtry” */
    .list-chips-wrap + .ledger-toolbar { align-items: stretch; }
    .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field--search { flex: 1 1 0; min-width: 0; }
    .ledger-toolbar .list-filters-btn { display: inline-flex; align-self: flex-end; padding: 0 var(--spacing-3); }
    .list-filters-btn .icon { width: 1.1rem; height: 1.1rem; }
    .list-filters { display: none; }
    .ledger-toolbar.is-filters-open .list-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-3); flex-basis: 100%; }
    .list-filters .ledger-toolbar__field { min-width: 0; }
    .list-columns { display: none; }
    .list-chips-wrap + .ledger-toolbar .ledger-toolbar__clear { min-height: 44px; font-size: var(--font-size-base); }
    .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field .label { font-size: var(--font-size-sm); }
    /* The field keeps 16 px (no iOS zoom); only the hint is smaller, so „Numer, sprzedawca, NIP” fits next to „Filtry” */
    .list-chips-wrap + .ledger-toolbar .ledger-toolbar__search::placeholder { font-size: var(--font-size-sm); }
    .list-chips-wrap + .ledger-toolbar .ledger-toolbar__count { font-size: var(--font-size-sm); }

    .list-bulk { padding: var(--spacing-3) var(--spacing-4); font-size: var(--font-size-base); }
    .list-bulk__actions { margin-left: 0; }
    .list-bulk__actions .btn { min-height: 44px; font-size: var(--font-size-base); }

    .list-manual > .notice { font-size: var(--font-size-base); }
    .panel-card { padding: var(--spacing-4); }
    .panel-card__sub { font-size: var(--font-size-base); }
    .list-menu__item, .list-menu__check { min-height: 44px; font-size: var(--font-size-base); }
}

/* ---------- Sprzedaż and Zakupy „Faktury” 1:1 with .mockups/kalkulator-v2 (#108) ---------- */
/* Header actions (mockup InvoiceViews.actions): KSeF, Eksport CSV, Dodaj paragon (Zakupy) before the primary button */
.ledger-head-btn[hidden], .ledger-fab[hidden] { display: none; }
.ledger-fab { display: none; }

/* Toolbar as the mockup's filter grid: search 1.6fr, four 1fr tracks, tools; Zakupy 1.4fr + six tracks from 1200 px */
@media (min-width: 768px) {
    .ledger-root .list-chips-wrap + .ledger-toolbar {
        display: grid; grid-template-columns: minmax(12rem, 1.6fr) repeat(4, minmax(7rem, 1fr)) auto; align-items: end; gap: var(--spacing-3);
    }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field--search { max-width: none; min-width: 0; }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field { min-width: 0; }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__select { width: 100%; min-width: 0; }
    .ledger-root .list-chips-wrap + .ledger-toolbar .list-columns { align-self: end; }
    /* Column switch and „Wyczyść filtry” share one cell, as the mockup .inv-filters__tools */
    .ledger-root .list-chips-wrap + .ledger-toolbar :is(.list-columns, .ledger-toolbar__clear) { grid-row: 1; grid-column: 5; justify-self: start; align-self: end; }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__clear { margin-left: 44px; }
}
/* The count is read out (role="status"); the mockup shows it in the pager, not in the toolbar */
.ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__count { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; margin: 0; }
@media (min-width: 1200px) {
    #purchases-root .list-chips-wrap + .ledger-toolbar { grid-template-columns: minmax(11rem, 1.4fr) repeat(6, minmax(6.5rem, 1fr)) auto; }
    #purchases-root .list-chips-wrap + .ledger-toolbar :is(.list-columns, .ledger-toolbar__clear) { grid-column: 8; }
}
@media (min-width: 768px) and (max-width: 1199px) {
    #purchases-root .list-chips-wrap + .ledger-toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    #purchases-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field--search { grid-column: 1 / -1; }
    #purchases-root .list-chips-wrap + .ledger-toolbar :is(.list-columns, .ledger-toolbar__clear) { grid-row: auto; grid-column: auto / span 1; }
    #purchases-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__clear { margin-left: 0; }
}

/* Empty month (mockup UI.empty): icon, title 17/600, hint and the actions in one row */
.ledger-root .ledger-empty .empty__title { font-size: var(--font-size-lg); font-weight: 600; line-height: var(--line-height-normal); margin: 0; }
.ledger-root .ledger-empty .empty__text { margin-bottom: 0; }
.ledger-root .ledger-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--spacing-2); margin-top: var(--spacing-6); }

@media (max-width: 767px) {
    /* Phone header: KSeF as an icon button, CSV / receipt / primary off; adding goes through the round button */
    .ledger-head-btn { padding: 0 var(--spacing-3); }
    .ledger-head-btn .ledger-head-btn__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
    .page-header__right .ledger-head-btn--wide { display: none; }
    body.has-ledger-list #add-entry-btn { display: none; }
    body.has-ledger-list .ledger-fab:not([hidden]) {
        display: inline-flex; align-items: center; justify-content: center; position: fixed; z-index: var(--z-dropdown);
        right: var(--spacing-4); bottom: calc(80px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; padding: 0; border: 0;
        border-radius: var(--radius-full); background: var(--btn-primary-bg); color: var(--btn-primary-fg); box-shadow: var(--shadow-xl); cursor: pointer;
    }
    .ledger-fab .icon { width: 1.5rem; height: 1.5rem; }
    .ledger-fab:focus-visible { outline: none; box-shadow: var(--focus-ring); }
    /* Toolbar as the mockup's phone filter row: chips, then search (label for screen readers only) and „Filtry” */
    .ledger-root .list-chips { padding-bottom: 2px; }
    .ledger-root .list-chips-wrap + .ledger-toolbar { gap: var(--spacing-3); }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__field--search > .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
    .ledger-root .ledger-toolbar .list-filters-btn { padding: 0 var(--spacing-4); }
    .ledger-root .list-chips-wrap + .ledger-toolbar .ledger-toolbar__clear:disabled { display: none; }
    .ledger-root .ledger-empty-actions { flex-direction: column; align-items: flex-start; align-self: stretch; gap: var(--spacing-5); }
}
