/**
 * ProRank Design System - Table Components
 * 
 * Consistent table styles for data display across the plugin.
 * Includes responsive tables, sorting indicators, and row states.
 * 
 * @module components/tables
 * @since 3.0.0
 */

/* ============================================
   BASE TABLE
   Foundation table styles
   ============================================ */

.prorank-table {
  width: 100%;
  background: white;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 14px;
}

.prorank-table-container {
  background: white;
  border: 1px solid var(--prorank-border);
  border-radius: var(--prorank-radius-sm);
  overflow: hidden;
}

/* Table wrapper for scroll */
.prorank-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   TABLE STRUCTURE
   Header, body, and cell styles
   ============================================ */

/* Table Header */
.prorank-table thead {
  background: var(--prorank-bg-secondary);
  border-bottom: 2px solid var(--prorank-border);
}

.prorank-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--prorank-text);
  white-space: nowrap;
  position: relative;
}

/* Sortable headers */
.prorank-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: var(--prorank-transition);
}

.prorank-table th.sortable:hover {
  background: var(--prorank-bg-tertiary);
}

.prorank-table th.sortable::after {
  content: '↕';
  margin-left: 8px;
  opacity: 0.3;
  font-size: 12px;
}

.prorank-table th.sort-asc::after {
  content: '↑';
  opacity: 1;
  color: var(--prorank-primary);
}

.prorank-table th.sort-desc::after {
  content: '↓';
  opacity: 1;
  color: var(--prorank-primary);
}

/* Table Body */
.prorank-table tbody tr {
  border-bottom: 1px solid var(--prorank-border-light);
  transition: var(--prorank-transition);
}

.prorank-table tbody tr:hover {
  background: var(--prorank-bg-secondary);
}

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

/* Table Cells */
.prorank-table td {
  padding: 12px 16px;
  color: var(--prorank-text);
  vertical-align: middle;
}

/* Alignment utilities */
.prorank-table .text-left { text-align: left; }
.prorank-table .text-center { text-align: center; }
.prorank-table .text-right { text-align: right; }

/* Numeric columns */
.prorank-table .numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================
   TABLE VARIANTS
   Different table styles
   ============================================ */

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

/* Compact table */
.prorank-table--compact th,
.prorank-table--compact td {
  padding: 8px 12px;
}

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

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

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

/* ============================================
   ROW STATES
   Different row states and highlights
   ============================================ */

.prorank-table tr.selected {
  background: rgba(37, 99, 235, 0.05);
}

.prorank-table tr.selected td {
  position: relative;
}

.prorank-table tr.selected td:first-child::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--prorank-primary);
}

.prorank-table tr.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.prorank-table tr.error {
  background: rgba(239, 68, 68, 0.05);
}

.prorank-table tr.warning {
  background: rgba(251, 191, 36, 0.05);
}

.prorank-table tr.success {
  background: rgba(16, 185, 129, 0.05);
}

/* ============================================
   TABLE ACTIONS
   Action buttons in table cells
   ============================================ */

.prorank-table-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.prorank-table-action {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--prorank-transition);
  background: transparent;
  border: 1px solid transparent;
  color: var(--prorank-text-secondary);
}

.prorank-table-action:hover {
  background: var(--prorank-bg-tertiary);
  color: var(--prorank-text);
}

.prorank-table-action--edit {
  color: var(--prorank-primary);
}

.prorank-table-action--delete {
  color: var(--prorank-error);
}

/* ============================================
   EMPTY STATE
   When table has no data
   ============================================ */

.prorank-table-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--prorank-text-secondary);
}

.prorank-table-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.prorank-table-empty-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--prorank-text);
}

.prorank-table-empty-description {
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================
   TABLE PAGINATION
   Pagination controls for tables
   ============================================ */

.prorank-table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--prorank-bg-secondary);
  border-top: 1px solid var(--prorank-border);
}

.prorank-table-pagination-info {
  font-size: 14px;
  color: var(--prorank-text-secondary);
}

.prorank-table-pagination-controls {
  display: flex;
  gap: 8px;
}

.prorank-table-pagination-button {
  padding: 6px 12px;
  border: 1px solid var(--prorank-border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--prorank-transition);
  font-size: 14px;
}

.prorank-table-pagination-button:hover:not(:disabled) {
  background: var(--prorank-bg-tertiary);
  border-color: var(--prorank-border-dark);
}

.prorank-table-pagination-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.prorank-table-pagination-button.active {
  background: var(--prorank-primary);
  color: white;
  border-color: var(--prorank-primary);
}

/* ============================================
   TABLE FILTERS
   Filter controls above table
   ============================================ */

.prorank-table-filters {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--prorank-bg-secondary);
  border-bottom: 1px solid var(--prorank-border);
  flex-wrap: wrap;
}

.prorank-table-search {
  flex: 1;
  min-width: 200px;
}

.prorank-table-filter-select {
  min-width: 150px;
}

/* ============================================
   RESPONSIVE TABLES
   Mobile-friendly table layouts
   ============================================ */

@media (max-width: 768px) {
  /* Stack table on mobile */
  .prorank-table--responsive {
    display: block;
  }
  
  .prorank-table--responsive thead {
    display: none;
  }
  
  .prorank-table--responsive tbody {
    display: block;
  }
  
  .prorank-table--responsive tr {
    display: block;
    margin-bottom: 16px;
    border: 1px solid var(--prorank-border);
    border-radius: var(--prorank-radius-sm);
    padding: 12px;
  }
  
  .prorank-table--responsive td {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border: none;
  }
  
  .prorank-table--responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 8px;
    color: var(--prorank-text-secondary);
  }
  
  .prorank-table--responsive td:last-child {
    border-bottom: none;
  }
}

/* Horizontal scroll for non-responsive tables */
@media (max-width: 768px) {
  .prorank-table-wrapper {
    margin: 0 -16px;
    padding: 0 16px;
    overflow-x: auto;
  }
}