/* ==================== DATA TABLES ==================== */
/* Compact density: 39px rows, 12px cells, 11px headers, no-wrap, subtle zebra */

.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card > .table-container {
  border-radius: inherit;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card > .table-container > .data-table {
  margin: 0;
}

.data-table {
  width: 100%;
  /* Lock column geometry at first paint: with the default auto layout, column
     widths are recomputed from cell content when the remaining rows stream in
     after a mid-parse paint and again when webfonts swap — the whole-table
     column jump that reads as the page loading twice. Fixed layout takes the
     widths from the header row's col-w-* hints and never re-lays-out. */
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-caption);
}

/* ---- Column width hints (th only) ----
   With table-layout: fixed, the header row sets every column's width. Give
   each th a hint; when the hinted widths total less than the container the
   surplus is distributed proportionally, and when they total more the table
   overflows into .table-container's horizontal scroll (mobile). A th without
   a hint shares only the leftover space — fine for the primary text column
   of small tables, but it collapses on narrow screens in wide tables. */
.data-table th.col-w-2xs { width: 56px; }  /* HTTP status, small counts */
.data-table th.col-w-xs  { width: 80px; }  /* counts, short flags */
.data-table th.col-w-sm  { width: 104px; } /* dates, relative times */
.data-table th.col-w-md  { width: 128px; } /* status badges, currency */
.data-table th.col-w-lg  { width: 152px; } /* shipment ids, vendor names */
.data-table th.col-w-xl  { width: 192px; } /* long names, vessels, emails */
.data-table th.col-w-2xl { width: 240px; } /* references, routes */
.data-table th.col-w-3xl { width: 320px; } /* filenames, descriptions */

/* ---- Header ---- */
.data-table thead {
  position: relative;
  top: auto;
  z-index: 10;
}

.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--pk-gray-500);
  padding: 8px 10px;
  background: transparent;
  border-bottom: 1px solid var(--pk-gray-200);
  white-space: nowrap;
  /* Fixed layout means a header can be narrower than its label — clip like
     the cells do instead of bleeding into the next column. */
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th.align-right,
.data-table th.right {
  text-align: right;
}

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

/* ---- Body Rows ---- */
.data-table tbody tr {
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

/* Subtle zebra — even rows get a faint stone tint for row definition without
   spreadsheet-style separator lines. Uses --table-row-stripe so dark mode
   (--pk-surface-2) themes automatically. Placed before :hover so hover wins on
   even rows (equal specificity → source order). */
.data-table tbody tr:nth-child(even) {
  background: var(--table-row-stripe);
}

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

/* ---- Cells ---- */
.data-table td {
  padding: 6px 10px;
  color: var(--pk-gray-700);
  font-size: var(--text-caption);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  height: 39px;
}

.data-table td.align-right,
.data-table td.right {
  text-align: right;
}

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

/* Invoice # cell that can carry an inline "Duplicate" badge. The cell stays
   clipped (global overflow: hidden) so nothing spills into the next column.
   Inside, the number + badge are a flex row: the badge is pinned at full size
   (flex: none) while the number ellipsizes first when the viewport is tight —
   so the badge is never clipped and never overlaps the Shipment column. */
.cell-badge-visible .cell-inline {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.cell-badge-visible .cell-inline .data-id {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-badge-visible .cell-inline .duplicate-badge {
  flex: none;
  margin-left: 0;
}

/* ---- Table Toolbar ---- */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--pk-gray-100);
}

.table-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--text-sm);
  color: var(--pk-gray-500);
}

.table-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- Table Footer ---- */
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--pk-gray-100);
  font-size: var(--text-sm);
  color: var(--pk-gray-500);
}

/* ---- Cell Type Styles ---- */

