/* Podatki: month settlement (#90). Layout of .mockups/kalkulator-v2 (views-b.css „Podatki (M3)”):
 * settings chips, white cards Sprzedaż / Zakupy / Zysk netto, VAT | Terminy, ZUS | Podatek dochodowy,
 * year to date and „Jak to liczymy?”. Colours only from css/variables.css tokens. Everything is scoped
 * to .tax-summary, so the older summary rules of components.css do not reach other tabs and vice versa. */

.tax-summary { display: flex; flex-direction: column; gap: var(--spacing-6); min-width: 0; }

.tax-summary .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Settings chips */
/* Tax settings as static chips of the mockup (DESIGN.md chip-static, D28) */
.tax-settings { display: flex; flex-wrap: wrap; align-items: center; gap: var(--spacing-2); }
.tax-settings .link-more { font-size: var(--font-size-sm); }
/* The views of Podatki (subnav panels) stack their cards like the section */
.tax-screen { display: flex; flex-direction: column; gap: var(--spacing-6); }
.tax-screen > .list-view { display: flex; flex-direction: column; gap: var(--spacing-6); min-width: 0; }
.tax-screen > .list-view[hidden] { display: none; }

.tax-summary .notice--success { background: var(--status-success-bg); color: var(--status-success-fg); }
.tax-summary .notice .icon { flex: none; width: 1.1rem; height: 1.1rem; }

/* Grid of cards as in the mockup (#108): Sprzedaż | Zakupy | Zysk, VAT | Terminy, ZUS | Podatek, year to date.
   Cards of one row share the row height (grid stretch), the content stays at the top of each card. */
.tax-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--spacing-6); }
.tax-card--sales, .tax-card--purch, .tax-card--profit { grid-column: span 4; }
.tax-card--vat, .tax-card--dead, .tax-card--zus, .tax-card--income { grid-column: span 6; }
.tax-card--ytd { grid-column: 1 / -1; }
/* #109: a paid obligation is dimmed as in the mockup (views.css .deadline--paid) */
.tax-summary .deadline--paid { opacity: .85; }
/* The deadline sum follows the last row directly (#107 P0: no hole above it) */
p.tax-card__foot:not(.tax-note) {
    display: flex; justify-content: space-between; align-items: baseline; gap: var(--spacing-3);
    padding-top: var(--spacing-3); border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm); color: var(--color-text-secondary);
}
p.tax-card__foot:not(.tax-note) strong { font-size: var(--font-size-xl); font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* VAT: „no split by rate” note only while the rate table is hidden (mockup) */
.tax-note--norates { display: flex; gap: 6px; align-items: flex-start; }
.tax-note--norates .icon { flex: none; width: 1rem; height: 1rem; }
#vat-rates-breakdown:not(.hidden) ~ .tax-note--norates { display: none; }

.tax-summary .tax-card > .card__title { line-height: var(--line-height-normal); }
.tax-summary .tax-card { display: flex; flex-direction: column; gap: var(--spacing-3); min-width: 0; overflow: visible; }

/* Label / amount rows */
.tax-rows { display: flex; flex-direction: column; gap: var(--spacing-2); }
.tax-summary .summary-row { align-items: baseline; padding: 0; font-size: var(--font-size-sm); }
.tax-summary .summary-label { color: var(--color-text-secondary); }
.tax-summary .summary-value { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--color-text); }
/* Label and amount follow the row size: 13 px on a computer, 16 px on a phone */
.tax-summary .summary-label, .tax-summary .summary-value { font-size: inherit; }
.tax-summary .summary-note { color: var(--color-text-muted); line-height: 1.35; }
.tax-summary .summary-row--subtotal,
.tax-summary .summary-row--ytd,
.tax-summary .summary-row--separate,
.tax-summary .summary-row--info { margin-top: var(--spacing-1); padding-top: var(--spacing-2); }
.tax-summary .summary-row--tax-note { margin-top: calc(-1 * var(--spacing-1)); }

.tax-summary .tax-row--big {
    align-items: center; padding-top: var(--spacing-2);
    border-top: 1px solid var(--color-border); font-size: var(--font-size-base);
}
.tax-summary .tax-row--big .summary-label { color: var(--color-text-secondary); }
.tax-summary .tax-row--big .summary-value { font-size: var(--font-size-xl); color: var(--color-primary-700); }

