/* ═══════════════════════════════════════════════════════════════
   Tables — MC Виан B2B Portal
   ═══════════════════════════════════════════════════════════════ */

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table thead {
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 1;
}
.table thead th {
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-secondary);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
  user-select: none;
}

.table tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: var(--transition-fast);
}
.table tbody tr:last-child {
  border-bottom: none;
}
.table tbody tr:hover {
  background: var(--color-primary-light);
}
.table tbody tr.is-selected {
  background: rgba(0, 126, 255, 0.06);
}

.table td {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text);
  vertical-align: middle;
}

/* Sortable columns */
.table th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 28px;
}
.table th.sortable::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-text-muted);
  opacity: 0.4;
}
.table th.sortable:hover::after {
  opacity: 0.8;
}
.table th.sorted-asc::after {
  border-top: none;
  border-bottom: 5px solid var(--color-primary);
  opacity: 1;
}
.table th.sorted-desc::after {
  border-top: 5px solid var(--color-primary);
  opacity: 1;
}

/* Clickable rows */
.table tr.clickable {
  cursor: pointer;
}

/* Table checkbox */
.table .table-check {
  width: 40px;
  text-align: center;
}

/* Compact table */
.table--compact th,
.table--compact td {
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

/* Striped */
.table--striped tbody tr:nth-child(even) {
  background: var(--color-bg);
}
.table--striped tbody tr:nth-child(even):hover {
  background: var(--color-primary-light);
}

/* Empty state */
.table-empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
}
.table-empty__icon {
  font-size: 48px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  opacity: 0.5;
}
.table-empty__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}
.table-empty__text {
  font-size: 14px;
  color: var(--color-text-secondary);
}

/* ── Responsive ───────────────────────────────────────────────
   На мобиле таблицы делаем горизонтально скроллируемыми, если они
   обёрнуты в .table-responsive (Bootstrap-стиль). Опционально
   .table--stacked превращает строки в карточки (нужен data-label на td). */
@media (max-width: 767px) {
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin-bottom: var(--space-md);
  }
  .table { font-size: 13px; }
  .table th, .table td {
    padding: 8px 10px;
    white-space: nowrap;
  }
  /* Stacked-режим: строки → карточки. data-label на td → подпись */
  .table--stacked,
  .table--stacked thead,
  .table--stacked tbody,
  .table--stacked tr,
  .table--stacked th,
  .table--stacked td {
    display: block;
    width: 100%;
  }
  .table--stacked thead { display: none; }
  .table--stacked tr {
    margin-bottom: var(--space-md);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    background: var(--color-surface);
  }
  .table--stacked td {
    padding: 4px 0;
    border: none;
    white-space: normal;
  }
  .table--stacked td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 2px;
  }
}
