.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.table__scroll {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
}

.table__cell {
  padding: var(--s-3) var(--s-4);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

thead .table__cell {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table__cell--check {
  width: 40px;
  white-space: nowrap;
}

.table__cell--sortable {
  padding: 0;
}

.table__sort-btn {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  width: 100%;
  padding: var(--s-3) var(--s-4);
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
}

.table__sort-btn:hover {
  color: var(--text);
}

.table__sort-icon {
  display: flex;
  color: var(--brand);
}

.table__row {
  transition: background-color var(--dur) var(--ease);
}

.table__row:hover {
  background: var(--surface-2);
}

.table__row--selected {
  background: var(--brand-soft);
}

.table__row--skeleton:hover {
  background: transparent;
}

.table__row:last-child .table__cell {
  border-bottom: none;
}

.table__state-row td {
  padding: var(--s-8) var(--s-4);
  border-bottom: none;
}

.table__pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
}

.table__pagination-summary {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.table__pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.table__pagination-page {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .table__pagination {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---------- phones: each row becomes a stacked card ----------
   A wide table forces sideways scrolling and hides columns. Under 640px the header row
   is hidden and every cell prints its column label (from data-label, set in table.js)
   before its value. The first cell is the card title; the actions cell is the footer. */

@media (max-width: 640px) {
  .table-wrap {
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
  }

  .table__scroll {
    overflow: visible;
  }

  .table,
  .table tbody {
    display: block;
    width: 100%;
  }

  /* visually hidden but still read by screen readers as the column names */
  .table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .table__row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    margin-bottom: var(--s-3);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
  }

  .table__row:hover {
    background: var(--surface-1);
  }

  .table__row--selected {
    background: var(--brand-soft);
    border-color: var(--brand);
  }

  .table__row .table__cell,
  .table__row:last-child .table__cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    min-width: 0;
    padding: var(--s-2) var(--s-4);
    white-space: normal;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }

  .table__row .table__cell:last-child {
    border-bottom: none;
  }

  .table__row .table__cell[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* first data cell = card title, full width, no label */
  .table__row .table__cell:first-child {
    display: block;
    padding-top: var(--s-3);
    text-align: left;
    border-bottom: none;
  }

  /* ...but a title made of a main line + sub line (.cell-title) is self-explanatory */
  .table__row .table__cell:first-child:has(.cell-title)::before {
    content: none;
  }

  /* the card title still names its column, as a small caption above the value, so a
     table whose first column is not a name (e.g. "Type") stays self-explanatory */
  .table__row .table__cell:first-child[data-label]::before {
    display: block;
    margin-bottom: 2px;
  }

  /* when a selection checkbox leads the row, put it top-right and let the title be next */
  .table__row .table__cell--check {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 0;
    border-bottom: none;
    width: auto;
  }

  .table__row .table__cell--check + .table__cell {
    padding-top: var(--s-1);
  }

  .table__row .table__cell.table__cell--check::before {
    content: none;
  }

  /* actions footer: no label, buttons right-aligned and easy to hit */
  .table__row .cell-actions {
    justify-content: flex-end;
    width: auto;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-bottom: none;
  }

  .table__row .table__cell.cell-actions::before {
    content: none;
  }

  /* loading skeleton rows and empty/error rows stay simple blocks */
  .table__row.table__row--skeleton .table__cell::before {
    content: none;
  }

  .table__state-row {
    display: block;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
  }

  .table__state-row td {
    display: block;
    padding: var(--s-6) var(--s-4);
  }

  .table__pagination {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
  }

  /* a table inside a card: the card is already the frame, so rows become divided list
     items instead of cards nested in a card */
  .card .table__row {
    margin-bottom: 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

  .card .table__row:last-child {
    border-bottom: none;
  }

  .card .table__row .table__cell:first-child {
    padding-top: var(--s-3);
  }

  .card .table__row .table__cell:last-child {
    padding-bottom: var(--s-3);
  }

  .card .table__state-row,
  .card .table__pagination {
    background: transparent;
    border: none;
    border-radius: 0;
  }

  /* cell titles fill the card instead of the fixed desktop cap */
  .table-wrap .table__row .cell-title {
    max-width: none;
  }
}

