/* Tables: plain HTML tables (h:dataTable) and PrimeFaces data tables share one look.
   Quiet header, comfortable rows, row hover, sticky header inside scroll areas,
   horizontal scrolling with edge shadows on small screens, money and code cells, selectable rows. */

.table-wrap {
    overflow: auto;
    border: 1px solid var(--ep-border);
    border-radius: var(--radius-lg);
    background: var(--ep-surface);
    /* Edge shadows hint that the table scrolls sideways. */
    background:
        linear-gradient(to right, var(--ep-surface) 30%, transparent) left / 24px 100% no-repeat local,
        linear-gradient(to left, var(--ep-surface) 30%, transparent) right / 24px 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%, rgb(16 24 40 / 12%), transparent) left / 10px 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, rgb(16 24 40 / 12%), transparent) right / 10px 100% no-repeat scroll,
        var(--ep-surface);
}
.table-wrap > table { border: 0; }

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    background: transparent;
}

th,
.ui-datatable thead > tr > th {
    padding: 11px 14px;
    background: var(--ep-surface-subtle);
    color: var(--ep-muted);
    font-size: 12.5px;
    font-weight: 700;
    text-align: start;
    white-space: nowrap;
    border-bottom: 1px solid var(--ep-border);
}
/* Header stays visible while a scroll area scrolls. */
.table-wrap th, .account-audit-table th, .paid-rents-table-wrap th, .ui-datatable-scrollable-header th { position: sticky; top: 0; z-index: 1; }
tbody th { position: static; background: transparent; color: var(--text-heading); font-size: 14px; }

td,
.ui-datatable .ui-datatable-data > tr > td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--ep-border);
    color: var(--text);
    line-height: 1.55;
    vertical-align: middle;
}
tbody tr:last-child > td, tbody tr:last-child > th,
.ui-datatable .ui-datatable-data > tr:last-child > td { border-bottom: 0; }

tbody tr, .ui-datatable .ui-datatable-data > tr { transition: background-color var(--duration-fast) ease; }
tbody tr:hover, .ui-datatable .ui-datatable-data > tr:hover { background: color-mix(in srgb, var(--ep-primary-soft) 45%, transparent); }

/* PrimeFaces table frame */
.ui-datatable { border: 1px solid var(--ep-border); border-radius: var(--radius-lg); overflow: hidden; background: var(--ep-surface); }
.ui-datatable .ui-datatable-tablewrapper, .ui-datatable .ui-datatable-scrollable-body { overflow-x: auto; }
.ui-datatable table { border: 0; }
.ui-datatable .ui-datatable-empty-message td { padding: 32px 16px; text-align: center; color: var(--ep-muted); }
.ui-paginator {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px;
    padding: 10px; border-top: 1px solid var(--ep-border); background: var(--ep-surface);
}
.ui-paginator a, .ui-paginator .ui-paginator-page {
    display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px;
    border-radius: var(--radius-sm); color: var(--text-heading); text-decoration: none; font-weight: 600; font-size: 13.5px; cursor: pointer;
}
.ui-paginator a:hover { background: var(--ep-surface-subtle); }
.ui-paginator .ui-state-active { background: var(--ep-primary); color: var(--white); }
.ui-paginator .ui-state-disabled { opacity: 0.4; cursor: default; }

/* Money and code cells */
.money {
    display: inline-block;
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--text-heading);
}
.code-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--ep-surface-subtle);
    border: 1px solid var(--ep-border);
    color: var(--text-heading);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    direction: ltr;
    white-space: nowrap;
}

/* Selectable rows (properties list) */
.selectable-properties tbody tr { cursor: pointer; }
.selectable-properties tbody tr.selected-property {
    background: var(--selection-background);
    box-shadow: inset 4px 0 var(--ep-primary);
}
html[dir=rtl] .selectable-properties tbody tr.selected-property { box-shadow: inset -4px 0 var(--ep-primary); }

/* Tools above data tables (ui-enhancements.js): instant filter on the start side, List / Cards switch on the end side. */
.ep-table-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-3); }
.ep-table-tools.is-inside-table { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--ep-border); background: var(--ep-surface); }
.ep-table-filter {
    display: flex; align-items: center; gap: var(--space-2); flex: 1; max-width: 360px; position: relative;
}
.ep-table-filter input[type=search] { padding-inline-start: 38px; min-height: 38px; font-size: 14px; }
.ep-table-filter::before {
    content: ""; position: absolute; inset-inline-start: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
    background: var(--ep-muted);
    -webkit-mask: var(--icon-search) center / contain no-repeat; mask: var(--icon-search) center / contain no-repeat;
    pointer-events: none;
}
.ep-table-filter-count { font-size: var(--text-xs); color: var(--ep-muted); white-space: nowrap; }
tr.ep-filtered-out { display: none; }
.ep-filter-empty td { text-align: center; color: var(--ep-muted); padding: 24px; }

