@use '../variables' as v;
@use '../mixins' as m;

// ─────────────────────────────────────────────
// Table wrapper
// ─────────────────────────────────────────────
.table-wrap {
  @include m.card-base;
  overflow: hidden;
}

.table-toolbar {
  @include m.flex-between;
  padding: 14px 20px;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid v.$border-color;

  &-left,
  &-right {
    @include m.flex-start;
    gap: 8px;
    flex-wrap: wrap;
  }
}

.table-scroll {
  overflow-x: auto;
  @include m.scrollbar-thin;
}

// ─────────────────────────────────────────────
// Table
// ─────────────────────────────────────────────
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: v.$font-size-sm;

  thead {
    background: v.$gray-50;
    border-bottom: 1px solid v.$border-color;
  }

  th {
    padding: 10px 16px;
    font-size: v.$font-size-xs;
    font-weight: 600;
    color: v.$gray-500;
    text-align: left;
    white-space: nowrap;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    user-select: none;

    &.sortable {
      cursor: pointer;

      &:hover { color: v.$gray-700; }

      .sort-icon {
        display: inline-flex;
        flex-direction: column;
        gap: 1px;
        margin-left: 4px;
        vertical-align: middle;

        svg { width: 12px; height: 12px; color: v.$gray-300; }
      }

      &.sort-asc  .sort-icon svg:first-child  { color: v.$primary; }
      &.sort-desc .sort-icon svg:last-child   { color: v.$primary; }
    }
  }

  td {
    padding: 12px 16px;
    color: v.$gray-700;
    vertical-align: middle;
    border-bottom: 1px solid v.$border-color;
  }

  tbody tr {
    transition: background v.$transition-fast;

    &:hover { background: v.$gray-50; }
    &:last-child td { border-bottom: none; }

    &.is-selected { background: v.$primary-light; }
  }
}

// ─────────────────────────────────────────────
// Table footer / pagination
// ─────────────────────────────────────────────
.table-footer {
  @include m.flex-between;
  padding: 12px 20px;
  border-top: 1px solid v.$border-color;
  gap: 12px;
  flex-wrap: wrap;

  &-info {
    font-size: v.$font-size-xs;
    color: v.$gray-500;
  }
}

.pagination {
  @include m.flex-start;
  gap: 4px;
}

.page-btn {
  @include m.flex-center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius-sm;
  font-size: v.$font-size-xs;
  font-weight: 500;
  color: v.$gray-600;
  background: v.$white;
  cursor: pointer;
  transition: background v.$transition-base, border-color v.$transition-base, color v.$transition-base;

  &:hover { background: v.$gray-50; border-color: v.$gray-300; }

  &.is-active {
    background: v.$primary;
    border-color: v.$primary;
    color: v.$white;
  }

  &:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

  svg { width: 14px; height: 14px; }
}

// ─────────────────────────────────────────────
// Table search input
// ─────────────────────────────────────────────
.table-search {
  position: relative;

  svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: v.$gray-400;
    pointer-events: none;
  }

  input {
    height: 34px;
    padding: 0 10px 0 32px;
    border: 1px solid v.$border-color;
    border-radius: v.$radius;
    font-size: v.$font-size-sm;
    color: v.$gray-700;
    background: v.$white;
    width: 220px;
    transition: border-color v.$transition-base, box-shadow v.$transition-base;

    &::placeholder { color: v.$gray-400; }
    &:focus { outline: none; border-color: v.$primary-border; @include m.focus-ring; }
  }
}

// ─────────────────────────────────────────────
// Select / filter dropdown
// ─────────────────────────────────────────────
.table-filter-select {
  height: 34px;
  padding: 0 30px 0 10px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: v.$font-size-sm;
  color: v.$gray-700;
  background: v.$white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  appearance: none;
  cursor: pointer;
  transition: border-color v.$transition-base;

  &:focus { outline: none; border-color: v.$primary-border; }
}

// Checkbox in table
.table-checkbox {
  width: 16px;
  height: 16px;
  accent-color: v.$primary;
  cursor: pointer;
}

// Contact email cell
.contact-email-cell {
  @include m.flex-start;
  gap: 10px;
}

.contact-avatar {
  width: 28px;
  height: 28px;
  border-radius: v.$radius-full;
  background: v.$primary-light;
  @include m.flex-center;
  font-size: v.$font-size-xs;
  font-weight: 600;
  color: v.$primary;
  flex-shrink: 0;
  border: 1px solid v.$primary-border;
}

// Rate cell with mini bar
.rate-cell {
  &-value {
    font-weight: 600;
    color: v.$gray-800;
  }

  &-bar {
    height: 2px;
    background: v.$gray-100;
    border-radius: v.$radius-full;
    margin-top: 4px;
    width: 60px;

    &-fill {
      height: 100%;
      background: v.$primary;
      border-radius: v.$radius-full;
    }
  }
}
