/**
 * Data Table Styles
 * @countermeasure/web-components
 *
 * Full-width responsive data table with sorting, badges, and inline code.
 */

/* ============================================================================
   DATA TABLE WRAPPER
   ============================================================================ */
.cmm-data-table {
  position: relative;
  width: 100%;
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background-color: hsl(var(--card));
}

.cmm-data-table table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

/* ============================================================================
   TABLE HEADER
   ============================================================================ */
.cmm-data-table__header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.625rem 0.75rem;
  background-color: hsl(var(--secondary));
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
  user-select: none;
}

.cmm-data-table__header--sortable {
  cursor: pointer;
  transition: color var(--transition-fast, 150ms);
}

.cmm-data-table__header--sortable:hover {
  color: hsl(var(--foreground));
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cmm-data-table__header--sorted {
  color: hsl(var(--foreground));
}

.cmm-data-table__sort-icon {
  display: inline-flex;
  align-items: center;
  margin-left: 0.25rem;
  font-size: 0.625rem;
  vertical-align: middle;
  transition: transform var(--transition-fast, 150ms);
}

.cmm-data-table__sort-icon--asc {
  transform: rotate(0deg);
}

.cmm-data-table__sort-icon--desc {
  transform: rotate(180deg);
}

/* ============================================================================
   TABLE ROWS & CELLS
   ============================================================================ */
.cmm-data-table__row {
  border-bottom: 1px solid hsl(var(--border));
  transition: background-color var(--transition-fast, 150ms);
}

.cmm-data-table__row:last-child {
  border-bottom: none;
}

.cmm-data-table__row:hover {
  background-color: hsl(var(--accent) / 0.5);
}

.cmm-data-table__row--selected {
  background-color: hsl(var(--accent));
}

.cmm-data-table__row--clickable {
  cursor: pointer;
}

.cmm-data-table__cell {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.cmm-data-table__cell--wrap {
  white-space: normal;
  max-width: none;
}

.cmm-data-table__cell--mono {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.8125rem;
}

.cmm-data-table__cell--numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cmm-data-table__cell--actions {
  text-align: right;
  white-space: nowrap;
}

/* ============================================================================
   EMPTY & LOADING STATES
   ============================================================================ */
.cmm-data-table__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  text-align: center;
}

.cmm-data-table__empty-icon {
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

.cmm-data-table__loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: hsl(var(--card) / 0.7);
  backdrop-filter: blur(2px);
  border-radius: var(--radius-lg);
}

/* ============================================================================
   EXPORT BUTTON GROUP
   ============================================================================ */
.cmm-data-table__export {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--secondary));
}

.cmm-data-table__export-button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--card));
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms),
              border-color var(--transition-fast, 150ms);
}

.cmm-data-table__export-button:hover {
  background-color: hsl(var(--accent));
  border-color: hsl(var(--accent));
}

/* ============================================================================
   BADGE
   ============================================================================ */
.cmm-data-table .cmm-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 9999px;
  white-space: nowrap;
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.cmm-data-table .cmm-badge--success {
  background-color: var(--color-bg-emerald-10);
  color: var(--color-success-text);
}

.cmm-data-table .cmm-badge--warning {
  background-color: var(--color-bg-amber-10);
  color: var(--color-warning-text);
}

.cmm-data-table .cmm-badge--error {
  background-color: var(--color-bg-rose-10);
  color: var(--color-error-text);
}

.cmm-data-table .cmm-badge--info {
  background-color: var(--color-bg-blue-10);
  color: var(--color-info-text);
}

.cmm-data-table .cmm-badge--neutral {
  background-color: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
}

.cmm-data-table .cmm-badge--sm {
  padding: 0.0625rem 0.375rem;
  font-size: 0.625rem;
}

.cmm-data-table .cmm-badge--lg {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

/* ============================================================================
   INLINE CODE
   ============================================================================ */
.cmm-code {
  display: inline;
  padding: 0.125rem 0.375rem;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.8125em;
  border-radius: var(--radius-sm);
  background-color: hsl(var(--secondary));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  word-break: break-all;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 640px) {
  .cmm-data-table__cell {
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
  }

  .cmm-data-table__header {
    padding: 0.5rem 0.5rem;
    font-size: 0.6875rem;
  }
}