@media (max-width: 700px) {
    /* Tables scroll sideways on phones instead of squeezing columns. */
    table:not(.ui-datatable table):not(.dash-table) { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td, .ui-datatable thead > tr > th, .ui-datatable .ui-datatable-data > tr > td { padding: 10px 12px; }
    /* Short values (dates, amounts, codes) stay on one line; the table scrolls sideways instead. */
    td, .ui-datatable .ui-datatable-data > tr > td { white-space: nowrap; }
    td small, td .invoice-apartment-location, td .hint { white-space: normal; min-width: 180px; display: block; }
    .ep-table-filter { max-width: none; }
}

/* Buttons and fields inside table rows use the compact size. */
td input[type=submit], td input[type=button], td button:not([class*=ep-]), td .ui-button {
    min-height: var(--control-height-sm);
    padding: 0 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}
th input[type=text], th .ui-column-filter { min-height: 34px; padding: 6px 10px; font-size: 13px; margin-top: 6px; font-weight: 400; }

/* Remove the PrimeFaces theme's vertical cell borders and dark frame lines. */
.ui-datatable thead > tr > th,
.ui-datatable tfoot > tr > td,
.ui-datatable .ui-datatable-data > tr > td {
    border-inline: 0 !important;
    border-top: 0 !important;
    border-color: var(--ep-border) !important;
}
.ui-datatable .ui-datatable-tablewrapper > table,
.ui-datatable table thead,
.ui-datatable table tbody { border: 0 !important; }
.ui-datatable .ui-datatable-header {
    padding: var(--space-4);
    background: var(--ep-surface-subtle);
    border: 0;
    border-bottom: 1px solid var(--ep-border);
    color: var(--text);
    font-weight: 400;
    text-align: start;
}
.ui-datatable th .ui-column-title { font-weight: 700; }
.ui-datatable th.ui-sortable-column:hover { background: color-mix(in srgb, var(--ep-surface-subtle) 60%, var(--ep-border)); }

/* List / Cards switch */
.ep-view-toggle { display: inline-flex; flex: none; padding: 3px; gap: 2px; border-radius: var(--radius-md); background: var(--ep-surface-subtle); border: 1px solid var(--ep-border); }
.ep-view-option {
    display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border: 0; border-radius: 7px;
    background: transparent; color: var(--ep-muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.ep-view-option svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ep-view-option:hover { color: var(--text-heading); }
.ep-view-option[aria-pressed=true] { background: var(--ep-surface); color: var(--ep-primary); box-shadow: var(--shadow-sm); }
.ep-view-option:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Cards view: the same table rows shown as cards (buttons and links keep working) ---------- */
.ep-cards-frame { border: 0 !important; background: transparent !important; overflow: visible !important; box-shadow: none !important; }
.ep-cards-frame .ui-datatable-tablewrapper { overflow: visible; }
table.ep-cards, table.ep-cards > tbody { display: block; overflow: visible !important; max-width: none; }
table.ep-cards > thead { display: none; }
/* Column filters stay usable above the cards. */
table.ep-cards > thead:has(input, select) { display: block; margin-bottom: var(--space-3); }
table.ep-cards > thead:has(input, select) > tr { display: flex; flex-wrap: wrap; gap: var(--space-2); }
table.ep-cards > thead:has(input, select) > tr > th { display: block; flex: 1 1 160px; padding: 0; background: none; border: 0 !important; position: static; }
table.ep-cards > thead > tr > th:not(:has(input, select)) { display: none; }
table.ep-cards > tbody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
    gap: var(--space-3);
}
table.ep-cards > tbody > tr {
    --card-tone: var(--ep-border);
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 14px 16px 12px;
    background: var(--ep-surface);
    border: 1px solid var(--ep-border);
    border-inline-start: 4px solid var(--card-tone);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: transform var(--duration) var(--ease-out), box-shadow var(--duration) ease, border-color var(--duration) ease;
    animation: ep-rise var(--duration-slow) var(--ease-out) both;
}
table.ep-cards > tbody > tr:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); background: var(--ep-surface); }
table.ep-cards > tbody > tr[data-tone=good] { --card-tone: var(--status-success); }
table.ep-cards > tbody > tr[data-tone=warn] { --card-tone: var(--status-warning); }
table.ep-cards > tbody > tr[data-tone=bad] { --card-tone: var(--status-danger); }
table.ep-cards > tbody > tr.selected-property { --card-tone: var(--ep-primary); box-shadow: 0 0 0 2px var(--ep-primary-border); }
table.ep-cards > tbody > tr.ep-filtered-out { display: none; }
table.ep-cards > tbody > tr > td,
table.ep-cards > tbody > tr > th {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 5px 0 !important;
    border: 0 !important;
    background: none;
    white-space: normal !important;
    text-align: end;
    font-size: 13.5px;
    min-width: 0;
}
table.ep-cards > tbody > tr > td::before {
    content: attr(data-label);
    flex: none;
    max-width: 48%;
    color: var(--ep-muted);
    font-size: 12.5px;
    font-weight: 500;
    text-align: start;
}
table.ep-cards > tbody > tr > td.ep-card-title {
    order: -1;
    justify-content: flex-start;
    margin-bottom: 6px;
    padding-bottom: 10px !important;
    border-bottom: 1px dashed var(--ep-border) !important;
    color: var(--text-heading);
    font-size: 15px;
    font-weight: 700;
    text-align: start;
}
table.ep-cards > tbody > tr > td.ep-card-title::before,
table.ep-cards > tbody > tr > td.ep-card-actions::before { display: none; }
table.ep-cards > tbody > tr > td.ep-card-actions {
    order: 10;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 12px !important;
    border-top: 1px solid var(--ep-border) !important;
}
table.ep-cards > tbody > tr > td.ep-card-empty { display: none; }
table.ep-cards > tbody > tr.ep-filter-empty { display: block; grid-column: 1 / -1; border-inline-start-width: 1px; }
table.ep-cards > tbody > tr.ep-filter-empty > td { display: block; text-align: center; }
table.ep-cards > tbody > tr.ep-filter-empty > td::before { display: none; }

