/* Unified full-width data grids. Attach AFTER existing styles.
   Scope: .app-shell-frame tables and rp-ledger classes. No colors of dialogs/alerts touched. */

/* ---- Width: release constraints only where a table exists ---- */
.app-shell-frame .max-w-7xl:has(table) { max-width: none !important; width: 100%; }
.rp-ledger-header,
.rp-ledger-tabs,
.rp-ledger-content,
.rp-ledger-content > [data-testid],
.rp-ledger-billing { max-width: none !important; }
.rp-ledger-page, .rp-ledger-content, .rp-ledger-grid, .rp-ledger-split { min-width: 0; }

/* ---- Internal horizontal overflow, never document overflow ---- */
.app-shell-frame :is(.overflow-auto, .overflow-x-auto, .rp-ledger-surface):has(> table) {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.app-shell-frame .rp-ledger-grid, .app-shell-frame .rp-ledger-surface { max-width: 100%; }

/* ---- Table base: system font, fine borders, compact rows ---- */
.app-shell-frame table {
  width: 100%;
  border-collapse: collapse;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
.app-shell-frame table :is(th, td) {
  vertical-align: middle;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}
.app-shell-frame table th { white-space: nowrap; overflow-wrap: normal; }
/* Contracts retain their explicitly sized, centered multi-line headers. */
.app-shell-frame .rp-resident-contracts th { white-space:normal; overflow-wrap:anywhere; }
.app-shell-frame table tbody tr { border-bottom: 1px solid var(--ledger-line, rgba(128,134,140,.28)); }
.app-shell-frame table td { padding-block: 8px; }

/* No truncation / clamping inside tables only */
.app-shell-frame table :is(.truncate, .line-clamp-1, .line-clamp-2, .line-clamp-3) {
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: normal !important;
  max-width: none !important;
  -webkit-line-clamp: unset !important;
  line-clamp: unset !important;
}
.app-shell-frame table :is(.line-clamp-1, .line-clamp-2, .line-clamp-3):not(td):not(th) { display: block; }
.app-shell-frame table :is(.whitespace-nowrap, .rp-ledger-date, .rp-ledger-number) { white-space: nowrap; overflow-wrap: normal; }

/* Numeric alignment */
.app-shell-frame table :is(.text-right, .rp-ledger-number, [data-numeric]) {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

/* ---- Ledger: lift old compact/min-width rules narrowly ---- */
.rp-ledger-table, .rp-ledger-request-table { width: 100%; }
.rp-ledger-split[data-detail-open="true"] .rp-ledger-request-table { min-width: 980px; }
.rp-ledger-split[data-detail-open="true"] .rp-ledger-hide-in-detail { display: table-cell; }
.rp-ledger-request-table td:nth-child(3) { min-width: 0; }
.rp-ledger-table th:first-child, .rp-ledger-table td:first-child { padding-left: 12px !important; }
.rp-ledger-table th:last-child, .rp-ledger-table td:last-child { padding-right: 12px !important; }
.rp-ledger-table .rp-ledger-actions { min-width: 0 !important; }
.rp-ledger-table td.rp-request-checkbox, .rp-ledger-table th.rp-request-checkbox { width: 38px; padding-inline: 8px !important; text-align: center; }

/* ---- Purchase orders: one line per item, grouped tbody ---- */
[data-testid="table-purchase-orders"] { table-layout: auto !important; min-width: 1480px !important; }
[data-testid="table-purchase-orders"] col.hidden { display: none; }
[data-testid="table-purchase-orders"] tbody {
  border-top: 1px solid var(--ledger-line, rgba(128,134,140,.4));
}
[data-testid="table-purchase-orders"] tbody + tbody { border-top-width: 2px; }
[data-testid="table-purchase-orders"] tbody tr + tr { border-top: 1px dashed var(--ledger-line, rgba(128,134,140,.28)); }
[data-testid="table-purchase-orders"] :is(th, td) { text-align: left; }
[data-testid="table-purchase-orders"] th:nth-child(-n+3) { text-align: center; }
[data-testid="table-purchase-orders"] td[rowspan] { text-align: center; vertical-align: middle; }
[data-testid="table-purchase-orders"] .rp-po-line-row td { padding-block: 6px; }
[data-testid="table-purchase-orders"] td.font-mono { text-align: right !important; }
[data-testid="table-purchase-orders"] .truncate { white-space: normal !important; }

/* ---- Small screens: keep paddings tight, scrolling stays internal ---- */
@media (max-width: 767px) {
  .app-shell-frame table :is(th, td) { padding-inline: 8px; }
  .rp-ledger-header, .rp-ledger-tabs, .rp-ledger-content > [data-testid] { padding-inline: 12px; }
}

/* Inventory uses div-based grids, not HTML tables. Keep headers/rows in
   the same scrollable surface and preserve stock-alert colors/actions. */
.rp-pharmacy-grids { width:100%; min-width:0; }
.rp-pharmacy-grids .testing-delete-inventory-scroll {
  overflow-x:auto !important; max-width:100%; width:100%;
}
.rp-pharmacy-grids .testing-delete-inventory-scroll > * { min-width:1120px; }
.rp-pharmacy-grids .testing-delete-inventory-scroll .truncate {
  overflow:visible !important; white-space:normal !important;
  text-overflow:clip !important; max-width:none !important;
  overflow-wrap:anywhere;
}
.rp-pharmacy-grids .testing-delete-inventory-scroll [class*="grid-cols-"] {
  min-width:0; align-items:center;
}
.rp-pharmacy-grids .testing-delete-inventory-scroll [class*="grid-cols-"] > * { min-width:0; }
.rp-pharmacy-grids .testing-delete-inventory-scroll > .grid { min-width:1120px; }
.rp-pharmacy-grids .testing-delete-inventory-scroll .grid[class*="1.4fr_1.6fr"] { padding-block:10px; }
.app-shell-frame .rp-ledger-page { width:100%; max-width:none !important; }
.app-shell-frame .rp-ledger-content { padding-inline:0; }
.app-shell-frame .rp-ledger-header, .app-shell-frame .rp-ledger-tabs { padding-inline:0; }
.app-shell-frame .rp-ledger-content > [data-testid] { padding-inline:0; }
