/* Table styles */
.table-container {
  background: var(--color-surface-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-primary);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.8rem;
}

.table-scroll-shell {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table thead {
  background: var(--color-surface-secondary);
}

.table th {
  padding: var(--ui-density-table-cell-y) var(--ui-density-table-cell-x);
  text-align: left;
  font-weight: 600;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border-primary);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.table-sortable-header {
  white-space: nowrap;
}

.table-sort-trigger {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  letter-spacing: inherit;
  padding: 0;
  text-transform: inherit;
}

.table-sort-trigger:focus-visible {
  outline: none;
  border-radius: 0.3rem;
  box-shadow: 0 0 0 3px var(--color-brand-primary-subtle);
}

.table-sort-indicator::before {
  content: "↕";
  color: var(--color-text-tertiary);
  font-size: 0.75rem;
}

.table-sortable-header[data-sort-direction="asc"] .table-sort-indicator::before {
  content: "↑";
  color: var(--color-brand-primary);
}

.table-sortable-header[data-sort-direction="desc"] .table-sort-indicator::before {
  content: "↓";
  color: var(--color-brand-primary);
}

.table td {
  padding: var(--ui-density-table-cell-y) var(--ui-density-table-cell-x);
  border-bottom: 1px solid var(--color-border-primary);
  vertical-align: middle;
  color: var(--color-text-primary);
}

.favorite-column,
.favorite-cell {
  width: 3.25rem;
  text-align: center;
  padding-left: 0.7rem !important;
  padding-right: 0.7rem !important;
}

.idea-favorite-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  border: 1px solid var(--color-border-secondary);
  background: var(--color-surface-secondary);
  color: var(--color-text-tertiary);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.2s ease;
}

.idea-favorite-btn:hover {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.45);
}

.idea-favorite-btn.is-active {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.14);
}

.table tbody tr:hover {
  background: var(--color-interactive-hover);
  transition: background-color 0.2s ease;
}

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

