/* ─── Data Table ─── */
.data-table-wrapper {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.data-table thead tr:first-child th:first-child {
  border-top-left-radius: var(--radius-card);
}

.data-table thead tr:first-child th:last-child {
  border-top-right-radius: var(--radius-card);
}

.data-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: var(--radius-card);
}

.data-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: var(--radius-card);
}

.data-table-wrapper:has(.pagination) tbody tr:last-child td:first-child,
.data-table-wrapper:has(.pagination) tbody tr:last-child td:last-child {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead th {
  height: 44px;
  padding: 0 16px;
  background: var(--surface-raised);
  text-align: left;
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.data-table thead th:hover { color: var(--text-primary); }

.data-table thead th .th-content {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Flex containers ignore the th's text-align — forward the column
   alignment to the inner flex container so labels line up with cells. */
.data-table thead th.text-right .th-content { justify-content: flex-end; }
.data-table thead th.text-center .th-content { justify-content: center; }

.data-table thead th .sort-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.data-table thead th .sort-icon svg { transition: transform 0.15s; }

.data-table thead th:hover .sort-icon { opacity: 0.5; }

.data-table thead th.sorted .sort-icon {
  opacity: 1;
  color: var(--primary);
}

/* Legacy tables emit only chevron-up; rotate it 180° for non-asc states. */
.data-table thead th:not(.sorted-asc) .sort-icon svg {
  transform: rotate(180deg);
}

.data-table tbody tr {
  height: 52px;
  border-top: 1px solid var(--border-light);
  transition: background 0.15s;
}

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

.data-table tbody td {
  padding: var(--space-2) 16px;
  font-size: var(--text-base);
  color: var(--text-primary);
}

.data-table tbody td.text-mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ─── Navigable row (whole-row click target) ─── */
.data-table tbody tr.row-link { cursor: pointer; }
.data-table tbody tr.row-link:hover { background: var(--primary-light); }
/* Keep the trailing chevron visible at all times on navigable rows so the
   click affordance never disappears, even before the row is hovered. */
.data-table tbody tr.row-link .row-actions { opacity: 1; }
.data-table tbody tr.row-link .row-actions .row-action-btn { color: var(--text-secondary); }

.data-table thead th.col-fixed-140 { width: 140px; }
.data-table thead th.col-fixed-160 { width: 160px; }

/* Row actions */
.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  opacity: 0.5;
  transition: opacity 0.15s;
}

.data-table tbody tr:hover .row-actions {
  opacity: 1;
}

.row-action-btn {
  width: 32px;
  height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-row);
  color: var(--text-secondary);
  transition: var(--transition);
}

button.row-action-btn:hover,
a.row-action-btn:hover { background: var(--primary-light); color: var(--primary); }

button.row-action-btn.danger:hover,
a.row-action-btn.danger:hover { background: var(--danger-light); color: var(--danger); }

/* ─── Table-local busy indicator ─── */
.js-table-fragment {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  transition: opacity 0.18s ease;
}

/* The placeholder pill lives inside an otherwise-empty flex column, so
   the wrapper collapses to 0px and the pill renders at the very top
   edge of the fragment area. Give the placeholder a minimum height so
   the pill has visible space to centre on during the initial fetch.
   `js-table-fragment-placeholder` is removed by swapFragment once the
   fragment swaps in, so this only affects the initial busy state and
   never interferes with subsequent filter/sort/paginate refreshes. */
.js-table-fragment.js-table-fragment-placeholder {
  min-height: 320px;
}

.js-tab-fragment {
  position: relative;
  transition: opacity 0.15s ease;
}

.js-table-fragment.js-table-busy::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.js-table-fragment.js-table-busy.is-fetching::before {
  opacity: 0.55;
  pointer-events: auto;
}

.js-table-fragment .js-table-busy-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: 22px var(--space-7);
  background: var(--surface-raised);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  box-shadow: 0 16px 48px rgba(var(--shadow-rgb), 0.10), 0 4px 12px rgba(var(--shadow-rgb), 0.05);
  z-index: 6;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  min-width: 280px;
  max-width: 90%;
}

.js-table-fragment.js-table-busy .js-table-busy-pill {
  display: flex;
}

.js-table-fragment.js-table-busy.is-fetching .js-table-busy-pill {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.js-table-busy-pill .js-table-busy-logo {
  width: 40px;
  height: var(--input-height);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
  flex-shrink: 0;
}

.js-table-busy-pill .js-table-busy-logo svg {
  width: 22px;
  height: 22px;
}

.js-table-busy-pill .js-table-busy-logo .icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.js-table-busy-pill .js-table-busy-stripe {
  width: 140px;
  height: 3px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
}

.js-table-busy-pill .js-table-busy-stripe::before {
  content: '';
  display: block;
  height: 100%;
  width: 30%;
  background: var(--primary);
  border-radius: 2px;
  animation: top-progress-slide 1.2s ease-in-out infinite;
}

.js-table-busy-pill .js-table-busy-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.5;
}

/* ─── Column select / bulk selection ─── */
.col-select {
  width: 36px;
  text-align: center;
}
.data-table tbody td.col-select,
.data-table thead th.col-select {
  padding-left: var(--space-3);
  padding-right: var(--space-1);
}
.data-table input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* ─── Responsive data table ─── */
@media (max-width: 768px) {
  .data-table-wrapper { overflow-x: auto; }
}
