// =============================================================================
// Users Index — Users & User Types page
// =============================================================================

@use '../variables' as *;

.users-index {
  padding: 1.5rem;
}

// -----------------------------------------------------------------------------
// Grid layout
// -----------------------------------------------------------------------------

.users-index__grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1.5rem;
}

.users-index__users-section {
  grid-column: span 8 / span 8;
}

.users-index__types-section {
  grid-column: span 4 / span 4;
}

// -----------------------------------------------------------------------------
// Section header
// -----------------------------------------------------------------------------

.users-index__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.users-index__section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: $font-size-lg;
  line-height: $line-height-lg;
  font-weight: $font-weight-semibold;
  color: $neutral-900;

  .dark & {
    color: $neutral-50;
  }
}

.users-index__section-icon {
  width: 1.25rem;
  height: 1.25rem;
  color: $neutral-400;
}

.users-index__btn-icon {
  width: 0.875rem;
  height: 0.875rem;
}

// -----------------------------------------------------------------------------
// Toolbar (search + filter)
// -----------------------------------------------------------------------------

.users-index__toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.users-index__search {
  flex: 1;
  min-width: 0;
}

.users-index__filter {
  width: 180px;
  flex-shrink: 0;
}

// -----------------------------------------------------------------------------
// Table cells
// -----------------------------------------------------------------------------

.users-index__cell-name {
  font-weight: $font-weight-medium;
  color: $neutral-900;

  .dark & {
    color: $neutral-50;
  }
}

.users-index__cell-email {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  color: $neutral-500;
}

.users-index__cell-muted {
  color: $neutral-400;
  font-size: $font-size-xs;
  line-height: $line-height-xs;
}

.users-index__cell-count {
  color: $neutral-500;
}

.users-index__cell-date {
  font-size: $font-size-xs;
  line-height: $line-height-xs;
  color: $neutral-500;
}

// -----------------------------------------------------------------------------
// Type cell (name + guard)
// -----------------------------------------------------------------------------

.users-index__type-cell {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

// -----------------------------------------------------------------------------
// Empty state
// -----------------------------------------------------------------------------

.users-index__empty {
  padding: 2rem 0;
  text-align: center;
}

.users-index__empty-icon {
  width: 2rem;
  height: 2rem;
  color: $neutral-300;
  margin: 0 auto 0.5rem;
}

.users-index__empty-text {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  color: $neutral-500;
}

// -----------------------------------------------------------------------------
// Drawer — Tabs
// -----------------------------------------------------------------------------

.users-index__tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid $neutral-200;

  .dark & {
    border-bottom-color: $neutral-700;
  }
}

.users-index__tab {
  padding: 0.75rem 1rem;
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  font-weight: $font-weight-medium;
  border-bottom: 2px solid transparent;
  transition: color $transition-fast, border-color $transition-fast;
  color: $neutral-500;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  cursor: pointer;

  &:hover {
    color: $neutral-700;

    .dark & {
      color: $neutral-300;
    }
  }

  &--active {
    color: $primary-600;
    border-bottom-color: $primary-500;

    .dark & {
      color: $primary-400;
    }
  }
}

.users-index__tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.375rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: $radius-full;
  background-color: $neutral-200;
  font-size: $font-size-xs;
  line-height: $line-height-xs;

  .dark & {
    background-color: $neutral-700;
  }
}

// -----------------------------------------------------------------------------
// Drawer — Main tab content
// -----------------------------------------------------------------------------

