/* Table Component Styles */

/* Base Table Styles */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--font-size-sm);
  background-color: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table thead {
  background-color: var(--gray-50);
}

.table th {
  padding: var(--space-3);
  text-align: left;
  font-weight: var(--font-weight-semibold);
  color: var(--gray-700);
  border-bottom: 2px solid var(--gray-200);
  position: sticky;
  top: 0;
  background-color: var(--gray-50);
  z-index: 10;
}

.table td {
  padding: var(--space-3);
  color: var(--gray-900);
  border-bottom: 1px solid var(--gray-100);
  transition: background-color var(--transition-fast);
}

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

/* Table Hover State */
.table tbody tr:hover {
  background-color: var(--gray-50);
}

/* Table Striped */
.table-striped tbody tr:nth-child(even) {
  background-color: var(--gray-50);
}

.table-striped tbody tr:hover {
  background-color: var(--gray-100);
}

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

/* Table Bordered */
.table-bordered {
  border: 1px solid var(--gray-300);
}

.table-bordered th,
.table-bordered td {
  border: 1px solid var(--gray-200);
}

/* Sortable Headers */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: calc(var(--space-3) + 16px);
}

.table th.sortable::after {
  content: "⇅";
  position: absolute;
  right: var(--space-2);
  opacity: 0.3;
  font-size: 12px;
}

.table th.sortable:hover::after {
  opacity: 0.6;
}

.table th.sortable.sort-asc::after {
  content: "↑";
  opacity: 1;
  color: var(--brand-secondary);
}

.table th.sortable.sort-desc::after {
  content: "↓";
  opacity: 1;
  color: var(--brand-secondary);
}

/* Table Cells Alignment */
.text-left {
  text-align: left;
}

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

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

/* Table Cell Types */
.table .cell-number {
  text-align: right;
  font-family: var(--font-family-mono);
}

.table .cell-currency {
  text-align: right;
  font-family: var(--font-family-mono);
}

.table .cell-percentage {
  text-align: right;
  font-family: var(--font-family-mono);
}

.table .cell-actions {
  text-align: center;
  white-space: nowrap;
}

/* Checkbox Column */
.table .checkbox-column {
  width: 40px;
  text-align: center;
}

.table .checkbox-column input[type="checkbox"] {
  cursor: pointer;
}

/* Status Badges in Tables */
.table .badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.table .badge-success {
  background-color: var(--color-success-light);
  color: var(--color-success-dark);
}

.table .badge-warning {
  background-color: var(--color-warning-light);
  color: var(--color-warning-dark);
}

.table .badge-error {
  background-color: var(--color-error-light);
  color: var(--color-error-dark);
}

.table .badge-info {
  background-color: var(--color-info-light);
  color: var(--color-info-dark);
}

/* Confidence Badges (specific to mapping tables) */
.confidence-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-sm);
  text-align: center;
  min-width: 60px;
}

.confidence-high {
  background-color: #dcfce7;
  color: #14532d;
}

.confidence-medium {
  background-color: #fef3c7;
  color: #713f12;
}

.confidence-low {
  background-color: #fee2e2;
  color: #7f1d1d;
}

/* Table Container with Scroll */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.table-container::-webkit-scrollbar {
  height: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: var(--radius-full);
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--gray-400);
  border-radius: var(--radius-full);
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: var(--gray-500);
}

/* Fixed Height Table with Scrolling Body */
.table-fixed {
  display: table;
  table-layout: fixed;
}

.table-scroll {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
}

.table-scroll .table {
  border: none;
  border-radius: 0;
}

/* Responsive Table */
@media (max-width: 768px) {
  .table-responsive {
    font-size: var(--font-size-xs);
  }
  
  .table-responsive th,
  .table-responsive td {
    padding: var(--space-2);
  }
  
  .table-responsive .hide-mobile {
    display: none;
  }
}

/* Table Actions Row */
.table-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.table-actions .btn {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
}

/* Empty State */
.table-empty {
  text-align: center;
  padding: var(--space-8);
  color: var(--gray-500);
}

.table-empty-icon {
  font-size: 48px;
  margin-bottom: var(--space-3);
  opacity: 0.5;
}

.table-empty-text {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-2);
}

.table-empty-hint {
  font-size: var(--font-size-sm);
  color: var(--gray-400);
}

/* Loading State */
.table-loading {
  position: relative;
  pointer-events: none;
}

.table-loading::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
}

.table-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--brand-secondary);
  border-radius: 50%;
  animation: table-spin 0.8s linear infinite;
}

@keyframes table-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Row Selection */
.table tbody tr.selected {
  background-color: rgba(74, 144, 226, 0.1);
}

.table tbody tr.selected:hover {
  background-color: rgba(74, 144, 226, 0.15);
}

/* Editable Cells */
.table .cell-editable {
  cursor: pointer;
  position: relative;
}

.table .cell-editable:hover {
  background-color: var(--gray-50);
}

.table .cell-editable::after {
  content: "✏️";
  position: absolute;
  right: var(--space-1);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  font-size: 12px;
  transition: opacity var(--transition-fast);
}

.table .cell-editable:hover::after {
  opacity: 0.5;
}