/* ==========================================================================
   Table Component Styles
   Modern table system with shadcn-inspired design
   ========================================================================== */

/* Base Table */
.table {
  width: 100%;
  caption-side: bottom;
  font-size: 0.875rem;
  border-collapse: collapse;
}

.table th {
  font-weight: 600;
  text-align: left;
  color: var(--muted-foreground);
  border-bottom: 2px solid var(--border);
  padding: 0.75rem 1rem;
  background-color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.025em;
}

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* Zebra striping by default for all tables */
.table tbody tr:nth-of-type(odd),
.table:not(.table-no-stripe) tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.02);
}

.table tbody tr {
  transition: background-color 0.2s;
}

.table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

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

/* Striped Table (redundant but kept for compatibility) */
.table-striped tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.02);
}

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

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

/* Borderless Table */
.table-borderless th,
.table-borderless td {
  border: none;
}

/* Hover Table */
.table-hover tbody tr {
  cursor: pointer;
}

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

/* Small Table */
.table-sm th,
.table-sm td {
  padding: 0.5rem;
}

/* Large Table */
.table-lg th,
.table-lg td {
  padding: 1rem;
}

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

/* Responsive Table Container */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

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

.table-responsive::-webkit-scrollbar-track {
  background: var(--muted);
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  border-radius: 4px;
  opacity: 0.5;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  opacity: 0.7;
}

/* Table with Cards */
.table-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.table-card .table {
  margin-bottom: 0;
}

.table-card .table thead th:first-child {
  border-top-left-radius: 0.5rem;
}

.table-card .table thead th:last-child {
  border-top-right-radius: 0.5rem;
}

/* Table Actions */
.table-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.table-actions .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

/* Sort Indicators */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.5rem;
}

.table th.sortable::after {
  content: "⇅";
  position: absolute;
  right: 0.5rem;
  opacity: 0.3;
  font-size: 0.75rem;
}

.table th.sortable.asc::after {
  content: "↑";
  opacity: 1;
}

.table th.sortable.desc::after {
  content: "↓";
  opacity: 1;
}

/* Status Cells */
.table .status-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table .status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-indicator.active {
  background-color: hsl(142 76% 36%);
}

.status-indicator.inactive {
  background-color: hsl(0 84% 60%);
}

.status-indicator.pending {
  background-color: hsl(48 96% 53%);
}

/* Text Alignment Classes for Tables */
.table .text-right,
.table td.text-right,
.table th.text-right {
  text-align: right !important;
}

.table .text-center,
.table td.text-center,
.table th.text-center {
  text-align: center !important;
}

.table .text-left,
.table td.text-left,
.table th.text-left {
  text-align: left !important;
}

/* Numeric columns should be right-aligned */
.table td.numeric,
.table th.numeric,
.table .numeric {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

/* Action columns should be centered */
.table td.actions,
.table th.actions,
.table .actions {
  text-align: center !important;
  white-space: nowrap;
}

/* User Management Table Specific */
#internal-users-tbl td {
  vertical-align: middle;
}

#internal-users-tbl th:nth-child(2),
#internal-users-tbl td:nth-child(2) {
  min-width: 200px;
}

/* Portal Management Tables Specific Fixes */
/* Manage Users table */
#manage-users .table tbody td:nth-child(3),
#manage-users .table tbody td:nth-child(4) {
  text-align: center;
}

/* PBI/Azure Connections table */
#pbi-azure-connections .table .badge {
  min-width: 70px;
  display: inline-block;
}

/* Manage Colabs table */
#manage-colabs .table tbody td:last-child {
  text-align: center;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .table th {
    background-color: hsl(0 0% 15%);
    color: hsl(0 0% 65%);
  }
  
  .table td {
    border-bottom-color: hsl(0 0% 18%);
  }
  
  .table tbody tr:hover {
    background-color: hsl(0 0% 15%);
  }
  
  .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.02);
  }
}

/* Mobile Table View */
@media (max-width: 768px) {
  .table-mobile-stack thead {
    display: none;
  }
  
  .table-mobile-stack tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    padding: 1rem;
  }
  
  .table-mobile-stack tbody td {
    display: block;
    text-align: left;
    border: none;
    padding: 0.5rem 0;
    position: relative;
    padding-left: 40%;
  }
  
  .table-mobile-stack tbody td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    width: 35%;
    font-weight: 600;
    color: var(--muted-foreground);
  }
}