.users-index__main-tab {
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

// -----------------------------------------------------------------------------
// Drawer body & fields
// -----------------------------------------------------------------------------

.users-index__drawer-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.users-index__drawer-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.users-index__type-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

// -----------------------------------------------------------------------------
// Custom fields tab
// -----------------------------------------------------------------------------

.users-index__fields-tab {
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

// -----------------------------------------------------------------------------
// Fields loading indicator
// -----------------------------------------------------------------------------

.users-index__fields-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0;
}

.users-index__fields-spinner {
  width: 1rem;
  height: 1rem;
  color: $neutral-400;
  animation: spin 1s linear infinite;
}

.users-index__fields-loading-text {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  color: $neutral-500;
}

// -----------------------------------------------------------------------------
// Status radios
// -----------------------------------------------------------------------------

.users-index__status-label {
  display: block;
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  font-weight: $font-weight-medium;
  color: $neutral-700;
  margin-bottom: 0.375rem;

  .dark & {
    color: $neutral-200;
  }
}

.users-index__status-options {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

.users-index__status-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.users-index__status-radio {
  width: 1rem;
  height: 1rem;
  color: $primary-500;
  border-color: $neutral-300;
  accent-color: $primary-500;

  &:focus {
    box-shadow: 0 0 0 2px rgba($primary-500, 0.2);
  }
}

.users-index__status-text {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  color: $neutral-700;

  .dark & {
    color: $neutral-200;
  }
}

// -----------------------------------------------------------------------------
// Password strength
// -----------------------------------------------------------------------------

.users-index__password-strength {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.users-index__strength-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.users-index__strength-track {
  flex: 1;
  height: 0.375rem;
  background-color: $neutral-200;
  border-radius: $radius-full;
  overflow: hidden;

  .dark & {
    background-color: $neutral-700;
  }
}

.users-index__strength-bar {
  height: 100%;
  border-radius: $radius-full;
  transition: all 300ms ease;

  &--weak {
    background-color: $error-500;
  }

  &--medium {
    background-color: $warning-500;
  }

  &--good {
    background-color: $primary-500;
  }

  &--strong {
    background-color: $success-500;
  }
}

.users-index__strength-label {
  font-size: $font-size-xs;
  line-height: $line-height-xs;
  font-weight: $font-weight-medium;

  &--weak {
    color: $error-600;
  }

  &--medium {
    color: $warning-600;
  }

  &--good {
    color: $primary-600;
  }

  &--strong {
    color: $success-600;
  }
}

// -----------------------------------------------------------------------------
// Password rules
// -----------------------------------------------------------------------------

.users-index__password-rules {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.users-index__password-rule {
  font-size: $font-size-xs;
  line-height: $line-height-xs;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: $neutral-400;

  .dark & {
    color: $neutral-500;
  }

  &--passed {
    color: $success-600;

    .dark & {
      color: $success-400;
    }
  }
}

.users-index__rule-icon {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

// -----------------------------------------------------------------------------
// Type edit drawer — info row
// -----------------------------------------------------------------------------

.users-index__info-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.users-index__info-label {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  font-weight: $font-weight-medium;
  color: $neutral-500;
}

// -----------------------------------------------------------------------------
// Type edit drawer — fields list
// -----------------------------------------------------------------------------

.users-index__fields-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid $neutral-200;

  .dark & {
    border-top-color: $neutral-700;
  }
}

.users-index__fields-empty {
  padding: 1rem 0;
  text-align: center;
}

.users-index__fields-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.users-index__fields-count-text {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  color: $neutral-500;
}

.users-index__fields-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.users-index__field-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border-radius: $radius;
  border: 1px solid $neutral-200;
  cursor: pointer;
  transition: border-color $transition-fast, background-color $transition-fast;

  &:hover {
    border-color: $primary-300;
    background-color: $primary-50;
  }

  .dark & {
    border-color: $neutral-700;

    &:hover {
      border-color: $primary-600;
      background-color: rgba($primary-500, 0.1);
    }
  }
}

.users-index__field-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.users-index__field-drag {
  cursor: grab;
  color: $neutral-400;
  flex-shrink: 0;

  &:active {
    cursor: grabbing;
  }
}

.users-index__field-drag-icon {
  width: 1rem;
  height: 1rem;
}

.users-index__field-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.users-index__field-name {
  font-size: $font-size-sm;
  line-height: $line-height-sm;
  font-weight: $font-weight-medium;
  color: $neutral-900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  .dark & {
    color: $neutral-50;
  }
}

.users-index__field-key {
  font-size: $font-size-xs;
  line-height: $line-height-xs;
  color: $neutral-400;
  font-family: monospace;
}

.users-index__field-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.users-index__field-delete {
  padding: 0.25rem;
  border-radius: $radius;
  color: $neutral-400;
  background: none;
  border: none;
  cursor: pointer;
  transition: color $transition-fast;

  &:hover {
    color: $error-500;
  }
}

.users-index__field-delete-icon {
  width: 0.875rem;
  height: 0.875rem;
}

// -----------------------------------------------------------------------------
// Responsive
// -----------------------------------------------------------------------------

@media (max-width: 1024px) {
  .users-index__grid {
    grid-template-columns: 1fr;
  }

  .users-index__users-section,
  .users-index__types-section {
    grid-column: span 1;
  }
}
