/* Canonical ERP table system
   Ordinary record lists fit their pane. Dense editor grids may scroll. */
:root {
  --table-font-size: var(--font-size-table);
  --table-heading-size: var(--font-size-table-heading);
  --table-header-height: 48px;
  --table-row-height: 48px;
  --table-cell-x: 12px;
  --table-cell-y: 10px;
  --table-radius: var(--radius-card);
  --table-frame-width: 2px;
  --table-grid-width: 1.5px;
}

.table-scroll,
.inventory-table-wrap,
.po-picker-table-wrap,
.erp-table-scroll,
.card > div:has(> .data-table) {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

/* One element owns every table outline. This prevents the mixed square,
   double-border, and partially rounded tables created by legacy wrappers. */
.erp-table-frame {
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
  background: var(--table-row);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: hidden;
}

.erp-table-frame > .data-table,
.erp-table-frame > table.data-table {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.card.has-table-frame {
  border: var(--table-frame-width) solid var(--table-frame);
  border-radius: var(--table-radius);
  overflow: hidden;
}

.card.has-table-frame > .card-hdr {
  border-bottom: var(--table-grid-width) solid var(--table-grid);
  border-radius: 0;
}

.table-section-title,
.app-layout .table-section-title,
.app-layout .card-hdr .table-section-title {
  color: #2F3B4A;
  font-family: var(--font-body);
  font-size: var(--table-heading-size);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: .45px;
  text-transform: uppercase;
}

.card.has-table-frame > .erp-table-frame {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.data-table {
  width: 100%;
  max-width: 100%;
  margin: 0;
  table-layout: fixed;
  /* The wrapper owns rounding; collapsing the cell grid keeps fractional
     1.5px rules inside the declared table width at every viewport. */
  border-collapse: collapse;
  border-spacing: 0;
  background: var(--table-row);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--table-font-size);
}

/* The table layer owns the final readable type scale. Earlier compatibility
   selectors are intentionally neutralized here instead of patched per page. */
.app-layout .data-table,
.app-layout .data-table[style*="font-size"] {
  font-size: var(--table-font-size);
}

.data-table th,
.data-table td {
  height: var(--table-row-height);
  padding: var(--table-cell-y) var(--table-cell-x);
  border-right: var(--table-grid-width) solid var(--table-grid);
  border-bottom: var(--table-grid-width) solid var(--table-grid);
  vertical-align: middle;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th {
  height: var(--table-header-height);
  padding-block: 8px;
  background: var(--table-header);
  color: #2F3B4A;
  font-size: var(--table-heading-size);
  font-weight: 800;
  letter-spacing: .45px;
  text-align: left;
  text-transform: uppercase;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.app-layout .data-table th {
  font-size: var(--table-heading-size);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.app-layout .data-table td,
.app-layout .data-table td[style*="font-size"],
.app-layout .data-table td.mono,
.app-layout .data-table .mono {
  font-size: var(--table-font-size);
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: 0;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:nth-child(even) td {
  background: var(--table-row-alt);
}

.data-table tbody tr:hover td {
  background: var(--table-hover);
}

.data-table td[colspan] {
  white-space: normal;
}

.data-table .mono,
.data-table td.mono {
  font-family: var(--font-mono);
  font-size: var(--table-font-size);
  font-variant-numeric: tabular-nums;
}

.data-table .text-right,
.data-table [data-col="money"],
.data-table [data-col="quantity"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .text-center {
  text-align: center;
}

.data-table .table-actions,
.data-table td:last-child > div {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.data-table .btn,
.data-table .btn-sm,
.data-table .btn-xs,
.data-table .btn-icon {
  min-height: 28px;
  padding: 4px 8px;
  font-size: var(--font-size-button);
  line-height: 1;
}

.data-table .form-control,
.data-table .tbl-input,
.data-table .tbl-select {
  min-width: 0;
  min-height: 30px;
  padding: 4px 7px;
  font-size: var(--font-size-table);
}

/* Work-center names need enough room for machine and process descriptors.
   The percentage contract preserves that room without forcing page overflow. */
.work-center-table col.work-center-name-col { width: 28%; }
.work-center-table col.work-center-rate-col { width: 13%; }
.work-center-table col.work-center-total-col { width: 15%; }
.work-center-table col.work-center-active-col { width: 10%; }
.work-center-table col.work-center-action-col { width: 8%; }

.work-center-table .work-center-name-input,
.work-center-table .work-center-rate-input {
  width: 100%;
  max-width: 100%;
}

.work-center-table .work-center-rate-input {
  font-family: var(--font-mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .empty-state,
.data-table tbody td.table-empty {
  color: var(--text-dim);
  text-align: center;
  white-space: normal;
}

/* Every record list uses the same one-row empty footprint as Accounting.
   Empty content changes; table geometry does not. */
.data-table tbody tr:only-child > td[colspan].table-empty {
  height: var(--table-row-height);
  padding: var(--table-cell-y) var(--table-cell-x);
  vertical-align: middle;
}

.sortable {
  cursor: pointer;
}

.sortable:hover {
  color: var(--text);
  background: var(--accent-soft);
}

/* Customer invoices */
.invoice-list-table col.invoice-number-col { width: 8%; }
.invoice-list-table col.invoice-quote-col { width: 7%; }
.invoice-list-table col.invoice-customer-col { width: 18%; }
.invoice-list-table col.invoice-date-col { width: 9%; }
.invoice-list-table col.invoice-money-col { width: 9%; }
.invoice-list-table col.invoice-status-col { width: 10%; }
.invoice-list-table col.invoice-action-col { width: 12%; }
.invoice-list-table th:nth-child(n+6):nth-child(-n+8),
.invoice-list-table td:nth-child(n+6):nth-child(-n+8) { text-align: right; }

/* Sales quotes */
.quote-db-table col.quote-number-col { width: 11%; }
.quote-db-table col.quote-customer-col { width: 24%; }
.quote-db-table col.quote-date-col { width: 11%; }
.quote-db-table col.quote-valid-col { width: 11%; }
.quote-db-table col.quote-status-col { width: 10%; }
.quote-db-table col.quote-total-col { width: 12%; }
.quote-db-table col.quote-ship-col { width: 11%; }
.quote-db-table col.quote-action-col { width: 10%; }
.quote-db-table th:nth-child(6),
.quote-db-table td:nth-child(6) { text-align: right; }

/* Purchase orders */
.po-table col.po-number-col { width: 13%; }
.po-table col.vendor-col { width: 19%; }
.po-table col.status-col { width: 13%; }
.po-table col.date-col { width: 10%; }
.po-table col.total-col { width: 9%; }
.po-table col.received-col { width: 10%; }
.po-table col.created-by-col { width: 9%; }
.po-table col.action-col { width: 7%; }

/* Vendor master */
.vendor-master-table th:nth-child(1),
.vendor-master-table td:nth-child(1) { width: 24%; }
.vendor-master-table th:nth-child(2),
.vendor-master-table td:nth-child(2) { width: 12%; }
.vendor-master-table th:nth-child(3),
.vendor-master-table td:nth-child(3) { width: 18%; }
.vendor-master-table th:nth-child(4),
.vendor-master-table td:nth-child(4) { width: 15%; }
.vendor-master-table th:nth-child(5),
.vendor-master-table td:nth-child(5) { width: 18%; }
.vendor-master-table th:nth-child(6),
.vendor-master-table td:nth-child(6) { width: 8%; }
.vendor-master-table th:nth-child(7),
.vendor-master-table td:nth-child(7) { width: 5%; }

/* Inventory item master */
.item-master-table col.item-number-col { width: 15%; }
.item-master-table col.item-description-col { width: 23%; }
.item-master-table col.item-category-col { width: 11%; }
.item-master-table col.item-uom-col { width: 6%; }
.item-master-table col.item-quantity-col { width: 8%; }
.item-master-table col.item-location-col { width: 11%; }
.item-master-table col.item-cost-col { width: 8%; }
.item-master-table col.item-action-col { width: 10%; }

/* Inventory ledger */
.inventory-ledger-table col.ledger-date-col { width: 12%; }
.inventory-ledger-table col.ledger-item-col { width: 20%; }
.inventory-ledger-table col.ledger-type-col { width: 10%; }
.inventory-ledger-table col.ledger-quantity-col { width: 7%; }
.inventory-ledger-table col.ledger-source-col { width: 13%; }
.inventory-ledger-table col.ledger-user-col { width: 10%; }
.inventory-ledger-table col.ledger-notes-col { width: 14%; }

/* Receiving and stock history */
.receiving-history-table th:nth-child(1),
.receiving-history-table td:nth-child(1) { width: 12%; }
.receiving-history-table th:nth-child(2),
.receiving-history-table td:nth-child(2) { width: 20%; }
.receiving-history-table th:nth-child(3),
.receiving-history-table td:nth-child(3) { width: 22%; }
.receiving-history-table th:nth-child(4),
.receiving-history-table td:nth-child(4) { width: 10%; text-align: right; }
.receiving-history-table th:nth-child(5),
.receiving-history-table td:nth-child(5) { width: 8%; }
.receiving-history-table th:nth-child(6),
.receiving-history-table td:nth-child(6) { width: 14%; }
.receiving-history-table th:nth-child(7),
.receiving-history-table td:nth-child(7) { width: 14%; }

.stock-level-table col.stock-number-col { width: 13%; }
.stock-level-table col.stock-description-col { width: 21%; }
.stock-level-table col.stock-type-col { width: 10%; }
.stock-level-table col.stock-vendor-col { width: 13%; }
.stock-level-table col.stock-quantity-col { width: 7%; }
.stock-level-table col.stock-uom-col { width: 5%; }
.stock-level-table col.stock-reorder-col { width: 7%; }
.stock-level-table col.stock-location-col { width: 9%; }
.stock-level-table col.stock-cost-col { width: 7%; }
.stock-level-table col.stock-status-col { width: 7%; }
.stock-level-table col.stock-action-col { width: 7%; }

/* User administration */
.users-table col.username-col { width: 20%; }
.users-table col.display-col { width: 24%; }
.users-table col.role-col { width: 15%; }
.users-table col.created-col { width: 18%; }
.users-table col.action-col { width: 23%; }

/* Dense editor grids: scrolling is intentional because inputs need usable widths. */
.po-line-table { min-width: 980px; }
.po-line-table th:nth-child(1) { width: 15%; }
.po-line-table th:nth-child(2) { width: 32%; }
.po-line-table th:nth-child(3) { width: 8%; }
.po-line-table th:nth-child(4),
.po-line-table th:nth-child(5),
.po-line-table th:nth-child(6) { width: 12%; }
.po-line-table th:nth-child(7) { width: 9%; }

.routing-table { min-width: 1120px; }
.routing-table col.seq-col { width: 6%; }
.routing-table col.work-center-col { width: 14%; }
.routing-table col.operation-col { width: 20%; }
.routing-table col.hours-col,
.routing-table col.rate-col,
.routing-table col.cost-col { width: 8%; }
.routing-table col.notes-col { width: 26%; }
.routing-table col.action-col { width: 8%; }

.outside-services-table { min-width: 1220px; }
.outside-services-table col.part-col { width: 9%; }
.outside-services-table col.vendor-col { width: 13%; }
.outside-services-table col.service-col { width: 17%; }
.outside-services-table col.description-col { width: 20%; }
.outside-services-table col.cost-col { width: 8%; }
.outside-services-table col.qty-col { width: 6%; }
.outside-services-table col.total-col { width: 8%; }
.outside-services-table col.lead-col { width: 7%; }
.outside-services-table col.notes-col { width: 9%; }
.outside-services-table col.action-col { width: 3%; }

.part-cost-table { min-width: 980px; }
.part-cost-table col.part-col { width: 12%; }
.part-cost-table col.name-col { width: 20%; }
.part-cost-table col.qty-col { width: 7%; }
.part-cost-table col.money-col { width: 9%; }
.part-cost-table col.scrap-col { width: 7%; }
.part-cost-table col.preprofit-col { width: 13%; }
.part-cost-table col.price-col { width: 14%; }

.po-picker-table { min-width: 760px; }
.po-picker-table th:nth-child(1) { width: 34%; }
.po-picker-table th:nth-child(2) { width: 13%; }
.po-picker-table th:nth-child(3) { width: 19%; }
.po-picker-table th:nth-child(4) { width: 12%; }
.po-picker-table th:nth-child(5) { width: 12%; }
.po-picker-table th:nth-child(6) { width: 10%; }

.po-vendor-picker-table { min-width: 780px; }
.po-vendor-picker-table th:nth-child(1) { width: 25%; }
.po-vendor-picker-table th:nth-child(2) { width: 17%; }
.po-vendor-picker-table th:nth-child(3) { width: 17%; }
.po-vendor-picker-table th:nth-child(4) { width: 20%; }
.po-vendor-picker-table th:nth-child(5) { width: 11%; }
.po-vendor-picker-table th:nth-child(6) { width: 10%; }

@media (max-width: 900px) {
  :root {
    --table-font-size: var(--font-size-meta);
    --table-cell-x: 8px;
  }

  .po-table,
  .item-master-table,
  .vendor-master-table,
  .invoice-list-table,
  .quote-db-table,
  .inventory-ledger-table,
  .stock-level-table {
    min-width: 860px;
  }
}