/* Big amounts: VAT, profit */
.tax-big {
    font-size: 2rem; font-weight: 700; line-height: 1.15; letter-spacing: var(--letter-spacing-tight);
    font-variant-numeric: tabular-nums; color: var(--color-text); overflow-wrap: anywhere;
}
.tax-card--vat .tax-big { color: var(--color-primary-700); }
.tax-card--vat .tax-big.summary-value--negative { color: var(--status-success-fg); }
.tax-card--profit .tax-big { color: var(--status-success-fg); }
.tax-card--profit.is-loss .tax-big { color: var(--status-danger-fg); }
.tax-card--profit.is-zero .tax-big { color: var(--color-text); }
.tax-note { font-size: var(--font-size-xs); color: var(--color-text-muted); line-height: 1.45; }

/* Rate tables (VAT, ZUS) */
.tax-table-wrap { overflow-x: auto; }
.tax-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
.tax-table th, .tax-table td { padding: 8px 6px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tax-table thead th {
    font-size: var(--font-size-2xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--color-text-muted); border-bottom: 1px solid var(--color-border);
}
.tax-table tbody td { border-bottom: 1px solid var(--color-border-light); color: var(--color-text); }
.tax-table th:first-child, .tax-table td:first-child { text-align: left; font-weight: 500; color: var(--color-text); white-space: normal; }
.tax-table thead th:first-child { color: var(--color-text-muted); font-weight: 600; }
.tax-table tfoot td { font-weight: 700; color: var(--color-text); border-top: 1px solid var(--color-border); }
.tax-table tfoot td:first-child { font-weight: 700; }

.tax-summary .tax-card__action { width: 100%; justify-content: center; margin-top: var(--spacing-1); padding: var(--spacing-2) var(--spacing-3); background: var(--color-bg-card); }

/* Terminy: the rows are the Pulpit „deadline” rows (css/shell.css) */
.tax-card--dead .deadline__title { line-height: 1.35; }

/* Year to date */
.tax-ytd { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--spacing-6); }
.tax-ytd__item { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tax-ytd__label { font-size: var(--font-size-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--color-text-muted); }
.tax-ytd__value { font-size: var(--font-size-xl); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-text); }
.tax-progress { height: 10px; margin-top: var(--spacing-1); border-radius: var(--radius-full); background: var(--color-slate-100); overflow: hidden; }
.tax-progress__fill { display: block; height: 100%; max-width: 100%; border-radius: inherit; background: var(--color-primary-500); transition: width var(--transition-slow); }

/* „Jak to liczymy?” */
.tax-summary .tax-how { overflow: visible; }
.tax-how summary { font-weight: 600; cursor: pointer; color: var(--color-text); }
.tax-how summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-md); }
.tax-how ul { margin-top: var(--spacing-3); display: flex; flex-direction: column; gap: var(--spacing-2); font-size: var(--font-size-sm); color: var(--color-text-secondary); list-style: disc; padding-left: var(--spacing-5); }
.tax-how .tax-note { margin-top: var(--spacing-3); }