@media (max-width: 700px) {
    .ep-table-tools { flex-wrap: wrap; }
    .ep-table-filter { max-width: none; flex-basis: 100%; order: 2; }
    .ep-view-option span { display: none; }
    .ep-view-option { padding: 0 9px; }
}
@media (prefers-reduced-motion: reduce) { table.ep-cards > tbody > tr { animation: none; } }
/* A reference code before the title becomes a small chip in the card's top corner. */
table.ep-cards > tbody > tr > td.ep-card-code { position: absolute; top: 12px; inset-inline-end: 14px; padding: 0 !important; }
table.ep-cards > tbody > tr > td.ep-card-code::before { display: none; }
table.ep-cards > tbody > tr:has(> td.ep-card-code) > td.ep-card-title { padding-inline-end: 110px; }
/* Cards view refinements: compact filter grid, block title (name and address stack), no sort arrows. */
table.ep-cards > thead:has(input, select) > tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-2); }
table.ep-cards > thead > tr > th::after, table.ep-cards > thead .ui-sortable-column-icon { display: none !important; }
table.ep-cards > thead > tr > th { font-size: 12px; }
table.ep-cards > thead input { min-height: 36px; margin-top: 4px; }
table.ep-cards > tbody > tr > td.ep-card-title { display: block; }
table.ep-cards > tbody > tr > td.ep-card-title small,
table.ep-cards > tbody > tr > td.ep-card-title .invoice-apartment-location { display: block; margin-top: 4px; font-size: 12px; font-weight: 500; color: var(--ep-muted); }
table.ep-cards > tbody > tr > td > * { max-width: 100%; }
@media (max-width: 700px) {
    /* PrimeFaces tables in list view scroll sideways instead of squeezing their headers. */
    .ui-datatable table:not(.ep-cards) { min-width: 560px; }
}

/* PrimeFaces gives every column the same fixed width and hides what does not fit (cut buttons, squeezed names).
   Let columns size to their content instead; the table scrolls sideways when it is wider than the card. */
.ui-datatable table { table-layout: auto !important; }
.ui-datatable thead > tr > th, .ui-datatable .ui-datatable-data > tr > td { overflow: visible !important; }
.ui-datatable .ui-datatable-data > tr > td .ui-button, .ui-datatable .ui-datatable-data > tr > td input[type=submit] { white-space: nowrap; }
/* A status text followed by its button: the button goes on its own line so the column stays narrow. */
.ui-datatable .ui-datatable-data > tr > td:has(> .ui-button) > .ui-button { display: flex; width: max-content; margin-top: 6px; }
.ui-datatable .ui-datatable-data > tr > td:has(> .ui-button):not(:has(> :not(.ui-button))) > .ui-button:first-child { margin-top: 0; }
.ui-datatable .ui-datatable-data > tr > td .invoice-receipt-link { white-space: normal; }
.ui-datatable .ui-datatable-data > tr > td .invoice-receipt-link small { display: block; white-space: normal; }
#work\:invoices th, #work\:invoices td { padding-inline: 10px; }
.ui-datatable .ui-datatable-data > tr > td:has(.invoice-apartment-location) { min-width: 190px; white-space: normal; }
.ui-datatable .ui-datatable-data > tr > td .invoice-apartment-location { max-width: 300px; }
/* Wide tables scroll sideways inside their card instead of cutting the action buttons. */
.ui-datatable .ui-datatable-tablewrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ui-datatable .ui-datatable-data > tr > td .ui-button, .ui-datatable .ui-datatable-data > tr > td input[type=submit] { flex: none; max-width: none; }
.ui-datatable .ui-datatable-data > tr > td:last-child:has(.ui-button, input[type=submit]) { width: 1%; }
/* Darker, clearer column titles. */
th, .ui-datatable thead > tr > th { color: var(--text-heading); font-weight: 700; }