.actions-column {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

/* Drag and drop styles */
.draggable-row {
  cursor: move;
  transition: background-color 0.2s ease;
}

.draggable-row:hover {
  background: var(--color-interactive-hover);
}

.draggable-row.is-dragging {
  opacity: 0.55;
}

.draggable-row.drag-over {
  background: var(--color-brand-primary-subtle);
  border-top: 2px solid var(--color-brand-primary);
}

.drag-handle {
  display: inline-block;
  margin-right: 0.5rem;
  color: var(--color-text-tertiary);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Table badges and status indicators */
.status-badge {
  padding: var(--ui-status-badge-padding-y) var(--ui-status-badge-padding-x);
  border: 1px solid transparent;
  border-radius: var(--ui-status-badge-radius);
  font-size: var(--ui-status-badge-font-size);
  font-weight: var(--ui-status-badge-font-weight);
  text-transform: uppercase;
  letter-spacing: var(--ui-status-badge-letter-spacing);
  line-height: 1;
  white-space: nowrap;
}

.status-badge.status-user {
  background: var(--color-brand-secondary-subtle);
  color: #c9a5ff;
}

.status-badge.status-champion {
  background: var(--color-status-warning-bg);
  border-color: var(--color-status-warning-border);
  color: var(--color-status-warning-text);
}

.status-badge.status-admin {
  background: var(--color-status-success-bg);
  border-color: var(--color-status-success-border);
  color: var(--color-status-success-text);
}

.status-badge.status-active {
  background: var(--color-status-success-bg);
  border-color: var(--color-status-success-border);
  color: var(--color-status-success-text);
  border-radius: 4px;
  font-weight: 500;
}

.status-badge.status-inactive {
  background: var(--color-status-neutral-bg);
  border-color: var(--color-status-neutral-border);
  color: var(--color-status-neutral-text);
  border-radius: 4px;
  font-weight: 500;
}

/* Idea status badges */
.status-badge.status-draft {
  background: var(--color-status-warning-bg);
  border-color: var(--color-status-warning-border);
  color: var(--color-status-warning-text);
}

.status-badge.status-submitted {
  background: var(--color-status-warning-bg);
  border-color: var(--color-status-warning-border);
  color: var(--color-status-warning-text);
}

.status-badge.status-hold {
  background: var(--color-status-neutral-bg);
  border-color: var(--color-status-neutral-border);
  color: var(--color-status-neutral-text);
}

.status-badge.status-approved {
  background: var(--color-status-success-bg);
  border-color: var(--color-status-success-border);
  color: var(--color-status-success-text);
}

.status-badge.status-promoted {
  background: var(--color-status-info-bg);
  border-color: var(--color-status-info-border);
  color: var(--color-status-info-text);
}

.status-badge.status-rejected {
  background: var(--color-status-danger-bg);
  border-color: var(--color-status-danger-border);
  color: var(--color-status-danger-text);
}

/* Status controls and actions */
.status-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.status-actions label {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin: 0;
}

.status-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 0.25rem;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
}

.status-btn-hold {
  background-color: var(--color-surface-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-secondary);
}

.status-btn-hold:hover {
  background-color: var(--color-interactive-active);
  color: var(--color-text-primary);
}

.status-btn-approved {
  background-color: rgba(34, 197, 94, 0.12);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.status-btn-approved:hover {
  background-color: rgba(34, 197, 94, 0.18);
}

.status-btn-rejected {
  background-color: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.status-btn-rejected:hover {
  background-color: rgba(239, 68, 68, 0.18);
}

.status-btn-submitted {
  background-color: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.status-btn-submitted:hover {
  background-color: rgba(245, 158, 11, 0.2);
}

.idea-link {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.idea-link:hover,
.idea-link:focus-visible {
  color: inherit;
  text-decoration: underline;
}

.table .actions-column .btn {
  margin-left: 0.5rem;
}

.table .actions-column .btn:first-child {
  margin-left: 0;
}

.table .actions-column .ui-row-actions--fixed {
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.table .actions-column .ui-row-actions--fixed .ui-action-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ui-density-control-height-sm);
  min-width: var(--ui-density-control-height-sm);
  height: var(--ui-density-control-height-sm);
}

.table .actions-column .ui-row-actions--fixed .btn {
  margin-left: 0;
}

.table .actions-column .ui-row-actions--fixed .ui-action-slot__placeholder {
  display: inline-block;
  width: var(--ui-density-control-height-sm);
  height: var(--ui-density-control-height-sm);
  pointer-events: none;
}

@media (min-width: 769px) {
  .table .table-col-name {
    min-width: 12rem;
  }

  .table th.table-col-score,
  .table td.table-col-score {
    text-align: center;
    white-space: nowrap;
    overflow-wrap: normal;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  .table th.table-col-score-mini,
  .table td.table-col-score-mini {
    width: 3.1rem;
    text-align: center;
    white-space: nowrap;
    overflow-wrap: normal;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
  }

  .table th.table-col-truncate,
  .table td.table-col-truncate {
    width: 8rem;
    max-width: 8rem;
  }

  .table .table-col-truncate-text {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .table .actions-column .ui-row-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
    white-space: nowrap;
  }
}

/* Dense table strategy: hide low-priority columns before forcing horizontal scroll. */
@media (min-width: 769px) and (max-width: 1800px) {
  .table .table-col-priority-low {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 1500px) {
  .table .table-col-priority-medium {
    display: none;
  }
}

.table-container--stacked,
.table-scroll-shell--stacked {
  max-height: var(--table-scroll-max-height, 340px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.table-container--stacked .table thead th,
.table-scroll-shell--stacked .table thead th,
.table-scroll-shell--stacked .dashboard-mini-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface-secondary);
}

.section-header-promoted h3 {
  color: #93c5fd;
}

/* Creator scores in tables */
.creator-score {
  font-weight: 600;
}

.creator-score.score-na {
  color: var(--neutral-medium);
  font-style: italic;
}

/* Responsive table */
@media (max-width: 768px) {
  .table-container {
    margin: 1rem -1rem 0;
    border-radius: 0;
  }

  .table th,
  .table td {
    padding: 0.75rem 1rem;
  }

  .table .actions-column {
    width: auto;
    white-space: nowrap;
  }

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

  .table .actions-column .btn {
    display: inline-flex;
    width: auto;
    margin: 0 0 0 0.35rem;
    white-space: nowrap;
  }

  .table .actions-column .btn:first-child {
    margin-left: 0;
  }

  .table .actions-column .ui-row-actions--fixed .btn {
    margin-left: 0;
  }
}
