/* ═══════════════════════════════════════════════════════════════
   EVIDENT — Tables & Data Grids
   
   For evidence lists, case files, and data-heavy views.
   Features: sorting, filtering, selection, pagination, sticky headers.
   ═══════════════════════════════════════════════════════════════ */

/* ── Table Container ────────────────────────────────────────── */
.table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle, #e5e7eb);
  border-radius: var(--radius-lg, 12px);
  background: var(--surface-card, #fff);
}

/* ── Base Table ──────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.table th,
.table td {
  padding: 0.875rem 1rem;
  text-align: left;
  vertical-align: middle;
}

/* Header */
.table thead th {
  background: var(--surface-elevated, #f9fafb);
  font-weight: 600;
  color: var(--text-primary, #111827);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.025em;
  border-bottom: 1px solid var(--border-default, #e5e7eb);
  white-space: nowrap;
}

/* Sticky header */
.table--sticky-header thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-elevated, #f9fafb);
  backdrop-filter: blur(4px);
}

/* Body */
.table tbody tr {
  transition: background-color 0.15s ease;
}

.table tbody tr:hover {
  background: var(--surface-hover, #f9fafb);
}

.table tbody tr:not(:last-child) td {
  border-bottom: 1px solid var(--border-subtle, #f3f4f6);
}

/* ── Sortable Headers ───────────────────────────────────────── */
.table th[data-sortable] {
  cursor: pointer;
  user-select: none;
}

.table th[data-sortable]:hover {
  background: var(--surface-hover, #f3f4f6);
}

.table__sort-icon {
  display: inline-flex;
  margin-left: 0.5rem;
  opacity: 0.3;
  transition: opacity 0.15s ease;
}

.table th[data-sortable]:hover .table__sort-icon,
.table th[data-sort="asc"] .table__sort-icon,
.table th[data-sort="desc"] .table__sort-icon {
  opacity: 1;
}

.table th[data-sort="asc"] .table__sort-icon {
  transform: rotate(180deg);
}

/* ── Row Selection ──────────────────────────────────────────── */
.table tbody tr.is-selected {
  background: rgb(59 130 246 / 8%);
}

.table tbody tr.is-selected:hover {
  background: rgb(59 130 246 / 12%);
}

.table__checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ── Cell Types ──────────────────────────────────────────────── */
.table td.table__cell--numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.table td.table__cell--actions {
  text-align: right;
  white-space: nowrap;
}

/* ── Evidence-Specific Cells ─────────────────────────────────── */
.table__file-name {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.table__file-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-elevated, #f3f4f6);
  border-radius: 6px;
  flex-shrink: 0;
}

.table__file-info {
  min-width: 0;
}

.table__file-title {
  font-weight: 500;
  color: var(--text-primary, #111827);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table__file-meta {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
}

/* Status badges */
.table__status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.table__status--pending {
  background: #fef3c7;
  color: #92400e;
}

.table__status--processing {
  background: #dbeafe;
  color: #1e40af;
}

.table__status--complete {
  background: #d1fae5;
  color: #065f46;
}

.table__status--error {
  background: #fee2e2;
  color: #991b1b;
}

/* Hash cell (truncated) */
.table__hash {
  font-family: var(--font-mono, "IBM Plex Mono", monospace);
  font-size: 0.75rem;
  color: var(--text-muted, #6b7280);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Action Buttons ─────────────────────────────────────────── */
.table__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.table__action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted, #6b7280);
  transition: all 0.15s ease;
}

.table__action-btn:hover {
  background: var(--surface-hover, #f3f4f6);
  color: var(--text-primary, #111827);
}

.table__action-btn--danger:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* ── Table Variants ──────────────────────────────────────────── */

/* Compact (dense data) */
.table--compact th,
.table--compact td {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
}

/* Relaxed (readable) */
.table--relaxed th,
.table--relaxed td {
  padding: 1rem 1.25rem;
}

/* Striped */
.table--striped tbody tr:nth-child(even) {
  background: rgb(0 0 0 / 2%);
}

.table--striped tbody tr:nth-child(even):hover {
  background: rgb(0 0 0 / 4%);
}

/* Bordered */
.table--bordered th,
.table--bordered td {
  border: 1px solid var(--border-subtle, #e5e7eb);
}

/* Cards (mobile-like) */
@media (width <= 768px) {
  .table--cards thead {
    display: none;
  }

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

  .table--cards tr {
    margin-bottom: 1rem;
    border: 1px solid var(--border-default, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    padding: 1rem;
  }

  .table--cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border: none;
  }

  .table--cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    margin-right: 1rem;
  }

  .table--cards td:not(:last-child) {
    border-bottom: 1px solid var(--border-subtle, #f3f4f6);
  }
}

/* ── Table Toolbar ──────────────────────────────────────────── */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1rem;
  background: var(--surface-elevated, #f9fafb);
  border-bottom: 1px solid var(--border-default, #e5e7eb);
  border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
}

.table-toolbar__left,
.table-toolbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.table-toolbar__search {
  position: relative;
}

.table-toolbar__search input {
  padding-left: 2.5rem;
  background: var(--surface-card, #fff);
  border: 1px solid var(--border-default, #e5e7eb);
  border-radius: var(--radius-md, 8px);
  font-size: 0.875rem;
  min-width: 240px;
}

.table-toolbar__search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #9ca3af);
  pointer-events: none;
}

/* ── Pagination ──────────────────────────────────────────────── */
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border-default, #e5e7eb);
  background: var(--surface-elevated, #f9fafb);
  border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
}

.table-pagination__info {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
}

.table-pagination__controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.table-pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  background: var(--surface-card, #fff);
  border: 1px solid var(--border-default, #e5e7eb);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  transition: all 0.15s ease;
}

.table-pagination__btn:hover:not(:disabled) {
  background: var(--surface-hover, #f3f4f6);
  border-color: var(--border-strong, #d1d5db);
  color: var(--text-primary, #111827);
}

.table-pagination__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.table-pagination__btn--active {
  background: var(--color-primary, #3b82f6);
  border-color: var(--color-primary, #3b82f6);
  color: #fff;
}

.table-pagination__btn--active:hover {
  background: var(--color-primary-dark, #2563eb);
  border-color: var(--color-primary-dark, #2563eb);
}

/* ── Empty State (within table) ─────────────────────────────── */
.table__empty {
  text-align: center;
  padding: 3rem 1rem;
}

.table__empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--text-muted, #9ca3af);
}

.table__empty-title {
  font-weight: 600;
  color: var(--text-primary, #111827);
  margin: 0 0 0.5rem;
}

.table__empty-text {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 1.5rem;
}

/* ── Loading State ──────────────────────────────────────────── */
.table__loading {
  text-align: center;
  padding: 3rem 1rem;
}

.table__loading-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
}

/* ── Selection Bar (batch actions) ───────────────────────────── */
.table-selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-radius: var(--radius-md, 8px);
  margin-bottom: 1rem;
  animation: slide-down 0.3s ease;
}

@keyframes slide-down {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.table-selection-bar__count {
  font-weight: 500;
}

.table-selection-bar__actions {
  display: flex;
  gap: 0.5rem;
}

.table-selection-bar__btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  background: rgb(255 255 255 / 20%);
  border: none;
  border-radius: var(--radius-sm, 6px);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.table-selection-bar__btn:hover {
  background: rgb(255 255 255 / 30%);
}

.table-selection-bar__btn--danger {
  background: rgb(239 68 68 / 80%);
}

.table-selection-bar__btn--danger:hover {
  background: rgb(239 68 68 / 100%);
}
