table.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* All cells: bottom border + left border on non-first columns */
.table th,
.table td {
  border-bottom: 1px solid var(--border-default);
}

.table th + th,
.table td + td {
  border-left: 1px solid var(--border-default);
}

/* Outer edges */
.table thead tr:first-child th {
  border-top: 1px solid var(--border-default);
}

.table th:first-child,
.table td:first-child {
  border-left: 1px solid var(--border-default);
}

.table th:last-child,
.table td:last-child {
  border-right: 1px solid var(--border-default);
}

/* Corner radius */
.table thead tr:first-child th:first-child  { border-top-left-radius: var(--radius-lg); }
.table thead tr:first-child th:last-child   { border-top-right-radius: var(--radius-lg); }
.table tbody tr:last-child td:first-child   { border-bottom-left-radius: var(--radius-lg); }
.table tbody tr:last-child td:last-child    { border-bottom-right-radius: var(--radius-lg); }

/* Header */
.table th {
  padding: var(--space-2) var(--space-4);
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  vertical-align: middle;
  color: var(--text-secondary);
  background-color: var(--surface-sunken);
}

.table th .material-symbols-rounded {
  vertical-align: middle;
  font-size: 16px;
  line-height: 1;
}

/* Body */
.table td {
  padding: var(--space-3) var(--space-4);
  vertical-align: middle;
  color: var(--text-primary);
  background-color: var(--surface-base);
}

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

/* Cell variants */
.table__cell--primary a {
  color: var(--accent-primary);
  text-decoration: none;
}

.table__cell--primary a:hover {
  text-decoration: underline;
}

.table__cell--muted {
  color: var(--text-tertiary);
}

.table__cell--numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table__cell--truncate {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table__cell-subtitle {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.table__sort {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-secondary);
  text-decoration: none;
}

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

.table__sort--active {
  color: var(--text-primary);
}

.table__sort-icon {
  font-size: 14px;
  opacity: 0.6;
}

.table__sort--active .table__sort-icon {
  opacity: 1;
}

/* Row states — use color/background changes, not opacity (which affects borders) */
.table__row--muted td {
  color: var(--text-tertiary);
  background-color: var(--surface-sunken);
}
.table__row--muted .table__cell--actions {
  color: var(--text-primary);
  background-color: var(--surface-base);
}

.table__row--selected td { background-color: var(--accent-muted); }
.table__row--selected:hover td { background-color: var(--accent-muted); }

/* Total row — emphasized summary row (e.g. Weighted Average totals) */
.table__row--total td {
  background-color: var(--surface-sunken);
  border-top: 2px solid var(--border-default);
  font-weight: 700;
  color: var(--text-primary);
}
.table__row--total:hover td { background-color: var(--surface-sunken); }

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

.table--striped tbody tr:nth-child(even) td {
  background-color: var(--surface-sunken);
}

/* Breakdown — emphasizes the rightmost (contribution) column for
   weighted-average / rollup tables. Use with .table__cell--numeric. */
.table--breakdown th:last-child,
.table--breakdown td:last-child {
  font-weight: 600;
  background-color: var(--surface-sunken);
}

.table--breakdown tbody tr:hover td:last-child {
  background-color: var(--surface-hover);
}

.table--breakdown .table__row--total td:last-child {
  color: var(--accent-primary);
  background-color: var(--accent-subtle);
}

/* ── .table--sticky — sticky thead rows + sticky first column inside a
   .table--sticky-wrap scroll container. Composes with .table, .table--compact,
   .table__row--total, .table__row--muted. Used by data-dense participation
   tables where vertical or horizontal scroll would otherwise lose header
   context. ── */

.table--sticky-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border-radius: var(--radius-lg);
  /* No max-height: all rows render; vertical clipping is opt-in per-usage
     via inline style or a descendant rule. The sticky first column still
     anchors during horizontal scroll. */

  /* Hide the horizontal scrollbar — scrolling still works via
     trackpad/touch/keyboard, just without the visible gutter. */
  scrollbar-width: none;    /* Firefox */
  -ms-overflow-style: none; /* legacy Edge / IE */
}
.table--sticky-wrap::-webkit-scrollbar {
  display: none; /* WebKit (Chrome, Safari, modern Edge) */
}

.table--sticky thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background-color: var(--surface-sunken);
}

/* Two-row thead: second row's top equals the first row's rendered height.
   With .table--compact padding (--space-2 ~= 8px top + 8px bottom + 11px text
   line-box ~= 27px) the second row sits at top: 35px. Adjust per usage if
   the first row uses different padding. */
.table--sticky thead tr:nth-child(2) th { top: 35px; }

.table--sticky th:first-child,
.table--sticky td:first-child {
  position: sticky;
  left: 0;
  z-index: calc(var(--z-sticky) - 1);
  background-color: var(--surface-base);
}

.table--sticky thead th:first-child {
  z-index: calc(var(--z-sticky) + 1);
  background-color: var(--surface-sunken);
}

.table--sticky .table__row--total td:first-child,
.table--sticky .table__row--muted td:first-child {
  background-color: var(--surface-sunken);
}

/* Actions */
.table__cell--actions {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}

.table__cell--actions .action-group {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
}

/* Responsive */
@media (max-width: 768px) {
  .table th,
  .table td {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }
}
