/**
 * Component Library
 *
 * Reusable component styles for cards, tables, badges, and other UI elements.
 * Uses design tokens from design-tokens.css for consistency.
 */

/* ===========================
   Base Card Styles
   =========================== */

.card {
  background-color: var(--color-surface-0);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--bs-border-color);
  padding: var(--space-md) var(--space-lg);
  font-weight: 600;
}

.card-header h1, .card-header h2, .card-header h3,
.card-header h4, .card-header h5, .card-header h6 {
  margin-bottom: 0;
}

.card-body {
  padding: var(--space-lg, 1.5rem) !important;
}

/* Override for tables that need edge-to-edge content */
.card-body.p-0 {
  padding: 0 !important;
}

.card-footer {
  background-color: var(--color-surface-1);
  border-top: 1px solid var(--bs-border-color);
  padding: var(--space-md) var(--space-lg);
}

/* Card hover effect (for clickable cards) */
.card-clickable {
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card-clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card-clickable:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-primary);
  outline-offset: var(--focus-ring-offset);
}

/* ===========================
   Stat Card Styles (Typography - layout in gradients.css)
   =========================== */

.stat-card .stat-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  margin-bottom: var(--space-xs);
  font-weight: var(--font-weight-medium);
}

.stat-card .stat-value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: var(--line-height-tight);
}

.stat-card .stat-subtext {
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  margin-top: var(--space-xs);
}

.stat-card .stat-trend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.stat-card .stat-trend.up {
  color: var(--color-success);
}

.stat-card .stat-trend.down {
  color: var(--color-danger);
}

/* Stat Cards Grid */
.stat-cards-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* ===========================
   Table Styling
   =========================== */

.table {
  --bs-table-bg: var(--color-surface-0);
  margin-bottom: 0;
}

.table thead th {
  background-color: var(--color-surface-1);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--color-text-secondary);
  padding: var(--space-md);
  border-bottom: 2px solid var(--bs-border-color);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--space-md);
  vertical-align: middle;
  border-bottom: 1px solid var(--bs-border-color);
}

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

/* Hoverable rows */
.table-hover tbody tr {
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

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

/* Focusable rows (for keyboard navigation) */
.table tbody tr[tabindex]:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-ring-width) var(--color-primary);
}

/* Sortable headers */
.table th[aria-sort] {
  cursor: pointer;
  user-select: none;
}

.table th[aria-sort]::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: var(--space-sm);
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.table th[aria-sort="ascending"]::after {
  border-bottom: 4px solid currentColor;
}

.table th[aria-sort="descending"]::after {
  border-top: 4px solid currentColor;
}

.table th[aria-sort="none"]::after {
  border-bottom: 4px solid var(--color-text-tertiary);
  opacity: 0.5;
}

/* ===========================
   Table Wrapper
   =========================== */

.table-wrapper {
  background: var(--color-surface-0);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

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

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===========================
   DataTables Overrides
   =========================== */

/* Style DataTables to match design system */
.dataTables_wrapper .dataTables_filter input {
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--bs-border-color);
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 var(--focus-ring-width) rgba(37, 99, 235, 0.25);
  outline: none;
}

.dataTables_wrapper .dataTables_length select {
  border-radius: var(--radius-md);
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--bs-border-color);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--radius-md) !important;
  margin: 0 2px;
  padding: var(--space-xs) var(--space-sm);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  color: white !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--color-surface-1) !important;
  border-color: var(--bs-border-color) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:focus {
  outline: var(--focus-ring-width) solid var(--color-primary);
  outline-offset: var(--focus-ring-offset);
}

.dataTables_wrapper .dataTables_info {
  padding: var(--space-md) 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

/* ===========================
   Badges
   =========================== */

.badge {
  font-weight: var(--font-weight-medium);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
}

.badge-status {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-md);
}

/* ===========================
   Dark Mode Overrides
   =========================== */

[data-bs-theme="dark"] .card {
  background-color: var(--color-surface-1);
}

[data-bs-theme="dark"] .stat-card {
  background-color: var(--color-surface-1);
}

[data-bs-theme="dark"] .table {
  --bs-table-bg: var(--color-surface-1);
}

[data-bs-theme="dark"] .table thead th {
  background-color: var(--color-surface-2);
}

[data-bs-theme="dark"] .table-hover tbody tr:hover {
  background-color: var(--color-surface-2);
}

[data-bs-theme="dark"] .table-wrapper {
  background: var(--color-surface-1);
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length select {
  background-color: var(--color-surface-0);
  color: var(--color-text-primary);
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--color-surface-2) !important;
}

/* ===========================
   Responsive Design
   =========================== */

/* Mobile adjustments */
@media (max-width: 768px) {
  .stat-card .stat-value {
    font-size: var(--font-size-2xl);
  }

  .stat-cards-grid {
    grid-template-columns: 1fr;
  }

  .table thead th,
  .table tbody td {
    padding: var(--space-sm);
  }
}