@media (max-width: 1099px) {
    .tax-card--sales, .tax-card--purch { grid-column: span 6; }
    .tax-card--profit, .tax-card--vat, .tax-card--dead, .tax-card--zus, .tax-card--income { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
    .tax-summary { gap: var(--spacing-4); }
    .tax-grid { gap: var(--spacing-4); }
    .tax-grid .tax-card { grid-column: 1 / -1; }
    .tax-big { font-size: 1.6rem; }
    /* Rows, notes and rate tables keep the mockup sizes on a phone too (13 / 12 px, cells 8 × 6) (#108) */
    .tax-screen { gap: var(--spacing-4); }
}

@media (max-width: 767px) {
    /* VAT by rate on a phone: one block per rate, label left, amount right (#105) */
    #vat-rates-breakdown .tax-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    #vat-rates-breakdown .tax-table, #vat-rates-breakdown .tax-table tbody, #vat-rates-breakdown .tax-table tfoot { display: block; }
    #vat-rates-breakdown .tax-table tr { display: block; padding: var(--spacing-2) 6px; border-bottom: 1px solid var(--color-border-light); }
    #vat-rates-breakdown .tax-table :is(tbody, tfoot) td { display: flex; justify-content: space-between; gap: var(--spacing-3); padding: var(--spacing-1) 0; border: 0; text-align: right; }
    #vat-rates-breakdown .tax-table td[data-label]::before { content: attr(data-label); color: var(--color-text-muted); text-align: left; }
    #vat-rates-breakdown .tax-table tbody td:first-child { font-weight: 600; }
    #vat-rates-breakdown .tax-table tfoot td:empty { display: none; }
    #vat-rates-breakdown .tax-table tfoot tr { display: flex; justify-content: space-between; font-weight: 700; }
    .tax-ytd { grid-template-columns: 1fr; gap: var(--spacing-3); }
}

/* #107: VAT blocks on a phone start at the same 6 px inset as the ZUS table cells (rule above) */

/* #107 Roczny PIT: nine figures sit in a 3 × 3 grid instead of 4 + 4 + 1 */
@media (min-width: 768px) {
    .apit-figures:has(> :nth-child(9):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* #107 Roczny PIT on a phone: narrower POZ. column, more room for the field name */
@media (max-width: 767px) {
    .apit-table th.apit-field { width: 3rem; }
    /* #107 P1: the Miesiące table becomes one block per month (label left, amount right), no sideways scroll */
    .apit-wrap .apit-table--months thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .apit-wrap .apit-table--months, .apit-table--months tbody, .apit-table--months tfoot, .apit-table--months tr { display: block; width: 100%; }
    .apit-wrap .apit-table--months tr { padding: var(--spacing-2) var(--spacing-3); border-bottom: 1px solid var(--color-border-light); }
    .apit-wrap .apit-table--months tfoot tr { border-bottom: 0; border-top: 2px solid var(--color-border); }
    .apit-wrap .apit-table--months :is(tbody, tfoot) th { display: block; padding: var(--spacing-1) 0; border: 0; text-align: left; font-weight: 600; color: var(--color-text); }
    .apit-wrap .apit-table--months :is(tbody, tfoot) td { display: flex; justify-content: space-between; gap: var(--spacing-3); padding: 2px 0; border: 0; text-align: right; }
    .apit-wrap .apit-table--months td[data-label]::before { content: attr(data-label); color: var(--color-text-muted); text-align: left; font-weight: 400; }
}

/* #107 Dla księgowej: seller / buyer column wide enough for a company name, closing-day label on one line */
@media (min-width: 768px) {
    .pack-table thead th:nth-child(3) { width: 12rem; }
    .acct-form__extra { grid-template-columns: minmax(20rem, 1fr) minmax(0, 2fr); }
}

/* Header actions as in the mockup (#108): on the phone only the icon of „Eksport i druk”, no „Porównaj ZUS”
   (the card keeps its own „Porównaj warianty ZUS” button) */
@media (max-width: 767px) {
    #tax-zus-header-btn { display: none; }
}

/* #108 P0: cards of one row are equal (grid stretch); the footer of a stretched card sits at the bottom,
   so the free space is between the content and the footer, not under the footer. Two columns only (≥1100 px). */
@media (min-width: 1100px) {
    /* VAT: the rate table fills the card, its „Razem” row (tfoot) is pushed down. Sections keep one fixed
       column grid, so the cells of thead, tbody and tfoot stay aligned. */
    .tax-card--vat > .tax-table-wrap:not(.hidden) { flex: 1 0 auto; display: flex; flex-direction: column; }
    .tax-card--vat .tax-table { flex: 1 0 auto; display: flex; flex-direction: column; }
    .tax-card--vat .tax-table :is(thead, tbody, tfoot) { display: table; width: 100%; table-layout: fixed; border-collapse: collapse; }
    .tax-card--vat .tax-table tfoot { margin-top: auto; }
    /* ZUS: base note and „Porównaj warianty ZUS” at the bottom */
    .tax-card--zus > .tax-table-wrap ~ .tax-note:not([hidden]),
    .tax-card--zus > .tax-table-wrap ~ .tax-card__action { margin-top: auto; }
    .tax-card--zus > .tax-note:not([hidden]) + .tax-card__action { margin-top: var(--spacing-1); }
    /* Podatek dochodowy: „Zaliczka do zapłaty” and the rows under it at the bottom */
    .tax-card--income > .tax-rows { flex: 1 0 auto; }
    .tax-card--income .tax-rows > .tax-row--big { margin-top: auto; }
}
