/* Material Design 3 Table Component
 * ==========================================================================
 * Tables display data in rows and columns
 */

/* Base Table
 * -------------------------------------------------------------------------- */

.table {
  /* Structure */
  width: 100%;
  border-collapse: collapse;

  /* Appearance */
  background: var(--color-bg--surface);
  border-radius: var(--radius-large);
  overflow: hidden;

  /* Typography */
  font-size: var(--font-size-x-small);
  line-height: 1.5;
}

/* Table wrapper for scroll */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-large);
  background: var(--color-bg--surface);
}

/* Table Header
 * -------------------------------------------------------------------------- */

.table thead {
  background: var(--color-bg--surface-container);
  border-bottom: 1px solid var(--color-border);
}

.table th {
  padding: var(--size-3) var(--size-4);
  text-align: left;
  font-weight: 600;
  color: var(--color-ink--muted);
  white-space: nowrap;
}

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

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

/* Sortable headers */
.table th--sortable {
  cursor: pointer;
  user-select: none;
}

.table th--sortable:hover {
  background: var(--color-bg--surface-container-hover);
}

/* Table Body
 * -------------------------------------------------------------------------- */

.table tbody tr {
  border-bottom: 1px solid var(--color-border--light);
}

.table tbody tr:last-child {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--color-bg--surface-hover);
}

.table td {
  padding: var(--size-3) var(--size-4);
  color: var(--color-ink);
}

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

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

/* Truncate text in cells */
.table td--truncate {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Table Variants
 * -------------------------------------------------------------------------- */

/* Striped table */
.table--striped tbody tr:nth-child(even) {
  background: var(--color-bg--surface-container);
}

.table--striped tbody tr:hover {
  background: var(--color-bg--surface-container-hover);
}

/* Compact table */
.table--compact th,
.table--compact td {
  padding: var(--size-2) var(--size-3);
}

/* Borderless table */
.table--borderless thead {
  border-bottom: none;
}

.table--borderless tbody tr {
  border-bottom: none;
}

/* Fixed layout */
.table--fixed {
  table-layout: fixed;
}

/* Table with selection */
.table--selectable tbody tr {
  cursor: pointer;
}

.table tbody tr--selected {
  background: var(--color-bg--primary-container);
}

.table tbody tr--selected:hover {
  background: var(--color-bg--primary-container-hover);
}

/* Table Actions Cell
 * -------------------------------------------------------------------------- */

.table__actions {
  display: flex;
  gap: var(--size-2);
  align-items: center;
}

/* Table Empty State
 * -------------------------------------------------------------------------- */

.table__empty {
  padding: var(--size-8) var(--size-4);
  text-align: center;
  color: var(--color-ink--muted);
}

/* Table Footer
 * -------------------------------------------------------------------------- */

.table tfoot {
  background: var(--color-bg--surface-container);
  border-top: 1px solid var(--color-border);
}

.table tfoot td {
  font-weight: 600;
}

/* Responsive Table
 * -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .table--responsive {
    display: block;
  }

  .table--responsive thead {
    display: none;
  }

  .table--responsive tbody,
  .table--responsive tr,
  .table--responsive td {
    display: block;
  }

  .table--responsive tr {
    margin-bottom: var(--size-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-medium);
    padding: var(--size-3);
  }

  .table--responsive td {
    padding: var(--size-2) 0;
    border: none;
  }

  .table--responsive td::before {
    content: attr(data-label);
    display: inline-block;
    width: 40%;
    font-weight: 600;
    color: var(--color-ink--muted);
  }
}

/* Admin Table Variant
 * -------------------------------------------------------------------------- */

.admin-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--font-size-x-small);
}

.admin-table thead {
  background: var(--color-bg--canvas);
  border-bottom: 1px solid var(--color-border);
}

.admin-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--color-ink--muted);
  font-size: var(--font-size-x-small);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.admin-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background 0.15s ease;
}

.admin-table tbody tr:hover {
  background: var(--color-bg--canvas);
}

.admin-table tbody tr:last-child {
  border-bottom: none;
}

.admin-table td {
  padding: 1rem;
  color: var(--color-ink);
  vertical-align: middle;
}

/* Sortable Headers */
.table-header__sort {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease;
}

.table-header__sort:hover {
  color: var(--color-primary);
}

.table-header__sort--active {
  color: var(--color-primary);
}

.table-header__sort svg {
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.table-header__sort:hover svg,
.table-header__sort--active svg {
  opacity: 1;
}

/* Header Variants */
.table-header--numeric {
  text-align: right;
}

.table-header--centered {
  text-align: center;
}

.table-header--actions {
  text-align: right;
  width: 120px;
}

/* Cell Variants */
.table-cell--actions {
  text-align: right;
  padding: 0.5rem 1rem;
}

.table-actions {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
}

.table-actions .button {
  padding: 0.375rem;
  min-height: unset;
}

.table-actions .button--danger:hover {
  color: var(--color-error);
}

/* Empty State */
.empty-state {
  padding: 4rem 2rem;
  text-align: center;
}

.empty-state__icon {
  margin-bottom: 1rem;
  color: var(--color-ink--muted);
  opacity: 0.5;
}

.empty-state__title {
  margin: 0 0 0.5rem;
  font-size: var(--font-size-medium);
  font-weight: 600;
  color: var(--color-ink);
}

.empty-state__description {
  margin: 0 0 1.5rem;
  color: var(--color-ink--muted);
}

.empty-state__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}