.shipment-link {
  color: var(--pk-orange);
  font-weight: var(--font-normal);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.shipment-link:hover {
  text-decoration: underline;
}

.shipment-link .link-icon,
.shipment-link i {
  font-size: var(--text-xs);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.data-table tbody tr:hover .shipment-link .link-icon,
.data-table tbody tr:hover .shipment-link i {
  opacity: 1;
}

.filename-cell {
  font-weight: var(--font-normal);
  color: var(--pk-gray-700);
}

.filename-link {
  color: var(--pk-gray-700);
  text-decoration: none;
}

.filename-link:hover {
  color: var(--pk-orange);
}

.amount,
.data-table td.align-right {
  font-variant-numeric: tabular-nums;
}

.amount {
  font-weight: var(--font-medium);
}

/* Rate Cards list (List Page Pattern): dimension text + the low-margin flag.
 * .margin-low had been on the cell since the page was written with no rule
 * anywhere — the sub-15% warning was invisible. */
.dims {
  color: var(--pk-gray-500);
  font-size: var(--text-caption);
}

.dims-any {
  color: var(--pk-gray-400);
  font-size: var(--text-caption);
  font-style: italic;
}

.margin-low {
  color: var(--pk-warning);
  font-weight: var(--font-medium);
}

.currency-suffix {
  color: var(--pk-gray-400);
  font-weight: var(--font-normal);
  font-size: var(--text-caption);
  margin-left: 4px;
}

.vendor-code,
.vendor-cell,
.vendor-name {
  color: var(--pk-gray-500);
  font-size: var(--text-caption);
  font-weight: var(--font-normal);
}

.charge-code,
.customer-code {
  font-weight: var(--font-semibold);
  color: var(--pk-gray-700);
}

.customer-all {
  font-style: italic;
  color: var(--pk-gray-400);
}

.time-ago {
  color: var(--pk-gray-400);
  font-size: var(--text-caption);
}

.data-table td:empty::after {
  content: '\2014';
  color: var(--pk-gray-300);
}

.action-btn-group {
  display: flex;
  align-items: center;
  /* 8px keeps adjacent icon targets distinct — 4px invited misclicks between
     post/park/remove in dense rows */
  gap: 8px;
  justify-content: center;
}

.clickable-row {
  cursor: pointer;
}

/* ---- Semantic data classes — match table density ---- */
.data-table .data-code,
.data-table .data-id,
.data-table .data-currency,
.data-table .shipment-link,
.data-table .text-muted,
.data-table .currency-suffix {
  font-size: var(--text-caption);
}

.data-table .data-code,
.data-table .data-id {
  font-weight: var(--font-normal);
}

.data-table .data-currency {
  font-weight: var(--font-normal);
}

/* ---- Compact action buttons in tables ---- */
.data-table .btn-sm {
  padding: 3px 6px;
  font-size: var(--text-caption);
  border-radius: 5px;
  min-height: auto;
  min-width: 26px;
  height: 26px;
}

/* Raise in-table small buttons to touch-friendly floor on tablet/mobile */
@media (max-width: 1024px) {
  .data-table .btn-sm {
    min-height: 36px;
    min-width: 36px;
  }
}

.data-table .btn-sm.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Compact badges in tables ---- */
.data-table .status-badge {
  font-size: var(--text-micro);
  padding: 1px 6px;
  gap: 3px;
  border-radius: 4px;
}

.data-table .status-badge::before {
  width: 5px;
  height: 5px;
}

/* ---- Checkbox Columns ----
 * Specificity must beat `.data-table td` (0,1,1) — a bare `.td-checkbox`
 * (0,1,0) loses that fight, so the padding here was dead code: the 24px
 * WCAG 2.2 AA 2.5.8 target (checkbox-cell's min-width/min-height) was
 * clipped by `.data-table td`'s `padding: 6px 10px; overflow: hidden`
 * whenever `table-layout: fixed` held the column at 32px (narrow
 * containers). Qualifying with `.data-table` raises this to (0,2,1). */
.data-table th.th-checkbox,
.data-table td.td-checkbox {
  width: 34px;
  text-align: center;
  padding-left: 5px;
  padding-right: 5px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .data-table th,
  .data-table td {
    padding: 6px 8px;
    font-size: var(--text-caption);
  }

  .data-table th {
    font-size: var(--text-micro);
  }
}
